使用paypal api的多个产品的paypal订阅

时间:2015-08-12 06:43:29

标签: php paypal

我正在尝试Paypal订阅,但我没有获得任何与多个产品相关的演示或sdk相关Paypal订阅。它只允许我在一次只插入一个产品信息。

所以很遗憾,我必须将所有信息和价格合并到一个产品中。 关于这个问题有没有解决方案?

1 个答案:

答案 0 :(得分:0)

this网站上,您可以找到一个非常好的REST API。

以下是如何制作多个项目的示例:

<?php

$paypal = new DPayPal(); //Create an object
$requestParams = array(
    'RETURNURL' => "http://yourwebsite.com", //Enter your webiste URL here
    'CANCELURL' => "http://yourwebsite.com/payment/cancelled"//URL where user will be redirected if he/she cancel the payment
);


$item = array(

    //Total order amount and currency    
    'PAYMENTREQUEST_0_AMT' => "155",//This has to be equal to sum of all items
    'PAYMENTREQUEST_0_CURRENCYCODE' => 'GBP',
    'PAYMENTREQUEST_0_ITEMAMT' => "155",//This has to be equal to sum of all items


    //Item 1

    'L_PAYMENTREQUEST_0_NAME0' => 'Item 1',
    'L_PAYMENTREQUEST_0_DESC0' => 'Item 1 description',
    'L_PAYMENTREQUEST_0_AMT0' => "55",
    'L_PAYMENTREQUEST_0_QTY0' => '1',

    //Item 2
    'L_PAYMENTREQUEST_0_NAME1' => 'Item 2',
    'L_PAYMENTREQUEST_0_DESC1' => 'Item 2 description',
    'L_PAYMENTREQUEST_0_AMT1' => "100",
    'L_PAYMENTREQUEST_0_QTY1' => '1',
);

//Call SetExpressCheckout
$response = $paypal->SetExpressCheckout($requestParams + $orderParams + $item);

if (is_array($response) && $response['ACK'] == 'Success') { //Request successful
    //Now we have to redirect user to the PayPal
    $token = $response['TOKEN'];

    header('Location: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . urlencode($token));
} else if (is_array($response) && $response['ACK'] == 'Failure') {
    echo "Error";
    exit;
}