Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Product name too long causes payment to fail #332

Open
mbenoukaiss opened this issue Jan 21, 2025 · 0 comments
Open

[Bug] Product name too long causes payment to fail #332

mbenoukaiss opened this issue Jan 21, 2025 · 0 comments
Labels

Comments

@mbenoukaiss
Copy link

mbenoukaiss commented Jan 21, 2025

SyliusPayPalPlugin version affected: ^1.6 potentially *

Description
When the name of a product is too long and exceeds the length allowed by paypal, the request sent to paypal in Sylius\PayPalPlugin\Api\CreateOrderApi which is called by Sylius\PayPalPlugin\Payum\Action\CaptureAction fails and the error is not handled in any way which causes the request to fail with a cryptic error in CaptureAction line 58 when trying to access offset status on $content with Warning: Undefined array key "status" (and Warning: Undefined array key "paypal_order_id" in some cases).

Part of the error returned by PayPal :

{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","d
ebug_id":"XXXXXX","details":[{"field":"\/purchase_units\/@reference_id==XXXXXX'\/items\/1\/name","value":"thewaytoolongname","location":"body","issue":"INVALI
D_STRING_LENGTH","description":"The value of a field is either too short or too long."},{"field":"\/purchase_units\/@reference_id=='XXXXXX'\/items\/0\/name","value":"thewaytoolongname","location":"body","issue":"INVALID_STRING_LENGTH","description":"The value of a field is either too short or too long."}]

When trying to pay, the PayPal pop-up will open and close instantly with the error Expected an order id to be passed in console because the request to PayPal failed

Steps to reproduce

  • Create a product with a long name
  • Add the product to your cart
  • Try to checkout and pay with PayPal

Possible Solution

  • Truncate the name before sending it to PayPal (which length ?)
  • Make sure the data returned by PayPal is somewhat valid and throw an exception if need be in order to simplify debugging of similar potential future bugs

Temporary fix
Should probably not have such long product names in the first place, so truncate them, but just in case or if there is a legitimate reason to have long product names : if your project uses cweagans/composer-patches, add the following patch to your project :

diff --git a/vendor/sylius/paypal-plugin/src/Provider/PayPalItemDataProvider.php b/vendor/sylius/paypal-plugin/src/Provider/PayPalItemDataProvider.php
index 4b1d4dc95..dd2f6998d 100644
--- a/vendor/sylius/paypal-plugin/src/Provider/PayPalItemDataProvider.php
+++ b/vendor/sylius/paypal-plugin/src/Provider/PayPalItemDataProvider.php
@@ -47,7 +47,7 @@ final class PayPalItemDataProvider implements PayPalItemDataProviderInterface
                 $itemData['total_tax'] += ($nonNeutralTax * $displayQuantity) / 100;
 
                 $itemData['items'][] = [
-                    'name' => $orderItem->getProductName(),
+                    'name' => mb_substr($orderItem->getProductName(), 64),
                     'unit_amount' => [
                         'value' => number_format($itemValue / 100, 2, '.', ''),
                         'currency_code' => $order->getCurrencyCode(),

64 is arbitrary I did not check PayPal docs

@mbenoukaiss mbenoukaiss changed the title [Bug] [Bug] Product name too long causes payment to fail Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant