Netcraft

// 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 →

Gabriel Cazaciuc

By , 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 id

If 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.

  1. Read paid charges with read-only Stripe keys. The job cannot change anything in Stripe.
  2. 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.
  3. Skip rows that are final: issued, matched to an invoice made by hand, marked, or skipped.
  4. For company buyers, fetch the official name, address and VAT status from the public registry of the Romanian tax authority (ANAF) by tax ID.
  5. Before issuing, look for an invoice already made by hand in Keez for that payment, and match it instead.
  6. Issue the invoice. If a draft already exists from an earlier failed run, issue that draft instead of making a second one.
  7. 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.

// FAQ

Frequently asked questions

Another question? Write to us; you get an answer from the developer within one working day.

Should I use Stripe Checkout or build my own payment form?

Use Checkout for an MVP. It handles cards, strong customer authentication, wallets and tax ID collection, and your server only has to react to the webhook.

Is the success page enough to unlock a paid plan?

No. Anyone can open that URL. Grant access from the signed webhook, or from a server-side check of the checkout session with Stripe.

How do I handle Stripe sending the same webhook twice?

Store each event ID before acting, skip IDs you have seen, and make the grant itself safe to apply twice.

What happens when a customer's card fails at renewal?

Stripe retries the card on its schedule. Keep access during that period, email the customer, and remove access when Stripe cancels the subscription.

Can Stripe invoices replace my accountant's invoices?

It depends on the country and your accounting setup. In Romania we issue invoices in our accounting software with a daily job, one per Stripe payment.

// How production AI apps are built

Keep reading

// Start here

What does a production-ready AI app need?

A production-ready AI app needs ten things beyond working screens: accounts and roles, payments confirmed by Stripe webhooks, access rules on every table, automatic checks on AI output, cost limits per user and overall, background jobs that survive failures, error alerts, pages search engines can read, tested backups, and code, domain and data in the owner's name.

Read the guide

// How production AI apps are built

Should you use Payload CMS as the backend of your MVP?

For most MVPs with content, roles and an admin team, yes. Payload runs inside your Next.js app on your own Postgres database and gives you an admin panel, access rules in code and migrations on day one. Use plain SQL beside it for hot paths, and pick Supabase instead if you need realtime features or a browser-first app.

Read the guide

// How production AI apps are built

How do you run long AI jobs that don't fail halfway?

Split the job into durable steps whose results are saved, so a failed step is retried alone and the finished ones are kept. Mark errors a retry cannot fix as final. Run independent parts in parallel, within rate limits. Let optional steps fail without failing the job. Hold the user's credits until the end and return them once on failure.

Read the guide

// How production AI apps are built

How do you control AI costs in a production app?

Give each task the cheapest model that does it well and keep the expensive one for hard cases. Cap paid calls per user, per day and globally. Put a bot check in front of costly actions. Tie usage to the plan the user pays for. Refund failed jobs once. Tag every call to see what each feature costs.

Read the guide

SaaS MVP Development, at a fixed price

Subscriptions, teams, admin and AI features on a stack we run ourselves. From €3,500, 2–3 weeks. Written scope and price within 24 hours.