bbullis
bbullis

Reputation: 532

PayPal Order Summary Using REST API - - cURL or PHP

I am working with the PayPal RESTful API. https://developer.paypal.com/webapps/developer/docs/api/

How can I pass my consumers order items and purchase description to PayPal, so when my user is redirected to PayPal to approve the order by logging in, their order summary will show up on the left. .

.

ORDER SUMMARY ON THE LEFT paypal empty order summary

I have tried to passing in the transactions.item_list.items but that information isn't showing up in the order summary still.

Any help how to get an order summary to appear on the paypal approval page using the PayPal RESTful API?

I haven't been to pleased with their documentation as it is lacking some information and also has a few mistakes which wasted decent amount of my time to debug.

//
// prepare paypal data
$payment = array(
            'intent' => 'sale',
            'redirect_urls' => array(
                'return_url' => $url_success,
                'cancel_url' => $url_cancel,
                ),
            'payer' => array(
                'payment_method' => 'paypal'
                )
          );

//
// prepare basic payment details
$payment['transactions'][0] = array(
                            'amount' => array(
                                'total' => '0.03',
                                'currency' => 'USD',
                                'details' => array(
                                    'subtotal' => '0.02',
                                    'tax' => '0.00',
                                    'shipping' => '0.01'
                                    )
                                ),
                            'description' => 'This is the payment transaction description 1.'
                           );

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

//
//format payment array to pass to cURL
$CURL_POST = json_encode($payment);

Upvotes: 7

Views: 4385

Answers (3)

Jay Patel - PayPal
Jay Patel - PayPal

Reputation: 1489

Try using the sample shown here : http://htmlpreview.github.io/?https://raw.githubusercontent.com/paypal/PayPal-PHP-SDK/master/sample/doc/payments/CreatePaymentUsingPayPal.html

It is a sample that comes along with the PayPal REST API SDK. You can try those samples out yourselves, by following instructions on readme.

This is how it would look like, when you run that sample:

enter image description here

Upvotes: 0

Bryan CS
Bryan CS

Reputation: 611

I experienced the same issue while trying it out today. What I did was add the Items like below.

$item = new Item();
$item->setQuantity($item_quantity);
$item->setName($item_name);
$item->setPrice($item_price);
$item->setCurrency($item_currency);

$item_list = new ItemList();
$item_list->setItems(array($item));

The $item_list is a property of transaction so you should add it after.

$transaction = new Transaction();
$transaction->setItemList($item_list);
....

That should show on the Order summary pane on PayPal page. You can also check the answer here.

Upvotes: 0

Dennis
Dennis

Reputation: 949

your code is good. This is actually a bug that will be fixed very soon. Regarding documentation, can you share how we can make it better? I want to make sure your feedback gets passed to our documentation team.

Upvotes: 1

Related Questions