Integration Guide

circle-exclamation

Note from GitBook: Demo content

Know before you code

1

Create product

To create a product for your subscription plan, copy and modify the following code:

Sample request

API endpoint used: Create productarrow-up-right

Modify the code

After you copy the code in the sample request, modify the following:

  • Change ACCESS-TOKEN to your access token.

  • Replace REQUEST-ID with a unique ID that you generate. This ID helps prevent duplicate requests if the API call is disrupted.

  • Optional: Change parameters such as the name and description to represent your product.

Step result

A successful request results in the following:

  • The HTTP status code 201 Created.

  • A JSON response body that contains an id for the product. Use this ID to complete other actions through the REST API, such as creating a subscription plan.

Sample response

2

Create subscription plan

The following sample request is an example of a subscription plan. Modify the code to fit your subscription model.

Review the following topics to help understand how to modify the code for your use case:

Sample request

This sample request creates a subscription plan that:

  • Has a 1-month free trial and continues as a 12-month, fixed-price subscription

  • Includes a $10 USD setup fee

  • Bills any outstanding balance at the next billing cycle

  • Allows the subscription to continue if the initial payment for the setup fails

  • Suspends the subscription after 3 consecutive payment failures

  • Includes a 10% tax in the billing amount

circle-exclamation

API endpoint used: Create planarrow-up-right

Modify the code

After you copy the code in the sample request, modify the following:

  • Change ACCESS-TOKEN to your access token.

  • Replace REQUEST-ID with a unique ID that you generate. This ID helps prevent duplicate requests if the API call is disrupted.

  • Change the value of the product_id parameter to the ID returned when you created the product.

  • (Optional) Change or add parameters in the Create plan request bodyarrow-up-right to create a plan that meets your business needs. Some examples:

    • Fixed pricing plans

    • User or seat-based pricing plans

    • Free or discounted trials

Step result

A successful request results in the following:

  • The HTTP status code 201 Created.

  • A JSON response body containing an id for the subscription plan. Use the subscription plan ID to complete other actions through the REST API, such as editing or deactivating the plan.

  • A subscription plan in the seller's PayPal account in the On status.

Sample response

To see how this API call looks in the seller's account, use your sandbox business account credentials to log in to https://www.sandbox.paypal.com/billing/plansarrow-up-right. The subscription plan reflects the plan number from the REST API call you made.

3

Create payment button

To start a subscription from your website, add the PayPal JavaScript SDK code and modify it. This code adds buttons to your website so your buyers can use PayPal or a debit or credit card.

Add and modify the code

  1. Copy and paste this code into webpage to create the buttons. When your buyer selects a button, they are directed to PayPal to complete subscription agreement and payment.

  1. Modify the code as follows:

    • Change YOUR_CLIENT_ID to your client ID.

    • Change YOUR_PLAN_ID to the plan ID returned from the Create Plan API call.

  2. Load the webpage to see the payment buttons: PayPal and Debit or Credit Card buttons integrated in a webpage

circle-check
4

Test flow

Test a transaction to see the subscription created in the merchant account:

Test the transaction as a buyer

  1. Select the PayPal button on the page.

  2. Use the sandbox personal login information from the Developer Dashboard to log in and simulate the buyer making a purchase.

  3. In the Checkout window, make a note of the purchase amount in the upper right corner. USD is the default currency. You can customize the JavaScript SDK by adding a different currency codearrow-up-right.

    Availability: The JavaScript SDK onShippingChange, onShippingAddressChange, and onShippingOptionsChange functions are not compatible with Subscriptions.

  4. Select the arrow next to the purchase amount to view the subscription details:The subscription details popup, which shows a breakdown of the subscription cost, when the subscription starts, and the total amount due.

  5. Select the test credit card as the payment method and select Continue.

  6. Select Agree & Subscribe to agree to the terms of the subscription.

Confirm the movement of funds from the buyer account

  1. Use the sandbox personal account you used to complete the purchase to log in to https://www.sandbox.paypal.com/myaccount/autopay/connect/arrow-up-right.

  2. Confirm the subscription appears in the active automatic payment list. Select the active automatic payment to see the details of the subscription.

  3. Log out of the account.

Confirm the movement of funds to the merchant account

  1. Use the sandbox business account information from the Developer Dashboard to log in to https://www.sandbox.paypal.com/billing/subscriptionsarrow-up-right.

  2. Confirm the subscription made by the test buyer appears on the Subscriptions tab. Select the subscription to see the details of the subscription.

  3. Log out of the account.

Next steps

See also

Last updated

Was this helpful?