public async Task Handle(OrderStatusChangedToValidatedIntegrationEvent @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 OrderStatusChangedToValidated 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 PaymentLimitToSucceed to simulate payment approval // The payment can be successful or it can fail await Task.Delay(3000); // Checking with the bank 😉 if (_settings.PaymentSucceeded && (!_settings.MaxOrderTotal.HasValue || @event.Total < _settings.MaxOrderTotal)) { orderPaymentIntegrationEvent = new OrderPaymentSucceededIntegrationEvent(@event.OrderId); } else { _logger.LogWarning("----- Payment for ${Total} rejected for order {OrderId} because of service configuration", @event.Total, @event.OrderId); orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId); } _logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, Program.AppName, orderPaymentIntegrationEvent); await _eventBus.PublishAsync(orderPaymentIntegrationEvent); } }
public async Task Handle(OrderStatusChangedToValidatedIntegrationEvent @event) { IntegrationEvent orderPaymentIntegrationEvent; // Business feature comment: // When OrderStatusChangedToValidated 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 MaxOrderTotal to simulate payment approval. // The payment can be successful or it can fail await Task.Delay(3000); // Checking with the bank 😉 if (_settings.PaymentSucceeded && (!_settings.MaxOrderTotal.HasValue || @event.Total < _settings.MaxOrderTotal)) { orderPaymentIntegrationEvent = new OrderPaymentSucceededIntegrationEvent(@event.OrderId); } else { _logger.LogWarning( "Payment for ${Total} rejected for order {OrderId} because of service configuration", @event.Total, @event.OrderId); orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId); } await _eventBus.PublishAsync(orderPaymentIntegrationEvent); }
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; } }
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event) { _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); await Task.Delay(10 * 1000); IntegrationEvent orderPaymentIntegrationEvent; if (_settings.Value.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; }
public async Task OrderStarted(OrderPaymentSucceededIntegrationEvent @event) { var handler = _serviceProvider.GetRequiredService <OrderPaymentSucceededIntegrationEventHandler>(); await handler.Handle(@event); }
public Task Handle(OrderPaymentSucceededIntegrationEvent integrationEvent) { return(GetOrderingProcessActor(integrationEvent.OrderId).NotifyPaymentSucceeded()); }