public async Task <Transaction> ExectureOrderPayment(PaymentOrderDto paymentOrder) { var order = new Order { Id = paymentOrder.OrderId, ClientId = paymentOrder.ClientId, Total = paymentOrder.Total }; var payment = new Payment { Total = paymentOrder.Total, NameCard = paymentOrder.NameCard, NumberCard = paymentOrder.NumberCard, ExpirationDateCard = paymentOrder.ExpirationDateCard, CvvCard = paymentOrder.CvvCard, OrderId = paymentOrder.OrderId }; var transaction = _paymentCreditCardFacade.ExecutePayment(order, payment); if (transaction.StatusTransaction == StatusTransaction.Paid) { payment.AddEvent(new PaymentRealizedEvent(payment.Id, transaction.Id, order.Id, order.ClientId, order.Total)); _orderRepository.Add(payment); _orderRepository.Add(transaction); await _orderRepository.UnitOfWork.Commit(); return(transaction); } await _mediatorHandler.PublishNotification(new DomainNotification(this.GetType().Name, "A operadora recusou o pagamento")); await _mediatorHandler.PublishEvent(new PaymentRefusedEvent(payment.Id, transaction.Id, order.Id, order.ClientId, order.Total)); return(transaction); }
public async Task <Transaction> MakeOrderPayment(PaymentOrder paymentOrder) { var order = new Order { Id = paymentOrder.OrderId, Value = paymentOrder.Total }; var payment = new Payment { Value = paymentOrder.Total, CardName = paymentOrder.CardName, CardNumber = paymentOrder.CardNumber, ExpirationCard = paymentOrder.ExpirationCard, CvvCard = paymentOrder.CvvCard, OrderId = paymentOrder.OrderId }; var transaction = _paymentCreditCardFacade.MakePayment(order, payment); if (transaction.StatusTransaction == StatusTransaction.Paid) { payment.AddEvent(new PaymentMadeEvent(order.Id, paymentOrder.ClientId, transaction.PaymentId, transaction.Id, order.Value)); _paymentRepository.Add(payment); _paymentRepository.AddTransaction(transaction); await _paymentRepository.UnitOfWork.Commit(); return(transaction); } await _mediatorHandler.PublishNotification(new DomainNotification("payment", "Card operator refused the payment")); await _mediatorHandler.PublishEvent(new PaymentOrderRefusedEvent(order.Id, paymentOrder.ClientId, transaction.PaymentId, transaction.Id, order.Value)); return(transaction); }