A payment gateway is a critical component in any online transaction system. It acts as a bridge between the user, the merchant, and financial institutions by securely processing payment requests, verifying details, and ensuring funds are transferred correctly.
For example, when a customer purchases a product on an e-commerce platform, the payment gateway handles the steps of capturing payment details, validating them, interacting with the bank or wallet provider, and communicating the result (success or failure) to the application.
In this chapter, we will explore the low-level design of a Payment Gateway.
Let’s start by clarifying the requirements:
Designing a payment gateway involves many moving parts. Before diving into the implementation, it's critical to clarify the scope and constraints of the system we are expected to design.
Candidate: Should the payment gateway support multiple payment methods?
Interviewer: Yes, it should support at least Credit Card, PayPal, and UPI. Additional methods can be added later.
Candidate: Should we support retry logic if a payment fails?
Interviewer: Yes, implement a basic retry mechanism—for example, retrying failed payments up to 3 times.
Candidate: What happens after a payment is processed? Should we notify anyone?
Interviewer: Yes, the system should notify the merchant and customer about transaction status updates.
Candidate: Are refunds or reversals in scope?
Interviewer: No. Just implement the core payment flow from request to processing to response.
Candidate: Do we need to support currency conversions?
Interviewer: No, just support basic multi-currency payments, but assume the currency is provided by the merchant.
After gathering the details, we can summarize the key system requirements.
After the requirements are clear, the next step is to identify the core entities that we will form the foundation of our design.