Payments foundations
Who is who in a payment, which methods customers use around the world, what happens between 'Pay' and money in the bank, and how to make your first safe API calls in a sandbox.
- Level
- Beginner
- Modules
- 5
- Lessons
- 10
- Price
- Free
What you will learn
- Explain the roles of gateway, processor, acquirer, issuer, card scheme, PSP and merchant of record
- Choose sensible payment methods for a given country and customer type
- Describe the payment lifecycle: authorization, capture, clearing, settlement, refunds and chargebacks
- Authenticate against a payment API with keys or OAuth without leaking secrets
- Run end-to-end test payments in a sandbox and know what sandboxes do not prove
Module 1: Gateways, processors and who holds the money
Map the parties in a card and a mobile-money payment, and see where your business sits.
The four-party card model
Every card payment involves at least four parties. The cardholder pays, the issuer (their bank) approves, the merchant sells, and the acquirer (the merchant's bank or licensed institution) receives funds on the merchant's behalf. The card scheme (Visa, Mastercard, and domestic schemes such as RuPay or Verve) connects issuers and acquirers and writes the rules.
Between you and the acquirer sit technical services:
- A payment gateway collects payment details securely and forwards authorization requests.
- A processor moves the messages to and from the network.
- A PSP bundles gateway, processing, acquiring partnerships, local methods and reporting into one contract.
In practice most developers integrate one PSP (Stripe, Adyen, Paystack, Flutterwave…) and never talk to an acquirer directly. Knowing the layers still matters: a decline usually comes from the issuer, a delayed payout from settlement rules, and a fee line from interchange.
Merchant accounts, PayFacs and merchants of record
To accept cards you need a merchant account (a merchant ID under an acquirer). Small businesses usually get one *indirectly*: the PSP or a payment facilitator boards you as a sub-merchant under its master account. That is why sign-up takes minutes — and why the provider can hold funds if your risk profile changes.
A merchant of record (MoR) goes one step further: it legally *sells* your product to the customer, so it handles sales tax/VAT, refunds and chargebacks, and appears on the customer's statement. You trade a higher fee for less compliance work.
### Mobile money is different
With mobile money (M-Pesa, MTN MoMo, Airtel Money) there is no card scheme. You contract with the operator for a till/paybill/collection account, or with an aggregator that already has one, and the operator's API is the network. Each operator and country has its own onboarding and API.
Exercise: Draw the money map
Pick one real business you know (a local shop selling online, or a SaaS). Draw two diagrams: a card payment and a mobile-money or bank-transfer payment. Label every party, where the customer authenticates, and which company pays the merchant.
Module 2: Payment methods around the world
Cards, wallets, mobile money, bank transfers and real-time rails — and why local methods win.
Cards and digital wallets
Cards are global, support refunds and recurring charges, and carry consumer protection via chargebacks. They also carry the highest cost and the heaviest compliance (PCI DSS, 3-D Secure in markets with SCA).
Digital wallets come in two kinds:
- Pass-through wallets (Apple Pay, Google Pay) carry a tokenized card — they ride on your card integration and often raise approval rates.
- Stored-value wallets (PayPal, GCash, GrabPay, Alipay) hold balances and need their own integration or a PSP that supports them.
Buy now, pay later (BNPL) providers such as Klarna or Afterpay appear as another checkout option: the shopper pays in instalments, you are paid upfront minus a higher fee.
Rule of thumb: if your customers are mostly abroad or in card-heavy markets (Europe, North America, Oceania), cards and pass-through wallets cover most demand.
Mobile money, bank transfers and real-time rails
In much of Africa, mobile money is the default way to pay. Customers approve a prompt on their phone (STK Push for M-Pesa, *request to pay* for MTN MoMo) or dial a USSD code. Payments are near-instant but asynchronous: your server learns the result via a callback.
Elsewhere, account-to-account (A2A) payments over real-time payment systems are booming:
- Pix (Brazil) and UPI (India) — QR or alias based, extremely popular, low or zero merchant cost.
- SEPA Instant (euro), Faster Payments (UK), FedNow (US) — instant bank transfers, often via open banking 'pay by bank'.
- Direct debit (SEPA, Bacs) — pull payments under a mandate, good for recurring bills.
Choosing methods is a *market* decision first, a technical decision second. Look at what customers in your country actually use.
Exercise: Method mix for three markets
For Kenya, Brazil and Germany, list the top payment methods you'd offer an online store and justify each with one sentence. Then use the Payment Intelligence recommender with each country to compare against your list.
Module 3: The payment lifecycle
From 'Pay' to settled funds — and the ways a payment can go backwards.
Authorize, capture, clear, settle
A card payment is not one event; it is a sequence:
- Authorization — the issuer approves and places a hold on funds.
- Capture — the merchant confirms it wants the money (immediately, or later when goods ship).
- Clearing — captured transactions are exchanged between acquirer and issuer, with fees calculated.
- Settlement — money moves; your PSP pays out to your bank account net of fees.
Online shops selling digital goods usually auth-and-capture in one step. Hotels, rentals and marketplaces authorize first and capture later. Uncaptured authorizations expire, so capture within the window your provider documents.
Mobile money and instant bank transfers collapse these steps: the customer pushes funds, and the payment is final when it succeeds. Settlement to your bank may still be scheduled.
Voids, refunds, reversals and chargebacks
Payments go backwards in four different ways — use the right one:
- Void — cancel an *uncaptured* authorization. Fast, often free, the hold disappears.
- Refund — you send money back for a captured payment. Full or partial; takes days on cards.
- Reversal — a system-level undo (e.g. after a timeout, or an operator reversal in mobile money).
- Chargeback — the *customer's bank* takes money back after a complaint. You may contest it with evidence in a dispute.
Good refund policies and clear descriptors (the business name on statements) prevent many chargebacks. Mobile-money refunds often need a separate disbursement call rather than a one-click refund — check each provider.
Exercise: Lifecycle timeline
Write a timeline for an order of a physical product paid by card: checkout → shipped 2 days later → one item returned 10 days later. For each step, write the API operation (authorize, capture, refund…) and the state of the customer's funds.
Module 4: Payment APIs and authentication
What payment APIs look like and how to call them without leaking secrets.
Anatomy of a payment API
Most modern payment APIs are REST + JSON over HTTPS. A typical flow:
- Your server creates a payment/order/session: POST /payments { amount, currency, reference }.
- The customer completes it on a hosted page, an SDK component or their phone.
- The provider notifies you via a webhook (callback) with the final status.
No-code options exist too: a payment link is a provider-hosted page you can share by email or chat — useful before you build anything.
Amounts are usually in the currency's minor unit (cents, kobo) as integers — never floats. Every payment should carry your own reference (order id) so you can match it later.
### Why the server, not the browser?
Anything in the browser can be edited by the user. The amount, currency and order must be decided server-side, and secret keys must never reach the frontend. The frontend only gets a publishable key, a client secret, or a redirect URL.
API keys vs OAuth tokens
Providers authenticate your server in two common ways:
- Secret API key sent on each request (e.g. Authorization: Bearer sk_test_…). Simple; must be kept server-side and rotated.
- OAuth 2.0 client credentials — you exchange a consumer key/secret for a short-lived access token, cache it, and refresh before expiry. Safaricom Daraja and MTN MoMo work this way.
Secrets belong in environment variables or a secrets manager, never in git, mobile apps or frontend bundles. Use separate keys for sandbox and live, and restricted keys where providers support them.
See the OAuth 2.0 specification (RFC 6749) for the underlying protocol.
Exercise: Token cache
Write (in any language) a small function `getAccessToken()` for an OAuth client-credentials API that caches the token in memory and refreshes it 60 seconds before expiry. Read the client id and secret from environment variables.
Module 5: Sandboxes and your first test payment
Use test environments well — and know what they cannot tell you.
Working in a sandbox
A sandbox is a copy of the provider's API with fake money. It has its own keys and base URL, plus test data: test card numbers that succeed or decline, test phone numbers or shortcodes for mobile money.
To receive webhooks locally, expose your dev server through a tunnel or use the provider's CLI/webhook tester, and register that URL in the sandbox dashboard.
Test the unhappy paths on purpose: declines, insufficient funds, the customer cancelling the STK prompt, timeouts and duplicate webhooks.
From sandbox to live
Going live usually requires business verification (KYB): registration documents, tax ids, director IDs, a website with policies. Plan for days or weeks, not minutes, especially for mobile-money operators.
Sandboxes are not production. Callback timing, rate limits, error messages and even field formats can differ. Before launch:
- Swap keys and base URLs via configuration, not code edits.
- Run a few small live payments and refunds end-to-end.
- Confirm settlement reaches your bank and reconciles with your records.
Exercise: First sandbox payment
Create a sandbox account with any provider that has a guide on Payment Intelligence. Make one successful and one failed test payment and capture the webhook payloads for both.