Stage 3 · Launch · Chapter 26

How to Build SaaS Subscriptions and Payments That Hold

Build SaaS trials, plans, feature locks and payments that cannot be bypassed: enforce everything on the server, fail closed on paid add-ons, use webhooks.

Dr. Yahia Elkhouli · November 29, 2026 · 7 min read

In September 2026, I asked my AI assistant to add a button to my admin panel that extends a customer's free trial. A small, boring feature. While building it, the assistant stopped and reported something I did not want to hear: any customer could make their own subscription "active" for as long as they liked.

It proved it with a test that undid itself at the end. It pretended to be the owner of a company on a free trial and sent one request to the database saying "set my subscription to active, ending ten years from now." The database accepted it. One row changed. No admin, no payment, no warning. The security rule on the subscriptions table let any user of a company update that company's own subscription, and nobody noticed because no honest customer would try.

We locked it the same day. But it changed how I think about subscriptions: the screen that says "your trial ends in 3 days" is the easy part. The parts that matter are invisible.

The short answer

A SaaS subscription system has four parts: the record (plan, status, end date), the gate (what happens when the date passes), the locks (which features each plan can use) and the money. The record, the gate and the locks must be enforced on the server, never only in the app. Update subscriptions only from verified payment-provider notifications, and make paid add-ons fail closed so a missing setting means "no".

Record, gate, locks, money

Think of a gym. The membership card is the record. The turnstile at the entrance is the gate. The rooms your card opens are the locks. The front desk where you pay is the money. A sign saying "members only" is not a turnstile, because anyone can walk past a sign.

In software, the sign is your app's screen and the turnstile is your server. If the check lives only in the app, someone with a modified app, or anyone calling your database directly, walks past it. The screen should only explain what the server decided.

A trial is a status, not a plan

When someone signs up, a database function creates their company and a subscription row with the status "trial" and an end date. There is no separate trial plan. The trial sits on a real plan, so subscribing only changes the status and date.

THE MISTAKE WE MADE

We shortened the trial from 14 days to 7 and discovered the length was written in two places. Email signups got their trial from the database function. Google signups got theirs from a line of app code with the number typed in. A configuration value called "trial days" existed that no code used at all. On top of that, the old number was promised in eight places, from signup screens to blog articles. Change only one place and new customers would get different trials depending on how they signed up, while the website promised something else.

We connected the dead setting, changed the database function and updated all eight texts in one release. Old trials were untouched. Now before changing any business rule, I ask the AI to find every place it lives.

THE PROMPT
I want to change [BUSINESS RULE, FOR EXAMPLE THE TRIAL LENGTH] from [OLD VALUE] to [NEW VALUE].
Search the whole project: app code, database functions, settings, website pages and blog articles.
List every place this value is written or promised, including text shown to customers.
Tell me which places affect new customers only and which could change existing customers.
Do not change anything until I approve the list.

The gate belongs on the server

An outside code review found that our gate lived only in the app. When a trial ended, the app showed a "renew" screen, but the database would still accept new sales from a modified app. We added a server function that answers "is this company's subscription valid right now?" with the same logic as the app, and attached it to the moment an invoice is saved. An expired customer can still read history but cannot keep selling.

One design choice matters. If the function finds no subscription row or an unknown status, it allows the action. A paying customer should never be locked out by a data gap. That is "fail-open", and it is right for the gate, but wrong for paid add-ons.

The opposite mistake hurt more. A sales rep opening the app in the morning with no signal was sent to a "Your subscription has stopped" screen. The app cached the "valid" answer for only five minutes, and when the check failed because of the network, the code returned "no subscription" instead of "I don't know". No internet looked exactly like no payment. Your check needs three answers: valid, not valid and unknown. The app now keeps the last known valid subscription and uses it only when the server cannot be reached.

Locks that cannot be bypassed

KashBoss has cheaper plans with fewer modules, and I made one product decision early: never hide a locked feature. It stays in the menu with a lock icon, and tapping it explains the plan and offers a way to contact us. A visible lock is a quiet advertisement. Underneath are three layers: a catalog of every lockable feature, which features each plan includes, and per-company overrides with three states (on, off, or follow the plan).

Paid add-ons need two checks, not one: a role check (who inside the company may use it) and a plan check (has this company paid for it). And they must fail closed.

We learned this when we shipped an integration without adding it to the feature catalog. Its only guard checked whether the user was the company owner, and every company has an owner. For three months every account could use a module we intended to sell, and nobody reported it, because it worked perfectly. A broken feature gets reported. A free one does not.

THE PROMPT
List every module in my app that customers should pay for separately: [LIST THE MODULES].
For each one, show me where the server checks that the company has paid for it,
not only that the user has the right role.
Include every entry point: screens, server functions, webhooks and scheduled jobs.
If a check is missing or allows access when the feature data is missing, flag it.
Also list any feature keys in the database that no code actually reads.

Taking the money

Record every payment as its own row from day one: amount, date, method and reference. A status that says "paid" is not a record of money. Then make your subscription change only when your server receives the payment provider's signed notification, called a webhook, never because a browser landed on a "payment successful" page. Anyone can open that page.

For most founders the choice is between Stripe, a payment processor with subscription billing where you handle sales tax filing, and Lemon Squeezy, a merchant of record that sells on your behalf and handles tax for you. Fees differ and change, so check current terms. One more detail: some gateways only store the card and leave renewal scheduling to your own server, while others schedule renewals for you. Ask which kind you are using before designing anything.

THE PROMPT
Set up subscription payments for my app with [STRIPE OR LEMON SQUEEZY].
Plans: [PLAN NAMES, PRICES AND BILLING PERIODS].
Use their hosted checkout page and their customer portal for cards and cancellations.
Update my subscriptions table only from a verified, signed webhook, and record every payment as its own row.
Handle these events: payment succeeded, payment failed, subscription canceled, card expiring.
Explain each step in plain words and give me a test plan using their test mode.

Finally, mobile stores. If you sell a digital subscription inside a mobile app, both Google and Apple generally require their own billing and take a commission, with exceptions that vary by country. We chose to take payment on our website only, and the mobile app has no button or link leading to outside payment. Check how the rules apply where you sell. Chapter 26 of the book compares the options in more detail.

Key takeaways

Frequently asked questions

Where should I check whether a subscription is active?

On the server, at the moment a protected action happens, such as saving an invoice. The app can also check so it can show a helpful message, but the app alone can be bypassed by a modified client or a direct request to your database.

What is a webhook and why do subscriptions depend on it?

A webhook is a signed message the payment provider sends to your server when a payment succeeds or fails. Your subscription record should change only when that verified message arrives, because a "payment successful" page in the browser can be opened by anyone.

Should paid add-ons fail open or fail closed?

Fail closed. If the feature setting is missing or fails to load, the answer should be no, otherwise the add-on quietly becomes free. Core plan features are different: there we fail open so a paying customer is never locked out by a technical glitch.