A class for building requests to generate client tokens, which are used to authenticate requests clients make directly on behalf of merchants
Inheritance: Braintree.Request
 public static string GenerateDecodedClientToken(BraintreeGateway gateway, ClientTokenRequest request = null)
 {
   var encodedClientToken = gateway.ClientToken.generate(request);
   var decodedClientToken = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(encodedClientToken));
   var unescapedClientToken = System.Text.RegularExpressions.Regex.Unescape(decodedClientToken);
   return unescapedClientToken;
 }
        private void verifyOptions(ClientTokenRequest request)
        {
            if (request.Options != null && request.CustomerId == null)
            {
                var invalidOptions = new List <string> {
                };

                if (request.Options.VerifyCard != null)
                {
                    invalidOptions.Add("VerifyCard");
                }
                if (request.Options.MakeDefault != null)
                {
                    invalidOptions.Add("MakeDefault");
                }
                if (request.Options.FailOnDuplicatePaymentMethod != null)
                {
                    invalidOptions.Add("FailOnDuplicatePaymentMethod");
                }

                if (invalidOptions.Count != 0)
                {
                    var message = "Following arguments are invalid without customerId: ";
                    foreach (var invalidOption in invalidOptions)
                    {
                        message += " " + invalidOption;
                    }
                    throw new ArgumentException(message);
                }
            }
        }
        public virtual string generate(ClientTokenRequest request = null)
        {
            if (request == null) request = new ClientTokenRequest();
            verifyOptions(request);
            XmlNode response = Service.Post(Service.MerchantPath() + "/client_token", request);

            if (response.Name.Equals("client-token")) {
                return Regex.Unescape(response.InnerText);
            } else {
                throw new ArgumentException(response.SelectSingleNode("message").InnerText);
            }
        }
        public string GetToken([FromBody] string email)
        {
            ClientTokenRequest request = null;
            var id = this.GetCustomerId(email);
            if (id != null)
            {
                request = new ClientTokenRequest
                {
                    CustomerId = id
                };
            }

            return this.gateway.Value.ClientToken.generate(request);
        }
        public virtual string generate(ClientTokenRequest request = null)
        {
            if (request == null)
            {
                request = new ClientTokenRequest();
            }
            verifyOptions(request);
            XmlNode response = Service.Post(Service.MerchantPath() + "/client_token", request);

            if (response.Name.Equals("client-token"))
            {
                return(Regex.Unescape(response.InnerText));
            }
            else
            {
                throw new ArgumentException(response.SelectSingleNode("message").InnerText);
            }
        }
        public virtual async Task <string> GenerateAsync(ClientTokenRequest request = null)
        {
            if (request == null)
            {
                request = new ClientTokenRequest();
            }
            VerifyOptions(request);
            XmlNode response = await Service.PostAsync(Service.MerchantPath() + "/client_token", request).ConfigureAwait(false);

            if (response.Name.Equals("client-token"))
            {
                return(Regex.Unescape(response.InnerText));
            }
            else
            {
                throw new ArgumentException(response.SelectSingleNode("message").InnerText);
            }
        }
        private void verifyOptions(ClientTokenRequest request)
        {
            if (request.Options != null && request.CustomerId == null) {
                var invalidOptions = new List<string>{};

                if (request.Options.VerifyCard != null) {
                    invalidOptions.Add("VerifyCard");
                }
                if (request.Options.MakeDefault != null) {
                    invalidOptions.Add("MakeDefault");
                }
                if (request.Options.FailOnDuplicatePaymentMethod != null) {
                    invalidOptions.Add("FailOnDuplicatePaymentMethod");
                }

                if (invalidOptions.Count != 0) {
                    var message = "Following arguments are invalid without customerId: ";
                    foreach (var invalidOption in invalidOptions) {
                        message += " " + invalidOption;
                    }
                    throw new ArgumentException(message);
                }
            }
        }
 public virtual Task <string> generateAsync(ClientTokenRequest request = null)
 {
     return(GenerateAsync(request));
 }
 public virtual string generate(ClientTokenRequest request = null)
 {
     return(Generate(request));
 }