public async Task RequestAdvanceOnceTest() { //load the context await GetAdvancePaymentRequestDetailsTest(); var registeredCustomer = await DbContext.Customers.FirstOrDefaultAsync(); var waiToken = registeredCustomer.MapToWhoAmI().EncryptToken(); PaymentController controller = new PaymentController(DbContext, FakeAcquirer, FakeAccount, FakeLogger); var paymentListModel = new PaymentListModel() { AuthToken = waiToken }; var seccondPaymentForAdvance = new AdvanceListModel() { AuthToken = waiToken, Payments = new[] { (await controller.ListAvailableForAdvance(paymentListModel)).Payments.ToList()[0] }.Select(q => q.Id) }; var adv2 = await controller.RequestForAdvance(seccondPaymentForAdvance); Assert.IsType <AdvanceErrorJson>(adv2); }
public async Task <AdvanceListJson> ListAdvanceRequests([FromQuery] AdvanceListModel model) { var wai = await _accountApi.WhoAdminAmI(model.AuthToken); var advances = _context.Advances.Include(q => q.Payments).Where(q => q.EvaluationDateStart == null || q.EvaluationBy == wai.AdminId).ToList(); return(new AdvanceListJson(advances, advances.Count())); }
public async Task <AdvanceJson> RequestForAdvance([FromBody] AdvanceListModel model) { var advProcessing = new AdvanceProcessing(_context, _acquirerApi, _accountApi, _log); var advance = model.Map(); try { advance = await advProcessing.Request(advance, model.AuthToken); await _context.SaveChangesAsync(); } catch (Exception ex) { return(new AdvanceErrorJson(ex.Message)); } return(new AdvanceJson(advance)); }
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); }
public async Task RequestForAdvancePaymentTest() { var customer = new CustomerModel() { Name = "Olavo Neto", Email = "*****@*****.**", }; var registeredCustomer = await DbContext.Customers.FirstOrDefaultAsync(); var waiToken = registeredCustomer.MapToWhoAmI().EncryptToken(); customer.Id = registeredCustomer.Id; var paymentModel = new PaymentModel() { Customer = customer, 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 = customer, 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); Assert.Equal(150, adv.GrossAmount); 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); }