09 / 11

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

Difficulty: 5/10
Strategy pattern, Adapter pattern, Abstraction

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.

Scenario Questions

0-2 years experience

  1. 1We have a simple checkout service that currently talks directly to PayPal. How would you refactor it so we can also process Stripe payments without rewriting the whole flow?
  2. 2If Stripe returns an error code you don’t recognize, what would your code do to surface that to the user?

2-5 years experience

  1. 1Explain why you would choose a Strategy pattern over a big if‑else switch when supporting multiple payment providers.
  2. 2During a release we notice that some PayPal transactions are duplicated after a retry. How would you modify the design to prevent duplicate charges?

5-8 years experience

  1. 1Our platform needs to handle thousands of payments per second and must fall back to a secondary provider if the primary is slow. How would you design the integration layer to meet latency and reliability goals?
  2. 2Discuss how you would implement idempotent payment requests and reconcile failures across PayPal and Stripe while keeping PCI‑DSS compliance.

8+ years experience

  1. 1We plan to migrate the payment integration to a micro‑service architecture that will be used by multiple product teams. What architectural decisions would you make to keep the provider implementations reusable and versioned?
  2. 2How would you set up a cross‑team governance model for adding, deprecating, or updating payment providers without causing regressions in existing services?

Follow-up Questions

  • What would you change if a new provider required a webhook callback?
  • How do you ensure that sensitive credentials are not hard‑coded?
  • Can you walk me through how you would test the integration locally?
Share

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