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
.envfile (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.prismafile in the root of the project to use the provider"sqlite"datasource db { provider = "sqlite" url = env("DATABASE_URL") } - Update the
DATABASE_URLvar in your.envfile to befile:./dev.db - Replace the contents of
./prisma/index.tswith 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 Productbutton. - Give your product any name.
- Tick the
Paid Productcheckbox. - 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
GBPas the product's default currency.
- Go to the
Planstab andCreate Plan. - Plan name will be
Random String Generator. - Select
Usagefor pricing model. - Select
Monthfor subscription cycle. - Select
Paidto 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.
- Click
Nextto proceed to Features. - This is section is for creating features and assigning values to plans.
- Click Create feature and create feature of type Boolean for 16, 32, 64 and 128. These will be used to lock features behind the entitlements check in the demo app.
- Create the plan.
- Copy the Product ID from the "Overview" tab and assign to
NEXT_PUBLIC_PRODUCT_UUIDin the.envfile. - Go to
Plans. Assign theRandom String Generatorplan 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.
