Error code 400 on actions.order.create() using javascript sdk

game-hub_us
Contributor
Contributor

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)

Login to Me Too
1 REPLY 1

RexS
Contributor
Contributor

(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"
}
}
}

}]
});

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.