General
Billing

One-time Payments

Learn how to set up one-time payments to charge customers for lifetime deals.

While not a typical SaaS billing type, the starter kit offers built-in support for one-time payments.

The primary use-case are lifetime deals which are products that offer permanent access without a subscription, but in theory you can also use it to offer purchasable addons for a subscription.

Some customization may be necessary depending on your business logic. The starter kit provides flexible support for these cases but expects you to adapt the implementation to your specific needs.

Billing configuration

Let's define a lifetime deal in packages/billing/src/config.ts:

packages/billing/src/config.ts
export const config = createBillingConfig({
  products: [
    {
      id: 'lifetime',
      name: 'Lifetime',
      description: 'Buy once. Use forever.',
      label: 'Get started',
      features: ['Feature 1', 'Feature 2'],
      plans: [
        {
          id: 'lifetime',
          displayIntervals: [PriceInterval.Month, PriceInterval.Year],
          prices: [
            {
              id: 'price-lifetime-id',
              // [\!code highlight:3]
              type: PriceType.OneTime,
              model: PriceModel.Flat, // Must be flat
              interval: undefined, // Must be undefined
              cost: 699,
              currency: 'USD'
            }
          ]
        }
      ]
    }
  ]
});

Order Creation

When a product is purchased, the starter kit will:

  • Create a record in the Order table.
  • Create corresponding entries in the OrderItem table.

You can then use the purchases helper to check what the user has purchased.

Deleting an organization

When an organization get's deleted, the starter kit will:

  • Delete the Order entry.
  • Delete the OrderItem entry.

This is fine since the billing provider will hold the data.