Most SaaS applications have paid tiers that users can subscribe to for an upgraded experience. If a user is on a paid subscription tier, they have access to more features as compared to free users.
GeniePy provides this functionality out-of-the-box. In this guide we show you how you can configure it.
GeniePy uses Stripe Subscriptions for providing subscriptions.
The application code has the knowledge of what all subscription plans are available and what plan each user is on. The rest of the sensitive information (credit card numbers, billing addresses, etc.) is stored on Stripe, which means you don't have to worry about the security of such sensitive data.
The application configures the following three subscription plans:
- Free: this is the plan that every user starts with. Free users don't need to add any billing details.
- Basic: the Basic plan is the first level of paid tier that users can subscribe to. This should provide more features than the Free plan.
- Premium: the Premium plan is the highest level of paid tier that users can subscribe to. This should provide the most number of features your application's users.
Register for a Stripe account if you do not already have one.
After you have a verified Stripe account, create Products and the associated Prices within Stripe. Products are the subscription plans your users will subscribe to and Prices are the monthly price they will pay for access to that plan. How to create those two is outside the scope of this guide, but Stripe has an excellent guide that covers this topic which we recommend working through.
After setting this up, the Products section on your Stripe dashboard should look similar to the following:
Visit each Product page and copy the "API ID" value. We'll need this information later.
As with everything else, GeniePy expects a few environment variables to be able to talk to Stripe.
STRIPE_API_KEY: this is the API key you receive from Stripe
STRIPE_ENDPOINT_SECRET: the webhook endpoint secret from Stripe that makes the communication between your application and Stripe encrypted
STRIPE_PRICE_ID_BASIC: the "API ID" of the "Basic" subscription plan you created earlier
STRIPE_PRICE_ID_PREMIUM: the "API ID" of the "Premium" subscription plan you created earlier
In local development, make sure that the "API IDs" you're using are from
Stripe's Test Mode. These values should go in the local
.env file for any
local development/testing around subscriptions.
In addition, Stripe communicates with applications using webhooks. In production, this is easy because the production application is publicly available to everyone. For local development, we use the Stripe CLI.
invoke app.stripe in a separate terminal/tab, which should start a webhook
listener locally that listens to (test) webhook events from Stripe and relays
them to your application server running locally.
After you've gone through the steps above, your application should be ready to accept payments from users and have them subscribed to Basic and Premium plans on your site!