CreditCardOptionsRequest

Namespace: Braintree
We found 10 examples in language CSharp for this search. You will see 43 fragments of code.

        public override string ToXml(string root)
        {
            return BuildRequest(root).ToXml();
        }

        public override string ToQueryString(string root)
        {
            return BuildRequest(root).ToQueryString();
        }

        protected virtual RequestBuilder BuildRequest(string root)
        {
            var builder = new RequestBuilder(root);

            builder.AddElement("make-default", MakeDefault);
            builder.AddElement("verification-merchant-account-id", VerificationMerchantAccountId);
            builder.AddElement("verify-card", VerifyCard);
            builder.AddElement("verification-amount", VerificationAmount);
            builder.AddElement("fail-on-duplicate-payment-method", FailOnDuplicatePaymentMethod);
            builder.AddElement("update-existing-token", UpdateExistingToken);
            builder.AddElement("venmo-sdk-session", VenmoSdkSession);

            return builder;
        }


        #endregion




        #region public methods

        public void Authorize_DotNet_Process_Charge(string api_login_id, string transaction_key)
        {
            try
            {
                // Step 1 - Create the request
                var request = new AuthorizationRequest(card_number, card_date, amount, description);

                // Step 2 - Create the gateway, sending in your credentials
                var gate = new Gateway(api_login_id, transaction_key);

                // Step 3 - Send the request to the gateway
                var response = gate.Send(request);
                approved = response.Approved;
                authorization_code = response.AuthorizationCode;
                response_code = response.ResponseCode;
                message = response.Message;
                transaction_code = response.TransactionID;
            }
            catch (Exception ex)
            {
                successful = false;
                error_text = ex.Message.ToString();
            }
        }

        public void Braintree_Process_Charge(string public_key, string private_key, string merchant_id)
        {
            try
            {
                Braintree_Gateway_Transaction(Braintree.Environment.PRODUCTION, public_key, private_key, merchant_id);
            }
            catch (Exception ex)
            {
                successful = false;
                error_text = ex.Message.ToString();
            }
        }

        public void Braintree_Sandbox_Process_Charge(string public_key, string private_key, string merchant_id)
        {
            try
            {
                Braintree_Gateway_Transaction(Braintree.Environment.SANDBOX, public_key, private_key, merchant_id);
            }
            catch (Exception ex)
            {
                successful = false;
                error_text = ex.Message.ToString();
            }
        }

        public void Braintree_Card_Verification(string public_key, string private_key, string merchant_id)
        {
            try
            {
                Braintree_Gateway_Verification(Braintree.Environment.PRODUCTION, public_key, private_key, merchant_id);
            }
            catch (Exception ex)
            {
                successful = false;
                error_text = ex.Message.ToString();
            }
        }

        public void Braintree_Sandbox_Card_Verification(string public_key, string private_key, string merchant_id)
        {
            try
            {
                Braintree_Gateway_Verification(Braintree.Environment.SANDBOX, public_key, private_key, merchant_id);
            }
            catch (Exception ex)
            {
                successful = false;
                error_text = ex.Message.ToString();
            }
        }

        public void IsValid_Credit_Card()
        {
            //// check whether input string is null or empty
            if (string.IsNullOrEmpty(card_number))
            {
                successful = false;
            }
            else
            {
                //// 1.	Starting with the check digit double the value of every other digit 
                //// 2.	If doubling of a number results in a two digits number, add up
                ///   the digits to get a single digit number. This will results in eight single digit numbers                    
                //// 3. Get the sum of the digits
                int sumOfDigits = card_number.Where((e) => e >= '0' && e <= '9')
                                .Reverse()
                                .Select((e, i) => ((int)e - 48) * (i % 2 == 0 ? 1 : 2))
                                .Sum((e) => e / 10 + e % 10);


                //// If the final sum is divisible by 10, then the credit card number
                //   is valid. If it is not divisible by 10, the number is invalid.     
                if (sumOfDigits % 10 == 0)
                    successful = true;
                else
                    successful = false;
            }
        }


        public TokenizedCreditCardResponse Post(TokenizeCreditCardBraintreeRequest tokenizeRequest)
        {
            return TokenizedCreditCard(BraintreeGateway,
                tokenizeRequest.EncryptedCreditCardNumber,
                tokenizeRequest.EncryptedExpirationDate,
                tokenizeRequest.EncryptedCvv,
                tokenizeRequest.PaymentMethodNonce);
        }

        public object Get(GenerateClientTokenBraintreeRequest request)
        {
            try
            {
                return BraintreeGateway.ClientToken.generate();
            }
            catch (Exception ex)
            {
                throw new HttpException((int) HttpStatusCode.InternalServerError, ex.Message);
            }
        }

        public static bool TestClient(BraintreeServerSettings settings, BraintreeClientSettings braintreeClientSettings)
        {
            var client = GetBraintreeGateway(settings);

            var dummyCreditCard = new TestCreditCards(TestCreditCards.TestCreditCardSetting.Braintree).Visa;

            var braintreeEncrypter = new BraintreeEncrypter(braintreeClientSettings.ClientKey);

            return TokenizedCreditCard(client, braintreeEncrypter.Encrypt(dummyCreditCard.Number),
                    braintreeEncrypter.Encrypt(dummyCreditCard.ExpirationDate.ToString("MM/yyyy", CultureInfo.InvariantCulture)),
                    braintreeEncrypter.Encrypt(dummyCreditCard.AvcCvvCvv2 + "")
                ).IsSuccessful;
        }

        private static TokenizedCreditCardResponse TokenizedCreditCard(
            BraintreeGateway client,
            string encryptedCreditCardNumber,
            string encryptedExpirationDate,
            string encryptedCvv,
            string paymentMethodNonce = null)
        {
            try
            {
                var request = new CustomerRequest
                {
                    CreditCard = new CreditCardRequest
                    {
                        Number = encryptedCreditCardNumber,
                        ExpirationDate = encryptedExpirationDate,
                        CVV = encryptedCvv,
                        PaymentMethodNonce = paymentMethodNonce, // Used for tokenization from javascript API
                        Options = new CreditCardOptionsRequest
                        {
                            VerifyCard = true
                        }
                    }
                };

                var result = client.Customer.Create(request);
                var customer = result.Target;

                var creditCardCvvSuccess = CheckCvvResponseCodeForSuccess(customer);
                

                if (!result.IsSuccess() || !creditCardCvvSuccess)
                {
                    return new TokenizedCreditCardResponse
                    {
                        IsSuccessful = false,
                        Message = result.Message
                    };
                }

                var creditCard = customer.CreditCards.First();

                return new TokenizedCreditCardResponse
                {
                    CardOnFileToken = creditCard.Token,
                    CardType = creditCard.CardType.ToString(),
                    LastFour = creditCard.LastFour,
                    IsSuccessful = result.IsSuccess(),
                    Message = result.Message
                };
            }
            catch (Exception e)
            {
                return new TokenizedCreditCardResponse
                {
                    IsSuccessful = false,
                    Message = e.Message
                };
            }
        }

        private static bool CheckCvvResponseCodeForSuccess(Customer customer)
        {
            try
            {
                // "M" = matches, "N" = does not match, "U" = not verified, "S" = bank doesn't participate, "I" = not provided
                return customer.CreditCards[0].Verification.CvvResponseCode != "N";
            }
            catch (Exception)
            {
                // an error occured
                return false;
            }
        }

        private static BraintreeGateway GetBraintreeGateway(BraintreeServerSettings settings)
        {
            var env = Environment.SANDBOX;
            if (!settings.IsSandbox)
            {
                env = Environment.PRODUCTION;
            }

            return new BraintreeGateway
            {
                Environment = env,
                MerchantId = settings.MerchantId,
                PublicKey = settings.PublicKey,
                PrivateKey = settings.PrivateKey,
            };
        }

        public User Login(string username, string password)
        {

            string EncryptedPassword = Encryption.Encrypt(password);
            string EncryptedPassword2 = Encryption.Decrypt("rBfYEYK_aAs=");
            var user = dal.login(username, EncryptedPassword);

            if (user == null)
            {
                throw new Exception("Username or password is invalid");
            }
            return user;
        }
        public dynamic ResetPassword(SignupUser model)
        {
            try
            {

                if (model.Email != null && model.VerificationCode == null && model.Password == null)
                {
                    Random generator = new Random();
                    model.VerificationCode = generator.Next(0, 999999).ToString("D6");
                    if (dal.EmailActivation(model.Email, model.Password, model.VerificationCode))
                    {
                        var user = dal.GetUserByEmail(model.Email);
                        model.FirstName = user.FirstName;
                        model.LastName = user.LastName;
                        Email.GetEmailTemplate("Forgot Password", model);
                        return Shared.returnMessageJSON(Messages.EmailExistSuccessTitle, Messages.EmailExistSuccessDescription, false);
                    }
                    else
                    {
                        return Shared.returnMessageJSON(Messages.EmailExistErrorTitle, Messages.EmailExistErrorDescription, true);
                    }

                }
                else if (model.Email != null && model.VerificationCode != null && model.Password == null)
                {
                    if (dal.CheckVarificationCode(model.VerificationCode))
                    {
                        return Shared.returnMessageJSON(Messages.CodeVerificationSuccessTitle, Messages.CodeVerificationSuccessDescription, false);
                    }
                    else
                    {
                        return Shared.returnMessageJSON(Messages.CodeVerificationErrorTitle, Messages.CodeVerificationErrorDescription, true);
                    }

                }
                else if (model.Email != null && model.VerificationCode != null && model.Password != null)
                {
                    string EncryptedPassword = Encryption.Encrypt(model.Password);
                    if (dal.UpdatePassword(model.Email, EncryptedPassword))
                    {
                        return Shared.returnMessageJSON(Messages.PasswordUpdateSuccessTitle, Messages.PasswordUpdateSuccessDescription, false);
                    }
                    else
                    {
                        return Shared.returnMessageJSON(Messages.PasswordUpdateErrorTitle, Messages.PasswordUpdateErrorDescription, true);
                    }

                }
                else
                {
                    return Shared.returnMessageJSON(Messages.PasswordResetVerificationDataTitle, Messages.PasswordResetVerificationDescription, true);
                }
            }
            catch (Exception exp)
            {
                var email = EscalateSession.CurrentUser;
                if (email != null)
                {
                    dal.SaveErrorLog(email.Email, "BAL_Login - ResetPassword", exp.Message, DateTime.Now);
                }
                else
                {
                    dal.SaveErrorLog("", "BAL_Login - ResetPassword", exp.Message, DateTime.Now);
                }
                return Shared.returnMessageJSON(exp.Data.ToString(), exp.Message.ToString(), true);
            }

        }


        public override string ToXml(string root)
        {
            return BuildRequest(root).ToXml();
        }

        public override string ToQueryString(string root)
        {
            return BuildRequest(root).ToQueryString();
        }

        protected virtual RequestBuilder BuildRequest(string root)
        {
            return new RequestBuilder(root).
                AddElement("fail-on-duplicate-payment-method", FailOnDuplicatePaymentMethod).
                AddElement("make-default", MakeDefault).
                AddElement("skip-advanced-fraud-checking", SkipAdvancedFraudChecking).
                AddElement("update-existing-token", UpdateExistingToken).
                AddElement("venmo-sdk-session", VenmoSdkSession).
                AddElement("verification-account-type", VerificationAccountType).
                AddElement("verification-amount", VerificationAmount).
                AddElement("verification-currency-iso-code", VerificationCurrencyIsoCode).
                AddElement("verification-merchant-account-id", VerificationMerchantAccountId).
                AddElement("verify-card", VerifyCard);
        }

        [Test]
        public void Append()
        {
            string actual = new QueryString().Append("foo", "f").Append("bar", "b").ToString();
            Assert.AreEqual("foo=f&bar=b", actual);
        }

        [Test]
        public void AppendEmptyStringOrNulls()
        {
            string actual = new QueryString().
                Append("foo", "f").
                Append("", "b").
                Append("bar", "").
                Append("boom", null).
                Append("", "c").ToString();

            Assert.AreEqual("foo=f&bar=", actual);
        }

        [Test]
        public void AppendOtherObjectsWithCanBeConvertedToStrings()
        {
            string actual = new QueryString().
                Append("foo", 10).
                Append("bar", "20.00").ToString();

            Assert.AreEqual("foo=10&bar=20.00", actual);
        }

        [Test]
        public void AppendWithRequest()
        {
            Request request = new CreditCardRequest
            {
                CVV = "123",
                CardholderName = "Drew"
            };

            string actual = new QueryString().Append("[credit_card]", request).ToString();
            Assert.AreEqual("%5Bcredit_card%5D%5Bcardholder_name%5D=Drew&%5Bcredit_card%5D%5Bcvv%5D=123", actual);
        }

        [Test]
        public void AppendWithNestedRequest()
        {
            Request request = new CreditCardRequest
            {
                CVV = "123",
                CardholderName = "Drew",
                Options = new CreditCardOptionsRequest
                {
                    VerifyCard = true,
                    MakeDefault = true
                }
            };
            
            string actual = new QueryString().Append("[credit_card]", request).ToString();
            Assert.AreEqual("%5Bcredit_card%5D%5Bcardholder_name%5D=Drew&%5Bcredit_card%5D%5Bcvv%5D=123&%5Bcredit_card%5D%5Boptions%5D%5Bmake_default%5D=true&%5Bcredit_card%5D%5Boptions%5D%5Bverify_card%5D=true", actual);
        }

        public Dictionary<string, string> CreateCustomer(string paymentNonce, string firstName, string lastName, string email)
        {
            var request = new CustomerRequest
            {
                FirstName = firstName,
                LastName = lastName,
                Email = email,
                CreditCard = new CreditCardRequest
                {
                    PaymentMethodNonce = paymentNonce,
                    Options = new CreditCardOptionsRequest
                    {
                        VerifyCard = true
                    }
                }
            };

            Result<Customer> result = BraintreeConfig.Gateway().Customer.Create(request);
            bool success = result.IsSuccess();
            if (success)
            {
                var cardInfo = new Dictionary<string, string>();
                cardInfo.Add("customerId", result.Target.CreditCards[0].CustomerId);
                cardInfo.Add("paymentToken", result.Target.CreditCards[0].Token);
                cardInfo.Add("maskedCard", result.Target.CreditCards[0].MaskedNumber);
                cardInfo.Add("cardType", result.Target.CreditCards[0].CardType.ToString());
                return cardInfo;
            }

            var errors = string.Empty;

            foreach (var error in result.Errors.All())
            {
                errors += string.Format("Code[{0}] Message[{1}]. ", error.Code.ToString(), error.Message);
            }
            foreach (var error in result.Errors.DeepAll())
            {
                errors += string.Format("Code[{0}] Message[{1}]. ", error.Code.ToString(), error.Message);
            }

            throw new Exception(errors);
        }

        public string CreatePayment(float total, string token)
        {

            Result<PaymentMethodNonce> result = BraintreeConfig.Gateway().PaymentMethodNonce.Create(token);
            bool success = result.IsSuccess();

            if (!success)
                throw new Exception("Failed to create payment nonce for accesstoken[" + token + "]");

            var totalPlannerPayments = ComputeTotalFee(total);

            TransactionRequest transactionRequest = new TransactionRequest
                {
                    Amount = decimal.Parse(totalPlannerPayments.ToString("0.00")),
                    PaymentMethodNonce = result.Target.Nonce
                };

            Result<Transaction> result2 = BraintreeConfig.Gateway().Transaction.Sale(transactionRequest);

            success = result2.IsSuccess();

            if (!success)
            {
                var errors = string.Empty;

                foreach (var error in result2.Errors.All())
                {
                    errors += string.Format("Code[{0}] Message[{1}]. ", error.Code.ToString(), error.Message);
                }
                foreach (var error in result2.Errors.DeepAll())
                {
                    errors += string.Format("Code[{0}] Message[{1}]. ", error.Code.ToString(), error.Message);
                }
                throw new Exception("Failed to create payment for accesstoken [" + token + "]" + errors);
            }

            return result2.Target.Id;
        }

        public string CapturePayment(float total, string authorizationId, string token)
        {
            Result<Transaction> result = BraintreeConfig.Gateway().Transaction.SubmitForSettlement(authorizationId);
            bool success = result.IsSuccess();

            if (!success)
            {
                var errors = string.Empty;

                foreach (var error in result.Errors.All())
                {
                    errors += string.Format("Code[{0}] Message[{1}]. ", error.Code.ToString(), error.Message);
                }
                foreach (var error in result.Errors.DeepAll())
                {
                    errors += string.Format("Code[{0}] Message[{1}]. ", error.Code.ToString(), error.Message);
                }

                throw new Exception("Failed to create payment for transaction [" + authorizationId + "]" + errors);
            }

            return result.Target.Id;
        }

        private float ComputeTotalFee(float total)
        {
            //admin fee
            var adminPayPercent = _settings.ContainsKey("admin_pay_percentage") ? float.Parse(_settings["admin_pay_percentage"]) / 100 : 0;
            _adminFee = adminPayPercent * total;

            //braintree fee
            var braintreePercentage = _settings.ContainsKey("braintree_percentage") ? float.Parse(_settings["braintree_percentage"]) / 100 : 0;
            var braintreeAdditional = _settings.ContainsKey("braintree_additional") ? float.Parse(_settings["braintree_additional"]) : 0;
            _braintreeFee = (braintreePercentage * (total + _adminFee)) + braintreeAdditional;

            //the planner will shoulder the admin fee and braintreeFee.
            _handlingFee = _adminFee + _braintreeFee;


            return (total + _handlingFee); 
        }

        public IDictionary<string, string> CreatePaymetMethod(string authorizationCode, string firstName, string lastName, string email)
        {
            return this.CreateCustomer(authorizationCode, firstName, lastName, email);
        }

        [Test]
        public void ToXml_IncludesAllProperties()
        {
            var request = new CreditCardOptionsRequest()
            {
                FailOnDuplicatePaymentMethod = false,
                MakeDefault = false,
                SkipAdvancedFraudChecking = false,
                UpdateExistingToken = "foo",
                VenmoSdkSession = "session",
                VerificationAccountType = "type",
                VerificationAmount = "0.01",
                VerificationCurrencyIsoCode = "123",
                VerificationMerchantAccountId = "merchantaccount",
                VerifyCard = true
            };

            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<fail-on-duplicate-payment-method>false</fail-on-duplicate-payment-method>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<make-default>false</make-default>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<skip-advanced-fraud-checking>false</skip-advanced-fraud-checking>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<update-existing-token>foo</update-existing-token>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<venmo-sdk-session>session</venmo-sdk-session>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<verification-account-type>type</verification-account-type>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<verification-amount>0.01</verification-amount>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<verification-currency-iso-code>123</verification-currency-iso-code>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<verification-merchant-account-id>merchantaccount</verification-merchant-account-id>"));
            Assert.IsTrue(request.ToXml("credit-card-options").Contains("<verify-card>true</verify-card>"));
        }


        #region Address

        /// <summary>
        /// Creates an <see cref="AddressRequest"/>.
        /// </summary>
        /// <param name="address">
        /// The address.
        /// </param>
        /// <returns>
        /// The <see cref="AddressRequest"/>.
        /// </returns>
        public AddressRequest CreateAddressRequest(IAddress address)
        {
            return new AddressRequest()
            {
                FirstName = address.TrySplitFirstName(),
                LastName = address.TrySplitLastName(),
                Company = address.Organization,
                StreetAddress = address.Address1,
                ExtendedAddress = address.Address2,
                Locality = address.Locality,
                Region = address.Region,
                PostalCode = address.PostalCode,
                CountryCodeAlpha2 = address.CountryCode
            };
        }

        #endregion

        #region Client Token

        /// <summary>
        /// Creates a <see cref="ClientTokenRequest"/>.
        /// </summary>
        /// <param name="customerKey">
        /// The customer key.
        /// </param>
        /// <returns>
        /// The <see cref="ClientTokenRequest"/>.
        /// </returns>
        public ClientTokenRequest CreateClientTokenRequest(Guid customerKey)
        {
            return customerKey == Guid.Empty ? 
                new ClientTokenRequest() : 
                new ClientTokenRequest()
                    {
                        CustomerId = customerKey.ToString() 
                    };
        }

        #endregion

        #region Credit Card

        /// <summary>
        /// Creates a new <see cref="CreditCardRequest"/>
        /// </summary>
        /// <param name="paymentMethodNonce">
        /// The "nonce-from-the-client"
        /// </param>
        /// <param name="billingAddress">
        /// The billing address associated with the credit card
        /// </param>
        /// <param name="shippingAddress">
        /// The shipping Address.
        /// </param>
        /// <param name="isUpdate">
        /// A value indicating whether or not this is an Update request
        /// </param>
        /// <returns>
        /// The <see cref="CreditCardRequest"/>.
        /// </returns>
        /// <remarks>
        /// Uses VerifyCard = true as a default option
        /// </remarks>
        public CreditCardRequest CreateCreditCardRequest(string paymentMethodNonce, IAddress billingAddress = null, IAddress shippingAddress = null, bool isUpdate = false)
        {
            return this.CreateCreditCardRequest(paymentMethodNonce, new CreditCardOptionsRequest { VerifyCard = true }, billingAddress, isUpdate);
        }

        /// <summary>
        /// Creates a new <see cref="CreditCardRequest"/>
        /// </summary>
        /// <param name="paymentMethodNonce">
        /// The "nonce-from-the-client"
        /// </param>
        /// <param name="optionsRequest">
        /// The options request.
        /// </param>
        /// <param name="billingAddress">The billing address associated with the credit card</param>
        /// <param name="isUpdate">A value indicating whether or not this is an update request</param>
        /// <returns>
        /// The <see cref="CreditCardRequest"/>.
        /// </returns>
        public CreditCardRequest CreateCreditCardRequest(string paymentMethodNonce, CreditCardOptionsRequest optionsRequest, IAddress billingAddress = null, bool isUpdate = false)
        {
            Mandate.ParameterNotNullOrEmpty(paymentMethodNonce, "paymentMethodNonce");

            var request = new CreditCardRequest()
            {
                PaymentMethodNonce = paymentMethodNonce
            };
            if (optionsRequest != null) request.Options = optionsRequest;
            if (billingAddress != null) request.BillingAddress = this.CreateCreditCardAddressRequest(billingAddress, isUpdate);

            return request;
        }

        /// <summary>
        /// Creates a <see cref="CreditCardRequest"/>.
        /// </summary>
        /// <param name="address">
        /// The address.
        /// </param>
        /// <param name="isUpdate">
        /// The is update.
        /// </param>
        /// <returns>
        /// The <see cref="CreditCardAddressRequest"/>.
        /// </returns>
        public CreditCardAddressRequest CreateCreditCardAddressRequest(IAddress address, bool isUpdate = false)
        {
            return new CreditCardAddressRequest
            {
                FirstName = address.TrySplitFirstName(),
                LastName = address.TrySplitLastName(),
                Company = address.Organization,
                StreetAddress = address.Address1,
                ExtendedAddress = address.Address2,
                Locality = address.Locality,
                Region = address.Region,
                PostalCode = address.PostalCode,
                CountryCodeAlpha2 = address.CountryCode,
                Options = new CreditCardAddressOptionsRequest { UpdateExisting = isUpdate }
            };
        }

        #endregion

        #region Customer Request

        /// <summary>
        /// Creates a simple <see cref="CustomerRequest"/>.
        /// </summary>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <returns>
        /// The <see cref="CustomerRequest"/>.
        /// </returns>
        public CustomerRequest CreateCustomerRequest(ICustomer customer)
        {
            Mandate.ParameterNotNull(customer, "customer");

            return new CustomerRequest
                       {
                           Id = customer.Key.ToString(),
                           CustomerId = customer.Key.ToString(),
                           FirstName = customer.FirstName,
                           LastName = customer.LastName,
                           Email = customer.Email
                       };
        }


        #region Address

        /// <summary>
        /// Creates an <see cref="AddressRequest"/>.
        /// </summary>
        /// <param name="address">
        /// The address.
        /// </param>
        /// <returns>
        /// The <see cref="AddressRequest"/>.
        /// </returns>
        public AddressRequest CreateAddressRequest(IAddress address)
        {
            return new AddressRequest()
            {
                FirstName = address.TrySplitFirstName(),
                LastName = address.TrySplitLastName(),
                Company = address.Organization,
                StreetAddress = address.Address1,
                ExtendedAddress = address.Address2,
                Locality = address.Locality,
                Region = address.Region,
                PostalCode = address.PostalCode,
                CountryCodeAlpha2 = address.CountryCode
            };
        }

        #endregion

        #region Client Token

        /// <summary>
        /// Creates a <see cref="ClientTokenRequest"/>.
        /// </summary>
        /// <param name="customerKey">
        /// The customer key.
        /// </param>
        /// <returns>
        /// The <see cref="ClientTokenRequest"/>.
        /// </returns>
        public ClientTokenRequest CreateClientTokenRequest(Guid customerKey)
        {
            return customerKey == Guid.Empty ? 
                new ClientTokenRequest() : 
                new ClientTokenRequest()
                    {
                        CustomerId = customerKey.ToString() 
                    };
        }

        #endregion

        #region Credit Card

        /// <summary>
        /// Creates a new <see cref="CreditCardRequest"/>
        /// </summary>
        /// <param name="paymentMethodNonce">
        /// The "nonce-from-the-client"
        /// </param>
        /// <param name="billingAddress">
        /// The billing address associated with the credit card
        /// </param>
        /// <param name="shippingAddress">
        /// The shipping Address.
        /// </param>
        /// <param name="isUpdate">
        /// A value indicating whether or not this is an Update request
        /// </param>
        /// <returns>
        /// The <see cref="CreditCardRequest"/>.
        /// </returns>
        /// <remarks>
        /// Uses VerifyCard = true as a default option
        /// </remarks>
        public CreditCardRequest CreateCreditCardRequest(string paymentMethodNonce, IAddress billingAddress = null, IAddress shippingAddress = null, bool isUpdate = false)
        {
            return this.CreateCreditCardRequest(paymentMethodNonce, new CreditCardOptionsRequest() { VerifyCard = true }, billingAddress, isUpdate);
        }

        /// <summary>
        /// Creates a new <see cref="CreditCardRequest"/>
        /// </summary>
        /// <param name="paymentMethodNonce">
        /// The "nonce-from-the-client"
        /// </param>
        /// <param name="optionsRequest">
        /// The options request.
        /// </param>
        /// <param name="billingAddress">The billing address associated with the credit card</param>
        /// <param name="isUpdate">A value indicating whether or not this is an update request</param>
        /// <returns>
        /// The <see cref="CreditCardRequest"/>.
        /// </returns>
        public CreditCardRequest CreateCreditCardRequest(string paymentMethodNonce, CreditCardOptionsRequest optionsRequest, IAddress billingAddress = null, bool isUpdate = false)
        {
            Mandate.ParameterNotNullOrEmpty(paymentMethodNonce, "paymentMethodNonce");

            var request = new CreditCardRequest()
            {
                PaymentMethodNonce = paymentMethodNonce
            };
            if (optionsRequest != null) request.Options = optionsRequest;
            if (billingAddress != null) request.BillingAddress = this.CreateCreditCardAddressRequest(billingAddress, isUpdate);

            return request;
        }

        /// <summary>
        /// Creates a <see cref="CreditCardRequest"/>.
        /// </summary>
        /// <param name="address">
        /// The address.
        /// </param>
        /// <param name="isUpdate">
        /// The is update.
        /// </param>
        /// <returns>
        /// The <see cref="CreditCardAddressRequest"/>.
        /// </returns>
        public CreditCardAddressRequest CreateCreditCardAddressRequest(IAddress address, bool isUpdate = false)
        {
            return new CreditCardAddressRequest()
            {
                FirstName = address.TrySplitFirstName(),
                LastName = address.TrySplitLastName(),
                Company = address.Organization,
                StreetAddress = address.Address1,
                ExtendedAddress = address.Address2,
                Locality = address.Locality,
                Region = address.Region,
                PostalCode = address.PostalCode,
                CountryCodeAlpha2 = address.CountryCode,
                Options = new CreditCardAddressOptionsRequest() { UpdateExisting = isUpdate }
            };
        }

        #endregion

        #region Customer Request

        /// <summary>
        /// Creates a simple <see cref="CustomerRequest"/>.
        /// </summary>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <returns>
        /// The <see cref="CustomerRequest"/>.
        /// </returns>
        public CustomerRequest CreateCustomerRequest(ICustomer customer)
        {
            Mandate.ParameterNotNull(customer, "customer");

            return new CustomerRequest()
                       {
                           Id = customer.Key.ToString(),
                           CustomerId = customer.Key.ToString(),
                           FirstName = customer.FirstName,
                           LastName = customer.LastName,
                           Email = customer.Email
                       };
        }

Braintree.CreditCardOptionsRequest : Request

Constructors :

public CreditCardOptionsRequest()

Methods :

public Nullable<Boolean> get_FailOnDuplicatePaymentMethod()
public Void set_FailOnDuplicatePaymentMethod(Nullable<Boolean> value = )
public Nullable<Boolean> get_MakeDefault()
public Void set_MakeDefault(Nullable<Boolean> value = )
public Nullable<Boolean> get_SkipAdvancedFraudChecking()
public Void set_SkipAdvancedFraudChecking(Nullable<Boolean> value = )
public Nullable<Boolean> get_VerifyCard()
public Void set_VerifyCard(Nullable<Boolean> value = )
public String get_UpdateExistingToken()
public Void set_UpdateExistingToken(String value = )
public String get_VenmoSdkSession()
public Void set_VenmoSdkSession(String value = )
public String get_VerificationAccountType()
public Void set_VerificationAccountType(String value = )
public String get_VerificationAmount()
public Void set_VerificationAmount(String value = )
public String get_VerificationCurrencyIsoCode()
public Void set_VerificationCurrencyIsoCode(String value = )
public String get_VerificationMerchantAccountId()
public Void set_VerificationMerchantAccountId(String value = )
public String ToXml(String root = )
public String ToQueryString(String root = )
public Dictionary<String, Object> ToDictionary()
public String ToXml()
public String ToQueryString()
public String Kind()
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods