09 / 11

How would you design a Payment Gateway integration that supports multiple providers (PayPal, Stripe)?

Difficulty: 4/10

Provider-Agnostic Payment Gateway Design

I would define an application-level payment abstraction and implement one adapter per provider. The business layer should work with our own PaymentRequest and PaymentResult models rather than provider-specific SDK types. A factory or dependency-injection strategy can select the appropriate provider. This isolates vendor-specific APIs and makes adding another provider much safer.

javascript
  1. 1

    Use an abstraction owned by the application rather than exposing provider SDK types.

  2. 2

    Use Adapter implementations to translate provider-specific APIs.

  3. 3

    Select providers through dependency injection, configuration, routing policy, or a factory.

  4. 4

    Normalize provider errors into meaningful application-level error categories.

  5. 5

    Design for idempotency because payment requests may be retried.

  6. 6

    Handle webhooks, asynchronous payment states, timeouts, retries, reconciliation, and duplicate notifications.

  7. 7

    Never assume a successful API response alone means the entire payment lifecycle is complete.

Follow-up Questions

  • How would you implement payment idempotency?
  • How would you handle provider timeouts?
  • How would you design payment webhooks?
  • How would you add automatic provider failover?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.