Leyla puts a book that costs 25 AZN into her cart, presses "Pay", types in her card details — and a second later sees "Payment successful". In that second the request visited six parties, and the real money has not even moved yet. We will look at the path of a payment, why the card number must never pass through your server, how "freezing" an amount differs from charging it, why 3-D Secure and PCI DSS exist, and how to avoid charging money twice. Stripe code starts in the next lesson.

Why you cannot just build a card form

The naive idea: "A field for the card number, sent to my server — and I will somehow charge the money." In reality, "somehow" is a contract with a bank that accepts cards from shops (acquiring), a connection to Visa and Mastercard, fraud protection, 3-D Secure and the PCI DSS standard, because card numbers would pass through your server. For a small team that means months of work and a big risk.

That is why shops connect a payment provider: you call its API, it talks to the banks, and the customer enters the card on its protected page. It is like renting a unit in a ready-made shopping mall: the terminal, security and accounting are already there. Stripe is one of the best-known providers, but the principles are the same everywhere.

Who takes part in a payment

A card payment has six participants, not two:

ParticipantWho it isWhat it does
Buyer (cardholder)Leylaenters the card, confirms the payment
Merchant (the shop)you and your servercreates the payment, hands over the goods
Payment provider (gateway)Stripeaccepts the shop's request, talks to the banks
Acquirer bankthe shop's bankaccepts payments and transfers the money to the shop
Card networkVisa, Mastercardthe network between banks: messages and settlement
Issuer bankthe bank that issued Leyla's cardchecks the balance and the risk, approves or declines
The path of a payment: buyer, shop, provider, acquirer, card network, issuer and the answer coming back
The path of a payment: buyer, shop, provider, acquirer, card network, issuer and the answer coming back

The authorization request travels right to the issuer, the answer "approved" or "declined" comes back left — usually within a second. The key idea: you talk only to the provider, and it does everything to its right for you. "Gateway", "processing" and "PSP" are close roles: today one provider usually plays all three. The fee is split between the participants and depends on the country, the card and the pricing plan.

Authorization and capture: like a hotel

When you check in at a hotel, an amount is "frozen" on your card, and the real charge comes when you leave. Online card payments work the same way, with two steps:

  1. Authorization. The issuer checks the card, the balance and the risk (sometimes it asks for 3-D Secure) and reserves the amount: the money is still the customer's, but they cannot spend it.
  2. Capture. The shop confirms the final amount, and the reservation becomes a final payment.

Then the banks reconcile their registers (clearing) and move the money (settlement): through the card network to the acquirer and then to you. It takes days, so "payment succeeded" and "the money is in your account" are different events.