Set up a subscription with PayPal
A Checkout Session represents the details of your customer’s intent to purchase. You create a Session when your customer wants to start a subscription. After redirecting your customer to a Checkout Session, Stripe presents a payment form where your customer can complete their purchase. Once your customer has completed a purchase, they will be redirected back to your site.
Caution
To start accepting PayPal subscriptions on Stripe, you need to enable PayPal recurring payments from the Dashboard.
Set up StripeServer-side
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
Create recurring products and prices
Caution
The Prices API unifies how one-time purchases and subscriptions are modeled on Stripe. Existing integrations that don’t use the Prices API are still supported. However, some Checkout features only support Prices. See the migration guide to upgrade to the Prices API.
To use Checkout, you first need to create a Product and a Price. Different physical goods or levels of service should be represented by products. Each product’s pricing is represented by one or more prices.
For example, you can create a software product that has four prices: 10 USD/month, 100 USD/year, 9 eur/month, and 90 eur/year. This allows you to change and add prices without needing to change the details of your underlying products. You can either create a product and price through the API or through the Stripe Dashboard.
If your price is determined at checkout (for example, the customer sets a donation amount) or you prefer not to create prices upfront, you can create prices inline at Checkout Session creation.
Create a Checkout SessionClient-sideServer-side
Add a checkout button to your website that calls a server-side endpoint to create a Checkout Session.
<html> <head> <title>Checkout</title> </head> <body> <form action="/create-checkout-session" method="POST"> <button type="submit">Checkout</button> </form> </body> </html>
Create a Session with the ID of an existing Price. Ensure that mode is set to subscription
and you pass at least one recurring price. You can add one-time prices in addition to recurring prices. After creating the Checkout Session, redirect your customer to the URL returned in the response.
When your customer successfully completes their payment, they are redirected to the success_url
, a page on your website that informs the customer that their payment was successful. Make the Session ID available on your success page by including the {CHECKOUT_SESSION_ID}
template variable in the success_url
as in the above example.
When your customer clicks on your logo in a Checkout Session without completing a payment, Checkout redirects them back to your website by navigating to the cancel_url
. Typically, this is the page on your website that the customer viewed prior to redirecting to Checkout.
Checkout Sessions expire 24 hours after creation.
Caution
Don’t rely on the redirect to the success_url
alone for detecting payment initiation, as:
- Malicious users could directly access the
success_url
without paying and gain access to your goods or services. - Customers may not always reach the
success_url
after a successful payment—they might close their browser tab before the redirect occurs.
Confirm the payment is successful
Note
When a buyer successfully confirms a subscription on Stripe with PayPal, they receive a receipt from Stripe as well as from PayPal.
When your customer completes a payment, they’re redirected to the URL that you specified as the success_url
. This is typically a page on your website that informs your customer that their payment was successful.
Use the Dashboard, a custom webhook, or a third-party plugin to handle post-payment events like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
You can use plugins like Zapier to automate updating your purchase fulfillment systems with information from Stripe payments.
Some examples of automation supported by plugins include:
- Updating spreadsheets used for order tracking in response to successful payments
- Updating inventory management systems in response to successful payments
- Triggering notifications to internal customer service teams using email or chat applications
Test the integration
Test your PayPal integration with your test API keys by viewing the redirect page. You can test the successful payment case by authenticating the payment on the redirect page. The PaymentIntent will transition from requires_action
to succeeded
.
To test the case where the user fails to authenticate, use your test API keys and view the redirect page. On the redirect page, click Fail test payment. The PaymentIntent will transition from requires_action
to requires_payment_method
.