PayPal: Recurring payments profile not created in Live
P粉306523969
P粉306523969 2023-09-13 08:53:03
0
1
449

I am working with PayPal NVP to create a subscription based service on my website, I will accept payments through PayPal and the payment type will be recurring payments.

I'm using the following PayPal method:

//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']
                );

Here are my PayPal functions:

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;
    }

I send the nvp data to PayPal like this:

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

Now the problem is, everything seems to be working fine on the Sandbox, but in Live the recurring account is not created on my main PayPal account.

Did I miss anything? In addition, I don’t know if I need to install NVP SDK or something.

Additionally, in the sandbox, when I run print_r() on the response from GetRecurringPaymentsProfileDetails, PROFILESTARTDATE and NEXTPAYMENTDATE< /code> Are the same. Is this the problem?

Thank you all for taking the time.

P粉306523969
P粉306523969

reply all(1)
P粉986028039

Don't use the old NVP API.

Current PayPal subscription integrations are documented here.

To save time, you can generate a button in your account's GUI:

But everything can be managed via API, see the first documentation and its API reference.


Using the client ID that is creating the subscription, subscribe to the webhook event PAYMENT.SALE.COMPLETED to get notifications about the initial subscription as well as all future payments.

If you need other metadata to track, such as the user/profile corresponding to the subscription, please add custom_id

in the createSubscription object
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!