🐛 Trying to fix payment handler

This commit is contained in:
2025-07-09 22:00:06 +08:00
parent ad1166190f
commit 837a123c3b
2 changed files with 3 additions and 11 deletions

View File

@ -87,9 +87,8 @@ public class AfdianPaymentHandler(
/// Get a specific order by its ID (out_trade_no)
/// </summary>
/// <param name="orderId">The order ID to query</param>
/// <param name="accountId">The account ID</param>
/// <returns>The order item if found, otherwise null</returns>
public async Task<OrderItem?> GetOrderAsync(string orderId, Guid accountId)
public async Task<OrderItem?> GetOrderAsync(string orderId)
{
if (string.IsNullOrEmpty(orderId))
{
@ -97,11 +96,6 @@ public class AfdianPaymentHandler(
return null;
}
var connection = await db.AccountConnections
.Where(c => c.AccountId == accountId && c.Provider == "afdian")
.FirstOrDefaultAsync();
if (connection is null) throw new InvalidOperationException("Account need to link an afdian account first.");
try
{
var token = _configuration["Payment:Auth:Afdian"] ?? "_:_";
@ -119,7 +113,7 @@ public class AfdianPaymentHandler(
{
Content = new StringContent(JsonSerializer.Serialize(new
{
user_id = connection.ProvidedIdentifier,
user_id = userId,
@params = paramsJson,
ts,
sign

View File

@ -183,9 +183,7 @@ public class SubscriptionController(SubscriptionService subscriptions, AfdianPay
[Authorize]
public async Task<IActionResult> RestorePurchaseFromAfdian([FromBody] RestorePurchaseRequest request)
{
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
var order = await afdian.GetOrderAsync(request.OrderId, currentUser.Id);
var order = await afdian.GetOrderAsync(request.OrderId);
if (order is null) return NotFound($"Order with ID {request.OrderId} was not found.");
var subscription = await subscriptions.CreateSubscriptionFromOrder(order);