1

I am trying to send item information to paypal using json formatted array in php, but I haven't been able to find any resources to figure out how to do this.

Here is my current json array being passed to paypal with cURL in php:

$dataArray = array(
    "intent" => "sale",
    "redirect_urls" => array(
            "return_url" => $url_success,
            "cancel_url" => $url_cancel
        ),
    "payer" => array(
            "payment_method" => "paypal"
        )
);

$dataArray['transactions'][0] = array(
    'amount' => array(
        'total' => round($sale->GetTotal(), 2, PHP_ROUND_HALF_UP),
        'currency' => $sale->GetCurrency(),
        'details' => array(
            'subtotal' => round($sale->GetSubTotal(), 2, PHP_ROUND_HALF_UP),
            'tax' => round($sale->GetTax(), 2, PHP_ROUND_HALF_UP)
        )
    ),
    'description' => "Test Payment"
);

The above is currently working, but the order summary is blank on paypal. I found the following code to add information on individual items.

// prepare individual items
$dataArray['transactions'][0]['item_list']['items'][] = array(
    'quantity' => '1',
    'name' => 'Womens Large',
    'price' => '0.01',
    'currency' => 'USD',
    'sku' => '31Wf'
);

$dataArray['transactions'][0]['item_list']['items'][] = array(
    'quantity' => '1',
    'name' => 'Womens Medium',
    'price' => '0.01',
    'currency' => 'USD',
    'sku' => '31WfW'
);

This code is not working. This was supposedly working for the person who posted it. I'm not sure why both items appear to be adding the same item to the same location in the array, but this was essentially copy and pasted from that site, with only the array name changed, so I'm sure this is what they had. I've been trying to find the site back that I found this on, but I can't remember how I got there. The site I found this on did not specify what parts of the array were required. I'm sure $dataArray['transactions'] is required, but I don't know about the rest of the identifiers : ([0]['item_list']['items'][]). Can someone give me an example of how to send this info for multiple items? Thank you!

Jason247
  • 974
  • 4
  • 16
  • 38
  • Have you considered using $_POST through an html form? That's a very easy process and there are lots of resources out there – maestro416 Oct 08 '13 at 06:52
  • I've seen others using that method, but I have already done everything else with this method, and prefer to keep it all the same. Thanks though! :) – Jason247 Oct 08 '13 at 16:52

1 Answers1

0

Ok, so apparently I had this correct after all. It turns out my problem was that the price fields for each item didn't add up to the subtotal of the whole transaction. I had random values in there to test it. Apparently it requires the values to match.

Jason247
  • 974
  • 4
  • 16
  • 38