// How production AI apps are built
How do you set up Stripe subscriptions and invoicing for an MVP?
Use Stripe Checkout for payment, and grant access only when your server receives a signed webhook. Record each event once, so retries cannot grant twice. Read the current subscription from Stripe instead of trusting event order. Keep a grace period for failed renewals. Run a scheduled job that issues exactly one invoice per payment in your accounting software.
Want it done for you? SaaS MVP Development: from €3,500, fixed quote in 24h →

By Gabriel Cazaciuc, Founder & lead developer, Netcraft Digital
Last updated
Key facts
- Grace after a failed renewal
- 14 days, matching Stripe's retry schedule
- Source: Netcraft Studio, our product, Nov 2026
- Invoices per Stripe payment
- Exactly one: unique key per charge plus a Postgres lock
- Source: Our Stripe → Keez invoicing, Nov 2026
- Stripe accounts invoiced by one job
- 2 (netcraft.digital and fisaedu.ro)
- Source: Our Stripe → Keez invoicing, Nov 2026
- Stripe access used by the invoicing job
- Read-only keys
- Source: Our Stripe → Keez invoicing, Nov 2026
What does Stripe do for you, and what is left to build?
Stripe takes the card, charges renewals, retries failed payments and gives customers a portal to manage their plan. Your app still has to decide who gets access, keep that in sync with Stripe, handle refunds and failed renewals, and, in most EU countries, issue an invoice in the format your accountant needs.
We run Stripe in production in Netcraft Studio (an annual plan per site, plus domains and mailboxes) and in FișaEdu (a one-time 12-month pass and worksheet packs). The payments of FișaEdu and of this site are invoiced automatically by a job we built. This guide is part of our production-ready AI app checklist.
Why must the webhook be the source of truth?
Because the browser can lie and can close early. A customer can type your success URL without paying, or pay and close the tab before the redirect. Stripe's webhook reaches your server either way, signed with a secret only you and Stripe know.
FișaEdu's webhook route checks the signature first and rejects anything that fails. Netcraft Studio also confirms on the success page, for speed, but not from what the browser sends. The server asks Stripe for the checkout session, checks that it belongs to the signed-in user, and then claims the order in the database. Whichever arrives first, the webhook or the page, fulfills the order, and the other finds it already claimed.
How do you stop a payment from being applied twice?
Record every event ID before you act on it, and skip IDs you have already seen. Stripe can send the same event more than once, and it retries until your server answers with success. In FișaEdu, the first thing the handler does is this insert:
INSERT INTO stripe_events (id, type)
VALUES ($1, $2)
ON CONFLICT (id) DO NOTHING
RETURNING idIf no row comes back, the event was already handled and the handler stops. If the handler fails halfway, it deletes the row and returns an error. Stripe then retries, and the retry starts clean. Grants themselves are also written so that applying one twice changes nothing.
What about events that arrive out of order?
Do not trust the event's copy of the subscription. Fetch the current one. A “subscription updated” event can arrive after a newer one. Both our products answer every subscription event by asking Stripe for the subscription as it is now, and saving that.
Delayed payment methods need the same care. A checkout can complete before the money arrives. FișaEdu grants the plan only when the session's payment status is “paid”, and handles the later “payment succeeded” or “payment failed” event. A full refund in Stripe removes what the payment granted. A partial refund leaves access as it is.
What should happen when a renewal fails?
Keep the customer's access for as long as Stripe keeps retrying the card, tell them, and stop only when Stripe gives up. Netcraft Studio keeps a site's plan for 14 days after a failed renewal. That matches Stripe's default retry schedule, after which Stripe cancels the subscription. The customer gets an email about the failed payment. A wrong amount, a refund, a dispute or a failed renewal also raises an alert for us.
Some payments trigger work outside Stripe. When a Studio customer pays for a domain, the registration at the domain provider can fail. The platform retries it automatically, at growing intervals and up to a limit, so the customer never has to write to us after paying.
How do you keep your database in sync with Stripe?
Run a scheduled job that compares the two. A webhook can be missed during an outage or a deploy. FișaEdu runs a sync job that lists the subscriptions in Stripe, compares them with local accounts and corrects any difference. FișaEdu also tags its Checkout sessions with the app they belong to, so it ignores payments made for another app on the same Stripe account.
How do you issue invoices automatically in the EU?
Stripe's receipt is not always the invoice your country requires. In Romania we keep our books in Keez, a Romanian accounting service, so we built a daily job that reads the paid charges of two Stripe accounts (netcraft.digital and fisaedu.ro) and gives each one exactly one invoice in Keez.
- Read paid charges with read-only Stripe keys. The job cannot change anything in Stripe.
- Look up every charge in a ledger table, keyed by Keez environment plus Stripe charge ID. The key is unique, so a charge cannot get two rows.
- Skip rows that are final: issued, matched to an invoice made by hand, marked, or skipped.
- For company buyers, fetch the official name, address and VAT status from the public registry of the Romanian tax authority (ANAF) by tax ID.
- Before issuing, look for an invoice already made by hand in Keez for that payment, and match it instead.
- Issue the invoice. If a draft already exists from an earlier failed run, issue that draft instead of making a second one.
- Report every payment that still lacks data or failed, so a person can fix it.
Two runs at the same time could both read the same uninvoiced charge. So the daily run, and the on-demand run fisaedu.ro can trigger right after a payment, both take a Postgres advisory lock first. A run that finds the lock taken does nothing. We tested everything against Keez's staging environment, with a dry-run mode that shows the invoice it would send, before switching to production.
What is the minimum for an MVP?
Stripe checklist for launch
- Stripe Checkout for payment; the Customer Portal for plan changes and cards
- Webhook signature verified on every request
- Event IDs recorded once; a failed handler releases its claim so Stripe retries
- Access granted from the webhook or a server-side session check, never from the URL
- Current subscription fetched from Stripe on every subscription event
- Grace period for failed renewals and an email to the customer
- Refunds and disputes remove access and alert you
- A scheduled sync that corrects drift between Stripe and your database
- Invoices issued once per payment, in the system your accountant uses
Subscriptions like these are part of our SaaS MVP development offer. The ledger and the admin view behind it run on Payload CMS; see Payload CMS as the backend of an MVP. What payments add to the budget is in how much an MVP costs. For a fixed quote, contact us.
