Customer
Customer: Create
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.
- DOTNET
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
stringCompany
stringCountryCodeAlpha2
stringThe ISO 3166-1 alpha-2 country code specified in an address. The gateway only accepts specific alpha-2 values.
CountryCodeAlpha3
stringThe ISO 3166-1 alpha-3 country code specified in an address. The gateway only accepts specific alpha-3 values.
CountryCodeNumeric
stringThe ISO 3166-1 numeric country code specified in an address. The gateway only accepts specific numeric values.
CountryName
stringThe country name specified in an address. We only accept specific country names.
ExtendedAddress
stringFirstName
stringCountryCode
stringNationalNumber
stringLastName
stringLocality
stringPhoneNumber
stringDeprecated.
We recommend using international_phone
. This functionality still exists in the gateway but is no longer documented. This parameter will be removed in the future.
PostalCode
stringRegion
stringStreetAddress
stringCardholderName
stringCvv
stringTypically 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
stringTypically 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
stringTypically 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
stringTypically 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
stringTypically 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).
MakeDefault
boolSkipAdvancedFraudChecking
booleanIf the payment method is a credit card, prevents the verification from being evaluated as part of Premium Fraud Management Tools checks. Use with caution – once you've skipped checks for a verification, it is not possible to run them retroactively.
VerificationAmount
stringSpecify the merchant account ID that you want to use to verify a card. Can't be a Braintree Marketplace sub-merchant account. For more details on merchant accounts in general, see MerchantAccountId
on Transaction: Sale
.
VerifyCard
boolIf 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.
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 Credit Card Verification
result if verification runs and is unsuccessful.
Results of a merchant-performed 3D Secure authentication. You will only need to use these fields if you've performed your own integration with a 3D Secure MPI provider (e.g. Cardinal Centinel). Otherwise, Braintree's SDKs handle this for you in our standard 3D Secure integration.
Cavv
stringCardholder authentication verification value or CAVV. The main encrypted message issuers and card networks use to verify authentication has occurred. Mastercard uses an AVV message and American Express uses an AEVV message, each of which should also be passed in the Cavv parameter.
DsTransactionId
stringTransaction identifier resulting from 3D Secure 2 authentication. This field must be supplied for Mastercard Identity Check.
EciFlag
stringThe value of the electronic commerce indicator (ECI) flag, which indicates the outcome of the 3DS authentication.
Accepted values for Mastercard:
00
= Failed or not attempted01
= Attempted02
= Success04
= Data-Only (Applies to limited processors)
Accepted values for all other card brands:
07
= Failed or not attempted06
= Attempted05
= Success
ThreeDSecureVersion
stringThe version of 3D Secure authentication used for the transaction. Required
on Visa and Mastercard authentications. Must be composed of digits separated
by periods (e.g. 1.0.2
).
Xid
stringTransaction identifier resulting from 3D Secure authentication. Uniquely identifies the transaction and sometimes required in the authorization message. Must be base64-encoded. This field will no longer be used in 3D Secure 2 authentications.
Token
stringAn 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 with a customer ID to vault payment methods, you can't specify your own token. Length and format of gateway-generated tokens and IDs may change at any time.
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
stringCustomer device information. Pass this value only if you have Premium Fraud Management Tools enabled and are adding credit card data to your Vault. Be sure to provide the full string received from the Braintree client SDK.
Email
stringFax
stringFirstName
stringId
stringCountryCode
stringNationalNumber
stringLastName
stringPaymentMethodNonce
stringPhone
stringDeprecated.
We recommend using international_phone
. This functionality still exists in the gateway but is no longer documented. This parameter will be removed in the future.
Customer device information, which is sent directly to supported processors for fraud analysis. These fields are automatically populated if using Premium Fraud Management Tools. Currently only available when processing American Express via Amex Direct. Contact us with any questions.
CustomerBrowser
stringCustomerIp
stringTaxIdentifiers
arrayCountryCode
stringThe ISO 3166-1 alpha-2 country code specified in an address. The gateway only accepts specific alpha-2 values.
Identifier
stringWebsite
stringExamples
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 . Braintree strongly recommends verifying all cards before they are stored in your Vault by enabling card verification for your entire account in the Control Panel. If you choose to manually verify cards, set VerifyCard to True.
- C#
CustomerRequest request = new CustomerRequest
{
PaymentMethodNonce = nonceFromTheClient,
FirstName = "Fred",
LastName = "Jones",
CreditCard = new CreditCardRequest
{
Options = new CreditCardOptionsRequest
{
VerifyCard = true
}
}
};
Result<Customer> result = gateway.Customer.Create(request);
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;
}