添加多个产品到paypal快速结账

时间:2013-09-07 15:09:06

标签: api paypal integration checkout

我花了几个小时试图列出到paypal快速结账多个产品。必须这样做是为了增加客户对他们所购买产品的信任。

我如何创建波纹管阵列以便通过贝宝作为多个产品进行重新调整?

1个产品的列表不是问题。这是代码:

$requestParams = array(
       'RETURNURL' => '***',
       'CANCELURL' => '***'
    );

    $item = array('L_PAYMENTREQUEST_0_NAME0' => 'Test product ',
                  'L_PAYMENTREQUEST_0_DESC0' => 'Description of my item',
                  'L_PAYMENTREQUEST_0_AMT0' => '0.01',
                  'L_PAYMENTREQUEST_0_QTY0' => '1'
                 );

    $orderParams = array(
       'PAYMENTREQUEST_0_AMT' => '0.01',
       'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
       'PAYMENTREQUEST_0_ITEMAMT' => '0.01',
       'PAYMENTREQUEST_0_SHIPPINGAMT' => '0'
    );


$response = $core->paypal->request('SetExpressCheckout',$requestParams + $item + $orderParams);

我尝试过很多组合,例如在$ item数组中添加键和值,以便添加更多要列出的产品:

我还尝试以类似的方式添加$ orderParams数组的键,但没有成功。 要么我从paypal api得到错误,要么paypal只列出第一个产品。

$item = array('L_PAYMENTREQUEST_0_NAME0' => 'Test product ',
              'L_PAYMENTREQUEST_0_DESC0' => 'Description of my item',
              'L_PAYMENTREQUEST_0_AMT0' => '0.01',
              'L_PAYMENTREQUEST_0_QTY0' => '1',

              'L_PAYMENTREQUEST_1_NAME1' => 'Test product 1',
              'L_PAYMENTREQUEST_1_DESC1' => 'Description of my next item',
              'L_PAYMENTREQUEST_1_AMT1' => '0.01',
              'L_PAYMENTREQUEST_1_QTY1' => '1'
             );

这是我的第一次集成,我理解paypal流程,但我无法解决这个问题。 感谢。

1 个答案:

答案 0 :(得分:6)

好的,这是一个简单的伎俩。对于那些可能需要它的人:

L_PAYMENTREQUEST_n_NAMEm - " n"是交易次数,0是1次单笔交易 - " m"是产品的编号

$item = array('L_PAYMENTREQUEST_0_NAME0' => 'Test product ', //title of the first product
                  'L_PAYMENTREQUEST_0_DESC0' => 'Description of my item', //description of the forst product
                  'L_PAYMENTREQUEST_0_AMT0' => '0.01', //amount first product
                  'L_PAYMENTREQUEST_0_QTY0' => '1', //qty first product

                  'L_PAYMENTREQUEST_0_NAME1' => 'Test ', // title of the second product
                  'L_PAYMENTREQUEST_0_DESC1' => 'Description item',//description of the second product
                  'L_PAYMENTREQUEST_0_AMT1' => '0.01',//amount second product
                  'L_PAYMENTREQUEST_0_QTY1' => '1'//qty second product
                 );

    $orderParams = array(
       'PAYMENTREQUEST_0_PAYMENTACTION'=>'Sale', //becouse we want to sale something
       'PAYMENTREQUEST_0_AMT' => '0.02', //total amount (items amount+shipping..etc)
       'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD', //curency code
       'PAYMENTREQUEST_0_ITEMAMT' => '0.02', //total amount items, without shipping and other taxes
       'PAYMENTREQUEST_0_SHIPPINGAMT' => '0' //the shipping amount, will be 0 coz we sell digital products
    );

上面你可以看到两个产品的例子。 这些键和值将被发送到express checkout api以便传递令牌。 这些变量将与GET一起发送。