Fix: Add confirmations support and fix notification logic
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 <noreply@anthropic.com>
This commit is contained in:
parent
2ae44a3c56
commit
110ad5f956
@ -175,10 +175,11 @@ public class OrdersController : ControllerBase
|
||||
public async Task<ActionResult> 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;
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user