/// <summary> /// OrderCanceledIntegrationEvent is listened for Payment API and Order API, it does not need to publish, only need to cancel the payment /// </summary> /// <param name="message"></param> /// <returns></returns> private async Task CancelPayment(OrderCanceledIntegrationEvent message) { using var scope = _serviceProvider.CreateScope(); var paymentService = scope.ServiceProvider.GetRequiredService <IPaymentService>(); var response = await paymentService.CancelPayment(message.OrderId); if (!response.ValidResult.IsValid) { throw new DomainException($"Error to cancel the payment for the order {message.OrderId}"); } }
private async Task CancelOrder(OrderCanceledIntegrationEvent message) { using var scope = _serviceProvider.CreateScope(); var orderRepository = scope.ServiceProvider.GetRequiredService <IOrderRepository>(); var order = await orderRepository.GetOrderById(message.OrderId); order.CancelOrder(); orderRepository.UpdateOrder(order); if (!await orderRepository.UnitOfWork.Commit()) { throw new DomainException($"An error occured to cancel the order {message.OrderId}"); } }
/// <summary> /// There will have 2 consumers (Payment and Order) /// </summary> /// <param name="message"></param> private async void CancelOrderWithoutStock(OrderAuthorizedIntegrationEvent message) { var canceledOrder = new OrderCanceledIntegrationEvent(message.CustomerId, message.OrderId); await _messageBus.PublishAsync(canceledOrder); }
public async void CancelOrderWithOutStock(OrderAuthorizedIntegrationEvent message) { var orderCanceled = new OrderCanceledIntegrationEvent(message.CustomerId, message.OrderId); await _bus.PublishAsync(orderCanceled); }