cancel
Showing results for 
Search instead for 
Did you mean: 

Items array not being sent via the API?

Options
Morphosis
Contributor
Posted on

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 🙂 

Haven't Found your Answer?

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