Exemple #1
0
        public async Task <PaymentDTO> MakePayment(AddPaymentDTO addPaymentDTO)
        {
            var invoice = await _invoicesRepository.ByID(addPaymentDTO.InvoiceID);


            if (invoice != null && invoice?.Total == addPaymentDTO.PaymentAmount)
            {
                Payment invoicePayment = await _paymentRepository.ByInvoiceID(invoice.InvoiceID);

                //если оплата по счету уже сделана то повторно она не проводится
                if (invoicePayment != null)
                {
                    return(_mapper.Map <PaymentDTO>(invoicePayment));
                }

                Payment newPayment = new Payment()
                {
                    InvoiceID     = invoice.InvoiceID,
                    PaymentAmount = invoice.Total,
                    PaidAt        = DateTime.Now
                };

                Payment addedPayment = await _paymentRepository.Add(newPayment);

                _rmqProducer.PaymentSuccessful(invoice.ShoppingCartID);

                return(_mapper.Map <PaymentDTO>(addedPayment));
            }

            return(new PaymentDTO());
        }