Pergunta

For a few hours i'm trying to list into paypal express checkout multiple products. This has to be done in order to increase the customers trust for what they buy.

How i can create the bellow array in order to be reconized by paypal as multiple products?

Listing of 1 product is not a problem. Here is the code:

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

I have tried lots of combinations like adding keys and values into $item array like that in order to add more products to be listed:

I tried also to add in a similar way keys to $orderParams array but without success. Either i got errors from paypal api, either the paypal listed only the first product.

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

This is my first integration, i understand the paypal flow but i can't go over this. Thanks.

Foi útil?

Solução

Ok, it was a simple trick to do. For those who might need it:

L_PAYMENTREQUEST_n_NAMEm - "n" is the number of transaction, 0 for 1 single transaction - "m" is the number of the product

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

Above you can see an example for two products. These keys and values will be send to express checkout api in order to deliver the token. The vars will be sent with GET.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top