Items array not being sent via the API?
Morphosis
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Mar-13-2021
07:28 AM
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 🙂
0 REPLIES 0
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- IPN works in sandbox but not live in Sandbox Environment
- Shipping options are not appearing in my cart through link or button. in PayPal Payments Standard
- User is asked for shipping address when creating a credit card order in REST APIs
- My webhook stopped working 2 weeks ago in REST APIs
- Cart dropps items, fails to return customer to previous window in PayPal Payments Standard