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

我正在与 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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板