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.

Description

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:

  1. Free: this is the plan that every user starts with. Free users don't need to add any billing details.
  2. 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.
  3. 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.

Setup

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.

Configuration

As with everything else, GeniePy expects a few environment variables to be able to talk to Stripe.

  1. STRIPE_API_KEY: this is the API key you receive from Stripe
  2. STRIPE_ENDPOINT_SECRET: the webhook endpoint secret from Stripe that makes the communication between your application and Stripe encrypted
  3. STRIPE_PRICE_ID_BASIC: the "API ID" of the "Basic" subscription plan you created earlier
  4. STRIPE_PRICE_ID_PREMIUM: the "API ID" of the "Premium" subscription plan you created earlier

Development

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.

Run 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!