SOLID & Design Patterns Interview Question #144

How would you design a payment integration that supports multiple providers?

Anti-Patterns, Refactoring, DI Lifetimes & Senior Design Scenarios Senior Advanced

Quick Interview Answer

Define a provider abstraction around the payment capability required by the application, implement adapters for each external provider, and select the correct implementation using configuration or a factory/strategy.

Detailed Explanation

Define a provider abstraction around the payment capability required by the application, implement adapters for each external provider, and select the correct implementation using configuration or a factory/strategy.

Keep provider-specific DTOs and error formats inside adapters. This prevents third-party contracts from leaking into the domain and makes testing possible with a fake provider.

Code Example

public interface IPaymentProvider
{
    Task<PaymentResult> ChargeAsync(
        PaymentRequest request);
}

public class ProviderFactory
{
    public IPaymentProvider Get(string provider)
        => provider switch
        {
            "A" => _providerA,
            "B" => _providerB,
            _ => throw new NotSupportedException()
        };
}