Skip to main content
In this example we’ll create the pricing for a premium AI chatbot. We’re going to have:
  • A Free plan that gives users 5 chat messages per month for free
  • A Pro plan that gives users 100 chat messages per month for $20 per month.
Autumn’s client-side hooks are supported for fullstack TypeScript apps. Please use the Server SDK for other frameworks.
1

Create your pricing plans

Create a plan for each pricing tier that your app offers. In our example we’ll create a “Free” and “Pro” plan, and assign them features.
Browse our Examples for guides on setting up credit systems, top ups and other common pricing models.
Run the following command in your root directory:
This will prompt you to login or create an account, and create an autumn.config.ts file. Paste in the code below, or view our config schema to build your own.
autumn.config.ts
Then, push your changes to Autumn’s sandbox environment.
If you already have products created in the dashboard, run atmn pull to pull them into your local config.
2

Installation

Create an Autumn Secret key, and paste it in your .env variables. Then, install the Autumn SDK. If you’re using the CLI, this will be done for you.
.env
If you’re using a separate backend and frontend, make sure to install the library in both.
3

Add Endpoints Server-side

Server-side, mount the Autumn handler. This will create endpoints in the /api/autumn/* path, which will be called by Autumn’s frontend React hooks. These endpoints in turn call Autumn’s API.The handler takes in an identify function where you should pass in the user ID or organization ID from your auth provider.
Autumn’s customer ID is the same as your internal user or org ID generated from your auth provider. No need to store any extra IDs.
4

Add Provider Client-side

Client side, wrap your application with the <AutumnProvider> component.
5

Create an Autumn customer

From a frontend component, use the useCustomer() hook. This will automatically create an Autumn customer if they’re a new user and enable the Free plan for them, or get the customer’s state for existing users.
React
You will see your user under the customers page in the Autumn dashboard.
6

Stripe Payment Flow

Call attach when the customer wants to purchase the Pro plan. This will return a Stripe payment URL. Once they’ve paid, Autumn will grant access to “100 messages per month” defined in Step 1.
Use Stripe’s test card 4242 4242 4242 4242 to make a purchase in sandbox. You can enter any Expiry and CVV.
React
This will handle any plan changes scenario (upgrades, downgrades, one-time topups, renewals, etc).Upgrades will happen immediately, and downgrades will be scheduled for the next billing cycle.
The redirectMode: "always" flag will always return a payment URL.New purchases redirect to Stripe Checkout to enter payment details, and subsequent charges redirect to an Autumn hosted, one-click confirmation page.You can build your own billing confirmation flows by using the previewAttach function.
Next: Track and limit usage Now that the plan is enabled and you’ve handled payments, you can now make sure that customers have the access to the right features and limits based on their plan.

Track and limit usage

Enforce usage limits and feature permissions using Autumn’s check and track functions