Stage 1: Problem
The Problem
You are building a payment service for an e-commerce platform. Right now you only support Stripe. The code is simple:
typescript
| 1 | class PaymentService { |
| 2 | async processPayment(amount: number, currency: string, token: string) { |
| 3 | const stripe = new Stripe(process.env.STRIPE_KEY!); |
| 4 | const charge = await stripe.charges.create({ amount, currency, source: token }); |
| 5 | return { id: charge.id, status: charge.status }; |
| 6 | } |
| 7 | } |
Then requirements grow:
- India launch ā you need Razorpay for UPI and domestic card payments.
- Europe launch ā you need PayPal support.
- Merchant choice ā each merchant configures their preferred gateway in the admin panel.
- New gateways keep coming ā the business team wants to add Adyen, Square, and local processors. Each has a different SDK, different auth flow, different response shape.
You need a system where adding a new payment gateway does not require changing the core payment processing logic.
How would you solve this? Think for a moment before scrolling. Write your approach below.