From 110ad5f95662138f20bbea356f0b0d93f07957ae Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Mon, 6 Oct 2025 16:26:39 +0100 Subject: [PATCH] Fix: Add confirmations support and fix notification logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Webhook Improvements: - Added Confirmations field to PaymentWebhookDto (default: 0) - Updated webhook controller to pass confirmations to service layer - Fixed notification logic to match order update conditions Payment Confirmation Logic: - Paid (2): Confirmed immediately regardless of confirmations - Overpaid (3): Confirmed immediately regardless of confirmations - Completed (7): Requires 3+ blockchain confirmations - Notifications only sent when order is actually updated This prevents premature notifications for unconfirmed 'Completed' status while maintaining immediate processing for 'Paid' and 'Overpaid' statuses. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- LittleShop/Controllers/OrdersController.cs | 10 ++++++---- LittleShop/Services/CryptoPaymentService.cs | 11 ++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/LittleShop/Controllers/OrdersController.cs b/LittleShop/Controllers/OrdersController.cs index c9dc969..a90d7b8 100644 --- a/LittleShop/Controllers/OrdersController.cs +++ b/LittleShop/Controllers/OrdersController.cs @@ -175,10 +175,11 @@ public class OrdersController : ControllerBase public async Task PaymentWebhook([FromBody] PaymentWebhookDto webhookDto) { var success = await _cryptoPaymentService.ProcessPaymentWebhookAsync( - webhookDto.InvoiceId, - webhookDto.Status, - webhookDto.Amount, - webhookDto.TransactionHash); + webhookDto.InvoiceId, + webhookDto.Status, + webhookDto.Amount, + webhookDto.TransactionHash, + webhookDto.Confirmations); if (!success) { @@ -205,4 +206,5 @@ public class PaymentWebhookDto public PaymentStatus Status { get; set; } public decimal Amount { get; set; } public string? TransactionHash { get; set; } + public int Confirmations { get; set; } = 0; } \ No newline at end of file diff --git a/LittleShop/Services/CryptoPaymentService.cs b/LittleShop/Services/CryptoPaymentService.cs index 842536f..bef4d31 100644 --- a/LittleShop/Services/CryptoPaymentService.cs +++ b/LittleShop/Services/CryptoPaymentService.cs @@ -139,7 +139,12 @@ public class CryptoPaymentService : ICryptoPaymentService payment.PaidAmount = amount; payment.TransactionHash = transactionHash; - if (status == PaymentStatus.Paid || status == PaymentStatus.Overpaid || (status == PaymentStatus.Completed && confirmations >= 3)) + // Determine if payment is confirmed (ready to fulfill order) + var isPaymentConfirmed = status == PaymentStatus.Paid || + status == PaymentStatus.Overpaid || + (status == PaymentStatus.Completed && confirmations >= 3); + + if (isPaymentConfirmed) { payment.PaidAt = DateTime.UtcNow; @@ -156,8 +161,8 @@ public class CryptoPaymentService : ICryptoPaymentService await _context.SaveChangesAsync(); - // Send notification for payment confirmation (including overpaid since payment was successful) - if (status == PaymentStatus.Paid || status == PaymentStatus.Overpaid || status == PaymentStatus.Completed) + // Send notification only when payment is confirmed and order is updated + if (isPaymentConfirmed) { await SendPaymentConfirmedNotification(payment.OrderId, amount); }