public virtual async Task HandleEventAsync(ProductInventoryReductionAfterOrderPaidResultEto eventData) { using (_currentTenant.Change(eventData.TenantId)) { var order = await _orderRepository.GetAsync(eventData.OrderId); if (order.ReducedInventoryAfterPaymentTime.HasValue) { throw new OrderIsInWrongStageException(order.Id); } if (!eventData.IsSuccess) { var refundOrderEto = CreateRefundOrderEto(order); await _orderManager.CancelAsync(order, OrdersConsts.InventoryReductionFailedAutoCancellationReason); await RefundOrderAsync(refundOrderEto); return; } order.SetReducedInventoryAfterPaymentTime(_clock.Now); await _orderRepository.UpdateAsync(order, true); } }
public virtual async Task HandleEventAsync(ProductInventoryReductionAfterOrderPaidResultEto eventData) { using (_currentTenant.Change(eventData.TenantId)) { var order = await _orderRepository.GetAsync(eventData.OrderId); if (order.ReducedInventoryAfterPaymentTime.HasValue) { throw new OrderIsInWrongStageException(order.Id); } if (!eventData.IsSuccess) { // Todo: Refund. // Todo: Cancel order. return; } order.SetReducedInventoryAfterPaymentTime(_clock.Now); await _orderRepository.UpdateAsync(order, true); } }