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());
        }
Exemple #2
0
        public async Task IfDoublePayment()
        {
            Invoice newInvoice = new Invoice()
            {
                ShoppingCartID     = 2,
                UserID             = 2,
                CountOfCommodities = 3,
                CreatedAt          = DateTime.Now,
                Total = 1500
            };

            Invoice addedInvoice = await _invoicesRepository.Add(newInvoice);

            AddPaymentDTO addPaymentDTO = new AddPaymentDTO()
            {
                InvoiceID = addedInvoice.InvoiceID, PaymentAmount = addedInvoice.Total
            };

            PaymentDTO firstPayment = await _paymentService.MakePayment(addPaymentDTO);

            PaymentDTO secondPayment = await _paymentService.MakePayment(addPaymentDTO);

            //На повторную оплату должен вернуть уже существующую по счету
            Assert.AreEqual(firstPayment.PaymentID, secondPayment.PaymentID);
        }
Exemple #3
0
        public async Task IfInvoiceDoesntExists()
        {
            AddPaymentDTO addPaymentDTO = new AddPaymentDTO()
            {
                InvoiceID = -1, PaymentAmount = 0
            };
            PaymentDTO paymentDTO = await _paymentService.MakePayment(addPaymentDTO);

            //оплата по несуществующему счету должна не пройти
            Assert.AreEqual(0, paymentDTO.PaymentID);
        }
Exemple #4
0
        public async Task PaymentIntegrity()
        {
            var invoice = await _invoicesRepository.ByShoppingCartID(1);

            AddPaymentDTO addPaymentDTO = new AddPaymentDTO()
            {
                InvoiceID     = invoice.InvoiceID,
                PaymentAmount = invoice.Total
            };

            PaymentDTO paymentDTO = await _paymentService.MakePayment(addPaymentDTO);

            Assert.IsTrue(paymentDTO.PaymentID > 0);
            Assert.AreNotEqual(DateTime.MinValue, paymentDTO.PaidAt);
            Assert.IsTrue(Convert.ToDouble(paymentDTO.PaymentAmount) == addPaymentDTO.PaymentAmount);
        }
 public async Task <PaymentDTO> Post([FromBody] AddPaymentDTO addPaymentDTO)
 {
     return(await _paymentService.MakePayment(addPaymentDTO));
 }