Flat-Rate Billing Quick Start

Flat-rate billing is when a customer is charged a fixed, recurring fee. This guide will take you from no payment processing to a simple but functional billing system that handles Stripe's webhooks for you, and allows for the gating of features in your app.

Introduction

Flat-rate billing means charging a fixed amount per billing cycle. £99 per/year, £14 per/14 days and £20 per/month are all examples of this billing model.

Flat-rate line items support a quantity field, allowing you to charge for things that come in units such as consultancy hours, training sessions, support tickets, and retainer time. Each billing cycle the customer will be charged the flat rate price multiplied by the quantity specified at checkout.

1. Create and configure your product

Before you can start implementing Salable into your codebase, you need to sign up for an account and create a product in the Salable dashboard.

You will need to create a product, the plans that you want the users to be able to subscribe to, and any entitlements your users should be able to access depending on their subscription.

As an example, if your application was a music streaming service. You may offer “Basic” and “Pro” plans, with ad_free_listening, curated_playlists, and unlimited_playlists as your entitlements.

To charge money for your "Pro" plan, set up a Line Item with a Pricing Type of "Flat Rate".

Related Tier Tags make Plans mutually exclusive — an Owner can only subscribe to one Plan sharing the same tag at a time. In the example above, Basic and Pro would share the Tier Tag "core". The same Owner can still purchase add-on Plans that do not share the tag.

Read more about Tier Tags

Tier tags restrict Owners from purchasing multiple Plans that share the same tag. Plans sharing a tier tag belong to the same tier set, and an Owner can only subscribe to one Plan in a tier set at a time — making those Plans mutually exclusive.

An Owner cannot add multiple Plans from the same tier set to a cart, nor add a Plan from a tier set they are already subscribed to. They can, however, replace an existing Plan with another from the same tier set — they will still only hold one Plan in the set.

View Tier Tags in Core Concepts →

In order to accept payment from a user, you will need to generate a checkout link.

import { Salable } from '@salable/sdk';
const salable = new Salable('secret-api-key');
 
const { data } = await salable.api.checkout.post({
    planId: 'plan_01KHNZHBA28YMY720VVD8KVKF5',
    owner: 'user_123',
    grantee: 'user_123',
    interval: 'month',
    intervalCount: 1,
    currency: 'USD',
    successUrl: 'https://your-app.com/success',
    cancelUrl: 'https://your-app.com/cancel'
});
// Redirect user to data.url

3. Add entitlement checks to your application

In your application, you will only want to allow the grantee to perform certain actions if they have an active subscription.

We can check for a grantee's active entitlements as follows:

import { Salable } from '@salable/sdk';
const salable = new Salable('secret-api-key');
 
const { data } = await salable.api.entitlements.check.get({
    queryParameters: {
        granteeId: 'user_123'
    }
});
 
const granteeHasEntitlement = data.entitlements.find(e => e.value === 'ad_free_listening');
 
if (granteeHasEntitlement) {
    // Allow the user to perform the action in your system.
}

Tip Setting up Entitlements allows you to easily create tailored plans for your customers' requirements. Copy any existing Plan, adjust its Entitlements and cost based on the agreed terms with the customer, and they immediately get the exact feature set you agreed without any code change. Now everything flows through Entitlements, sales can be instant. For a deeper dive, see Understanding Entitlements.

4. Next steps

Now that you have payment processing and entitlement checking set up in your application, there are some further things you should set up to enable full subscription handling in your application:

  • Cancel a Subscription Cancel an active subscription and stop future billing.
  • Subscription Management Portal Let customers manage their own subscription through a Stripe-hosted portal.
  • Webhooks Handle subscription lifecycle events like renewals, payment failures, and cancellations in your application.