From a97bf15362a616fb34b665471aab81d8fc50af4f Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 23 Jun 2025 01:58:12 +0800 Subject: [PATCH] :bug: Trying to fix afdian webhook --- .../PaymentHandlers/AfdianPaymentHandler.cs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/DysonNetwork.Sphere/Wallet/PaymentHandlers/AfdianPaymentHandler.cs b/DysonNetwork.Sphere/Wallet/PaymentHandlers/AfdianPaymentHandler.cs index 4c4bd91..439e092 100644 --- a/DysonNetwork.Sphere/Wallet/PaymentHandlers/AfdianPaymentHandler.cs +++ b/DysonNetwork.Sphere/Wallet/PaymentHandlers/AfdianPaymentHandler.cs @@ -203,8 +203,13 @@ public class AfdianPaymentHandler( /// The HTTP request containing webhook data /// An action to process the received order /// A WebhookResponse object to be returned to Afdian - public async Task HandleWebhook(HttpRequest request, Func? processOrderAction) + public async Task HandleWebhook( + HttpRequest request, + Func? processOrderAction + ) { + _logger.LogInformation("Received webhook request from afdian..."); + try { // Read the request body @@ -235,7 +240,7 @@ public class AfdianPaymentHandler( if (webhook.Data.Type != "order") { _logger.LogWarning($"Unsupported webhook type: {webhook.Data.Type}"); - return new WebhookResponse { ErrorCode = 200, ErrorMessage = "Unsupported type, but acknowledged" }; + return WebhookResponse.Success; } // Process the order @@ -246,7 +251,8 @@ public class AfdianPaymentHandler( if (processOrderAction != null) await processOrderAction(webhook.Data); else - _logger.LogInformation($"Order received but no processing action provided: {webhook.Data.Order.TradeNumber}"); + _logger.LogInformation( + $"Order received but no processing action provided: {webhook.Data.Order.TradeNumber}"); } catch (Exception ex) { @@ -256,12 +262,12 @@ public class AfdianPaymentHandler( } // Return success response to Afdian - return new WebhookResponse { ErrorCode = 200, ErrorMessage = "" }; + return WebhookResponse.Success; } catch (Exception ex) { _logger.LogError(ex, "Error handling webhook"); - return new WebhookResponse { ErrorCode = 500, ErrorMessage = "Internal server error" }; + return WebhookResponse.Success; } } @@ -401,6 +407,12 @@ public class WebhookResponse [JsonProperty("ec")] public int ErrorCode { get; set; } = 200; [JsonProperty("em")] public string ErrorMessage { get; set; } = ""; + + public static WebhookResponse Success => new() + { + ErrorCode = 200, + ErrorMessage = string.Empty + }; } /// @@ -417,4 +429,4 @@ public class SkuDetailItem [JsonProperty("album_id")] public string AlbumId { get; set; } = null!; [JsonProperty("pic")] public string Picture { get; set; } = null!; -} +} \ No newline at end of file