src/Services/Payment/Payment.API/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs
(完整代码) 2KBnamespace Microsoft.eShopOnContainers.Payment.API.IntegrationEvents.EventHandling;
public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
{
private readonly IEventBus _eventBus;
private readonly PaymentSettings _settings;
private readonly ILogger<OrderStatusChangedToStockConfirmedIntegrationEventHandler> _logger;
public OrderStatusChangedToStockConfirmedIntegrationEventHandler(
IEventBus eventBus,
IOptionsSnapshot<PaymentSettings> settings,
ILogger<OrderStatusChangedToStockConfirmedIntegrationEventHandler> logger)
{
_eventBus = eventBus;
_settings = settings.Value;
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
_logger.LogTrace("PaymentSettings: {@PaymentSettings}", _settings);
}
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
IntegrationEvent orderPaymentIntegrationEvent;
//Business feature comment:
// When OrderStatusChangedToStockConfirmed Integration Event is handled.
// Here we're simulating that we'd be performing the payment against any payment gateway
// Instead of a real payment we just take the env. var to simulate the payment
// The payment can be successful or it can fail
if (_settings.PaymentSucceeded)
{
orderPaymentIntegrationEvent = new OrderPaymentSucceededIntegrationEvent(@event.OrderId);
}
else
{
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
}
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, Program.AppName, orderPaymentIntegrationEvent);
_eventBus.Publish(orderPaymentIntegrationEvent);
await Task.CompletedTask;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。