Topup

It is very common that your SaaS needs a way for your users to topup their credits on top of their base plan. The kit provides an easy of doing it.

Setup plan

First you need to setup a plan for the topup. This is similar to the User Plan setup and set the category to TOPUP.

export const PLAN_TOPUP: Plan = {
  id: "topup",
  name: "Topup",
  price: 10,
  type: "ONE_TIME",
  credits: 100,
  resetType: "one-time",
  category: "TOPUP",
};
 
export const planMap: Record<string, Plan> = {
  ...,
  [PLAN_TOPUP.id]: PLAN_TOPUP,
};

With the default setup, this is what all you need to do this work. Use checkout API - /api/checkout/stripe?planId=<planId>&metadata=<metadata> to checkout for the topup plan by passing appropriate planId and metadata.

Webhook

The webhooks already handle the topup plans and update the user credits accordingly.

Database

The topups are recorded under User.topups field in the database. You can use these details in your app logic as needed.


MIT 2025 Β© Nextra.