Display usage and billing data in your app for your users
When you have paying users, you should display a billing page in your app. This typically allows them to change plan, cancel subscription and view their usage.The customer endpoint will return the current state of the customer, including their active plans, feature usage and remaining balances.
Display the plan the user is currently on. You can also display price information and features granted with that plan.As users can have multiple active plans (eg, add ons), this is an array.
Copy
import { Autumn } from "autumn-js";const autumn = new Autumn({ secretKey: process.env.AUTUMN_SECRET_KEY,});const { data } = await autumn.customers.get("user_or_org_id_from_auth");//filter for active productsconst activeProducts = data?.products.filter( (product) => product.status === "active",);console.log( `Users active plans are: ${activeProducts?.map((product) => product.name).join(", ")}`,);
The Stripe billing portal is a convenient way to allow users to manage their payment method, see past invoices and also cancel their current plan. You can also set up “churn offers” to encourage users to stay with you.
To use the Stripe billing portal, you’ll need to enable it in your Stripe settings.
Copy
import { Autumn } from "autumn-js";const autumn = new Autumn({ secretKey: process.env.AUTUMN_SECRET_KEY,});await autumn.customers.billingPortal('customer_id', { return_url: "https://your-app.com/billing" });
Autumn replicates your usage data to Clickhouse, so you can retrieve aggregate time series usage data for your customers. The response can be passed into a charting library like Recharts to display a usage history graph.
Copy
import { Autumn } from "autumn-js";const autumn = new Autumn({ secretKey: process.env.AUTUMN_SECRET_KEY,});const { data } = await autumn.query({ customer_id: 'user_or_org_id_from_auth', feature_id: 'messages', range: '30d'})