- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to implement on my webpage the PayPal Checkout (javascript) following the manual: https://developer.paypal.com/docs/checkout/
Everything is great with standard options. But when I try to be more specific about the order details it gives me an error:
"description": "Cannot deserialize instance of `com.paypal.api.platform.checkout.orders.v2.model.AmountBreakdown` out of START_ARRAY token line: 1, column: 82"
"links": [ { "href": "https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_SYNTAX", "rel": "information_link", "encType": "application/json" }
This is my code:
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
currency_code: 'EUR',
value: '120.16',
breakdown: [{
item_total: {
currency_code: 'EUR',
value: '120.16'
}
}]
},
description: 'Purchase Unit test description',
custom_id: '64735',
items: [{
name: 'Test item 1',
unit_amount: {
currency_code: 'EUR',
value: '60.12'
},
quantity: 2,
description: 'Uaua item 1 description'
}, {
name: 'Test item 2',
unit_amount: {
currency_code: 'EUR',
value: '60.00'
},
quantity: 5,
description: 'Test item 2 description'
}]
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
// Call your server to save the transaction
return fetch('/api/paypal-transaction-complete', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
});
});
}
}).render('#paypal-button-container');
Someone told me to remove unit_amount from the breakdown but it does not change anything.
I can not find any more elaborated example how the breakdown should look like 😞
Help will be very appreciated.
Solved! Go to Solution.
- Labels:
-
Payments REST APIs
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
After some digging I have found the answer:
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [
{
reference_id: "PUHF",
description: "Some description",
custom_id: "Something7364",
soft_descriptor: "Great description 1",
amount: {
currency_code: "EUR",
value: "200.00",
breakdown: {
item_total: {
currency_code: "EUR",
value: "200.00"
}
}
},
items: [
{
name: "Item 1",
description: "The best item ever",
sku: "xyz-2654",
unit_amount: {
currency_code: "EUR",
value: "100.00"
},
quantity: "1"
},
{
name: "Item 2",
description: "Not bad too",
sku: "zdc-3942",
unit_amount: {
currency_code: "EUR",
value: "50.00"
},
quantity: "2"
}
],
}
]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
// Call your server to save the transaction
return fetch('/api/paypal-transaction-complete', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
});
});
}
}).render('#paypal-button-container');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
After some digging I have found the answer:
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [
{
reference_id: "PUHF",
description: "Some description",
custom_id: "Something7364",
soft_descriptor: "Great description 1",
amount: {
currency_code: "EUR",
value: "200.00",
breakdown: {
item_total: {
currency_code: "EUR",
value: "200.00"
}
}
},
items: [
{
name: "Item 1",
description: "The best item ever",
sku: "xyz-2654",
unit_amount: {
currency_code: "EUR",
value: "100.00"
},
quantity: "1"
},
{
name: "Item 2",
description: "Not bad too",
sku: "zdc-3942",
unit_amount: {
currency_code: "EUR",
value: "50.00"
},
quantity: "2"
}
],
}
]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
// Call your server to save the transaction
return fetch('/api/paypal-transaction-complete', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
});
});
}
}).render('#paypal-button-container');

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Paypal subscription Api in REST APIs
- Selected Shipping Method amount not updating to cart for card payment in SDKs
- CHECKOUT.ORDER.APPROVED webhook event not triggered if payment_source is passed in in REST APIs
- ExpressCheckout to REST API - Is Partner Program Now Required to Host Simple 3rd Party Transactions? in REST APIs
- Are there any restrictions to charge using only html, vanilla javascript and php with rest api? in REST APIs