I am creating a customer PayPal Class. The current flow is the user orders, clicks paypal, and approves the price. Once approved, we collect the delivery address from PayPal, and get a shipping price. We then update the order with the delivery price and updated Vat and Total Order Value.
This is the error I keep getting:
{"name":"UNPROCESSABLE_ENTITY","details":[{"field":"path","value":"/purchase_units/@reference_id=="default"/amount","location":"body","issue":"INVALID_JSON_POINTER_FORMAT","description":"Path should be a valid JSON Pointer https://tools.ietf.org/html/rfc6901 that references a location within the request where the operation is performed."}],"message":"The requested action could not be performed, semantically incorrect, or failed business validation.","debug_id":"c*******d","links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_JSON_POINTER_FORMAT","rel":"information_link","method":"GET"}]}
This is the template for the order:
$order = ['intent' => 'CAPTURE','application_context' => ['return_url' => BASE_URL . 'shoppingcart/view_papa_cart.php?pp=ret', // Replace with your return URL'cancel_url' => BASE_URL . 'shoppingcart/view_cart_update.php?pp=can', // Replace with your cancel URL ],'purchase_units' => [ ['description' => 'Order', // Update as needed'amount' => ['currency_code' => $_COOKIE['PriceNameCookie'], // Update based on your currency'value' => '0', // The total will be calculated in the loop below'breakdown' => ['item_total' => ['currency_code' => $_COOKIE['PriceNameCookie'], // Update based on your currency'value' => '0', // The total will be calculated in the loop below ],'shipping' => ['currency_code' => $_COOKIE['PriceNameCookie'],'value' => '0' // Initial value for shipping ],'tax_total' => ['currency_code' => $_COOKIE['PriceNameCookie'],'value' => '0' // Initial value for tax (VAT) ] ], ],'items' => [], ] ], ];
This is the patch code I want to update:
$patchData = [ ['op' => 'replace','path' => '/purchase_units/@reference_id=="default"/amount','value' => ['value' => number_format($newTotal, 2, '.', '') ],'breakdown' => ['item_total' => ['currency_code' => $_COOKIE['PriceNameCookie'],'value' => number_format($itemTotal, 2, '.', '') ],'shipping' => ['currency_code' => $_COOKIE['PriceNameCookie'],'value' => number_format($deliveryPrice, 2, '.', '') ],'tax_total' => ['currency_code' => $_COOKIE['PriceNameCookie'],'value' => number_format($vatAmount, 2, '.', '') ] ] ] ];
Based on the error, it is this part which is causing the issue:
'op' => 'replace','path' => '/purchase_units/@reference_id=="default"/amount','value' => ['value' => number_format($newTotal, 2, '.', '') ],
I have spend some time trying to figure it out but I can not get the code working properly. I did have a lot of errors but now it's just this one. Could someone please help and point me in the right direction.