forked from gongxuegit/tiku-backend.net
fix: enable sdk payment checkout providers
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using Aop.Api;
|
||||
using Aop.Api.Domain;
|
||||
using Aop.Api.Request;
|
||||
using Aop.Api.Util;
|
||||
using Tiku.Application.Commerce;
|
||||
|
||||
@@ -14,10 +16,47 @@ internal sealed class AlipayProvider : IPaymentProvider
|
||||
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");
|
||||
_ = cancellationToken;
|
||||
var client = BuildClient(account);
|
||||
var alipayRequest = new AlipayTradeWapPayRequest();
|
||||
alipayRequest.SetNotifyUrl(request.NotifyUrl);
|
||||
if (!string.IsNullOrWhiteSpace(request.ReturnUrl))
|
||||
{
|
||||
alipayRequest.SetReturnUrl(request.ReturnUrl);
|
||||
}
|
||||
|
||||
alipayRequest.SetBizModel(new AlipayTradeWapPayModel
|
||||
{
|
||||
OutTradeNo = request.OrderNo,
|
||||
Subject = request.Subject,
|
||||
TotalAmount = FormatYuan(request.AmountCents),
|
||||
ProductCode = "QUICK_WAP_WAY",
|
||||
QuitUrl = request.QuitUrl
|
||||
});
|
||||
var response = client.pageExecute(alipayRequest);
|
||||
if (string.IsNullOrWhiteSpace(response.Body))
|
||||
{
|
||||
throw new PaymentProviderException("Alipay create payment returned an empty body.", "alipay_create_failed");
|
||||
}
|
||||
|
||||
var clientPayload = JsonSerializer.SerializeToElement(new
|
||||
{
|
||||
formHtml = response.Body
|
||||
});
|
||||
var rawPayload = JsonSerializer.SerializeToElement(new
|
||||
{
|
||||
response.Body,
|
||||
request.OrderNo,
|
||||
request.AmountCents
|
||||
});
|
||||
|
||||
return Task.FromResult(new CreatePaymentProviderResult(
|
||||
Provider,
|
||||
request.Method,
|
||||
"pending",
|
||||
null,
|
||||
clientPayload,
|
||||
rawPayload));
|
||||
}
|
||||
|
||||
public Task<PaymentNotificationResult> ParsePaymentNotificationAsync(
|
||||
@@ -138,4 +177,7 @@ internal sealed class AlipayProvider : IPaymentProvider
|
||||
? (int)Math.Round(amount * 100, MidpointRounding.AwayFromZero)
|
||||
: 0;
|
||||
}
|
||||
|
||||
private static string FormatYuan(int cents) =>
|
||||
(cents / 100m).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user