Search code examples
paypal

How to Format Paypal Update Request to Update Order Amounts


I have tried several different ways to update the total, tax, and shipping values on an order, but haven't had any success yet. Most recently, PayPal support told me to send the following data:

            'json' => [
                'intent' => 'replace',
                'purchase_units' => [
                    [
                        'amount' => [
                            'currency_code' => 'USD',
                            'value' => totalFormatter($order->grand_total),
                            'breakdown' => [
                                'tax_total' => [
                                    'currency_code' => 'USD',
                                    'value' => totalFormatter($order->tax_total),
                                ],
                                'shipping' => [
                                    'currency_code' => 'USD',
                                    'value' => totalFormatter($order->shipping_total),
                                ],
                            ],
                        ],
                    ],
                ],
            ],

But I get an error:

    {
      "description": "The request JSON is not well formed.",
      "field": "/",
      "issue": "MALFORMED_REQUEST_JSON",
      "location": "body"
    }

When I look at the documentation (https://developer.paypal.com/docs/api/orders/v2/#orders_patch) it shows a completely different format:

[
  {
    "op": "replace",
    "path": "/purchase_units/@reference_id=='PUHF'/amount",
    "value": {
      'currency_code' => 'USD',
      'value' => totalFormatter($order->grand_total),
      'breakdown' => [
          'tax_total' => [
              'currency_code' => 'USD',
              'value' => totalFormatter($order->tax_total),
          ],
          'shipping' => [
              'currency_code' => 'USD',
              'value' => totalFormatter($order->shipping_total),
          ],
      ],
    }
  }
]

However, I don't understand the @reference_id =='PUHF' and if I am supposed to replace that with something?


Solution

  • For v2/checkout/orders, use the "Update Order" http PATCH method with op:replace for changes.

    There is no replace intent, that appears to be nonsense.

    The default reference_id of a purchase_unit is default. This is basically only useful when there is more than one purchase_unit, which is uncommon. If you haven't specified a reference_id during creation, use 'default' in the patch.