2

是否可以在 PayPal 的网站“购物车”中列出所有产品。我问是因为 PayPal 说的是“描述”而不是描述,这比将总数与“你的篮子”的无益描述相结合更好

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

文档含糊不清,或者我可能忽略了这种可能性,但我尝试过:

 $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();

其中数据遵循上述布局。

4

2 回答 2

5

在 Github 上找到了这篇文章,它解释了这是如何实现的。

setItems添加了函数,以便可以像这样传递项目数组:

$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();

注意事项
如果购买金额不等于商品数组的总和,请求将失败。

于 2014-08-18T11:01:46.390 回答
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();
于 2015-05-05T07:28:42.417 回答