1

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"}

Peter
  • 1,860
  • 2
  • 18
  • 47
  • Discussed, and possibly answered, here: https://stackoverflow.com/q/3308898/1531971 –  Aug 29 '17 at 15:13
  • @jdv i was able to loop through it using paypal pay now button, but i don't want to use that as the values can be change by inspecting element – Peter Aug 29 '17 at 15:17
  • You should put details about what you want to do, what you have tried, and what the results were in the body of the question. –  Aug 29 '17 at 15:20
  • Basically, you need to show that you have exhausted all the other resources that come up with a simple web search for your problem. –  Aug 29 '17 at 15:22
  • @jdv please i only want to loop through everything in my cart then pass them by array to ItemList – Peter Aug 29 '17 at 15:26
  • No one wants to debug your code. You haven't shared why your approach is not working. "I have been trying..." Well, what isn't working? https://stackoverflow.com/help/how-to-ask –  Aug 29 '17 at 15:27
  • @jdv i just updated my question now, you can see the error am getting from what i have tried. When i check `ver_export($item)` i got this some data in the array – Peter Aug 29 '17 at 16:34

0 Answers0