I try to implement a paypal express checkout flow to a website.
The user must be able to adjust the order after they have logged in with paypal and choosed their payment option.
To do so, I create the order with paypal with the intent “AUTHORIZE” and user action “CONTINUE”. It is created, the user is sent back to our website and I can fetch order and payer information with the (order) id created.
But then, when the payer is done checking and adjusting some final parameters and clicks the “buy now” button, I want to send the update order call as referenced here:
https://developer.paypal.com/api/orders/v2/#orders_patch
I create the payload in exactly the same way as for order creation, but this time with intent “CAPTURE” and user_action=”PAY_NOW”. I PATCH it to the correct path, but I keep getting the failure message “MALFORMED_REQUEST_JSON” .
Hoewever, the JSON itself is a valid JSON, no errors thrown in creation. Here is a sample:
{
intent: "CAPTURE",
application_context: {
landing_page: "NO_PREFERENCE",
shipping_preference: "SET_PROVIDED_ADDRESS",
user_action: "PAY_NOW",
},
purchase_units: [{
reference_id: "2289256",
description: "Your Order with us",
custom_id: "OrderId 2289256",
soft_descriptor: "Name of the site",
invoice_id: "2289256",
amount: {
currency_code: "EUR",
value: 59.98,
breakdown: {
item_total: {
currency_code: "EUR",
value: 50.41,
},
shipping: {
currency_code: "EUR",
value: 0,
},
discount: {
currency_code: "EUR",
value: 0,
},
tax_total: {
currency_code: "EUR",
value: 9.57,
},
},
},
items: [{
name: "Product 1",
description: "Product 1 description",
sku: "1019879",
unit_amount: {
currency_code: "EUR",
value: 16.8,
},
tax: {
currency_code: "EUR",
value: 3.19,
},
quantity: "1",
category: "PHYSICAL_GOODS",
}, {
name: "Product 2",
description: "Product 2 description",
sku: "1024593",
unit_amount: {
currency_code: "EUR",
value: 33.61,
},
tax: {
currency_code: "EUR",
value: 6.38,
},
quantity: "1",
category: "PHYSICAL_GOODS",
}, ],
shipping: {
name: {
full_name: "John Doe"
},
address: {
address_line_1: "Badensche Str. 24",
address_line_2: " ",
admin_area_2: "Berlin(Berlin)",
postal_code: "10715",
country_code: "DE",
},
},
}],
}
Here is paypal´s response
{
name: "INVALID_REQUEST",
message: "Request is not well-formed, syntactically incorrect, or violates schema.",
debug_id: "c315ce9eb90b4",
details: [{
field: "/",
location: "body",
issue: "MALFORMED_REQUEST_JSON",
description: "The request JSON is not well formed.",
}],
links: [{
href: "https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON",
rel: "information_link",
encType: "application/json",
}],
}
I just cannot figure out the problem. I tried to remove the whole application_context, purchase_units, intent and see if there is a problem within any of these parameters. Nothing changed. What exactly is wrong with this call?