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,66 @@
using System.Text.Json;
using Aop.Api;
using Tiku.Application.Commerce;
namespace Tiku.Infrastructure.Commerce;
internal sealed class AlipayProvider : IPaymentProvider
{
public string Provider => PaymentProviders.Alipay;
public Task<CreatePaymentProviderResult> CreatePaymentAsync(
PaymentProviderAccount account,
CreatePaymentProviderRequest request,
CancellationToken cancellationToken = default)
{
_ = BuildClient(account);
throw new PaymentProviderException(
"Alipay SDK is configured; checkout call is enabled in the commerce checkout batch.",
"alipay_checkout_not_enabled");
}
public Task<PaymentNotificationResult> ParsePaymentNotificationAsync(
PaymentProviderAccount account,
PaymentNotificationRequest request,
CancellationToken cancellationToken = default)
{
_ = BuildClient(account);
throw new PaymentProviderException(
"Alipay SDK is configured; notification parsing is enabled in the notification batch.",
"alipay_notification_not_enabled");
}
private static DefaultAopClient BuildClient(PaymentProviderAccount account)
{
return new DefaultAopClient(
Required(account.ConfigPublic, "gatewayUrl", "gateway"),
Required(account.ConfigPublic, "appId"),
Required(account.SecretPayload, "privateKey", "appPrivateKey"),
"json",
"1.0",
"RSA2",
Required(account.ConfigPublic, "alipayPublicKey"),
"UTF-8",
false);
}
private static string Required(JsonElement element, params string[] keys)
{
if (element.ValueKind == JsonValueKind.Object)
{
foreach (var key in keys)
{
if (element.TryGetProperty(key, out var property) &&
property.ValueKind == JsonValueKind.String &&
!string.IsNullOrWhiteSpace(property.GetString()))
{
return property.GetString()!;
}
}
}
throw new PaymentProviderException(
"Alipay provider configuration is incomplete.",
"alipay_config_incomplete");
}
}