DEV Community

Youngjun Yoon
Youngjun Yoon

Posted on

Payments are where AI-built apps stop: seven things to wire before launch

Every AI-built app I have finished in the last year had the same shape. The screens look right, the database reads and writes, the demo runs on a laptop. Then someone tries to pay, and the project stops.

Not because payments are hard to code. Because a payment is the first thing in the app that has to be correct in a way nobody can see from the outside: money leaves one account, lands in another, and either side can be wrong for days before anyone notices.

Here are the seven things I wire, in this order, before a build is allowed to take a real card. Most of them are one afternoon of work. All of them are the reason a launch stays quiet instead of becoming a refund week.

1. Test keys and live keys must never share a screen

The single most common state I find: the app reads STRIPE_SECRET_KEY from an environment variable, and the value in production is the test key, or the reverse — a live key sitting in a preview deployment that anyone with the URL can reach.

What I do instead:

  • A single PAYMENTS_MODE value (test or live) that the app reads once at boot, and a startup check that refuses to run if the key prefix does not match the mode.
  • A visible banner in the admin screen that says TEST when mode is test. If someone pays in test mode, staff should see it before the customer does.
  • Preview and staging deployments get the test key only. Live key exists in exactly one place.

If your app can take a live card from a preview URL, that is not a configuration detail. It is the whole problem.

2. The webhook is the source of truth, not the redirect

Success pages lie. Users close tabs, browsers lose the redirect, networks drop. The payment provider's webhook is the only statement you can build on.

Two things go wrong with webhooks constantly:

Signature verification is skipped. The endpoint accepts any POST and marks the order paid. Anyone who guesses the URL can mark orders paid for free. Verify the signature with the provider's library and reject anything that fails — including requests with no signature header.

Processing is not idempotent. Providers retry. The same checkout.session.completed arrives three times and the customer gets three months of credit. Store the provider's event id in the database with a unique constraint, and make the handler a no-op when it has already been seen.

A minimal handler looks like this in shape, whatever the stack:

1. verify signature
2. insert event_id into payments_events (unique)  -> if conflict, return 200 and stop
3. load order by provider metadata id
4. if order.status is already paid -> return 200 and stop
5. mark paid, grant entitlement
6. commit
Enter fullscreen mode Exit fullscreen mode

Steps 2 and 4 look redundant. They are not: the unique insert stops duplicate events, and the status check stops two different events describing the same payment.

3. The amount is checked against the server's own number

A cart total computed in the browser is a suggestion. Before creating a checkout session, the server recomputes the price from its own records — product id, quantity, currency, tax rules — and uses that number. If the client sends an amount, compare it and reject a mismatch rather than trusting it.

This is also where currency appears. If you sell in KRW, remember that most providers in Korea expect the amount in whole won with no decimals, while Stripe expects the smallest currency unit. A 1000 that means 1,000 won in one place and 10.00 USD in another is a real bug I have fixed twice.

4. Refunds, partial refunds and the order that is "paid but canceled"

Launch week produces refunds. Two questions decide whether they cost you an hour or a day:

  • Who can refund from where? If the only refund path is the provider's dashboard, staff will refund without the app knowing, and the customer keeps the entitlement. Either build a small refund action in the admin screen that calls the API and updates the order, or accept that someone reconciles it by hand every week.
  • What happens to access? Decide before launch: refund removes access immediately, at period end, or not at all. Any of those can be right. Not deciding means every refund becomes a conversation.

5. The receipt, the tax field and the thing your accountant will ask for

Korean customers expect a cash receipt or a tax invoice; overseas customers expect a receipt email with a VAT or GST line where their country requires one. This is not a design problem, it is a data problem: the payment record must carry the business number or tax id the customer entered, and the email that goes out must be regenerated from that record, not from the session that has already expired.

Practical minimum: store customer name, business number (optional), tax id (optional), country, and the exact amount and currency paid. When the accountant asks in February, that row is the answer.

6. The failure paths nobody tests

Before launch I run these four by hand, with a real card, once each:

  • A card that is declined. Does the user come back to a page that explains it, or to a blank screen?
  • A payment that succeeds but the webhook is delayed by 30 seconds. Does the UI say "processing" or does it say "failed" and double-charge the customer who tries again?
  • A user who pays twice in two tabs. One entitlement, or two?
  • A refund issued while the user is logged in. Does the app notice?

None of these needs new features. They need the state machine to have a pending state that is not the same as failed.

7. The boring one: an audit row for every attempt

Write a row for every checkout attempt, every webhook received, every refund, with a timestamp and the provider's id. It costs one table and saves the entire support conversation that starts with "I paid and nothing happened". When a customer writes in, you search their email and read four lines instead of guessing.

Where this fits in a short build

On a 3–5 day build, payments take one of those days: half for the happy path, half for the seven items above. Skipping the second half is how a five-day build turns into a three-week one — not because the code is hard, but because every one of these issues shows up after money has moved.

If you are finishing an AI-built app and the payment step is where it stalls, that is usually the cheapest part of the project to have someone else close. I do this from Seoul for clients in Japan, Australia, Germany and the US, in English or Japanese, at a price set for a small build rather than an agency retainer.

Three to five days, fixed scope, fixed price, and a handover document that lists every key, webhook and dashboard you will need after I am gone.

Top comments (0)