Skip to content
NASHSOFTWARE SERVICES
Writing

Published For buyers

Before You Take Payments in an App Built With AI

Taking payments in an app built with Lovable, Bolt or Claude? Six things to check first: keys, prices, webhooks, duplicates, who can mark themselves as paid, and testing.

Mike Nash · Fractional CTO and independent code reviewer

Before you switch on live payments, check that your app only treats an order as paid when your server hears it from the payment provider, and that nothing in the browser can change a price or mark an account as paid. Get those two right and you've dealt with the payment problems I'd worry about first. Everything below is a way of checking them. I've used Stripe as the example; other providers work the same way in outline, with different names.

Do all of this in Stripe's test mode (Stripe now calls it a sandbox), on an app you own, with made-up customers. Never use a real card to test.

1. Where do the keys live?

Your app needs two Stripe keys. The publishable key, starting pk_, goes in the browser. The secret key, starting sk_, or a restricted key starting rk_, must only ever be on the server. Test keys contain _test_ and live keys contain _live_, and each mode has its own set.

Are your API keys visible in the browser shows how to check where yours end up. Stripe now recommends a restricted key, with only the permissions your app needs, over the secret key.

2. Who decides the price?

The amount someone pays should come from your server, never from the browser. With Stripe Checkout, your server creates the checkout session using a price you set up in Stripe, or an amount it looks up itself.

Ask your developer or your AI tool: "When a customer clicks buy, where does the amount come from?" If the answer involves the page sending the amount or the price to the server, someone can change it before it's sent. The safe answer is that the browser sends which product, and the server works out what it costs.

3. What marks an order as paid?

After paying on Stripe's checkout page, the customer is sent back to a success page on your site. It's tempting to mark the order as paid when that page loads. Don't rely on that alone. Anyone can type that address in, and Stripe's own docs point out that a customer can pay and then lose their connection before the page loads, so the order never gets marked at all.

Stripe's answer is a webhook: a message Stripe's servers send to yours when something happens, such as checkout.session.completed. Your app should do the fulfilling, meaning granting access or shipping the order, when that message arrives. Stripe also suggests running the same fulfilment from the success page so the customer isn't kept waiting, as long as both paths check the payment status with Stripe and the order only gets fulfilled once.

Some payment methods, such as bank debits, aren't confirmed straight away. For those, Stripe sends checkout.session.async_payment_succeeded later. If you accept them, your app needs to handle that event too.

4. Does the webhook check it came from Stripe?

Your webhook address is public. Without a check, anyone who finds it can send a fake "payment completed" message. Stripe signs every webhook with a Stripe-Signature header, and your code should verify it using the signing secret for that endpoint, which starts whsec_.

Two details that often go wrong:

  • Verification needs the raw request body, exactly as Stripe sent it. If the framework parses the body as JSON first, verification fails, and the tempting fix is to switch verification off.
  • Test mode and live mode have different signing secrets. Moving to live means a new whsec_ value in your server settings.

Ask: "Show me the line that verifies the Stripe signature, and what happens if it fails." It should reject the request.

5. What happens if the same message arrives twice?

Stripe can send the same event more than once, and doesn't promise to send events in order. If it can't reach your server, it keeps retrying for up to three days in live mode. So your fulfilment has to be safe to run twice for the same payment: no second order, no second credit, no second welcome email.

Stripe's docs suggest recording which event IDs, or which checkout sessions, you've already handled, and skipping any you've seen.

6. Can a user mark themselves as paid?

This one is easy to miss in apps built on Supabase. Say paid status lives in a column such as plan or is_paid on the user's profile. If the database rules let users update their own profile row, which is common so they can change their name, then a user may be able to set that column themselves from the browser and skip paying altogether.

Paid status should only ever be written by your server, after a verified webhook. Check the update rules on any table that holds it. Checking row level security in Supabase explains how to read those rules.

Test it before you go live

In test mode, with made-up details:

  1. Buy something using Stripe's test card 4242 4242 4242 4242, any future expiry date and any three-digit security code. Check the order is marked as paid.
  2. Start a checkout and close the tab before paying. Nothing should be granted.
  3. Type the success page address in directly without paying. Nothing should be granted.
  4. Use Stripe's own test cards for a declined payment and check the app says so clearly.
  5. If you have the Stripe command-line tool, stripe listen forwards test webhooks to your machine, and you can resend an event from the Stripe dashboard to see whether it gets handled twice.

Stripe's go-live checklist is worth working through before you switch keys.

When to get it checked

If you couldn't get clear answers above, or a test turned up something odd, fix it before real money moves. Payment webhooks are part of the Launch Check described on the code audit for AI-built software page, along with keys exposed to the browser and who can change which records. It reads the code and configuration and tests on made-up accounts. It isn't a penetration test, and it isn't a guarantee that nothing is wrong. For the other checks worth doing before launch, see what to pay to get your Lovable app reviewed.

Official documentation

Share