cebo
cebo

Reputation: 818

PayPal Orders Create: Status 422, amount mismatch error despite matching values

I am receiving a 422 UNPROCESSABLE_ENTITY error from paypal, indicating that my amount->value and breakdown values don't match up, but as far as I can tell they aren't. The request body is as follows:

"amount": {
  "currency_code": "USD",
  "value": 5,
  "breakdown": {
    "item_total": {
      "value": 10,
      "currency_code": "USD",
      "discount": {
        "value": 5,
        "currency_code": "USD"
      }
    }
  }
}

The error message says about amount->value: Should equal item_total + tax_total + shipping + handling + insurance - shipping_discount - discount.

Since I don't have shipping/handling/insurance/etc, shouldn't it just be 5(amount) = 10(item_total) - 5(discount)? What am I missing here?

Also, just in case it matters, I have just a single item in the purchase unit:

"items": [
  {
    "name": "...",
    "unit_amount": {
      "value": 10,
      "currency_code": "USD"
    },
    "quantity": 1,
    "category": "DIGITAL_GOODS"
  }
]

Upvotes: 1

Views: 1260

Answers (2)

max4ever
max4ever

Reputation: 12140

For PHP that would be :

$request->body = [
        'intent' => 'CAPTURE',
        'purchase_units' => [
            [
                'invoice_id' => 'some-id',
                'amount' => [
                    'value' => 15,
                    'currency_code' => 'EUR',
                    'breakdown' => [
                        'shipping' => [
                            'value' => 5,
                            'currency_code' => 'EUR',
                        ],
                        'item_total' => [
                            'value' => 10,
                            'currency_code' => 'EUR',
                        ]
                    ],
                ],
            ],
        ],
        'application_context' => [
            'cancel_url' => $cancelUrl,
            'return_url' => $returnUrl,
        ],
    ];

Upvotes: -1

Preston PHX
Preston PHX

Reputation: 30432

discount is in the wrong place here:

"breakdown": {
   "item_total": {
     "value": 10,
     "currency_code": "USD",
     "discount": {
       "value": 5,
       "currency_code": "USD"
     }
   }
 }

Move it out of item_total (where it's being ignored as an unknown field), and into the parent breakdown object where it belongs.

Upvotes: 2

Related Questions