Adding payments and subscriptions to a SaaS: Stripe, VAT and what goes wrong

How to add subscription billing with Stripe to a live SaaS: webhooks, idempotency, failed payments, plus VAT basics for EU, UK and US customers.

The short answer

Let the payment provider hold the card data and the subscription state, and treat your database as a mirror updated by verified webhooks that you process exactly once. Plan for failed payments, plan changes and refunds before launch. For VAT, the rules depend on where your customers are and where you are established, so decide that early; this is not tax advice.

On this page
  1. How should the integration be shaped?
  2. What goes wrong with webhooks?
  3. What about failed payments?
  4. What about plan changes, trials and refunds?
  5. What are the VAT basics?
  6. What is the order of work?
  7. How do you test a billing integration?
  8. Working with us

Adding payments to a SaaS looks like a small job: a checkout page and a price. The work is in everything after the first successful payment. This article covers the technical parts that go wrong and the tax basics you must know exist. It is not legal or tax advice; confirm your own position with an accountant.

How should the integration be shaped?

Stripe, like other providers, can hold customers, subscriptions and invoices. Use that. Your app should:

  • send people to the provider’s hosted checkout, or use its embedded elements, so card details never touch your servers;
  • store the provider’s customer and subscription ids against your organization or user;
  • mirror the subscription state (active, past due, canceled) in your own database, updated by webhooks;
  • decide access from your mirror, not from a live API call on every request.

Hold money amounts as integers in the smallest currency unit, with the currency, never as floats.

What goes wrong with webhooks?

Webhooks are how the provider tells you what happened. Four problems recur:

  1. Unverified events. Anyone can post to your webhook URL. Verify the signature with the provider’s library, and reject what fails.
  2. Duplicates. Providers retry, so the same event arrives twice. Record each event id in the database with a unique constraint and process it once. Keep this record in the database, not in memory, so a second server sees it. Run the handler twice in a test: it must pay, grant or email once.
  3. Out-of-order events. An “updated” event can arrive after a “canceled” one. Compare timestamps or fetch the current object from the provider before acting.
  4. Slow handlers. If your endpoint takes too long, the provider retries. Acknowledge fast and do the work in a background job.

Money code gets extra checks: run it twice, it pays once; totals net correctly; use property tests with random sequences of events checked against invariants. Treat the subscription status as a state machine with one transition table, as in status columns are state machines.

What about failed payments?

Cards fail: expired, declined, insufficient funds. Decide your policy before launch:

  • How many retries, over how many days?
  • Is there a grace period before access is cut?
  • What does the user see, and what email do they get?
  • What happens to their data when they downgrade or lapse? Read-only is kinder than deleted.

Most providers have built-in retry and email features; configure them rather than rebuilding them.

What about plan changes, trials and refunds?

  • Upgrades and downgrades need proration rules. Let the provider calculate them and test each combination you offer.
  • Trials need a decision: card up front or not, and what happens at the end.
  • Refunds and disputes must update your mirror too. Test them.
  • Per-seat pricing needs member counting that matches what you bill; see adding team accounts.

Test with the provider’s test mode and its test clocks or equivalent, so you can build the “30 days later” state directly instead of waiting.

What are the VAT basics?

The rules differ by where you and your customers are. These points come from the official sources listed at the end; check them again before you rely on them, as rules change.

EU customers, business to consumer (B2C). VAT on digital services to private consumers is due in the customer’s country. The EU One Stop Shop (OSS) lets you declare and pay it through one return in your own country instead of registering in every member state. A business established in the EU can use an EU-wide threshold of EUR 10,000 per year for cross-border sales; below it, its own country’s VAT can apply. A business established outside the EU has no such threshold and uses the non-Union scheme. The Commission says some of these rules are being changed in phases, so check the current position.

EU customers, business to business (B2B). Generally the customer accounts for the VAT (the reverse charge) when they give a valid VAT number. Validate numbers against the EU’s VIES service and keep the result.

UK customers. HMRC guidance says a business not established in the UK has no registration threshold for taxable supplies of services, so UK VAT can apply from the first sale to UK consumers.

US customers. There is no federal VAT. Sales tax is set state by state, and whether your SaaS is taxable and whether you must collect it depends on the state and your sales there.

Practical consequences for the build:

  • collect the customer’s country and, where needed, a billing address and VAT number;
  • store evidence of the customer’s location;
  • use the provider’s tax tooling or a tax service rather than hand-coding rates;
  • put VAT on invoices as the rules require.

What is the order of work?

  1. Decide who you sell to and where, and talk to an accountant.
  2. Model plans and the state machine.
  3. Build checkout and the webhook with signature checks and idempotency.
  4. Build the mirror and access rules.
  5. Handle failures, changes and refunds, with tests.
  6. Add tax collection and invoices.
  7. Run a real payment in production with a small amount and refund it.

How do you test a billing integration?

Use the provider’s test mode and simulate time. Create a subscription, move the clock forward to a renewal, then make the payment fail, then recover it. Replay each webhook twice and confirm that nothing happens twice. Send events out of order. Cancel and refund, and check that your mirror and the provider agree. Then reconcile: a scheduled job that compares your records with the provider’s and reports differences catches the cases you did not think of. Keep these tests permanently, since money tests are never removed to save time.

Working with us

We add billing to existing SaaS products with the webhook handling, idempotency and tests described above, and we leave tax decisions to your accountant. Describe your product and customer locations via contact, or read about our SaaS platform work.

Keep reading

Tell us what you want to build.

A product, a website, a search problem or a system that should work better. We reply with a plain answer and the first step.

A few sentences are enough (at least 20 characters).

We use your details only to answer your inquiry. See our privacy policy.