Implement comprehensive notification system for LittleShop
- Add admin PWA push notifications for order management - Integrate TeleBot customer messaging service - Add push notification endpoints and VAPID key support - Implement order status notifications throughout workflow - Add notification UI components in admin panel - Create TeleBotMessagingService for customer updates - Add WebPush configuration to appsettings - Fix compilation issues (BotStatus, BotContacts DbSet) - Add comprehensive testing documentation Features: - Real-time admin notifications for new orders and status changes - Customer order progress updates via TeleBot - Graceful failure handling for notification services - Test endpoints for notification system validation 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -14,17 +14,23 @@ public class CryptoPaymentService : ICryptoPaymentService
|
||||
private readonly IBTCPayServerService _btcPayService;
|
||||
private readonly ILogger<CryptoPaymentService> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IPushNotificationService _pushNotificationService;
|
||||
private readonly ITeleBotMessagingService _teleBotMessagingService;
|
||||
|
||||
public CryptoPaymentService(
|
||||
LittleShopContext context,
|
||||
IBTCPayServerService btcPayService,
|
||||
ILogger<CryptoPaymentService> logger,
|
||||
IConfiguration configuration)
|
||||
IConfiguration configuration,
|
||||
IPushNotificationService pushNotificationService,
|
||||
ITeleBotMessagingService teleBotMessagingService)
|
||||
{
|
||||
_context = context;
|
||||
_btcPayService = btcPayService;
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_pushNotificationService = pushNotificationService;
|
||||
_teleBotMessagingService = teleBotMessagingService;
|
||||
}
|
||||
|
||||
public async Task<CryptoPaymentDto> CreatePaymentAsync(Guid orderId, CryptoCurrency currency)
|
||||
@@ -157,9 +163,11 @@ public class CryptoPaymentService : ICryptoPaymentService
|
||||
if (status == PaymentStatus.Paid)
|
||||
{
|
||||
payment.PaidAt = DateTime.UtcNow;
|
||||
|
||||
|
||||
// Update order status
|
||||
var order = await _context.Orders.FindAsync(payment.OrderId);
|
||||
var order = await _context.Orders
|
||||
.Include(o => o.Customer)
|
||||
.FirstOrDefaultAsync(o => o.Id == payment.OrderId);
|
||||
if (order != null)
|
||||
{
|
||||
order.Status = OrderStatus.PaymentReceived;
|
||||
@@ -169,7 +177,13 @@ public class CryptoPaymentService : ICryptoPaymentService
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("Processed payment webhook for invoice {InvoiceId}, status: {Status}",
|
||||
// Send notification for payment confirmation
|
||||
if (status == PaymentStatus.Paid)
|
||||
{
|
||||
await SendPaymentConfirmedNotification(payment.OrderId, amount);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Processed payment webhook for invoice {InvoiceId}, status: {Status}",
|
||||
invoiceId, status);
|
||||
|
||||
return true;
|
||||
@@ -209,4 +223,25 @@ public class CryptoPaymentService : ICryptoPaymentService
|
||||
_ => "BTC"
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SendPaymentConfirmedNotification(Guid orderId, decimal amount)
|
||||
{
|
||||
try
|
||||
{
|
||||
var title = "💰 Payment Confirmed";
|
||||
var body = $"Order #{orderId.ToString()[..8]} payment of £{amount:F2} confirmed. Ready for acceptance.";
|
||||
|
||||
// Send push notification to admin users
|
||||
await _pushNotificationService.SendOrderNotificationAsync(orderId, title, body);
|
||||
|
||||
// Send TeleBot message to customer
|
||||
await _teleBotMessagingService.SendPaymentConfirmedAsync(orderId);
|
||||
|
||||
_logger.LogInformation("Sent payment confirmation notifications for order {OrderId} (Admin + Customer)", orderId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to send payment confirmation notification for order {OrderId}", orderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user