feat: add payment sdk and tenant secret foundation

This commit is contained in:
xiong
2026-07-26 19:28:04 +08:00
parent 28befc57be
commit 5503d7a644
17 changed files with 16330 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
using Tiku.Application.Commerce;
namespace Tiku.Infrastructure.Commerce;
internal sealed class PaymentProviderGateway(
IEnumerable<IPaymentProvider> providers,
IPaymentProviderConfigService configService) : IPaymentProviderGateway
{
public async Task<CreatePaymentProviderResult> CreatePaymentAsync(
string provider,
CreatePaymentProviderRequest request,
CancellationToken cancellationToken = default)
{
var resolvedProvider = ResolveProvider(provider);
var account = await configService.GetActiveAccountAsync(
request.TenantId,
resolvedProvider.Provider,
cancellationToken);
return await resolvedProvider.CreatePaymentAsync(account, request, cancellationToken);
}
public async Task<PaymentNotificationResult> ParsePaymentNotificationAsync(
string provider,
PaymentNotificationRequest request,
CancellationToken cancellationToken = default)
{
var resolvedProvider = ResolveProvider(provider);
var account = await configService.GetActiveAccountAsync(
request.TenantId,
resolvedProvider.Provider,
cancellationToken);
return await resolvedProvider.ParsePaymentNotificationAsync(account, request, cancellationToken);
}
private IPaymentProvider ResolveProvider(string provider)
{
var normalized = provider.Trim().ToLowerInvariant().Replace("-", "_", StringComparison.Ordinal);
return providers.FirstOrDefault(item => item.Provider == normalized)
?? throw new PaymentProviderException(
"Payment provider is not supported.",
"payment_provider_not_supported");
}
}