Error code 400 on actions.order.create() using javascript sdk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have this code on my page:
<script type="text/javascript">paypal.Buttons({ createOrder: function(data, actions) { return actions.order.create({ purchase_units: [{ items: [ { name: 'Conan Exiles - 15 slots', unit_amount: { value: '15.73', currency_code: 'USD' }, quantity: '1', } ], amount: { value: '15.73', breakdown: { item_total: { value: '15.73'} }, } }] }); }, onApprove: function(data, actions) { return actions.order.capture().then(function(details) { alert('Transaction completed by ' + details.payer.name.given_name); }); }, onError: function(err) { alert("ERROR: " + err.errorMessage); } }).render('#paypalbtn');</script>
The button shows up, but I get the error code 400. Upon checking this with reference docs, it indicates a malformed/syntatically bad request. I've checked the code against a JavaScript code validator, and it shows that the syntax is valid.
Any suggestions would be appreciated. (PS: Doing this in sandbox mode)
- Labels:
-
Carts
-
PayPal HTML Buttons
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(1) You may need "intent" (not sure). (2) I am using try, catch, finally blocks for error capture (for me, Opera barked at your OnError section) (3) all of the examples I see (I am new to some of this) have the value pairs in double quotes like this (see enclosed example), but in general my dev environment allows use of either single or double quotes.
return actions.order.create({
"intent": "CAPTURE",
"purchase_units": [{
"items": [
{
"name": "Get Running - TechCrystals Code Package (Base) - v1.1",
"quantity": "1",
"sku": "GRTCPBLF",
"unit_amount": {
"currency_code": "USD",
"value": "295.00"
},
"unit_of_measure": "EACH"
},
{
"name": "Add-On 1 - Get Running - TechCrystals Code Package - v1.1",
"quantity": "1",
"sku": "GRTCP1LF",
"unit_amount": {
"currency_code": "USD",
"value": "195.00"
},
"unit_of_measure": "EACH"
}
],
"amount": {
"currency_code": "USD",
"value": "490.00",
"breakdown": {
"item_total": {
"currency_code": "USD",
"value": "490.00"
}
}
}
}]
});

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
- 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
- Disable shipping address in Pay with Credit or Debit card button integration in SDKs