Sub topic 3
Webhooks and the Operational Edge of Payments
Assume you know HTTP, relational database transactions, retries, and basic payment states such as authorized, captured, and refunded. A payment system must handle events that arrive late, arrive twice, or never arrive.
Webhooks and asynchronous status updates
A webhook is an HTTP request sent by a payment service provider (PSP) when a payment changes. Your endpoint should verify the signature, store the event, acknowledge it quickly, and process it asynchronously.
Treat event delivery as at least once. Deduplicate using the PSP event ID, and do not assume events arrive in business order. Fetch the current payment state when an event is ambiguous.
Tokenization, encryption, and PCI DSS scope
Tokenization replaces card data with a provider token. Your system stores and sends the token instead of the card number. TLS protects data in transit, while encryption protects stored secrets and sensitive fields.
PCI DSS is a security standard for systems handling payment-card data. Hosted checkout fields or provider-hosted pages can reduce your compliance scope, but they do not remove your responsibility for access control, logging, patching, and vendor oversight.
Integrating and routing across PSPs
Put each PSP behind an adapter with a common interface for authorization, capture, refund, and status lookup. Keep provider IDs and raw responses for diagnosis. Route by currency, country, cost, capability, and health. A fallback must not submit the same payment blindly to another PSP; first determine whether the original request succeeded.
Refunds, voids, and chargebacks
A void cancels an authorization before capture. A refund returns captured funds. A chargeback is a cardholder dispute handled through the network. Each operation needs its own idempotency key, authorization checks, state transition, and ledger entries.
Reconciliation with external reports
Reconciliation compares internal payments and ledger entries with PSP settlement files and bank deposits. Match by provider ID, amount, currency, fees, and date. Send unmatched, duplicated, or amount-mismatched records to an exception queue instead of silently “fixing” them.
Fraud, scaling, and observability
Risk checks can use velocity limits, device signals, location, and issuer responses. Keep risk decisions explainable and avoid storing unnecessary personal data.
Scale stateless API workers horizontally. Use durable queues, database constraints, timeouts, and circuit breakers. Monitor authorization success, webhook lag, duplicate events, retry counts, reconciliation exceptions, and end-to-end payment latency. Alert on trends and stuck states, not only on server errors.
Exercise
Why should a webhook handler acknowledge an event before performing slow business work?
Show answer
Fast acknowledgement prevents provider retries; durable storage and asynchronous processing preserve the event for later work.