Sub topic 2
Who takes part in a card payment
This chapter assumes you know basic HTTP APIs, relational database concepts such as transactions and unique constraints, and how timeouts and retries behave in distributed systems. You do not need prior payments knowledge. Here you learn who the parties in a card payment are, what each one owns, and which parts of your design depend on that.
Why the actors matter to a designer
A card payment is not one call to one bank. It crosses several organizations, each with its own systems, failure modes, and records. Your service is one link in that chain, so most design questions reduce to a few things:
- Which party decides the outcome?
- Which party can fail or time out?
- Which party's records must your records match?
If you can't name these parties, you can't reason about retries, refunds, or reconciliation later in this tutorial.
The four-party model
Card payments follow what the industry calls the four-party model. The parties are the merchant, the acquirer, the card network, and the issuer. Two more parties sit around that core: the cardholder, and the payment service provider (PSP) that most merchants use.
| Party | What it is | What it owns |
|---|---|---|
| Cardholder | The person paying with a card | The card and the decision to pay |
| Merchant | The business selling goods or services | The order, the price, and the customer relationship |
| PSP | A company that gives merchants one API to accept payments | The merchant-facing API, tokenization, routing, and often the merchant's ledger and payouts |
| Acquirer | A bank or licensed processor that holds the merchant's account | The merchant's settlement account, plus the merchant's contract with the card network |
| Card network | A scheme such as Visa or Mastercard | The rules, message formats, and routing between acquirers and issuers |
| Issuer | The bank that issued the customer's card | The customer's credit line or balance, and the approve or decline decision |
Two points are easy to get wrong:
- The acquirer serves the merchant and the issuer serves the cardholder. The card network sits between them.
- The issuer, not your system and not the network, decides whether a payment is approved.
Where your system sits
The tutorial's system accepts payments on behalf of merchants, so you are building the PSP. In practice the PSP does these jobs:
- It exposes the payment API that merchants call.
- It tokenizes card data so merchants never handle raw card numbers.
- It chooses which acquirer to send each payment to.
- It records every state change in its own ledger.
- It tells merchants about outcomes through webhooks.
- It reconciles its records against reports from acquirers.
Some PSPs are also the acquirer. Others connect to several acquirers and choose among them. This tutorial assumes the second case, since it creates the more interesting design problems. The routing chapter returns to it.
Some setups blur these roles. A payment facilitator, for example, sub-contracts merchants under its own acquiring relationship. The roles stay the same, but a different company may play each one.
How one payment travels
When a customer pays, a request travels from the merchant through each party and a response travels back. Here is the path for a single authorization request:
- The merchant calls your PSP API with a card token, an amount, and a currency.
- Your PSP adds routing information and sends the request to the chosen acquirer.
- The acquirer forwards it to the card network.
- The network looks up the issuer from the card number's leading digits and forwards it there.
- The issuer checks the balance, the card status, and its own fraud rules, then answers.
- The answer returns along the same path.
The next chapter covers what authorization, capture, and settlement mean. For now, notice that a payment passes through at least four network hops, each of which can time out. This is why the idempotency and retry chapters matter.
Who gets paid what
The merchant does not receive the full amount. Each party takes a fee. The figures below are illustrative only, because real rates vary by card type, region, and contract.
| Party paid | Fee type | Illustrative amount on a 100.00 USD sale |
|---|---|---|
| Issuer | Interchange fee | 1.80 |
| Card network | Scheme fee | 0.15 |
| Acquirer | Acquirer markup | 0.20 |
| PSP | PSP fee | 0.35 |
| Merchant | Receives the remainder | 97.50 |
The sum of fees here is 2.50, which leaves 97.50. A fee breakdown like this is one reason your ledger needs several accounts rather than a single "merchant balance" number. It is also why the amount an acquirer settles to you usually differs from the sum of captured payments.
References each party gives you
Every party identifies the same payment differently. If you store only your own payment ID, you cannot match a later settlement report or answer a dispute. Save each external identifier when it arrives.
from dataclasses import dataclass
from typing import Optional
@dataclass(frozen=True)
class ExternalReferences:
"""Identifiers other parties assign to one payment."""
acquirer_reference: Optional[str] = None # acquirer's own transaction ID
network_transaction_id: Optional[str] = None # assigned by the card network
issuer_auth_code: Optional[str] = None # present when the issuer approved
issuer_response_code: Optional[str] = None # "00" means approved
def is_issuer_decline(refs: ExternalReferences) -> bool:
"""A decline is a valid business outcome, not a system error."""
return refs.issuer_response_code not in (None, "00")
refs = ExternalReferences(
acquirer_reference="acq-8841",
network_transaction_id="NET123456789",
issuer_response_code="51", # insufficient funds in ISO 8583 style codes
)
print(is_issuer_decline(refs)) # TrueTreat the response code as data you store, not as an exception. A decline means the payment worked as designed, and the issuer said no.
Design consequences
Knowing the actors leads directly to design rules you will use in later chapters:
- Outcomes live outside your system. You do not decide approvals. Your database records what other parties said, and a timeout means you do not know the outcome yet.
- Each hop adds a failure mode. A timeout between your PSP and the acquirer is different from a timeout between the merchant and your PSP. Log which hop failed.
- Identifiers are evidence. Keep your payment ID, the merchant's idempotency key, and every external reference together.
- Trust boundaries are sharp. Merchants, acquirers, and networks are separate organizations. Validate everything crossing your boundary and authenticate every callback.
- Money moves in more than one place. The customer's bank, the acquirer, your PSP, and the merchant each hold balances at different times. A ledger tracks that.
Common mistakes
- Confusing the issuer and the acquirer. The issuer serves the cardholder, and the acquirer serves the merchant.
- Assuming the PSP and acquirer are always the same company. Many PSPs use several acquirers.
- Storing only your own IDs, which makes reconciliation and dispute handling very hard later.
- Showing raw issuer codes to customers. Map them to safe messages, because some codes hint at fraud rules.
Exercise
A merchant calls your PSP to charge a card. Your PSP forwards the request to its acquirer, which times out after sending it to the card network. Which party decides whether the payment is approved, and what should your PSP record about the outcome?
Show answer
The issuer decides, because it holds the cardholder's account. After the timeout the outcome is unknown, so the PSP should record the payment as pending or unknown rather than failed, keep the idempotency key and any references received, and resolve it later by retrying safely with the same key or querying the acquirer.
Exercise
Name the four parties in the four-party model, and say which one the PSP usually connects to directly.
Show answer
The merchant, the acquirer, the card network, and the issuer. The PSP usually connects directly to the acquirer, or to several acquirers, and reaches the network and issuer through them.