This app demonstrates using flat rate billing with Salable.
The product in the demo generates strings with random data which vary in size based on the number of bytes selected. To get access to the product a user must sign up and subscribe to a plan. 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 is used for storing user session data.
- Clone the repo (
git clone [email protected]:Salable/salable-flat-rate-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 in the Salable dashboard and click the
Import productbutton. - Navigate to this demo project in the file system on your machine. Select
salable-product.yamlin the root of the project and import it. - As this is a paid product, you'll need to select a payment integration.
- Click
Import file.
- Copy the Product ID from the
Overviewtab and assign toNEXT_PUBLIC_PRODUCT_UUIDin the.envfile. - Go to
Plans. Assign theBasicID toNEXT_PUBLIC_SALABLE_PLAN_UUIDand theProID toNEXT_PUBLIC_SALABLE_PRO_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.
