public async void CreatePaymentTestShouldReturnPaymentWhenBankSucceedsToProcessPayment() { Payment paymentResult = await paymentsService.CreatePayment(new Payment { Amount = 49.99F, CustomerEmail = "*****@*****.**", CustomerName = "Alex Winchester", CardExpiryDate = new DateTime(2019, 12, 1), CardNumber = "123456789101112", Currency = "GBP", CVV = "333" }); Assert.Equal("*****@*****.**", paymentResult.CustomerEmail); Assert.Equal("49.99", paymentResult.Amount.ToString()); Assert.Equal("123456789101112", paymentResult.CardNumber); Assert.Equal("1", paymentResult.PaymentStatus.ToString()); Assert.Equal("01/12/2019 00:00:00", paymentResult.CardExpiryDate.ToString()); }
public async void CreatePaymentTestShouldReturnNullWhenBankFailsToProcessPayment() { //update mockBankRepository to return failed payments MockBankRepository mockBankRepositoryFailProcess = new MockBankRepository(processPaymentSuccess: false); paymentsService = new PaymentsService(mockBankRepositoryFailProcess, paymentRepository); Payment paymentResult = await paymentsService.CreatePayment(new Payment { Amount = 449.99F, CustomerEmail = "*****@*****.**", CustomerName = "John Doe", CardExpiryDate = new DateTime(2019, 12, 1), CardNumber = "123456789101112", Currency = "GBP", CVV = "333" }); Assert.Null(paymentResult); }
public void Payments() { var service = new PaymentsService(_Client); var card = new Models.DirectCheckouts.Card { CardNumber = "5132 0723 8792 9820", ExpirationMonth = "04", ExpirationYear = "2022", HolderName = "HIDELBRANDO SILVA", SecurityCode = "732" }; var dc = new DirectCheckouts.DirectCheckout(_Client.Credentials.PublicToken, false); var creditCardHash = dc.GetCardHash(card); if (string.IsNullOrWhiteSpace(creditCardHash)) { throw new Exception("Definir hash do cartão de crédito"); } // // Cria a cobrança var chargesService = new ChargesService(_Client); var split = new List <Split> { new Split { AmountRemainder = true, ChargeFee = false, Percentage = 90.0m, RecipientToken = "5E64B2E0B0D4AE42A3F2981CC4055CF613F6C17B5C2912029C587581E72ECDB8", // Seller - Harry Potter - Document: 90564489603 - Id: dac_2585CBF0E2A23649 }, new Split { AmountRemainder = false, ChargeFee = false, Percentage = 1.0m, RecipientToken = "F3FEB619853E74753853E0BBFC1A6CBF53189A3F8059035877C136641897AAB9", // Optional - Hogwarts - Document: 78338726311040 - Id: dac_591251E5D47F08AE }, new Split { AmountRemainder = false, ChargeFee = true, Percentage = 9.0m, RecipientToken = _Client.Credentials.PrivateToken, // Bibi Peças } }; var newCharge = new Models.Requests.CreateChargeResource.CreateCharge { Charge = new Charge { Description = $"Cobrança Teste - {Guid.NewGuid()}", //References Amount = 100.0m, //TotalAmount = 100.0m, //Installments = 1, DueDate = DateTime.Now.AddDays(3), PaymentTypes = new List <PaymentType> { PaymentType.CREDIT_CARD }, Split = split }, Billing = new BillingForCharge { Name = "Hidelbrando da Silva", Document = Helpers.NewCPF(), Email = "*****@*****.**", Phone = "5585982061631", BirthDate = DateTime.Now.AddYears(-21), }, }; var createdCharges = chargesService.CreateCharge(_Client.Credentials.PrivateToken, newCharge); Assert.IsNotNull(createdCharges?.Embedded?.Charges.FirstOrDefault()?.Id); var chargeId = createdCharges.Embedded.Charges[0].Id; // TODO service.CreditCardTokenization var newPayment = new Models.Requests.CreatePaymentResource.CreatePayment { ChargeId = chargeId, Billing = new BillingForPayment { Delayed = true, Address = new Address { Street = "Rua dos Alfeneiros", Number = "4", Complement = "Armário debaixo da escada", Neighborhood = "Surrey", City = "Caucaia", State = AddressState.CE, PostCode = "61611220" }, Email = "*****@*****.**" }, CreditCardDetails = new CreditCardDetails { CreditCardHash = creditCardHash } }; var createdPayment = service.CreatePayment(_Client.Credentials.PrivateToken, newPayment); Assert.IsNotNull(createdPayment); Assert.IsNotNull(createdPayment.Payments); Assert.IsFalse(string.IsNullOrWhiteSpace(createdPayment.TransactionId)); var newCapturePayment = new Models.Requests.CaptureCreditCardPaymentResource.CaptureCreditCardPayment { ChargeId = chargeId, Amount = newCharge.Charge.Amount, }; var capturedPayment = service.CaptureCreditCardPayment(_Client.Credentials.PrivateToken, createdPayment.Payments[0].Id, newCapturePayment); Assert.IsNotNull(capturedPayment); Assert.IsNotNull(createdPayment.Payments); Assert.IsFalse(string.IsNullOrWhiteSpace(createdPayment.TransactionId)); var newRefundPayment = new Models.Requests.RefundCreditCardPaymentResource.RefundCreditCardPayment { Amount = newCharge.Charge.Amount, Split = split }; var refundedPayment = service.RefundCreditCardPayment(_Client.Credentials.PrivateToken, createdPayment.Payments[0].Id, newRefundPayment); Assert.IsNotNull(refundedPayment); Assert.IsNotNull(refundedPayment.Refunds); Assert.IsFalse(string.IsNullOrWhiteSpace(refundedPayment.TransactionId)); }