Stripe
Last updated
Last updated
Offering subscription plans with Stripe is very easy with Ready SaaS because all the hardest parts have been already implemented for you.
You just need to follow a few steps to generate a Stripe API key and send Stripe webhooks to your Django app.
Follow these steps to setup Stripe subscription plans within your Ready SaaS project.
Go to https://stripe.com/ and create an account
Navigate over to the Product Catalog section and create a new product.
name
description
price
type: for subscriptions use the recurring type
To connect Stripe to the Ready SaaS project you need set your Stripe API key
Type "API keys" in the Stripe Search bar and select Developers > API Keys
In that screen you will be able to extract the Secret Key
Now you can add that key as an environment variable in your Ready SaaS project:
For your local instance of Ready SaaS, add it as STRIPE_SECRET_KEY
within your .env
file
For your production instance, add it as an environment variable with the name STRIPE_SECRET_KEY
Navigate to the admin dashboard and create a Plan object
Define all the attributes of your plan and make sure to paste the price_id
from step 2 as the external plan id
so that the plan is linked to the Stripe product you created.
Ready SaaS uses Stripe webhooks In order for your app to know when a payment has been made. As mentioned in the Payments & Subscriptions section, the subscription management system follows the following lifecycle by reacting to Stripe's webhooks:
On Subscription Activated:
Automatically provisions the subscription for the user, granting them access to the subscribed content or features.
On Payment Received:
The system continues to provision the subscription and updates the subscription's end date to reflect the new billing cycle.
On Payment Failed:
Marks the subscription as past due and triggers a notification to the customer to update their payment information.
To enable this functionality, you need to specify the webhook url within your Stripe account.
Search for webhooks in your Stripe dashboard and click on Developers > Webhooks
Click on Add an endpoint. (if you're testing locally, feel free to use their local testing option)
Make sure you point the webhook to your Ready SaaS endpoint. By default the endpoint lives in /stripe/webhook
but you can change it to any other path.
Next, make sure you include the required events:
The following are the required events:
Yay! You're ready to accept subscription payments with Stripe