To simultaneously support multiple payment gateway integrations, each of the service interfaces mentioned above extend the PaymentGatewayTypeAware
interface. In doing so, each implementation must declare its relevant gateway type (e.g. CHECKOUT_COM
vs STRIPE
). From there, we use DefaultPaymentGatewayResourceProvider
to collect all the implementation beans for each integration and make them accessible by gateway type.
For example if you wanted to get the appropriate PaymentGatewayTransactionService to execute a transaction on a payment, you would simply call PaymentGatewayResourceProvider#getTransactionService("MY_GATEWAY_TYPE")
.
@Service
@lombok.RequiredArgsConstructor
public class MyPaymentService {
private final PaymentGatewayResourceProvider paymentGatewayResourceProvider;
PaymentGatewayTransactionService getTransactionServiceForPayment(final Payment payment) {
final String gatewayType = payment.getGatewayType();
return paymentGatewayResourceProvider.getTransactionService(gatewayType);
}
}