New to the community? Welcome! Please read our Community Rules and Guidelines
If you want to report illegal content under the EU Digital Services Act, please do so here
Hi there,
I am struggling through the setup of the new smart payments and javascript. I am trying to add items to the transaction from my website's shopping cart, but I cannot understand why the variable won't work.
// Render the PayPal button into #paypal-button-container
var itemsData = '{name: "Basic Class Fee", unit_amount: {currency_code: "CAD",value: "50.00"},quantity: "1"}';
console.log(itemsData)
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
currency_code: "CAD",
value: "50.00",
breakdown: {
item_total: {
currency_code: "CAD",
value: "50.00"
}}
},
items: [ (itemsData) ]
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
If I replace the itemsData variable with the string itself, the button works fine, however, as soon as I use the variable, the button breaks and returns a 400 error from PayPal.
Thanks for reading