示例#1
0
        public async Task <AdvanceJson> GetAdvanceDetails([FromQuery] AdvanceDetailsModel model)
        {
            var wai = await _accountApi.WhoAmI(model.AuthToken);

            var advance = _context.Advances.Include(q => q.Payments).SingleOrDefault(q => q.CustomerId == wai.CustomerId && q.Id == model.Id);

            return(new AdvanceJson(advance));
        }
示例#2
0
        public async Task GetAdvancePaymentRequestDetailsTest()
        {
            #region ContextSetup

            var dbContext = DbContext;

            var registeredCustomer = await dbContext.Customers.FirstOrDefaultAsync();

            var waiToken      = registeredCustomer.MapToWhoAmI().EncryptToken();
            var customerModel = new CustomerModel()
            {
                Id = registeredCustomer.Id, Name = registeredCustomer.Name, Email = registeredCustomer.Email
            };
            var paymentModel = new PaymentModel()
            {
                Customer           = customerModel,
                Amount             = 100,
                InstalmentsCount   = 5,
                CardNumber         = "5555111122223333",
                CardExpirationDate = "08/2021",
                CardName           = "OLAVO DE SOUZA ROCHA NETO",
                CardSecurityNumber = "558",
                AuthToken          = waiToken
            };
            var before = DateTime.Now;

            var paymentModel2 = new PaymentModel()
            {
                Customer           = customerModel,
                Amount             = 150,
                InstalmentsCount   = 5,
                CardNumber         = "5555111122223333",
                CardExpirationDate = "08/2021",
                CardName           = "OLAVO DE SOUZA ROCHA NETO",
                CardSecurityNumber = "558",
                AuthToken          = waiToken
            };

            PaymentController controller = new PaymentController(dbContext, FakeAcquirer, FakeAccount, FakeLogger);
            await controller.ProcessPayment(paymentModel);

            await controller.ProcessPayment(paymentModel2);

            var paymentListModel = new PaymentListModel()
            {
                AuthToken = waiToken
            };
            var firstPaymentForAdvance =
                new AdvanceListModel()
            {
                AuthToken = waiToken,
                Payments  = new[] { (await controller.ListAvailableForAdvance(paymentListModel)).Payments.First() }.Select(q => q.Id)
            };

            var adv = await controller.RequestForAdvance(firstPaymentForAdvance);

            #endregion

            var adModel = new AdvanceDetailsModel()
            {
                AuthToken = waiToken,
                Id        = adv.Id
            };
            var radv = await controller.GetAdvanceDetails(adModel);

            Assert.Equal(radv.Id, adModel.Id);
            Assert.Single(radv.Payments);

            var percentTax = 0.038m;
            var instalment = decimal.Divide(150, 5);
            Assert.Equal(150m - 0.9m - (1m * percentTax) * instalment - (2m * percentTax) * instalment - (3m * percentTax) * instalment - (4m * percentTax) * instalment - (5m * percentTax) * instalment, adv.NetAmount);
        }