2

Is it possible to list all products in a sites "cart" on PayPal. I ask because PayPal says "descriptions" instead of description and it would be nicer than having a combined total with a unhelpful description of "your basket"

$request = $gateway->purchase([
            'amount' => '150.00',
            'currency' => 'GBP',
            'description' => 'Your basket',
            'returnUrl' => 'http://localhost:8080/checkout/success',
            'cancelUrl' => 'http://localhost:8080/checkout/cancel'
        ])->send();

The documentation is vague or I may have overlooked the possibility but I've tried:

 $request = $gateway->purchase([
                'amount' => array('100','200'),
                'currency' => 'GBP',
                'description' => array('prod1','prod2'),
                'returnUrl' => 'http://localhost:8080/checkout/success',
                'cancelUrl' => 'http://localhost:8080/checkout/cancel'
            ])->send();

&
$request = $gateway->purchase([data],[data])->send();

where data follows the above layout.

Kiee
  • 10,661
  • 8
  • 31
  • 56

2 Answers2

5

I found this post on Github which explains how this is achievable.

setItems function was added so that an array of items can be passed like so:

$request = $gateway->purchase([
            'amount'=>'70.00',
            'returnUrl' => 'http://localhost:8080/checkout/success',
            'cancelUrl' => 'http://localhost:8080/checkout/cancel'
        ])->setItems(array(
            array('name' => 'item1', 'quantity' => 2, 'price' => '10.00'),
            array('name' => 'item2', 'quantity' => 1, 'price' => '50.00')
        ))->send();

Something to note
The request will fail if the purchase amount does not equal the sum of the array of items.

Kiee
  • 10,661
  • 8
  • 31
  • 56
0
$gateway = Omnipay\Omnipay::create('PayPal_Express');
$gateway->setUsername('....');
$gateway->setPassword('....');
$gateway->setSignature('.....');
$items = new Omnipay\Common\ItemBag();

$items->add(array(
            'name' => 'prova',
            'quantity' => '1',
            'price' => 40.00,
));
$items->add(array(
            'name' => 'prova 2',
            'quantity' => '1',
            'price' => 10.00,
));
$response = $gateway->purchase(
            array(
                'cancelUrl'=>'http://.../pay/',
                'returnUrl'=>'http://.../pay/return_to_site',
                'amount' =>  50.00,
                'currency' => 'EUR'
            )
)->setItems($items)->send();
$response->redirect();
tr1pp0
  • 31
  • 1
  • 6