public static string GetNonceForNewCreditCard(BraintreeGateway gateway, Params creditCardDetails, string customerId = null) { var authorizationFingerprint = GenerateAuthorizationFingerprint(gateway, customerId); var builder = new RequestBuilder(); builder. AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("shared_customer_identifier_type", "testing"); foreach (var param in creditCardDetails) { var nested = param.Value as Params; if (null != nested) { foreach (var nestedParam in nested) { builder.AddTopLevelElement(string.Format("credit_card[{0}][{1}]", param.Key, nestedParam.Key), nestedParam.Value.ToString()); } } else { builder.AddTopLevelElement(string.Format("credit_card[{0}]", param.Key), param.Value.ToString()); } } var response = new BraintreeTestHttpService().Post( gateway.MerchantId, "v1/payment_methods/credit_cards", builder.ToQueryString()); return(extractParamFromJson("nonce", response)); }
public static string GetNonceForNewPaymentMethod(BraintreeGateway gateway, Params @params, bool isCreditCard) { var clientToken = GenerateDecodedClientToken(gateway); var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); var paymentMethodType = isCreditCard ? "credit_card" : "paypal_account"; var paymentMethodTypePlural = paymentMethodType + "s"; var builder = new RequestBuilder(); builder. AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("shared_customer_identifier_type", "testing"); foreach (var param in @params) { builder.AddTopLevelElement(string.Format("{0}[{1}]", paymentMethodType, param.Key), param.Value.ToString()); } var response = new BraintreeTestHttpService().Post( gateway.MerchantId, "v1/payment_methods/" + paymentMethodTypePlural, builder.ToQueryString()); #if netcore StreamReader reader = new StreamReader(response.Content.ReadAsStreamAsync().Result, Encoding.UTF8); string responseBody = reader.ReadToEnd(); return(extractParamFromJson("nonce", responseBody)); #else return(extractParamFromJson("nonce", response)); #endif }
private static ClientConfiguration GetClientConfiguration(BraintreeGateway gateway, String authorizationFingerprint) { var queryParams = new RequestBuilder(); queryParams.AddTopLevelElement("authorizationFingerprint", authorizationFingerprint); queryParams.AddTopLevelElement("configVersion", "3"); var response = new BraintreeTestHttpService().Get( gateway.MerchantId, "v1/configuration?" + queryParams.ToQueryString() ); var json = GetResponseContent(response); return(JsonConvert.DeserializeObject <ClientConfiguration>(json)); }
public static string GenerateUnlockedNonce(BraintreeGateway gateway, string creditCardNumber, string customerId) { var authorizationFingerprint = GenerateAuthorizationFingerprint(gateway, customerId); RequestBuilder builder = new RequestBuilder(""); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier_type", "testing"). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("credit_card[number]", creditCardNumber). AddTopLevelElement("share", "true"). AddTopLevelElement("credit_card[expiration_month]", "11"). AddTopLevelElement("credit_card[expiration_year]", "2099"); var response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards", builder.ToQueryString()); #if netcore StreamReader reader = new StreamReader(response.Content.ReadAsStreamAsync().Result, Encoding.UTF8); #else StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); #endif string responseBody = reader.ReadToEnd(); return(extractParamFromJson("nonce", responseBody)); }
public static string GetNonceForPayPalAccount(BraintreeGateway gateway, Params paypalAccountDetails) { var clientToken = GenerateDecodedClientToken(gateway); var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); var builder = new RequestBuilder(); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint); foreach (var param in paypalAccountDetails) { builder.AddTopLevelElement(string.Format("paypal_account[{0}]", param.Key), param.Value.ToString()); } var response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/paypal_accounts", builder.ToQueryString()); return(extractParamFromJson("nonce", response)); }
public void GenerateAsync_GeneratesFingerprintAcceptedByGateway() { Task.Run(async() => #endif { var encodedClientToken = await gateway.ClientToken.generateAsync(); var decodedClientToken = Encoding.UTF8.GetString(Convert.FromBase64String(encodedClientToken)); var clientToken = Regex.Unescape(decodedClientToken); var authorizationFingerprint = TestHelper.extractParamFromJson("authorizationFingerprint", clientToken); var builder = new RequestBuilder(); builder. AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("shared_customer_identifier_type", "testing"); var response = new TestUtil.BraintreeTestHttpService().Get( gateway.MerchantId, "v1/payment_methods?" + builder.ToQueryString()); Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } #if net452 ).GetAwaiter().GetResult(); }
public static string GenerateFuturePaymentPayPalNonce(BraintreeGateway gateway) { var clientToken = GenerateDecodedClientToken(gateway); var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); RequestBuilder builder = new RequestBuilder(""); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier_type", "testing"). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("paypal_account[consent_code]", "consent"). AddTopLevelElement("paypal_account[correlation_id]", Guid.NewGuid().ToString()). AddTopLevelElement("paypal_account[options][validate]", "false"); var response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/paypal_accounts", builder.ToQueryString()); #if netcore StreamReader reader = new StreamReader(response.Content.ReadAsStreamAsync().Result, Encoding.UTF8); #else StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); #endif string responseBody = reader.ReadToEnd(); Regex regex = new Regex("nonce\":\"(?<nonce>[a-f0-9\\-]+)\""); Match match = regex.Match(responseBody); return(match.Groups["nonce"].Value); }
public void Generate_GatewayRespectsFailOnDuplicatePaymentMethod() { BraintreeGateway gateway = new BraintreeGateway { Environment = Environment.DEVELOPMENT, MerchantId = "integration_merchant_id", PublicKey = "integration_public_key", PrivateKey = "integration_private_key" }; Result <Customer> result = gateway.Customer.Create(new CustomerRequest()); Assert.IsTrue(result.IsSuccess()); string customerId = result.Target.Id; var request = new CreditCardRequest { CustomerId = customerId, Number = "4111111111111111", ExpirationDate = "05/2099" }; Result <CreditCard> creditCardResult = gateway.CreditCard.Create(request); Assert.IsTrue(creditCardResult.IsSuccess()); var clientToken = TestHelper.GenerateDecodedClientToken(gateway, new ClientTokenRequest { CustomerId = customerId, Options = new ClientTokenOptionsRequest { FailOnDuplicatePaymentMethod = true } } ); var authorizationFingerprint = TestHelper.extractParamFromJson("authorizationFingerprint", clientToken); RequestBuilder builder = new RequestBuilder(""); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier_type", "testing"). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("credit_card[number]", "4111111111111111"). AddTopLevelElement("credit_card[expiration_month]", "11"). AddTopLevelElement("credit_card[expiration_year]", "2099"); HttpWebResponse response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString()); response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString()); Assert.AreEqual(422, (int)response.StatusCode); response.Close(); Customer customer = gateway.Customer.Find(customerId); Assert.AreEqual(1, customer.CreditCards.Length); }
public static string GetNonceForPayPalAccount(BraintreeGateway gateway, Params paypalAccountDetails) { var authorizationFingerprint = GenerateAuthorizationFingerprint(gateway); var builder = new RequestBuilder(); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint); foreach (var param in paypalAccountDetails) { builder.AddTopLevelElement(string.Format("paypal_account[{0}]", param.Key), param.Value.ToString()); } var response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/paypal_accounts", builder.ToQueryString()); #if netcore StreamReader reader = new StreamReader(response.Content.ReadAsStreamAsync().Result, Encoding.UTF8); string responseBody = reader.ReadToEnd(); return(extractParamFromJson("nonce", responseBody)); #else return(extractParamFromJson("nonce", response)); #endif }
public override string ToQueryString() { var builder = new RequestBuilder(); builder.AddTopLevelElement("merchant_id", MerchantId); builder.AddTopLevelElement("redirect_uri", RedirectUri); builder.AddTopLevelElement("scope", Scope); builder.AddTopLevelElement("state", State); builder.AddTopLevelElement("landing_page", LandingPage); builder.AddTopLevelElement("login_only", LoginOnly.ToString().ToLower()); builder.AddTopLevelElement("client_id", ClientId); foreach (var paymentMethod in PaymentMethods) { builder.AddTopLevelElement("payment_methods[]", paymentMethod); } builder.AddElement("user", User); builder.AddElement("business", Business); return(builder.ToQueryString()); }
public static string GenerateUnlockedNonce(BraintreeGateway gateway, string creditCardNumber, string customerId) { var clientToken = ""; if (customerId == null) { clientToken = GenerateDecodedClientToken(gateway); } else { clientToken = GenerateDecodedClientToken(gateway, new ClientTokenRequest { CustomerId = customerId } ); } var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); RequestBuilder builder = new RequestBuilder(""); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier_type", "testing"). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("credit_card[number]", creditCardNumber). AddTopLevelElement("share", "true"). AddTopLevelElement("credit_card[expiration_month]", "11"). AddTopLevelElement("credit_card[expiration_year]", "2099"); var response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString()); #if netcore StreamReader reader = new StreamReader(response.Content.ReadAsStreamAsync().Result, Encoding.UTF8); #else StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); #endif string responseBody = reader.ReadToEnd(); Regex regex = new Regex("nonce\":\"(?<nonce>[a-f0-9\\-]+)\""); Match match = regex.Match(responseBody); return(match.Groups["nonce"].Value); }
public override string ToQueryString() { var builder = new RequestBuilder(); builder.AddTopLevelElement("merchant_id", MerchantId); builder.AddTopLevelElement("redirect_uri", RedirectUri); builder.AddTopLevelElement("scope", Scope); builder.AddTopLevelElement("state", State); builder.AddTopLevelElement("landing_page", LandingPage); builder.AddTopLevelElement("client_id", ClientId); foreach (var paymentMethod in PaymentMethods) { builder.AddTopLevelElement("payment_methods[]", paymentMethod); } builder.AddElement("user", User); builder.AddElement("business", Business); return builder.ToQueryString(); }
public static string GetNonceForNewCreditCard(BraintreeGateway gateway, Params creditCardDetails, string customerId = null) { var clientToken = TestHelper.GenerateDecodedClientToken( gateway, customerId == null ? null : new ClientTokenRequest { CustomerId = customerId }); var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); var builder = new RequestBuilder(); builder. AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("shared_customer_identifier_type", "testing"); foreach (var param in creditCardDetails) { var nested = param.Value as Params; if (null != nested) { foreach (var nestedParam in nested) { builder.AddTopLevelElement(string.Format("credit_card[{0}][{1}]", param.Key, nestedParam.Key), nestedParam.Value.ToString()); } } else builder.AddTopLevelElement(string.Format("credit_card[{0}]", param.Key), param.Value.ToString()); } var response = new BraintreeTestHttpService().Post( gateway.MerchantId, "v1/payment_methods/credit_cards", builder.ToQueryString()); return extractParamFromJson("nonce", response); }
public static string GetNonceForNewPaymentMethod(BraintreeGateway gateway, Params @params, bool isCreditCard) { var clientToken = GenerateDecodedClientToken(gateway); var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); var paymentMethodType = isCreditCard ? "credit_card" : "paypal_account"; var paymentMethodTypePlural = paymentMethodType + "s"; var builder = new RequestBuilder(); builder. AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("shared_customer_identifier_type", "testing"); foreach (var param in @params) builder.AddTopLevelElement(string.Format("{0}[{1}]", paymentMethodType, param.Key), param.Value.ToString()); var response = new BraintreeTestHttpService().Post( gateway.MerchantId, "v1/payment_methods/" + paymentMethodTypePlural, builder.ToQueryString()); return extractParamFromJson("nonce", response); }
public void Generate_GatewayRespectsMakeDefault() { var gateway = new BraintreeGateway(); Result<Customer> result = gateway.Customer.Create(new CustomerRequest()); Assert.IsTrue(result.IsSuccess()); string customerId = result.Target.Id; var request = new CreditCardRequest { CustomerId = customerId, Number = "5555555555554444", ExpirationDate = "05/2099" }; Result<CreditCard> creditCardResult = gateway.CreditCard.Create(request); Assert.IsTrue(creditCardResult.IsSuccess()); var clientToken = TestHelper.GenerateDecodedClientToken(gateway, new ClientTokenRequest { CustomerId = customerId, Options = new ClientTokenOptionsRequest { MakeDefault = true } } ); var authorizationFingerprint = TestHelper.extractParamFromJson("authorizationFingerprint", clientToken); var builder = new RequestBuilder(""); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier_type", "testing"). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("credit_card[number]", "4111111111111111"). AddTopLevelElement("credit_card[expiration_month]", "11"). AddTopLevelElement("credit_card[expiration_year]", "2099"); HttpWebResponse response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString()); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); response.Close(); Customer customer = gateway.Customer.Find(customerId); Assert.AreEqual(2, customer.CreditCards.Length); foreach (CreditCard creditCard in customer.CreditCards) { if (creditCard.LastFour == "1111") { Assert.IsTrue(creditCard.IsDefault.Value); } } }
public void Generate_GatewayRespectsVerifyCard() { var gateway = new BraintreeGateway(); Result<Customer> result = gateway.Customer.Create(new CustomerRequest()); Assert.IsTrue(result.IsSuccess()); string customerId = result.Target.Id; var clientToken = TestHelper.GenerateDecodedClientToken(gateway, new ClientTokenRequest { CustomerId = customerId, Options = new ClientTokenOptionsRequest { VerifyCard = true } } ); var authorizationFingerprint = TestHelper.extractParamFromJson("authorizationFingerprint", clientToken); var builder = new RequestBuilder(""); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier_type", "testing"). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("credit_card[number]", "4000111111111115"). AddTopLevelElement("credit_card[expiration_month]", "11"). AddTopLevelElement("credit_card[expiration_year]", "2099"); HttpWebResponse response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString()); Assert.AreEqual(422, (int)response.StatusCode); response.Close(); Customer customer = gateway.Customer.Find(customerId); Assert.AreEqual(0, customer.CreditCards.Length); }
public static string GenerateUnlockedNonce(BraintreeGateway gateway, string creditCardNumber, string customerId) { var clientToken = ""; if (customerId == null) { clientToken = TestHelper.GenerateDecodedClientToken(gateway); } else { clientToken = TestHelper.GenerateDecodedClientToken(gateway, new ClientTokenRequest { CustomerId = customerId } ); } var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); RequestBuilder builder = new RequestBuilder(""); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier_type", "testing"). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("credit_card[number]", creditCardNumber). AddTopLevelElement("share", "true"). AddTopLevelElement("credit_card[expiration_month]", "11"). AddTopLevelElement("credit_card[expiration_year]", "2099"); HttpWebResponse response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString()); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string responseBody = reader.ReadToEnd(); Regex regex = new Regex("nonce\":\"(?<nonce>[a-f0-9\\-]+)\""); Match match = regex.Match(responseBody); return match.Groups["nonce"].Value; }
public static string GenerateFuturePaymentPayPalNonce(BraintreeGateway gateway) { var clientToken = TestHelper.GenerateDecodedClientToken(gateway); var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); RequestBuilder builder = new RequestBuilder(""); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint). AddTopLevelElement("shared_customer_identifier_type", "testing"). AddTopLevelElement("shared_customer_identifier", "test-identifier"). AddTopLevelElement("paypal_account[consent_code]", "consent"). AddTopLevelElement("paypal_account[correlation_id]", System.Guid.NewGuid().ToString()). AddTopLevelElement("paypal_account[options][validate]", "false"); HttpWebResponse response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/paypal_accounts", builder.ToQueryString()); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string responseBody = reader.ReadToEnd(); Regex regex = new Regex("nonce\":\"(?<nonce>[a-f0-9\\-]+)\""); Match match = regex.Match(responseBody); return match.Groups["nonce"].Value; }
public static string GetNonceForPayPalAccount(BraintreeGateway gateway, Params paypalAccountDetails) { var clientToken = GenerateDecodedClientToken(gateway); var authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); var builder = new RequestBuilder(); builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint); foreach (var param in paypalAccountDetails) builder.AddTopLevelElement(string.Format("paypal_account[{0}]", param.Key), param.Value.ToString()); var response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/paypal_accounts", builder.ToQueryString()); return extractParamFromJson("nonce", response); }