🐛 Trying to fix payment handler
This commit is contained in:
@ -87,9 +87,8 @@ public class AfdianPaymentHandler(
|
|||||||
/// Get a specific order by its ID (out_trade_no)
|
/// Get a specific order by its ID (out_trade_no)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="orderId">The order ID to query</param>
|
/// <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>
|
/// <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))
|
if (string.IsNullOrEmpty(orderId))
|
||||||
{
|
{
|
||||||
@ -97,11 +96,6 @@ public class AfdianPaymentHandler(
|
|||||||
return null;
|
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
|
try
|
||||||
{
|
{
|
||||||
var token = _configuration["Payment:Auth:Afdian"] ?? "_:_";
|
var token = _configuration["Payment:Auth:Afdian"] ?? "_:_";
|
||||||
@ -119,7 +113,7 @@ public class AfdianPaymentHandler(
|
|||||||
{
|
{
|
||||||
Content = new StringContent(JsonSerializer.Serialize(new
|
Content = new StringContent(JsonSerializer.Serialize(new
|
||||||
{
|
{
|
||||||
user_id = connection.ProvidedIdentifier,
|
user_id = userId,
|
||||||
@params = paramsJson,
|
@params = paramsJson,
|
||||||
ts,
|
ts,
|
||||||
sign
|
sign
|
||||||
|
@ -183,9 +183,7 @@ public class SubscriptionController(SubscriptionService subscriptions, AfdianPay
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<IActionResult> RestorePurchaseFromAfdian([FromBody] RestorePurchaseRequest request)
|
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);
|
||||||
|
|
||||||
var order = await afdian.GetOrderAsync(request.OrderId, currentUser.Id);
|
|
||||||
if (order is null) return NotFound($"Order with ID {request.OrderId} was not found.");
|
if (order is null) return NotFound($"Order with ID {request.OrderId} was not found.");
|
||||||
|
|
||||||
var subscription = await subscriptions.CreateSubscriptionFromOrder(order);
|
var subscription = await subscriptions.CreateSubscriptionFromOrder(order);
|
||||||
|
Reference in New Issue
Block a user