PayPal:未在 Live 中建立定期付款資料
P粉306523969
P粉306523969 2023-09-13 08:53:03
0
1
516

我正在與 PayPal NVP 合作,在我的網站上建立基於訂閱的服務,我將透過 PayPal 接受付款,付款類型將是定期付款。

我正在使用以下 PayPal 方法:

//SetExpressCheckout
    $sec_data = array(
        'USER'                           => PAYPAL_API_USERNAME,
        'PWD'                            => PAYPAL_API_PASSWORD,
        'SIGNATURE'                      => PAYPAL_API_SIGNATURE,
        'VERSION'                        => "95.0",
        'METHOD'                         => "SetExpressCheckout",
        'PAYMENTREQUEST_0_AMT'           => $total_amt,
        'RETURNURL'                      => "<url_structure>",
        'CANCELURL'                      => "<url_structure>",
        'NOSHIPPING'                     => "1",
        'SOLUTIONTYPE'                   => "Sole",
        'LOGOIMG'                        => "<url_structure>",
        'BRANDNAME'                      => "My Website",
        'PAYMENTREQUEST_0_CURRENCYCODE'  => "USD",
        'PAYMENTREQUEST_0_ITEMAMT'       => $current_plan_price,
        'PAYMENTREQUEST_0_PAYMENTACTION' => "Sale",
        'L_PAYMENTREQUEST_0_AMT0'        => $current_plan_price,
        'L_BILLINGTYPE0'                 => "RecurringPayments",
        'L_BILLINGAGREEMENTDESCRIPTION0' => "You'll be billed USD ".$total_amt.".",
        'PAYMENTREQUEST_0_DESC'          => "You'll be billed USD ".$total_amt.".",
        'PAYMENTREQUEST_0_CUSTOM'        => "Thank you for your payment!",
        'PAYMENTREQUEST_0_INVNUM'        => "INV-".$invoice_num,
        'NOTETOBUYER'                    => $current_plan_name,
        'PAYMENTREQUEST_0_PAYMENTREASON' => "None",
        'EMAIL'                          => $email,
        'LANDINGPAGE'                    => "Billing",
        'PAYMENTREQUEST_0_TAXAMT'        => $tax_amt,
        'L_PAYMENTTYPE0'                 => "InstantOnly"
    );

//GetExpressCheckoutDetails
$get_ec_data = array(
        'USER'      => PAYPAL_API_USERNAME,
        'PWD'       => PAYPAL_API_PASSWORD,
        'SIGNATURE' => PAYPAL_API_SIGNATURE,
        'TOKEN'     => $ec_token,
        'METHOD'    => "GetExpressCheckoutDetails",
        'VERSION'   => "95.0"
    );

//DoExpressCheckoutPayment
$decp_data = array(
                'USER'                          => PAYPAL_API_USERNAME,
                'PWD'                           => PAYPAL_API_PASSWORD,
                'SIGNATURE'                     => PAYPAL_API_SIGNATURE,
                'METHOD'                        => "DoExpressCheckoutPayment",
                'TOKEN'                         => $ec_token,
                'PAYERID'                       => $ec_response['PAYERID'],
                'PAYMENTREQUEST_0_AMT'          => $total_amt,
                'PAYMENTREQUEST_0_CURRENCYCODE' => "USD",
                'PAYMENTREQUEST_0_ITEMAMT'      => $total_amt,
                'VERSION'                       => "95.0"
            );

//CreateRecurringPaymentsProfile
$crpp_array = array(
                'USER'               => PAYPAL_API_USERNAME,
                'PWD'                => PAYPAL_API_PASSWORD,
                'SIGNATURE'          => PAYPAL_API_SIGNATURE,
                'VERSION'            => "95.0",
                'METHOD'             => "CreateRecurringPaymentsProfile",
                'TOKEN'              => $ec_token,
                'PROFILESTARTDATE'   => $last_payment_date,
                'DESC'               => "You'll be billed USD ".$total_amt.".",
                'BILLINGPERIOD'      => "Month",
                'BILLINGFREQUENCY'   => "12",
                'TOTALBILLINGCYCLES' => '0',
                'AMT'                => $total_amt,
                'CURRENCYCODE'       => "USD",
                'EMAIL'              => $get_cx_data['cx_email'],
                'STREET'             => "Bedford Ave",
                'CITY'               => "Brooklyn",
                'STATE'              => "New York",
                'COUNTRYCODE'        => "US",
                'ZIP'                => "11211"
            );

//GetRecurringPaymentsProfileDetails
$grppd_array = array(
                    'USER'      => PAYPAL_API_USERNAME,
                    'PWD'       => PAYPAL_API_PASSWORD,
                    'SIGNATURE' => PAYPAL_API_SIGNATURE,
                    'VERSION'   => "95.0",
                    'METHOD'    => 'GetRecurringPaymentsProfileDetails',
                    'PROFILEID' => $get_crpp_response['PROFILEID']
                );

以下是我的 PayPal 功能:

function toPayPal($inputArray, $PayPalURL) {
        $nvp_post_data_str   = '';

        foreach($inputArray as $key => $value) {
            $nvp_post_data_str .= $key.'='.urlencode($value).'&';
        }

        $nvp_post_data_str = substr($nvp_post_data_str, 0, strlen($nvp_post_data_str) - 1);
        $ch = curl_init();
        
        curl_setopt($ch, CURLOPT_URL, $PayPalURL);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp_post_data_str);
        $httpResponse = curl_exec($ch);
        
        //$httpResponse;
        
        $httpResponse = explode('&', $httpResponse);
        
        for($i = 0; $i < count($httpResponse); $i++) {
            $temp_array = explode('=', $httpResponse[$i]);
            $httpResponseArray[$temp_array[0]] = urldecode($temp_array[1]);
        }
        
        return $httpResponseArray;
    }

我將 nvp 資料傳送到 PayPal,如下所示:

toPayPal($nvp_data, "https://api-3t." .(PAYPAL_MODE == 'TEST' ? 'sandbox.paypal' : 'paypal'). ".com/nvp");

現在的問題是,Sandbox 上似乎一切正常,但在 Live 中,我的 PayPal 主帳戶上並未建立定期帳戶。

我有什麼遺漏的嗎?另外,需要安裝NVP SDK什麼的嗎,我也不知道。

此外,在沙箱中,當我在GetRecurringPaymentsProfileDetails 的回應上執行print_r() 時,PROFILESTARTDATENEXTPAYMENTDATE< /code>#是相同的。是這個問題嗎?

感謝大家抽出寶貴的時間。

P粉306523969
P粉306523969

全部回覆(1)
P粉986028039

不要使用舊的 NVP API。

目前的 PayPal 訂閱整合記錄在此。

為了節省時間,您可以在帳戶的 GUI 中產生一個按鈕:

但是一切都可以透過 API 進行管理,請參閱第一個文件及其 API 參考。


使用正在建立訂閱的客戶端 ID,訂閱 Webhook 事件 PAYMENT.SALE.COMPLETED,以取得初始訂閱以及所有未來付款的通知。

如果您需要其他元資料進行跟踪,例如訂閱對應的使用者/個人資料,請在 createSubscription 物件中新增 custom_id##

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板