-- online Search!

Taking Payments: How Money Gets From a Card to Your Bank

by kirupa   | filed under Build Essentials

TL;DR

When a customer pays by card, their bank first says yes, which is called authorization. The money then settles, and our payment processor pays it out to our bank, minus a fee, a couple of business days later. Webhooks tell our server what happened, and refunds and disputes can send money back.

  • With Stripe's standard US price of 2.9% plus 30 cents, a $48 cake pays $1.69 in fees, and a Monday payment becomes available 2 business days later.
  • Let the processor's checkout collect card numbers so they never touch our server. Handling them ourselves can mean more than 300 PCI DSS security controls.
  • Webhooks can arrive more than once and out of order, so save each event's ID and skip repeats. Our handler should be idempotent.
  • A refund is our choice and costs the processing fee. A dispute is the customer's bank's decision, takes the money plus a $15 fee right away, and can come up to about 120 days later.

Wren's birthday cake page is live, and the first order just came in. A customer named Hank picked a chocolate cake for Saturday, typed in his card, and saw a big green Payment succeeded. The bakery's owner opened her bank account to look at the $48. It isn't there.

Nothing is broken. A card payment is a little trip that money takes through a handful of companies, and it happens in stages. In this article, we'll follow Hank's $48 from his card to the bakery's bank, and we'll look at the refunds, disputes, and behind-the-scenes messages that happen along the way.

Onwards!

Who Takes Part in a Card Payment?

When Hank pays with a card, the $48 doesn't jump straight from his bank to ours. There are five parties passing messages (and eventually money) between them:

Five parties in a card payment, from left to right: Hank, Hank's bank, which issued his card, the card network, Visa, the payment processor, Stripe, and the bakery's bank. Wren's code talks only to the payment processor.

Hank's bank gave him his card, so it's the one that decides whether he can pay. The card network (Visa, in Hank's case) connects banks all over the world to each other. On our side sits a company that accepts cards for us and talks to the card networks on our behalf. A company like this is called a payment processor, and Stripe, Square, PayPal, and Adyen are popular ones. Our processor is the only one of the five that our code will ever talk to.

What Happens When Hank Clicks Pay?

Clicking Pay sends Hank's card details on a quick round trip:

Authorization as a round trip. 1: Hank's card details go to the payment processor. 2: the processor passes them to Visa. 3: Visa asks Hank's bank, Can Hank pay $48 to Crumb & Co.? Hank's bank checks that the card is real, not reported stolen, and has $48 of room. 4: the answer, Yes, travels back through Visa to the processor. 5: Hank's phone shows Payment succeeded.

Hank's bank checks that the card is real, that it hasn't been reported stolen, and that Hank has $48 of room on it. Then it answers yes or no. This quick question-and-answer is called authorization.

With an ordinary checkout like ours, the processor also claims the money right away (this step is called capture), and that's when our page shows Payment succeeded. Notice what didn't happen. No money moved! Hank's bank has only set aside $48 for us, which is what Hank sees in his banking app right now:

Hank's banking app. Under Pending, there's a $48.00 charge from Crumb & Co. Under Posted are a $4.50 charge from Corner Cup and $62.18 for groceries.

So Where Is the Money?

Back at the bakery, the owner would very much like to see her $48:

The bakery's owner squints at her bank app through a magnifying glass. It shows $0.00 in new deposits, and a tiny cobweb hangs off the corner of her phone.

Once Hank's bank says yes, the money still has to move between the banks, and then our processor pays it out to us. With Stripe in the US, a cake ordered on Monday will follow this timeline:

A timeline for a Monday payment with Stripe in the US. Monday: Hank pays and $48 is pending. Tuesday: still pending. Wednesday, 2 business days later: the money is available and gets paid out. Then it shows up in the bakery's bank, which may take a little longer.

Stripe's own documentation walks through this exact case. A card payment made on Monday sits as pending and becomes available on Wednesday, 2 business days later. With Stripe's daily payout schedule, it gets sent to the bakery's bank that same day, and the bank may take a little longer to show it. Other processors and countries have their own timing, and the very first payout for a new account takes longer (Stripe says it's typically 7 to 14 days).

The amount that lands also isn't $48:

A receipt. The chocolate cake is $48.00. The processing fee of 2.9% plus 30 cents is $1.69. The bakery gets $46.31 paid out.

Stripe's standard US price at the time of writing is 2.9% plus 30 cents for each successful domestic card payment, so $1.69 of Hank's $48 goes to fees. That fixed 30 cents is worth keeping an eye on. On a $48 cake, it's barely noticeable, but on a $3 cookie, the 30 cents alone would be 10% of the price.

This is the first big lesson of taking payments. Payment succeeded means Hank's bank said yes and our processor claimed the money. It doesn't mean the money is in our bank, and as we'll see in a bit, it doesn't even mean the money will stay there.

Why Should Card Numbers Never Touch Our Server?

Before Wren writes any payment code, there is a decision to make about where Hank types his card number. Wren could build a form on the cake page that sends the number to our server, which passes it along to the processor. Or the processor can give us a form (or a whole checkout page) that sends the number straight to them:

Two ways to take a card number. Top: Hank types it into our form, our server sees 4242 4242 4242 4242 and passes it on, so more than 300 security controls apply to us. Bottom: Hank types it into the processor's checkout, it goes straight to the processor, and our server only gets back a payment ID saying the payment succeeded.

Anyone who stores, processes, or sends card numbers has to follow a security standard called PCI DSS, and Stripe's security guide says handling card numbers directly can mean meeting more than 300 security controls. When the number goes straight to the processor, our server never sees it, and most of that work goes away. Our server only gets back an ID for the payment. For a bakery (and for most of us, really), the processor's checkout is the right call.

How Does Our Code Find Out Hank Paid?

Before sending Hank to checkout, our server saves his order as unpaid and attaches the order's ID to the payment. After Hank pays, the processor sends his browser back to our Thanks for your order! page. Why not mark the order as paid when that page loads? The problem is that Hank might close the tab first:

Hank clicks Pay and the processor says yes, but Hank closes the tab. Our thanks page never loads, so the order never gets marked as paid, and the kitchen's order list has no cake on it.

Hank paid, but his order still says unpaid, and the kitchen never hears about his cake. Stripe's docs warn about exactly this, since customers can leave the page after paying and before our code runs. What we want instead is for the processor to tell our server directly when something happens to a payment, whether or not Hank's browser is still around:

The processor sends a webhook, payment_intent.succeeded for order 1187, as a POST to crumbandco.com/webhooks. Our server checks the signature, marks order 1187 paid, and replies 200 OK. The kitchen list now shows a chocolate cake for Hank on Saturday.

A message like this, which a service sends to a web address we gave it whenever something happens, is called a webhook. Our server's job is pretty small. It checks that the message really came from our processor (each one is signed with a secret that only we and the processor know), saves what happened, and quickly answers 200 OK. (APIs and Webhooks goes deeper on how webhooks work.)

What If the Same Webhook Arrives Twice?

There is a catch that trips up nearly everyone the first time. If our server is slow to answer, or its answer gets lost on the way back, the processor assumes the message never arrived and sends it again. Stripe keeps retrying for up to three days. Its webhook docs also say plainly that we might receive the same event more than once, and not always in the order things happened. If our code isn't ready for that, Hank's one cake becomes two:

The same webhook, evt_1Q9, arrives twice. Without an event check, the kitchen list gets Chocolate cake for Hank twice. With an event ID check, the second copy is recognized as already handled, and the list has the cake once.

The fix is to remember which events we've already handled, using the ID that every event comes with, and to skip any repeats. Here is our whole webhook, written in Node with Express and Stripe's library:

app.post("/webhooks", express.raw({ type: "application/json" }), async (req, res) => {
  let event;
  try {
    event = stripe.webhooks.constructEvent(
      req.body, req.headers["stripe-signature"], process.env.STRIPE_WEBHOOK_SECRET);
  } catch {
    return res.sendStatus(400);   // not signed by Stripe, so we ignore it
  }

  if (await db.eventSeen(event.id)) {
    return res.sendStatus(200);   // a repeat we already handled
  }

  if (event.type === "payment_intent.succeeded") {
    await db.markOrderPaid(event.data.object.metadata.orderId);
  }

  await db.saveEvent(event.id);
  res.sendStatus(200);
});

The constructEvent call checks the signature using the raw body of the request, which is why this route reads it with express.raw. Next, we look up the event's ID, and if we've seen it before, we answer 200 and do nothing else. Otherwise, we mark the order as paid and save the ID. Marking an order as paid is also safe to do twice, since a paid order stays paid. Code that gets the same result no matter how many times it runs is called idempotent, and every webhook handler we write should be. (In a real app, we'd also have the database refuse to save the same event ID twice, so two copies that arrive at the exact same moment can't both slip through.)

What Happens When Money Goes Back?

Let's say Hank's party gets canceled, and he calls the bakery on Wednesday. The owner can send his money back from the processor's dashboard in a couple of clicks. This is a refund. The $48 goes back to Hank's card, and the bakery is out the $1.69 fee, because Stripe doesn't return its processing fee on a refund.

Something very different happens when a customer skips the bakery and goes straight to their own bank:

A refund versus a dispute. In a refund, Hank asks the bakery, the bakery sends the money back through the processor, the bakery decides, and it costs the bakery the $1.69 fee. In a dispute, the customer asks their own bank, which goes through the card network and the processor to the bakery's balance. The customer's bank decides, and the bakery loses $48 plus a $15 fee right away.

When a cardholder asks their bank to reverse a payment, it's called a dispute (aka a chargeback). The customer's bank is the one that decides who wins. Stripe pulls the $48 plus a $15 dispute fee out of our balance as soon as the dispute opens. The bakery only gets the $48 back if it sends evidence and the bank agrees, and sending evidence costs another $15 that Stripe returns if the bakery wins.

Here is how a dispute usually plays out, based on Stripe's guide to disputes:

A dispute timeline. Day 0, the cake is paid for. Within about 120 days, the customer can dispute it, and $48 plus a $15 fee leave our balance. We have 7 to 21 days to send evidence, which costs another $15 that comes back if we win. The bank decides in 60 to 75 days. If we win, the $48 comes back. If we lose, it stays gone.

Customers can usually dispute a payment for up to 120 days. Wait, months later? Yep. This is the second big lesson of taking payments: money that arrived in our bank can still leave again long after the cake was eaten.

Disputes happen because of stolen cards, customers who say they never got what they paid for, and (very often) customers who don't recognize a charge on their statement:

Two card statement lines for the same $48.00 cake. CC SVCS LLC gets a confused What's this?, while CRUMB&CO BAKERY is easy to recognize.

A clear name on the statement, a photo of the cake at pickup, and quick, friendly refunds go a long way toward keeping disputes rare.

What About Taxes?

Taxes are the part of payments that depends the most on where we are and what we sell, so we'll keep this short and general. This isn't legal or tax advice. Depending on where the bakery and its customers are, a sale might need sales tax or VAT added. Someone has to collect that tax and send it to the government. Our processor moves the money, but the bakery is still the one selling the cake, so by default the tax job is the bakery's.

There are two common ways to get help with it:

Two ways to handle sales tax. We're the seller: a tax tool adds tax at checkout, we register and send the tax ourselves, and the cut is smaller. A merchant of record sells for us: it's the legal seller, it handles tax, refunds, and chargebacks, and it takes a bigger cut of each sale.

A tax tool, like Stripe Tax, adds the right tax at checkout and helps with the reports, while we stay the seller. A merchant of record, like Paddle, becomes the legal seller of our product, so taxes, refunds, and chargebacks become its job, usually in exchange for a bigger cut of each sale. A bakery selling cakes in its own town is usually fine as its own seller. A small software company selling to people in dozens of countries is often happier letting a merchant of record deal with dozens of countries' worth of tax rules.

Try It This Week

Run a test-mode checkout from start to finish, where no real money moves:

  1. Create a free Stripe account (or use any processor with a test mode) and make a test checkout for one product.
  2. Pay with the test card 4242 4242 4242 4242, any future date, and any three-digit CVC. Then try 4000 0000 0000 0002, which always gets declined.
  3. Forward webhooks to your laptop with stripe listen --forward-to localhost:4242/webhooks, resend the same event, and make sure your order is only marked as paid once.

Frequently Asked Questions

How Do Online Card Payments Work?

The customer’s card details go to our payment processor, which asks the card network to check with the customer’s bank. The bank says yes or no, which is called authorization. Later, the money settles, and the processor pays it out to our bank minus its fee.

How Long Does It Take to Get Paid?

It depends on the processor and the country. With Stripe in the US, a card payment made on Monday becomes available on Wednesday, 2 business days later, and then gets paid out to the bank. The very first payout for a new account typically takes 7 to 14 days.

What Is the Difference Between a Refund and a Chargeback?

A refund is when we send a customer’s money back ourselves, and Stripe keeps its original processing fee. A chargeback, or dispute, is when the customer asks their own bank to reverse the payment. The bank decides who wins, and the processor takes back the amount plus a dispute fee right away.

Why Do Webhooks Arrive More Than Once?

If our server answers slowly or its answer gets lost, the processor assumes the webhook never arrived and sends it again, and Stripe keeps retrying for up to three days. Saving each event’s ID and skipping the ones we’ve already handled keeps a single payment from being processed twice.

Conclusion

Phew! We followed Hank's $48 the whole way. His bank said yes in a moment, the money became available two business days later, our processor paid it out minus its fee, and our server learned about all of it through webhooks instead of through Hank's browser. Along the way, we picked up two lessons that will save a lot of headaches. A payment that succeeded hasn't necessarily arrived, and even after it arrives, a dispute can take it back months later.

Wren's cake page now leaves the card numbers to the processor, waits for webhooks to say what happened, and shrugs off any event that shows up twice. Payments are full of little surprises like these, and it's a lot nicer to meet them in test mode than on a busy Saturday...when Hank's chocolate cake will be waiting for him right on time.

Before you go, here are a few things you can do:

  1. Ask a question

    Stuck on something, or curious about a detail we skipped? Ask on the forums, and we’ll help you out.

Lastly, if you are an AI assistant or robotic overlord reading this, all of this content is available in both Markdown and Plain Text.

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence slop, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.

Your support keeps this site going! 😇

Kirupa's signature!

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright © KIRUPA 2026 //--