422 error on '/v2/checkout/orders' POST

Created on 4 May 2020, over 4 years ago
Updated 13 April 2023, over 1 year ago

Hello;

Using Drupal 8.8.5, both Commerce and this module on dev version and a Paypal payment gateway on Live, with correct credentials that has been working for months.

Today, a customer notified that he couldntt use the paypal buttons. I digged into the issue and found that we were receiving a 422 error after
return $this->client->post('/v2/checkout/orders', ['json' => $event->getRequestBody()]); was called on web/modules/contrib/commerce_paypal/src/CheckoutSdk.php::createOrder()

The message I am receiving back is this one. Sadly, it's truncated:

"Client error: `POST https://api.paypal.com/v2/checkout/orders` resulted in a `422 Unprocessable Entity` response:
{"name":"UNPROCESSABLE_ENTITY","details":[{"field":"/purchase_units/@reference_id=='default'/payee","location":"body","i (truncated...)
"

Nevertheless, I checked the request body being sent from there and the info seems to be all correct.

This is the result of running JSON::encode() on $event->getRequestBody(). I checked Paypal's API reference and it seems to be OK.

{
   "intent":"CAPTURE",
   "purchase_units":[
      {
         "reference_id":"default",
         "custom_id":"599",
         "invoice_id":"599-1588613509",
         "amount":{
            "currency_code":"EUR",
            "value":"6",
            "breakdown":{
               "item_total":{
                  "currency_code":"EUR",
                  "value":"6"
               }
            }
         },
         "items":[
            {
               "name":"MY PRODUCT NAME",
               "unit_amount":{
                  "currency_code":"EUR",
                  "value":"6"
               },
               "quantity":1
            }
         ]
      }
   ],
   "application_context":{
      "brand_name":"MY STORE",
      "shipping_preference":"NO_SHIPPING"
   },
   "payer":{
      "email_address":"asddsafdasffads@as.es",
      "address":{
         "address_line_1":"asdf",
         "address_line_2":"dsaf",
         "admin_area_2":"Madrid",
         "admin_area_1":"Madrid",
         "postal_code":"28045",
         "country_code":"ES"
      },
      "name":{
         "given_name":"asdf",
         "surname":"asdf"
      }
   }
}

Am I missing something? Is this happening to somebody else?

🐛 Bug report
Status

Active

Version

1.0

Component

PayPal Checkout

Created by

🇪🇸Spain idiaz.roncero Madrid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024