This demo is to demonstrate using usage pricing with Salable.
The product in the demo generates strings with random data which vary in size based on the number of bytes selected. Each byte size has a credit cost which will be charged to your subscription as consumption and billed at the end of the month. To get access to the product a user must sign up and subscribe to a plan. The email of the sign-up does not have to be real, this is just for demo purposes. The byte sizes for the strings are feature locked behind different plans. Once a user has subscribed they will be able to access some or all of these features depending on what plan they are licensed on.
The email of the sign-up does not have to be real, this is just for demo purposes.
The demo is integrated with Stripe to handle payments which is running in test mode so Stripe test cards can be used.
Card Number: 4242 4242 4242 4242
Expiry Date: Any future date (09/42
)
CVC: Any 3-digit number (123
)
Cardholder Name: Anything (Mr John Doe
)
User details are stored in a postgres database using Neon with Vercel. Passwords are securely hashed
with unique salts. The ID of the logged-in user is used as the granteeId
when
creating a license on Salable. It is also used for the license checks. If you're
developing an app within an existing ecosystem like Trello or Slack, you can
swap out the included authentication system with theirs.
Iron session to store user session data. View docs
- Clone the repo (
git clone git@github.com:Salable/salable-usage-demo.git
) - Run
npm install
- Create an
.env
file (cp .env.example .env
) - Install Docker. If you already have Docker installed skip this step. If you don't want to run Docker for local development skip to the next stage for an alternative.
- Run
docker compose up -d
- Run
npx prisma db push
If you are using Docker skip to Configure Salable.
To remove the requirement of Docker we will change the db provider to sqlite
.
- Update the datasource in the
schema.prisma
file in the root of the project to use the provider"sqlite"
datasource db { provider = "sqlite" url = env("DATABASE_URL") }
- Update the
DATABASE_URL
var in your.env
file to befile:./dev.db
- Replace the contents of
./prisma/index.ts
with the code below -import { PrismaClient } from "@prisma/client"; import { PrismaLibSQL } from "@prisma/adapter-libsql"; import { createClient } from "@libsql/client"; import { env } from "@/app/environment"; const libsql = createClient({ url: env.DATABASE_URL }); const adapter = new PrismaLibSQL(libsql); export const prismaClient = new PrismaClient({ adapter });
- Run
npx prisma db push
- Go to the Products page and click the
Create Product
button. - Give your product any name.
- Tick the
Paid Product
checkbox. - Select the test payment integration that is created for you on sign up. If you already have created a payment integration this can be used instead.
- Select
GBP
as the product's default currency.
- Go to the
Plans
tab on the sidebar and selectCreate Plan
- Set the plan name as
Random String Generator
and optionally provide a description. - Press
Continue
to configureLicense Type
information. - For the type of plan select
Standard
. - Select
Month
for subscription cycle. - Select
Usage
license type. - Select
Paid
to make it a paid plan. - Currencies will then appear, input
1
(£1) as per-unit cost. This will be what the customer will be charged per unit of consumption per billing cycle. The charge per billing cycle will be variable based on what the customer consumes. - Continue to
Assign values
. - This is section is for assigning feature values that can be used on pricing tables. This is not required to get set up.
- Click
Continue
toCapabilities
. - Create four capabilities of
16
,32
,64
and128
. These will be used to lock features behind the license check in the demo app. - Create Plan.
- Copy the Product ID from the "General Settings" tab and assign to
NEXT_PUBLIC_PRODUCT_UUID
in the.env
file. - Go to
Plans
. Assign theRandom String Generator
plan ID toNEXT_PUBLIC_SALABLE_PLAN_UUID
. - Go to
API Keys
. - Copy the API Key that was generated on sign up and assign to
SALABLE_API_KEY
. - Run
npm run dev
Get answers and guidance from our own developers and commercial model consultants. If you have an implementation query, or you are not sure which pricing model to use for your app, our people are ready to help.
