如何使用变量作为定期付款的金额(Paypal API)

时间:2014-03-07 06:26:04

标签: php paypal

我正在使用Paypal API创建订阅系统,其中有两种类型的订阅 每月订阅(5个星期) 全年订阅(50dlls) 我目前有以下代码:

用于设置结帐:

public function do_purchase($type){     

    $this->load->library('paypal');

    $requestParams = array(
       'RETURNURL' => site_url('restaurant/get_purchase_details'),
       'CANCELURL' => site_url('restaurant/afiliaturestaurante')
    );

    $orderParams = array(
       'L_BILLINGTYPE0' => 'RecurringPayments',
       'L_BILLINGAGREEMENTDESCRIPTION0' => 'Monthly',
       'AMT' => 0 
    );


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


    if(is_array($response) && $response['ACK'] == 'Success') { //Request successful
        $token = $response['TOKEN'];
        header( 'Location: https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) );
    }


}

创建经常性Paypal资料:

public function get_purchase_details(){

    if( isset($_GET['token']) && !empty($_GET['token']) ) { // Token parameter exists
       // Get checkout details, including buyer information.
       // We can save it for future reference or cross-check with the data we have

       $this->load->library('paypal');

       $paypal = new Paypal();
       $checkoutDetails = $paypal -> request('GetExpressCheckoutDetails', array('TOKEN' => $_GET['token']));

       // Complete the checkout transaction
       $requestParams = array(
            'TOKEN' => $_GET['token'],
            'PAYERID' => $checkoutDetails['PAYERID'],
            'PROFILESTARTDATE' => '2014-03-7T05:38:48Z',
            'DESC' => 'Monthly',
            'BILLINGPERIOD' => 'Month',
            'BILLINGFREQUENCY' => '1',
            'AMT' => '5',
            'CURRENCYCODE' => 'USD',
            'COUNTRYCODE' => 'US',
            'MAXFAILEDPAYMENTS' => '3',
       );

       $response = $paypal -> request('CreateRecurringPaymentsProfile',$requestParams);


       if( is_array($response) && $response['ACK'] == 'Success') { // Payment successful
           // We'll fetch the transaction ID for internal bookkeeping
           $profileID = $response['PROFILEID'];


       }
    }
}

我需要在get_purchase_details上使用$ type变量来设置配置文件的数量,如何通过Paypal传递变量以便我可以使用其他功能?我正在使用Paypal库来创建cURL请求。

提前致谢

1 个答案:

答案 0 :(得分:0)

您可以在会话变量中设置$ type的值,并且从PayPal返回时可以使用该值。

或者,您可以在SetExpressCheckout的CUSTOM参数中传递$ type值,这样就可以在GetExpressCheckoutDetails响应中返回它。