Am using PayPal SDK Api to accept payment, it worked very fine when i tried in a single item for credit card payment or paypal payment. But now when the items to pay for are more than 1 it couldn't process, i have been trying to loop the items in shopping cart to create ItemList
please can anyone help me on how i can loop my items.
<?php
if (isset($_POST['CheckOutByCreditCard'], $_POST['cardNumber'])) {
$conn->prepare('SELECT * cart WHERE client = :clien AND product = :product');
$conn->bind(':client', $client);
$conn->bind(':product', $checkoutEventId);
$conn->execute();
$loadCart = $conn->getAll();
$conn->free();
$x = 1;
$priceAll = $total = 0;
$shipping = 2.00;
if(!empty($loadCart)){
foreach($loadCart as $row){
$total += Event2uCurrencyRate($row->product_price * $row->ord_quantity + $shipping, 'NGN', 'USD', 1);
$price = Event2uCurrencyRate($row->product_price, 'NGN', 'USD', 1);
$priceAll += Event2uCurrencyRate($row->product_price, 'NGN', 'USD', 1);
//Set items loop through items in cart
//My problem is from this side and $itemList = new ItemList();
$item[$x] = new Item();
$item[$x]->setName($row->product_name)
->setDescription('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity($row->ord_quantity)
->setTax(0)
->setPrice($price);
$x++;
}
}
$itemList = new ItemList();
$itemList->setItems([$item]); // if by doing this manually $itemList->setItems([$item1, $item2, $item3]);
}
Using above code am getting this error
{"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].item_list.items[0].quantity","issue":""},{"field":"transactions[0].item_list.items[0].currency","issue":"Required field is missing."},{"field":"transactions[0].item_list.items[0].2","issue":"Field name is not defined for this resource type."},{"field":"transactions[0].item_list.items[0].1","issue":"Field name is not defined for this resource type."},{"field":"transactions[0].item_list.items[0].price","issue":"Required field is missing."},{"field":"transactions[0].item_list.items[0].name","issue":"Required field is missing."}],"message":"Invalid request. See details.","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"30b10b0b8076b"}