Flow of the explanation in this lesson.
Gateway APIs
What you will learn
Your objective. By the end of this lesson, you will be able to explain gateway APIs. A gateway REST API is a set of secure web endpoints that a merchant system calls to create payments, check status and issue refunds.
Why it matters. This matters because the architecture decides what the bank can build, how fast it can change, and where a payment can fail. Most payment requirements live in the architecture.
Chapter objective: Learner explains payment gateway architecture, including checkout, token vault, routing, retries, and settlement, and designs a gateway flow for an online merchant. Learner practises this skill on realistic banking cases, explaining the reasoning clearly and using correct terminology throughout the work.
Key learning points
- Gateway REST API
- Payment initiation
- Merchant stores the payment_id and maps it
- Robust merchant system polls the status endpoint
- Partial refund balance
- Merchant sends a different key
Key terms
Idempotency: The property that repeating the same request has the same effect as sending it once. In payments, an idempotency key lets a client safely retry a request after a timeout without creating a duplicate...
3D Secure: A security protocol that adds an authentication step to online card payments, usually by asking the cardholder to confirm the payment with their bank.
Acquirer: A bank or licensed institution that processes card payments for merchants and receives transaction funds from card schemes on their behalf.
Banking architecture diagram showing Gateway APIs.
Practise this lesson
Exercise
Map the payment in this lesson through the hub components.
Use the hub components and their order in this lesson.
- What to do. List each component the payment passes through, what it does, and what happens if it fails.
Correct result. The payment enters through a channel, passes the gateway, validation, fraud and sanctions checks, routing, and the ledger, then leaves through the right clearing system. A failure at any component stops or holds the payment, and the hub must record where it stopped.
Why. The hub is where most payment requirements live. If you cannot map a payment through it, you cannot specify, test or fix it.
Check your understanding
Practice question
A merchant wants to accept payments in three countries with different acquirers. A developer proposes a separate integration for each acquirer. What is the alternative, and when is it better?
Takeaway and next step
What to remember
A robust merchant system polls the status endpoint or waits for a webhook, and never ships goods on the basis of a browser redirect alone, since a redirect can be faked or interrupted.
Call the API described in this lesson with a valid request, then with a missing field, and compare the responses.
Builds on "Gateway Services".
Transcript and full text
Show transcript
A gateway REST API is a set of secure web endpoints that a merchant system calls to create payments, check status and issue refunds. Requests use HTTPS with an API key or OAuth token in the authorization header, and responses return JSON, which is a structured text format that programs can read easily. A typical base address looks like https://api.examplegateway.com/v1, and each operation has its own path, such as POST /v1/payments for creating a payment, GET /v1/payments/{payment_id} for checking status, and POST /v1/payments/{payment_id}/refunds for refunding it. The gateway validates the API key, the request format and the merchant account before it processes anything, and returns a clear error code when a required field is missing. Payment initiation is the first call, and it carries everything the gateway needs to authorize the transaction. A request includes merchant_id, order_id, amount, currency, payment_method, card token or card details, customer email, billing address and a return URL for redirect flows. For example, a request for order ORD-78412 might carry amount 499900, which represents 4,999 rupees in paise, currency INR, payment_method card, and card token tok_8f3k2m9q. The gateway responds with a payment_id such as pay_N8d2kL4m, a status such as authorized or failed, an authorization code, and a redirect URL when 3D Secure authentication is required. The merchant stores the payment_id and maps it to the order, because every later call uses that identifier. A status check lets the merchant confirm what really happened, even when the customer closes the browser or the network drops. The merchant calls GET /v1/payments/pay_N8d2kL4m and receives the current status, which may be created, authorized, captured, failed, refunded or partially refunded, plus the amount captured, the amount refunded, the acquirer reference number, and the time of the last update. This call is essential after a timeout, because the customer may have been charged even though the checkout page showed an error. A robust merchant system polls the status endpoint or waits for a webhook, and never ships goods on the basis of a browser redirect alone, since a redirect can be faked or interrupted. The refund API returns money to the customer, in full or in part, and it must be handled with the same care as a payment. A refund request includes the payment_id, the refund amount in the smallest currency unit, a refund reason such as duplicate charge or product returned, and a unique refund reference. The gateway checks that the refund amount does not exceed the captured amount, sends the refund to the acquirer, and returns a refund_id such as rfd_7Qw2xP9z and a status of processed or pending. A refund of 1,200 rupees against a 4,999 rupee order leaves a remaining refundable balance of 3,799 rupees. The customer usually sees the credit in three to five working days, depending on the issuing bank. Idempotency keys are the safety net that stops duplicate charges when a request is retried. The merchant generates a unique key for each logical operation, for example idem_ORD-78412_01, and sends it in a header called Idempotency-Key with the original request. If the network fails and the merchant resends the same request with the same key, the gateway recognizes the key and returns the original response instead of creating a second payment. If the merchant sends a different key, the gateway treats it as a new payment. This matters most during retries, timeouts and failover, where the same payment can be attempted twice through no fault of the customer, and the key is what keeps one order from becoming two charges.
A gateway REST API is a set of secure web endpoints that a merchant system calls to create payments, check status and issue refunds. Requests use HTTPS with an API key or OAuth token in the authorization header, and responses return JSON, which is a structured text format that programs can read easily. A typical base address looks like https://api.examplegateway.com/v1, and each operation has its own path, such as POST /v1/payments for creating a payment, GET /v1/payments/{payment_id} for checking status, and POST /v1/payments/{payment_id}/refunds for refunding it. The gateway validates the API key, the request format and the merchant account before it processes anything, and returns a clear error code when a required field is missing.
Payment initiation is the first call, and it carries everything the gateway needs to authorize the transaction. A request includes merchant_id, order_id, amount, currency, payment_method, card token or card details, customer email, billing address and a return URL for redirect flows. For example, a request for order ORD-78412 might carry amount 499900, which represents 4,999 rupees in paise, currency INR, payment_method card, and card token tok_8f3k2m9q. The gateway responds with a payment_id such as pay_N8d2kL4m, a status such as authorized or failed, an authorization code, and a redirect URL when 3D Secure authentication is required. The merchant stores the payment_id and maps it to the order, because every later call uses that identifier.
A status check lets the merchant confirm what really happened, even when the customer closes the browser or the network drops. The merchant calls GET /v1/payments/pay_N8d2kL4m and receives the current status, which may be created, authorized, captured, failed, refunded or partially refunded, plus the amount captured, the amount refunded, the acquirer reference number, and the time of the last update. This call is essential after a timeout, because the customer may have been charged even though the checkout page showed an error. A robust merchant system polls the status endpoint or waits for a webhook, and never ships goods on the basis of a browser redirect alone, since a redirect can be faked or interrupted.
The refund API returns money to the customer, in full or in part, and it must be handled with the same care as a payment. A refund request includes the payment_id, the refund amount in the smallest currency unit, a refund reason such as duplicate charge or product returned, and a unique refund reference. The gateway checks that the refund amount does not exceed the captured amount, sends the refund to the acquirer, and returns a refund_id such as rfd_7Qw2xP9z and a status of processed or pending. A refund of 1,200 rupees against a 4,999 rupee order leaves a remaining refundable balance of 3,799 rupees. The customer usually sees the credit in three to five working days, depending on the issuing bank.
Idempotency keys are the safety net that stops duplicate charges when a request is retried. The merchant generates a unique key for each logical operation, for example idem_ORD-78412_01, and sends it in a header called Idempotency-Key with the original request. If the network fails and the merchant resends the same request with the same key, the gateway recognizes the key and returns the original response instead of creating a second payment. If the merchant sends a different key, the gateway treats it as a new payment. This matters most during retries, timeouts and failover, where the same payment can be attempted twice through no fault of the customer, and the key is what keeps one order from becoming two charges.
Full lesson text (all scenes)
Completing a lesson updates your progress dashboard on the homepage.
Scene timestamps are estimated by allocating the narration text proportionally across the real audio length. The audio playback position is the source of truth: pause freezes the visual, seeking restores the correct scene, replay restarts the scene animation.