Reputation: 4051
I am trying to figure out how to use the paypal API to realize recurring payments. I am following this guide:
https://devtools-paypal.com/guide/recurring_payment_ec?interactive=OFF&env=sandbox
But I don't get it. How can this work. In step 1 payment details are build but are not filled with values like the interval or the value of the payment. Then I get a token and the user has to confirm the payment in step 2.
And after he has confirmed the payment. I set the value and payment in interval in step 3? That does not really makes sense to me. What prevents me to charge any amount I want in step 3?
Upvotes: 2
Views: 411
Reputation: 736
Better late than never?
The key pitfall that I had when I first set up recurring billing is that Recurring Billing is a paid "add-on" service and the Merchant account holder must initialize it on their PayPal account. Currently, the way PayPal throws this error is with their generic RESULT=1
response; however, the message is key. RESPMSG=User authentication failed: Recurring Billing"
almost certainly means that Recurring Billing has not been set up on the Merchant's account.
Once Recurring Billing has been set up on the account, the following steps should work.
'USER' => [[[Payflow User]]],
'VENDOR' => [[[Payflow Vendor]]],
'PARTNER' => [[[Payflow Partner]]],
'PWD' => [[[Payflow Password]]],
'TRXTYPE' => 'A', // to authorize a billing profile
'TENDER' => 'C', // even if the user uses PayPal to pay
'BILLINGTYPE' => 'MerchantInitiatedBilling',
'CURRENCY' => 'USD',
'RETURNURL' => [[[Return URL]]],
'CANCELURL' => [[[Cancel URL]]],
'ERRORURL' => [[[Cancel URL]]],
'BA_DESC' => 'A Fitting Description of the Profile',
'CREATESECURETOKEN' => 'Y',
'SECURETOKENID' => [[[Your generated ID]]],
'AMT' => '5.49' // a string, can not be zero
Notes: BILLINGTYPE
and BA_DESC
help you to create PayPal Billing Agreements. Despite PayPal's zero-auth abilities, you must not use 0.00 as your auth amount.
When the subscriber successfully completes the PayPal payment form, the information is POSTed to your RETURNURL
. Parse and use this POST data and perform one of the following PayPal API calls to create the recurring billing profile.
If the subscriber used PayPal to set up their account, then the POST will include the name/value BAID=########################
. You should create a PayPal billing agreement using the BAID ("billing agreement ID") as a reference:
'USER' => [[[Payflow User]]],
'VENDOR' => [[[Payflow Vendor]]],
'PARTNER' => [[[Payflow Partner]]],
'PWD' => [[[Payflow Password]]],
'TRXTYPE' => 'R', // recurring billing profile
'ACTION' => 'A', // add/create recurring billing profile
'TENDER' => 'P', // PayPal
'PROFILENAME' => 'A name for your subscription',
'BAID' => '##################', // The BAID POSTed from PayPal
'START' => '190721', // a starting date in mdY format
'PAYPERIOD' => 'MONT', // or YEAR or etc, see manual
'TERM' => '0', // # of payments (0 is until subscriber cancels)
'AMT' => '5.49' // same amount as your auth in previous step
If the subscriber used a credit card to set up their account, then the POST will NOT include the name/value BAID
, and you should create the recurring billing profile as a standard recurring credit card profile:
'USER' => [[[Payflow User]]],
'VENDOR' => [[[Payflow Vendor]]],
'PARTNER' => [[[Payflow Partner]]],
'PWD' => [[[Payflow Password]]],
'TRXTYPE' => 'R', // recurring billing profile
'ACTION' => 'A', // add/create recurring billing profile
'TENDER' => 'C', // credit card
'PROFILENAME' => 'A name for your subscription',
'ORIGID' => 'PN##########', // PNREF value POSTed from PayPal
'START' => '190721', // a starting date in mdY format
'PAYPERIOD' => 'MONT', // or YEAR or etc, see manual
'TERM' => '0', // # of payments (0 is until subscriber cancels)
'AMT' => '5.49' // same amount as your auth in previous step
Note that the last related doc that PayPal sent to me was from 2013 and was grossly out-of-date. It contained a cumbersome four-step process which just did not work. Hopefully this has been updated by the time you read this.
Hoping this helps you out. Let me know if you have any questions.
Upvotes: 1