From e1cd2a2239318686475b0c5d7fa84a5dd63a333f Mon Sep 17 00:00:00 2001 From: mglongbao Date: Fri, 9 May 2025 07:20:44 +0700 Subject: [PATCH] fix: remove cache when complete payment --- .../UC_Booking/Commands/ProcessPaymentWebhook.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/UseCases/UC_Booking/Commands/ProcessPaymentWebhook.cs b/src/UseCases/UC_Booking/Commands/ProcessPaymentWebhook.cs index 9d7467da..a2ad165e 100644 --- a/src/UseCases/UC_Booking/Commands/ProcessPaymentWebhook.cs +++ b/src/UseCases/UC_Booking/Commands/ProcessPaymentWebhook.cs @@ -7,10 +7,10 @@ using Hangfire; using MediatR; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; using Net.payOS.Types; using UseCases.Abstractions; -using UseCases.BackgroundServices.Bookings; using UseCases.Services.EmailService; using Transaction = Domain.Entities.Transaction; @@ -20,8 +20,12 @@ public sealed class ProcessPaymentWebhook { public sealed record Command(WebhookType WebhookType) : IRequest; - public class Handler(IAppDBContext context, IEmailService emailService, ILogger logger) - : IRequestHandler + public class Handler( + IAppDBContext context, + IEmailService emailService, + ILogger logger, + IMemoryCache cache + ) : IRequestHandler { public async Task Handle(Command request, CancellationToken cancellationToken) { @@ -130,6 +134,9 @@ out Transaction ownerEarningTransaction booking.IsPaid = true; } + var cacheKey = $"PaymentLink_{booking.Id}"; + cache.Remove(cacheKey); + context.Transactions.AddRange( bookingPayment, platformFeeTransaction,