public Payment MakePayment(Order order, Payment payment) { if (_paymentCreditCardFacade.MakePayment(order, payment)) { payment.SuccessfulPayment(); } else { payment.FailedPayment(); } return(payment); }
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); }