Skip to main content
Three Ways a Credit Purchase Quietly Goes Wrong
paymentsidempotencywebhooks+3

Three Ways a Credit Purchase Quietly Goes Wrong

If customers buy credits or top-ups, here's how purchases get under-charged, double-granted, or silently lost — and what to insist your checkout does to prevent it.

The money bugs you don’t see until a customer emails you

If your product sells credits, tokens, top-ups, or any kind of prepaid balance, there are three ways a purchase can go wrong without anyone noticing at the moment it happens:

  • Under-charged — the customer pays less than the real price because the price was decided on their device, not yours.
  • Double-granted — the balance goes up twice for one payment, because two systems both reported the same purchase.
  • Silently lost — the customer’s phone dies right after paying, the confirmation never reaches your app, and the credits never land.

None of these throw an error in front of you. They show up later as a support ticket, a reconciliation mismatch, or quietly as lost revenue you never attribute to anything. We build checkout and credit systems, and this is the part we treat as non-negotiable. Here’s what actually protects you — in plain terms, plus the one or two technical details where the decision really turns.

The price is yours, not the customer’s

The first rule is simple: the only price that counts is the one your server computes. The customer’s browser or app can ask to buy something, but it should never get to say what that something costs. If the amount is sent up from the client and trusted, a user can edit it before it leaves their device and pay whatever they like.

So when you’re reviewing how your checkout works, the question to ask whoever built it is: where does the charged amount come from? If the answer involves a number that originated on the client, that’s a hole. The price should be looked up server-side at the moment of purchase, and the payment provider should be told that amount — never the other way around.

“The payment succeeded” is a claim, not a fact

When a payment finishes, your app usually hears about it from the customer’s device: a callback that says done, it worked. That message cannot be trusted on its own, because it comes through the customer. It can be faked, replayed, or simply wrong.

The durable approach is to verify every payment server-to-server against a secret the customer never has — and to rely on the provider’s webhook, a message the payment provider sends directly to your server, as the authoritative confirmation.

There’s one detail here that quietly breaks real systems, and it’s worth knowing because it decides whether verification works at all. A webhook is signed, and you check that signature to prove it’s genuine. The signature must be checked against the exact raw bytes the provider signed — not against your own code’s parsed-and-re-saved version of the message. Re-saving JSON can reorder its fields, and that alone makes a valid signature look invalid. If your verification occasionally rejects legitimate payments for no obvious reason, this is a prime suspect. Ask your team: are we verifying the raw request body, or a reserialized copy?

Design for the message arriving twice — or out of order

Here’s the situation that causes both double-grants and lost purchases: two independent sources can confirm the same payment. The customer’s device sends a callback, and the provider sends a webhook. Either can arrive first. Either can arrive twice. Either can fail to arrive at all.

You can’t control which shows up or in what order, so the system has to be built to handle all of it and still land in exactly one outcome: the credits are granted once. Not zero times if the phone dies, not twice if both messages arrive.

The mechanism that guarantees this is an idempotent write — an operation that has the same effect whether it runs once or five times — backed by a database constraint that physically forbids granting the same purchase twice, with both done in a single transaction alongside the balance update. If the first confirmation already granted the credits, the second one hits the constraint and changes nothing. If the phone died before any callback, the webhook still arrives and grants them. Exactly once, regardless of order or duplication.

What to actually ask for

You don’t need to audit the code to know whether your checkout is safe. Three questions do most of the work:

  1. Does the server set the price, or does it trust a number from the client?
  2. Is every payment confirmed server-side against a secret the customer can’t see — and is the webhook signature checked against the raw bytes?
  3. If the same payment is confirmed twice, or the confirmation never arrives, does the customer end up with exactly the right balance?

If the answers are fuzzy, that’s the gap. Money systems don’t get a grace period — the first person to find the gap is either a confused customer or someone who’s happy to exploit it.

Have a project in mind?

Fixed price after a paid discovery — no hourly billing. A real engineer reads every enquiry, and we reply within 24 hours.