Stripe

Pace uses Stripe Checkout and Customer Portal to provide a seemless integration with Stripe for handling subscriptions.

Create Stripe account

To integrate your application with Stripe, you must register for a Stripe account.

Add Stripe credentials

Stripe credentials are stored inside config/stripe.ts:

// config/stripe.ts

import Env from '@ioc:Adonis/Core/Env'

const stripeConfig: StripeConfig = {
  secretKey: Env.get('STRIPE_SECRET_KEY'),
  publicKey: Env.get('STRIPE_PUBLIC_KEY'),
  webhookSecret: Env.get('STRIPE_WEBHOOK_SECRET'),
}

Head over to your API keys section on your Stripe developers page to grab your API keys. These credentials should be added in your application's .env file:

// .env

STRIPE_SECRET_KEY=YOUR_STRIPE_SECRET_KEY
STRIPE_PUBLIC_KEY=YOUR_STRIPE_PUBLIC_KEY

Plans

Before you can start billing your users, you need to first create plans that they can subscribe to. To create a plan, you need to first head over to your Stripe account and create the plans. Then in your admin area, you can provide the following details to create the respective plans:

  • Name: the name of the plan
  • Description: an optional description of the plan
  • Plan ID: price ID from Stripe
  • Price: the price for the plan
  • Interval: the plan interval which should match that of the plan created on Stripe.
  • Incentive: an optional plan incentive such as "best value", "popular", "save 40%", etc.
  • Features: a comma-separated list of features included in the plan.

Customer Portal

Pace uses Stripe Customer Portal for subscription management. With the Customer Portal, users can:

  • Change subscription (downgrade or upgrade)
  • Pause subscription
  • Cancel subscription
  • Update payment method and details

To be able to use the Customer Paortal, you need to first configure it. Kindly follow the Stripe’s integration guide on how to do that.

Stripe Webhooks

To be notified when events occur on Stripe and fulfill them accordingly on your application, you need to configure your application to receive webhooks from Stripe. That way, your application's billing data is in sync with Stripe's.

You should at least listen to the following events:

  • checkout.session.completed
  • customer.subscription.updated
  • customer.subscription.deleted

In your Stripe webhooks section of the developers page, add a webhook endpoint and enter https://project_name.com/webhook as the endpoint URL and select at least the events listed above.

Where `project_name.com` is your application domain or the site sharing URL generated.

You will also need to grap your webhook signing secret and add it inside .env:

// .env

STRIPE_WEBHOOK_SECRET=YOUR_STRIPE_WEBHOOK_SECRET

Webhooks in local development

For Stripe to be able to send your application webhooks during local development, you will need to expose your application to be publically available. You can do that using site sharing services such as Ngrok or Expose. Also, you can use Stripe CLI.

Disabling billing

By default, billing is enabled in Pace but if billing functionality doesn't apply to your application or you don't need it yet, you can disable it in config/pace.ts:

 billing: false,

Also, enable to remove all Stripe environment variables references inside the env.ts file.