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.PaymentSucceded)
                {
                    orderPaymentIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@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(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 HandleAsync(OrderStatusChangedToStockConfirmedIntegrationEvent @event)
        {
            IntegrationEvent orderPaymentIntegrationEvent;

            if (this._settings.PaymentSuccessed)
            {
                orderPaymentIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
            }
            else
            {
                orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
            }

            this._eventBus.Publish(orderPaymentIntegrationEvent);

            await Task.CompletedTask;
        }
        public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @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.PaymentSucceded)
            {
                orderPaymentIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
            }
            else
            {
                orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
            }

            _eventBus.Publish(orderPaymentIntegrationEvent);
        }
示例#6
0
        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(OrderPaymentFailedIntegrationEvent @event)
 {
     var handler = _serviceProvider.GetRequiredService <OrderPaymentFailedIntegrationEventHandler>();
     await handler.Handle(@event);
 }
 public Task Handle(OrderPaymentFailedIntegrationEvent message, IMessageHandlerContext context)
 {
     // Another handler for OrderPaymentFailedIntegrationEvent will update the status of the order
     MarkAsComplete();
     return(Task.CompletedTask);
 }
 public Task Handle(OrderPaymentFailedIntegrationEvent integrationEvent)
 {
     return(GetOrderingProcessActor(integrationEvent.OrderId).NotifyPaymentFailed());
 }