Flat-Rate Billing Quick Start

This guide is intended to take you from no payment processing to a simple, but functional, flat-rate billing system.

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.

Following this short guide will take you from zero to being up-and-running with a flat-rate billing model in your application.

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".

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

const response = await fetch('https://beta.salable.app/api/checkout', {
    method: 'POST',
    headers: {
        Authorization: 'Bearer YOUR_SECRET_KEY',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        planId: 'YOUR_PLAN_ID',
        owner: 'user_123',
        grantee: 'user_123',
        interval: 'YOUR_INTERVAL', // 'month' or 'year'
        intervalCount: 1,
        currency: 'YOUR_PLANS_CURRENCY', // USD, GBP, EUR, etc
        successUrl: 'https://your-app.com/success',
        cancelUrl: 'https://your-app.com/cancel'
    })
});
 
const { data } = await response.json();
// 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:

const { data } = await fetch('https://beta.salable.app/api/entitlements/check?granteeId=YOUR_GRANTEE_ID', {
    headers: {
        Authorization: 'Bearer YOUR_SECRET_KEY'
    }
});
 
const granteeHasEntitlement = data.entitlements.find(e => e.value === 'YOUR_ENTITLEMENT_NAME');
 
if (granteeHasEntitlement) {
    // Allow the user to perform the action in your system.
}

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: