feat(payment): implement multi-gateway support and enhance payment processing
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m44s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m44s
- Added support for multiple payment gateways, including ZarinPal and TwentyCard, through a new IPaymentGatewayResolver. - Updated PaymentRequest DTO to include payer name and invoice number for better transaction tracking. - Enhanced PackageService to dynamically determine payment amounts based on the selected gateway. - Updated appsettings to include configuration for TwentyCard payment options. - Bumped Protobuf project version to reflect the addition of new features and changes.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Infrastructure.Services.Payment;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Services.Payment;
|
||||
|
||||
public class PaymentGatewayResolver : IPaymentGatewayResolver
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public PaymentGatewayResolver(IServiceProvider serviceProvider, IConfiguration configuration)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public IPaymentGatewayService Get(string? provider)
|
||||
{
|
||||
var key = Normalize(provider)
|
||||
?? Normalize(_configuration["PaymentProvider"])
|
||||
?? "zarinpal";
|
||||
|
||||
return key switch
|
||||
{
|
||||
"20card" or "twentycard" => _serviceProvider.GetRequiredService<TwentyCardPaymentService>(),
|
||||
"zarinpal" => _serviceProvider.GetRequiredService<ZarinPalPaymentService>(),
|
||||
_ => _serviceProvider.GetRequiredService<IPaymentGatewayService>()
|
||||
};
|
||||
}
|
||||
|
||||
private static string? Normalize(string? value)
|
||||
=> string.IsNullOrWhiteSpace(value) ? null : value.Trim().ToLowerInvariant();
|
||||
}
|
||||
Reference in New Issue
Block a user