ToQueryString() public method

public ToQueryString ( ) : string
return string
        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("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 override string ToQueryString(string root)
 {
     var builder = new RequestBuilder("user"); // ignore the root as it is wrong
     builder.AddElement("country", Country);
     builder.AddElement("email", Email);
     builder.AddElement("first_name", FirstName);
     builder.AddElement("last_name", LastName);
     builder.AddElement("phone", Phone);
     builder.AddElement("dob_year", DobYear);
     builder.AddElement("dob_month", DobMonth);
     builder.AddElement("dob_day", DobDay);
     builder.AddElement("street_address", StreetAddress);
     builder.AddElement("locality", Locality);
     builder.AddElement("region", Region);
     builder.AddElement("postal_code", PostalCode);
     return builder.ToQueryString();
 }
Ejemplo n.º 3
0
        public override string ToQueryString(string root)
        {
            var builder = new RequestBuilder("user"); // ignore the root as it is wrong

            builder.AddElement("country", Country);
            builder.AddElement("email", Email);
            builder.AddElement("first_name", FirstName);
            builder.AddElement("last_name", LastName);
            builder.AddElement("phone", Phone);
            builder.AddElement("dob_year", DobYear);
            builder.AddElement("dob_month", DobMonth);
            builder.AddElement("dob_day", DobDay);
            builder.AddElement("street_address", StreetAddress);
            builder.AddElement("locality", Locality);
            builder.AddElement("region", Region);
            builder.AddElement("postal_code", PostalCode);
            return(builder.ToQueryString());
        }
        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("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 override string ToQueryString(string root)
 {
     var builder = new RequestBuilder("business");  // ignore the root as it is wrong
     builder.AddElement("name", Name);
     builder.AddElement("registered_as", RegisteredAs);
     builder.AddElement("industry", Industry);
     builder.AddElement("description", Description);
     builder.AddElement("street_address", StreetAddress);
     builder.AddElement("locality", Locality);
     builder.AddElement("region", Region);
     builder.AddElement("postal_code", PostalCode);
     builder.AddElement("country", Country);
     builder.AddElement("annual_volume_amount", AnnualVolumeAmount);
     builder.AddElement("average_transaction_amount", AverageTransactionAmount);
     builder.AddElement("maximum_transaction_amount", MaximumTransactionAmount);
     builder.AddElement("ship_physical_goods", ShipPhysicalGoods);
     builder.AddElement("fulfillment_completed_in", FulfillmentCompletedIn);
     builder.AddElement("currency", Currency);
     builder.AddElement("website", Website);
     return builder.ToQueryString();
 }
Ejemplo n.º 6
0
        public override string ToQueryString(string root)
        {
            var builder = new RequestBuilder("business");  // ignore the root as it is wrong

            builder.AddElement("name", Name);
            builder.AddElement("registered_as", RegisteredAs);
            builder.AddElement("industry", Industry);
            builder.AddElement("description", Description);
            builder.AddElement("street_address", StreetAddress);
            builder.AddElement("locality", Locality);
            builder.AddElement("region", Region);
            builder.AddElement("postal_code", PostalCode);
            builder.AddElement("country", Country);
            builder.AddElement("annual_volume_amount", AnnualVolumeAmount);
            builder.AddElement("average_transaction_amount", AverageTransactionAmount);
            builder.AddElement("maximum_transaction_amount", MaximumTransactionAmount);
            builder.AddElement("ship_physical_goods", ShipPhysicalGoods);
            builder.AddElement("fulfillment_completed_in", FulfillmentCompletedIn);
            builder.AddElement("currency", Currency);
            builder.AddElement("website", Website);
            return(builder.ToQueryString());
        }
Ejemplo n.º 7
0
    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;
    }
Ejemplo n.º 8
0
    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;
    }
Ejemplo n.º 9
0
    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);
    }
Ejemplo n.º 10
0
    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);
    }
Ejemplo n.º 11
0
    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);
    }
Ejemplo n.º 12
0
        public void Generate_GatewayRespectsMakeDefault()
        {
            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 = "5105105105105100",
                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);

            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());
            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);
                }
            }
        }