Help Article

How do I integrate the PayPal REST API for Recurring Payments?

Here's how:
  1. Create a billing plan.
  2. Activate the billing plan.
  3. Create a billing agreement.
  4. Execute the billing agreement.
Use cURL to set up these plans. Before you begin, check your REST API apps settings to make sure your REST API apps subscriptions are turned on.
 

Create a billing plan

The following example shows how to define parameters for your billing plan:
 
curl -k -v -H 
“Content-Type:application/json” 
-H “Authorization: Bearer ACCESS_TOKEN” 
-d '{“name”:”Test REST Club Plan”,
“description”:”Template creation.”,
“type”:”fixed”,
“payment_definitions”:[{“name”:”Regular Payments”,
“type”:”REGULAR”,
“frequency”:”MONTH”,
“frequency_interval”:”2”,
“amount”:{“value”:”100”,
“currency”:”USD”},
“cycles”:”12”,
“charge_models”:[{“type”:”SHIPPING”,
“amount”:{“value”:”10”,
“currency”:”USD”}},
{“type”:”TAX”,
“amount”:{“value”:”12”,
“currency”:”USD”}}]}],
“merchant_preferences”:{“setup_fee”:{“value”:”1”,
“currency”:”USD”},
“return_url”:”http://returnurl”,
“cancel_url”:”http://cancelurl”,
“auto_bill_amount”:”YES”,
“initial_fail_amount_action”:”CONTINUE”,
“max_fail_attempts”:”0”}}' https://api.sandbox.paypal.com/v1/payments/billing-plans 

PayPal returns a Billing Plan ID starting with “P-”.

Activate the billing plan

Next, use these commands to activate the billing plan:
 
curl -k -v -H 
“Content-Type:application/json” 
-H “Authorization: Bearer ACCESS_TOKEN” 
-d '[{“path”:”/”,
“value”:{“state”:”ACTIVE”},
“op”:”replace”}]' https://api.sandbox.paypal.com/v1/payments/billing-plans/

Create a billing agreement

Now, define parameters for your billing agreement, as shown here:
 
curl -k -v -H 
“Content-Type:application/json” 
-H “Authorization: Bearer ACCESS_TOKEN” 
-d '{“name”:”Test REST Club Plan”,
“description”:”Template creation.”,
“start_date”:”2015-03-20T07:49:27-07:00”,
“plan”:{“id”:”PLAN_ID_HERE”},
“payer”:{“payment_method”:”paypal”},
“shipping_address”:{“line1”:”111 First Street”,
“city”:”Saratoga”,
“state”:”CA”,
“postal_code”:”95070”,
“country_code”:”US”}}' https://api.sandbox.paypal.com/v1/payments/billing-agreements
PayPal returns an Express Checkout redirect URL with an EC token, similar to this one:

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-xxxxxxxxxxxxxxxxx

You’ll need to redirect your customer to PayPal via the returned URL. Once the billing agreement is authorized, the customer is redirected to your site, which is the return_url you set under Create billing plan.

Execute the billing agreement

The following commands activate the billing agreement:
 
curl -k -v -H 
“Content-Type:application/json” 
-H “Authorization: Bearer ACCESS_TOKEN” 
-d '{}' https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-TOKEN_HERE/agreement-execute
We’re sorry. The page you’re looking for is no longer available. To search again or contact us, please visit our Help Centre.