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); }