New to the community? Welcome! Please read our Community Rules and Guidelines
Pay, shop, and do even more on the PayPal appGet the App
Hi People.
This is really stumped me. I have read other threads and i'm still not getting the desired outcome.
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
reference_id: "BBB",
description: "Some description",
custom_id: "7364",
soft_descriptor: "Gdescription",
amount: {
currency_code: "GBP",
value: totalPaypalValue(),
breakdown: {
item_total: {
currency_code: "GBP",
value: totalPaypalValue(),
}
}
},
items: arrayOfItems(),
// items: [{
// name: "Item 1",
// quantity: "1",
// unit_amount: {
// currency_code: "GBP",
// value: "468.30"
// }
// }],
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
});
},
onCancel: function(data) {
alert('Cancelled Transaction');
},
onError: function(err) {
alert('Error with Transaction');
//window.location.href = "/your-error-page-here";
}
}).render('#paypal-button-container');
Then here is the item array function
function arrayOfItems() {
let _basketItems = JSON.parse(localStorage.getItem('<?php echo $cartKey; ?>'));
let items = [];
_basketItems.forEach((cartItem, index) => {
++index;
let currency = cartItem.itemPrice.toFixed(2).toString();
let quantity = cartItem.qty.toString();
let itemName = cartItem.title.toString();
item = {
name: itemName,
quantity: quantity,
unit_amount: {
currency_code: "GBP",
value: currency
}
};
items.push(item);
return items;
});
console.log(items);
}
So i'm not getting any errors and the transactions go through. But the array item is not showing in the API post 'orders' and yet when i uncomment the inline item and test the item get posted?
Any pointers would be great 🙂
©1999-2023 PayPal, Inc. All rights reserved.