See also the Customer response object.

You can create a customer by itself, with a payment method, or with a credit card with a billing address.

note

If you intend to create a transaction at the same time as a customer, you may want to use Transaction.Sale() with either the Options.StoreInVaultOnSuccess or Options.StoreInVault options.

C♯
var request = new CustomerRequest
{
    FirstName = "Mark",
    LastName = "Jones",
    Company = "Jones Co.",
    Email = "mark.jones@example.com",
    Fax = "419-555-1234",
    Phone = "614-555-1234",
    Website = "http://example.com"
};
Result<Customer> result = gateway.Customer.Create(request);

bool success = result.IsSuccess();
// true

string customerId = result.Target.Id;
// e.g. 594019
Parameters
Company string

Company name. Maximum 255 characters.

CreditCard

A credit or debit payment method.

BillingAddress

A billing address associated with a specific credit card. The maximum number of addresses per customer is 50.

Company string

Company name. Maximum 255 characters.

CountryCodeAlpha2 string

The ISO 3166-1 alpha-2 country code specified in an address. The gateway only accepts specific alpha-2 values.

CountryCodeAlpha3 string

The ISO 3166-1 alpha-3 country code specified in an address. The gateway only accepts specific alpha-3 values.

CountryCodeNumeric string

The ISO 3166-1 numeric country code specified in an address. The gateway only accepts specific numeric values.

CountryName string

The country name specified in an address. We only accept specific country names.

ExtendedAddress string

The extended address information—such as apartment or suite number. 255 character maximum.

FirstName string

The first name. Maximum 255 characters.

LastName string

The last name. Maximum 255 characters.

Locality string

The locality/city. Maximum 255 characters.

Options
PostalCode string

The postal code. Postal code must be a string of 4-9 alphanumeric characters, optionally separated by a dash or a space. Spaces, hyphens, and all other special characters are ignored.

Region string

The state or province. Maximum 255 characters.

StreetAddress string

The street address. Maximum 255 characters.

CardholderName string

The name associated with the credit card. Must be less than or equal to 175 characters.

Cvv string

Typically requires PCI SAQ D compliance

We recommend using PaymentMethodNonce to avoid any PCI concerns with raw credit card data being present on your server.

A 3 or 4 digit card verification value assigned to a credit card. The CVV will never be stored in the gateway, but it can be provided with one-time requests to verify the card.

ExpirationDate string

Typically requires PCI SAQ D compliance

We recommend using PaymentMethodNonce to avoid any PCI concerns with raw credit card data being present on your server.

The expiration date of a credit card, formatted MM/YY or MM/YYYY. May be used instead of ExpirationMonth and ExpirationYear.

ExpirationMonth string

Typically requires PCI SAQ D compliance

We recommend using PaymentMethodNonce to avoid any PCI concerns with raw credit card data being present on your server.

The expiration month of a credit card, formatted MM. May be used with ExpirationYear, and instead of ExpirationDate.

ExpirationYear string

Typically requires PCI SAQ D compliance

We recommend using PaymentMethodNonce to avoid any PCI concerns with raw credit card data being present on your server.

The two or four digit year associated with a credit card, formatted YYYY or YY. May be used with ExpirationMonth, and instead of ExpirationDate.

Number string

Typically requires PCI SAQ D compliance

We recommend using PaymentMethodNonce to avoid any PCI concerns with raw credit card data being present on your server.

The 12-19 digit value on a credit card consisting of a bank identification number (BIN) and primary account number (PAN).

Options

Optional values that can be passed with a request.

FailOnDuplicatePaymentMethod bool

If this option is passed and the payment method has already been added to the Vault, the request will fail. This option will not work with PayPal payment methods.

MakeDefault bool

This option makes the specified payment method the default for the customer.

VerificationAmount string

Specify a non-negative amount that you want to use to verify a card. If you do not pass this option, the gateway will automatically use a verification amount of $0 or $1, depending on the processor and/or card type.

VerificationMerchantAccountId string

Specify the merchant account ID that you want to use to verify a card. Cannot be a Braintree Marketplace sub-merchant account. For more details on merchant accounts in general, see MerchantAccountId on Transaction.Sale().

VerifyCard bool

If the payment method is a credit card, this option prompts the gateway to verify the card's number and expiration date. It also verifies the AVS and CVV information if you've enabled AVS and CVV rules. If you want to verify all cards before they are stored in your Vault, you can turn on card verification for your entire Braintree account in the Control Panel.

In some cases, cardholders may see a temporary authorization on their account after their card has been verified. The authorization will fall off the cardholder's account within a few days and will never settle.

Only returns a CreditCardVerification result if verification runs and is unsuccessful.

Token string

An alphanumeric value that references a specific payment method stored in your Vault. Must be less than or equal to 36 characters. If using a custom integration, you can specify what you want the token to be. If not specified, the gateway will generate one that can be accessed on the result. If using our Drop-in UI, you cannot specify your own token. Length and format of gateway-generated tokens and IDs may change at any time.

CustomFields

A collection of custom field/value pairs. Fields and values must be less than 255 characters. You must set up each custom field in the Control Panel prior to passing it with a request. Querying this value returns a collection of custom field values stored on the customer object.

DeviceData string

Customer device information. Passing this value is strongly recommended when using Advanced Fraud Tools and adding credit card data to your Vault. Not recommended when vaulting PayPal or Venmo accounts.

Email string

Email address composed of ASCII characters.

Fax string

Fax number. Maximum 255 characters.

FirstName string

The first name. The first name value must be less than or equal to 255 characters.

Id string

A string value that will represent this specific customer in your Vault. 36 character maximum; must be unique within your Vault; valid characters are letters, numbers, -, and _; the words "all" and "new" currently cannot be used. If not specified on creation, the gateway will generate an alphanumeric ID that can be accessed on the result. The generated IDs will never start with a leading 0 and are case insensitive.

LastName string

The last name. The last name value must be less than or equal to 255 characters.

PaymentMethodNonce string

One-time-use token that references a payment method provided by your customer, such as a credit card or PayPal account.

The nonce serves as proof that the user has authorized payment (e.g. credit card number or PayPal details). This should be sent to your server and used with any of Braintree's server-side client libraries that accept new or saved payment details. This can be passed instead of a payment_method_token. When used to create subscriptions, the payment_method_nonce must be Vaulted and must belong to the customer owning the subscription.

Phone string

Phone number. Maximum 255 characters.

RiskData

Customer request information. Sent to processor to help verify transaction integrity.

CustomerBrowser string

The User Agent field provided by the customer. Maximum 255 characters.

CustomerIp string

The customer's IP address.

Website string

Website URL. Must be less than or equal to 255 characters. Website must be well-formed. The URL scheme is optional.

Examples

Specify your own customer ID

You can optionally choose what you would like the ID to be. Customer IDs are case insensitive.

C♯
var request = new CustomerRequest
{
    Id = "customer_123",
    FirstName = "Mark"
};

Result<Customer> result = gateway.Customer.Create(request);

Blank customer

If you're only interested in storing a payment method without any customer information, you can create a blank customer:

C♯
Result<Customer> result = gateway.Customer.Create(new CustomerRequest());

Customer with a payment method

You can also create a payment method along with a customer. If all customer validations and credit card validations or PayPal account validations pass, and the credit card is verified (if supplied and verification is requested), success will return true.

C♯
var request = new CustomerRequest
{
    FirstName = "Fred",
    LastName = "Jones",
    PaymentMethodNonce = nonceFromTheClient
};
Result<Customer> result = gateway.Customer.Create(request);

bool success = result.IsSuccess();
// true

Customer customer = result.Target;
string customerId = customer.Id;
// e.g. 160923

string cardToken = customer.PaymentMethods[0].Token;
// e.g. f28w

If you do not specify a token for the payment method, as in the example above, the gateway will generate one. If you are using a custom integration, you can also choose what you want the token to be.

C♯
var request = new CustomerRequest
{
    CreditCard = new CreditCardRequest
    {
        Token = "credit_card_123"
    },
    PaymentMethodNonce = nonceFromTheClient
};

Result<Customer> result = gateway.Customer.Create(request);

Customer with a payment method and billing address

You can also pass in a billing address when creating a customer and payment method.

C♯
var request = new CustomerRequest
{
    PaymentMethodNonce = nonceFromTheClient,
    CreditCard = new CreditCardRequest
    {
        BillingAddress = new CreditCardAddressRequest
        {
            FirstName = "Jen",
            LastName = "Smith",
            Company = "Braintree",
            StreetAddress = "123 Address",
            Locality = "City",
            Region = "State",
            PostalCode = "12345"
        }
    }
};

Result<Customer> result = gateway.Customer.Create(request);

Card verification

By default we will run credit card validations but not perform verification. Set the verifyCard option to verify the card.

C♯
CustomerRequest request = new CustomerRequest
{
    FirstName = "Fred",
    LastName = "Jones",
    CreditCard = new CreditCardRequest
    {
        PaymentMethodNonce = nonceFromTheClient,
        Options = new CreditCardOptionsRequest
        {
            VerifyCard = true
        }
    }
};

Result<Customer> result = gateway.Customer.Create(request);
important

If you are using our Advanced Fraud Tools, we strongly recommend passing deviceData each time you verify a card.

Use custom fields

Use custom fields to store additional data about your customers in Braintree. You'll need to configure your custom fields in the Control Panel to use them via the API.

Here is an example of setting custom fields with API names of custom_field_one and custom_field_two:

C♯
var result = gateway.Customer.Create(
    new CustomerRequest
    {
        FirstName = "Bob",
        LastName = "Smith",
        CustomFields = new Dictionary<string, string>
        {
            { "custom_field_one", "value one" },
            { "custom_field_two", "value two" }
        }
    });

if (result.IsSuccess())
{
  Dictionary<string, string> customFields = result.Target.CustomFields;
}

See also

Still have questions?

If you can’t find an answer, contact our Support team.