public async Task CreateAsync_Success() { CustomerRequest customerRequest = BuildCustomerCreateRequest(); var customerClient = new CustomerClient(); Customer customer = await customerClient.CreateAsync(customerRequest); await Task.Delay(1000); try { CustomerCardCreateRequest cardRequest = await BuildCardCreateRequestAsync(); CustomerCard card = await customerClient.CreateCardAsync(customer.Id, cardRequest); var request = new CardTokenRequest { CustomerId = customer.Id, CardId = card.Id, SecurityCode = "123", }; CardToken cardToken = await client.CreateAsync(request); Assert.NotNull(cardToken); Assert.NotNull(cardToken.Id); } finally { customerClient.Delete(customer.Id); } }
private CardTokenRequest GetCardTokenRequest() { var phone = new Phone { CountryCode = "44", Number = "020 222333" }; var billingAddress = new Address { AddressLine1 = "CheckoutSdk.com", AddressLine2 = "90 Tottenham Court Road", City = "London", State = "London", Zip = "W1T 4TJ", Country = CountryCode.GB }; var cardTokenRequest = new CardTokenRequest { Name = TestCardSource.Visa.Name, Number = TestCardSource.Visa.Number, ExpiryYear = TestCardSource.Visa.ExpiryYear, ExpiryMonth = TestCardSource.Visa.ExpiryMonth, Cvv = TestCardSource.Visa.Cvv, BillingAddress = billingAddress, Phone = phone }; return(cardTokenRequest); }
public async Task <string> GenerateToken(string cardNumber, string cvv) { CardTokenRequest cardTokenRequest = new CardTokenRequest() { cardNumber = cardNumber, customerEmail = cardRequestModel.customerEmail, customerMobile = cardRequestModel.customerMobile, customerProfileId = cardRequestModel.customerProfileId, merchantCode = cardRequestModel.merchantCode, cvv = cvv, }; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri("https://atfawry.fawrystaging.com//ECommerceWeb/Fawry/cards/cardToken"); string JsonContent = JsonConvert.SerializeObject(cardTokenRequest); HttpContent requestContent = new StringContent(JsonContent, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://atfawry.fawrystaging.com//ECommerceWeb/Fawry/cards/cardToken", requestContent); string responseContent = await response.Content.ReadAsStringAsync(); CardTokenResponse cardTokenResponse = (CardTokenResponse)JsonConvert.DeserializeObject(responseContent); CardToken = cardTokenResponse.card.token; return(CardToken); } }
public void Get_Success() { CustomerRequest customerRequest = BuildCustomerCreateRequest(); var customerClient = new CustomerClient(); Customer customer = customerClient.Create(customerRequest); Thread.Sleep(1000); try { CustomerCardCreateRequest cardRequest = BuildCardCreateRequest(); CustomerCard card = customerClient.CreateCard(customer.Id, cardRequest); var request = new CardTokenRequest { CustomerId = customer.Id, CardId = card.Id, SecurityCode = "123", }; CardToken createdCartToken = client.Create(request); Thread.Sleep(1000); CardToken cardToken = client.Get(createdCartToken.Id); Assert.NotNull(cardToken); Assert.Equal(createdCartToken.Id, cardToken.Id); } finally { customerClient.Delete(customer.Id); } }
private async Task <CreateInstrumentResponse> CreateTokenInstrument() { var phone = new Phone { CountryCode = "44", Number = "020 222333" }; var billingAddress = new Address { AddressLine1 = "CheckoutSdk.com", AddressLine2 = "90 Tottenham Court Road", City = "London", State = "London", Zip = "W1T 4TJ", Country = CountryCode.GB }; var cardTokenRequest = new CardTokenRequest { Name = TestCardSource.Visa.Name, Number = TestCardSource.Visa.Number, ExpiryYear = TestCardSource.Visa.ExpiryYear, ExpiryMonth = TestCardSource.Visa.ExpiryMonth, Cvv = TestCardSource.Visa.Cvv, BillingAddress = billingAddress, Phone = phone }; var cardTokenResponse = await PreviousApi.TokensClient().Request(cardTokenRequest); cardTokenResponse.ShouldNotBeNull(); var request = new CreateInstrumentRequest { Token = cardTokenResponse.Token, Customer = new InstrumentCustomerRequest { Email = "*****@*****.**", Name = "Bruce Wayne", Default = true, Phone = new Phone { CountryCode = "+1", Number = "4155552671" } } }; var createInstrumentResponse = await PreviousApi.InstrumentsClient().Create(request); createInstrumentResponse.ShouldNotBeNull(); return(createInstrumentResponse); }
public async Task <IActionResult> RequestCardToken(CardTokenRequest tokenRequest) { try { var tokenResponse = await api.Tokens.RequestAsync(tokenRequest); return(CreatedAtAction(nameof(RequestCardToken), tokenResponse)); } catch (Exception e) { return(UnprocessableEntity(e.Message)); } }
private async Task ShouldRequestCardToken() { var phone = new Phone { CountryCode = "44", Number = "020 222333" }; var billingAddress = new Address { AddressLine1 = "CheckoutSdk.com", AddressLine2 = "90 Tottenham Court Road", City = "London", State = "London", Zip = "W1T 4TJ", Country = CountryCode.GB }; var cardTokenRequest = new CardTokenRequest { Name = TestCardSource.Visa.Name, Number = TestCardSource.Visa.Number, ExpiryYear = TestCardSource.Visa.ExpiryYear, ExpiryMonth = TestCardSource.Visa.ExpiryMonth, Cvv = TestCardSource.Visa.Cvv, BillingAddress = billingAddress, Phone = phone }; var cardTokenResponse = await PreviousApi.TokensClient().Request(cardTokenRequest); cardTokenResponse.ShouldNotBeNull(); cardTokenResponse.Token.ShouldNotBeNullOrEmpty(); cardTokenResponse.Type.ShouldBe(TokenType.Card); cardTokenResponse.ExpiryMonth.ShouldBe(cardTokenRequest.ExpiryMonth); cardTokenResponse.ExpiryYear.ShouldBe(cardTokenRequest.ExpiryYear); cardTokenResponse.ExpiresOn.ShouldNotBeNull(); cardTokenResponse.BillingAddress.ShouldNotBeNull(); cardTokenResponse.BillingAddress.AddressLine1.ShouldBe(cardTokenRequest.BillingAddress.AddressLine1); cardTokenResponse.BillingAddress.AddressLine2.ShouldBe(cardTokenResponse.BillingAddress.AddressLine2); cardTokenResponse.BillingAddress.City.ShouldBe(cardTokenRequest.BillingAddress.City); cardTokenResponse.BillingAddress.State.ShouldBe(cardTokenRequest.BillingAddress.State); cardTokenResponse.BillingAddress.Zip.ShouldBe(cardTokenRequest.BillingAddress.Zip); cardTokenResponse.BillingAddress.Country.ShouldBe(cardTokenRequest.BillingAddress.Country); cardTokenResponse.Phone.ShouldNotBeNull(); cardTokenResponse.Phone.CountryCode.ShouldBe(cardTokenRequest.Phone.CountryCode); cardTokenResponse.Phone.Number.ShouldBe(cardTokenRequest.Phone.Number); //cardTokenResponse.CardType.ShouldBe(CardType.Credit); //cardTokenResponse.CardCategory.ShouldBe(CardCategory.Consumer); }
protected async Task <CardTokenResponse> RequestToken() { var cardTokenRequest = new CardTokenRequest { Name = TestCardSource.Visa.Name, Number = TestCardSource.Visa.Number, ExpiryYear = TestCardSource.Visa.ExpiryYear, ExpiryMonth = TestCardSource.Visa.ExpiryMonth, Cvv = TestCardSource.Visa.Cvv, BillingAddress = GetAddress(), Phone = GetPhone() }; var cardTokenResponse = await DefaultApi.TokensClient().Request(cardTokenRequest); cardTokenResponse.ShouldNotBeNull(); return(cardTokenResponse); }
protected async Task <PaymentResponse> MakeTokenPayment() { var phone = GetPhone(); var billingAddress = GetAddress(); var cardTokenRequest = new CardTokenRequest { Name = TestCardSource.Visa.Name, Number = TestCardSource.Visa.Number, ExpiryYear = TestCardSource.Visa.ExpiryYear, ExpiryMonth = TestCardSource.Visa.ExpiryMonth, Cvv = TestCardSource.Visa.Cvv, BillingAddress = billingAddress, Phone = phone }; var cardTokenResponse = await PreviousApi.TokensClient().Request(cardTokenRequest); cardTokenResponse.ShouldNotBeNull(); var paymentRequest = new PaymentRequest { Source = new RequestTokenSource { Token = cardTokenResponse.Token }, Capture = true, Reference = Guid.NewGuid().ToString(), Amount = 10L, Currency = Currency.USD, Customer = new CustomerRequest { Email = GenerateRandomEmail() }, BillingDescriptor = new BillingDescriptor { Name = "name", City = "London", Reference = "reference" } }; var paymentResponse = await PreviousApi.PaymentsClient().RequestPayment(paymentRequest); paymentResponse.ShouldNotBeNull(); return(paymentResponse); }
public async Task CanTokenizeCard() { CardTokenRequest request = CreateValidRequest(); CardTokenResponse token = await _api.Tokens.RequestAsync(request); token.ShouldNotBeNull(); token.Token.ShouldNotBeNullOrEmpty(); token.ExpiresOn.ShouldBeGreaterThan(DateTime.UtcNow); token.BillingAddress.ShouldNotBeNull(); token.BillingAddress.AddressLine1.ShouldBe(request.BillingAddress.AddressLine1); token.BillingAddress.AddressLine2.ShouldBe(request.BillingAddress.AddressLine2); token.BillingAddress.City.ShouldBe(request.BillingAddress.City); token.BillingAddress.State.ShouldBe(request.BillingAddress.State); token.BillingAddress.Zip.ShouldBe(request.BillingAddress.Zip); token.BillingAddress.Country.ShouldBe(request.BillingAddress.Country); token.Phone.ShouldNotBeNull(); token.Phone.CountryCode.ShouldBe(request.Phone.CountryCode); token.Phone.Number.ShouldBe(request.Phone.Number); token.Type.ShouldBe("card"); token.ExpiryMonth.ShouldBe(request.ExpiryMonth); token.ExpiryYear.ShouldBe(request.ExpiryYear); }
void when_post_tokens() { context["given a card token request"] = () => { context["that is valid"] = () => { beforeAllAsync = async() => { tokenRequest = new CardTokenRequest(number: "4242424242424242", expiryMonth: 12, expiryYear: 2022); result = await controller.RequestCardToken(tokenRequest); token = (result as ObjectResult).Value as TokenResponse; }; it["should return 201 - Created"] = () => { (result as CreatedAtActionResult).StatusCode.ShouldBe(StatusCodes.Status201Created); }; context["with token that"] = () => { it["should not be null"] = () => { token.ShouldNotBeNull(); }; it["should expire in 15m"] = () => { var expiration = (token as CardTokenResponse).ExpiresOn; var now = DateTime.UtcNow; (expiration - now).Minutes.ShouldBeLessThanOrEqualTo(15); }; it["should match type of request"] = () => { token.Type.ShouldBe(tokenRequest.Type); }; it["should match expiry month of request"] = () => { (token as CardTokenResponse).ExpiryMonth.ShouldBe((tokenRequest as CardTokenRequest).ExpiryMonth); }; it["should match expiry year of request"] = () => { (token as CardTokenResponse).ExpiryYear.ShouldBe((tokenRequest as CardTokenRequest).ExpiryYear); }; it["should match last4 digits of request number"] = () => { (tokenRequest as CardTokenRequest).Number.ShouldEndWith((token as CardTokenResponse).Last4); }; it["should have expires_on field"] = () => { (token as CardTokenResponse).ExpiresOn.ShouldNotBeNull(); }; }; }; }; }