Skip to main content

Flat rate billing

If a plan uses the flat rate model, you specify a price and a billing cycle for the plan, and the customer pays that price each billing cycle. Flat rate models only allow for one grantee to use the subscription, if you need more you'll need a per-seat plan instead.


Taking payments

To receive payment for your subscription, you'll need to create a Stripe checkout. Here, a customer can add their bank card details and upon successful checkout the subscription will be created. The next payment will occur based on the plan's interval length.

import { getCheckoutLink } from '@salable/js'

const { checkoutUrl } = await getCheckoutLink({
apiKey: 'your-salable-api-key',
planUuid: 'your-salable-plans-uuid',
successUrl: 'https://your.app/payment-success'
cancelUrl: 'https://your.app/payment-cancelled',
granteeId: 'your-grantees-id',
owner: 'your-grantees-organisation-id',
});
OptionDescriptionRequired
successUrlThe url to redirect a customer after a successful checkout.
cancelUrlThe url to redirect a customer if they cancel the checkout.
granteeIdThe ID of the grantee which will be assigned to the first seat of the subscription, for example the user ID or a board ID. If the subscription is per-seat all additional seats created will be unassigned.
ownerThe ID of the customer's organisation.
currencyThe shortname of the currency to be used in the checkout. Default - plan's product default currency.

Create subscription

Creates a subscription without a payment.

tip

If you'd like to receive payment for a subscription, create a checkout link.

import { Salable } from '@salable/node-sdk';
const salable = new Salable('your-salable-api-key', 'v2');

const subscription = await salable.subscriptions.create({
planUuid: 'your-plan-uuid',
owner: 'orgId_1234',
granteeId: 'userId_1',
});

License check

Check whether a grantee can perform an action in your system. Feature values, capabilities, and plan names that belong to your user are checkable. If your grantee has multiple subscriptions, everything they have access to will be returned in the response.

import { getGrantee } from '@salable/js';

const { hasCapability } = await getGrantee({
apiKey: 'your-salable-api-key',
productUuid: 'your-products-uuid',
granteeId: 'your-grantees-id',
});

// Check for a capability
const isUserLicensedToPerformAction = hasCapability('acme-inc-whitelabelling');
// or a feature
const isUserLicensedToPerformAction = hasCapability('csv-export');
// or a plan
const isUserLicensedToPerformAction = hasCapability('pro');

Update seat

Change who can access the subscription.

import { Salable } from '@salable/node-sdk';

const salable = new Salable('your-salable-api-key', 'v2');
await salable.subscriptions.manageSeats('your-subscription-uuid', [
{
type: "replace",
granteeId: "current-grantee-id",
newGranteeId: "new-grantee-id"
}
]);

Upgrade and downgrade

Useful if you need to update the plan your grantee is on. For example, if they have upgraded or downgraded you would want to update the subscription to reflect this.

import { Salable } from '@salable/node-sdk';

const salable = new Salable('your-salable-api-key', 'v2');
const changeSubscriptionPlan = await salable.subscriptions.changePlan(
'your-subscription-uuid',
{
planUuid: 'the-new-plan-uuid',
proration: 'create_prorations', // optional. see table below for more options
}
);
info

Proration options are only applicable on subscriptions that have taken a payment.

ValueDescription
create_prorationsKeeps the subscription's billing cycle start/end date and refunds for unused time on the previous plan
always_invoiceChanges the billing cycle start date to the current date and immediately invoices
noneDisables proration behaviour

Cancel subscription

You can cancel a subscription with its associated subscriptionUuid.

import { Salable } from '@salable/node-sdk';

const salable = new Salable('your-salable-api-key', 'v2');
await salable.subscriptions.cancel('your-subscription-uuid', { when: 'end' });
info

The when query parameter represents when you want the subscription to cancel.

WhenDescription
nowImmediately cancels the Subscription. If the Subscription is paid, the customer will be immediately invoiced.
endCancels the Subscription at the end of its cycle. To undo this you can reactivate the subscription. If the Subscription is paid, the customer will be invoiced at the end of the cycle.

Demos

Flat rate billing in Next.js
Miro App with flat rate billing