From 5ce3598cc92205c1eeaef439301a6e74bdabce42 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 23 Jun 2025 02:59:41 +0800 Subject: [PATCH] :bug: Bug fixes in restore purchase with afdian --- .../PaymentHandlers/AfdianPaymentHandler.cs | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/DysonNetwork.Sphere/Wallet/PaymentHandlers/AfdianPaymentHandler.cs b/DysonNetwork.Sphere/Wallet/PaymentHandlers/AfdianPaymentHandler.cs index c961831..b265d99 100644 --- a/DysonNetwork.Sphere/Wallet/PaymentHandlers/AfdianPaymentHandler.cs +++ b/DysonNetwork.Sphere/Wallet/PaymentHandlers/AfdianPaymentHandler.cs @@ -40,8 +40,10 @@ public class AfdianPaymentHandler( { try { - var userId = "abc"; // Replace with your actual USER_ID - var token = _configuration["Payment:Auth:Afdian"] ?? ""; + var token = _configuration["Payment:Auth:Afdian"] ?? "_:_"; + var tokenParts = token.Split(':'); + var userId = tokenParts[0]; + token = tokenParts[1]; var paramsJson = JsonSerializer.Serialize(new { page }, JsonOptions); var ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)) .TotalSeconds; // Current timestamp in seconds @@ -94,8 +96,10 @@ public class AfdianPaymentHandler( try { - var userId = "abc"; // Replace with your actual USER_ID - var token = _configuration["Payment:Auth:Afdian"] ?? ""; + var token = _configuration["Payment:Auth:Afdian"] ?? "_:_"; + var tokenParts = token.Split(':'); + var userId = tokenParts[0]; + token = tokenParts[1]; var paramsJson = JsonSerializer.Serialize(new { out_trade_no = orderId }, JsonOptions); var ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)) .TotalSeconds; // Current timestamp in seconds @@ -126,7 +130,7 @@ public class AfdianPaymentHandler( await response.Content.ReadAsStreamAsync(), JsonOptions); // Check if we have a valid response and orders in the list - if (result?.Data?.Orders == null || result.Data.Orders.Count == 0) + if (result?.Data.Orders == null || result.Data.Orders.Count == 0) { _logger.LogWarning($"No order found with ID: {orderId}"); return null; @@ -147,21 +151,24 @@ public class AfdianPaymentHandler( /// /// A collection of order IDs to query /// A list of found order items - public async Task> GetOrders(IEnumerable orderIds) + public async Task> GetOrderBatchAsync(IEnumerable orderIds) { - if (orderIds == null || !orderIds.Any()) + var orders = orderIds.ToList(); + if (orders.Count == 0) { _logger.LogWarning("Order IDs cannot be null or empty"); - return new List(); + return []; } try { // Join the order IDs with commas as specified in the API documentation - var orderIdsParam = string.Join(",", orderIds); + var orderIdsParam = string.Join(",", orders); - var userId = "abc"; // Replace with your actual USER_ID - var token = _configuration["Payment:Auth:Afdian"] ?? ""; + var token = _configuration["Payment:Auth:Afdian"] ?? "_:_"; + var tokenParts = token.Split(':'); + var userId = tokenParts[0]; + token = tokenParts[1]; var paramsJson = JsonSerializer.Serialize(new { out_trade_no = orderIdsParam }, JsonOptions); var ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)) .TotalSeconds; // Current timestamp in seconds @@ -192,13 +199,9 @@ public class AfdianPaymentHandler( await response.Content.ReadAsStreamAsync(), JsonOptions); // Check if we have a valid response and orders in the list - if (result?.Data?.Orders == null || result.Data.Orders.Count == 0) - { - _logger.LogWarning($"No orders found with IDs: {orderIdsParam}"); - return new List(); - } - - return result.Data.Orders; + if (result?.Data?.Orders != null && result.Data.Orders.Count != 0) return result.Data.Orders; + _logger.LogWarning($"No orders found with IDs: {orderIdsParam}"); + return []; } catch (Exception ex) {