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.
$result = $gateway->customer()->create([
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'email' => 'mike.jones@example.com',
'phone' => '281.330.8004',
'fax' => '419.555.1235',
'website' => 'http://example.com'
]);
$result->success;
# true
$result->customer->id;
# Generated customer id
Parameters
'billingAddress'
A billing address associated with a specific credit card. The maximum number of addresses per customer is 50.
'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.
'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 and hyphens are ignored.
'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).
'failOnDuplicatePaymentMethod'
bool
If this option is passed and the same payment method has already been added to the Vault for any customer, the request will fail. This option will be ignored for PayPal, Pay with Venmo, Apple Pay, Google Pay, and Samsung Pay payment methods.
'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. Can't 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.
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 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.
'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. Pass this value only if you have Advanced Fraud Tools enabled and are adding credit card data to your Vault. Be sure to provide the full string received from the Braintree client SDK.
'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 can't 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.
'paymentMethodNonce'
string
One-time-use reference to payment information provided by your customer, such as a credit card or PayPal account. When passed on customer create, it creates a payment method associated with the new customer; see example below.
'riskData'
Customer device information, which is sent directly to supported processors for fraud analysis. These fields are automatically populated if using Advanced Fraud Tools. Currently only available when processing American Express via Amex Direct. Contact us with any questions.
Examples
Specify your own customer ID
You can optionally choose what you would like the ID to be. Customer IDs are case insensitive.
$result = $gateway->customer()->create([
'id' => 'customer_123',
'firstName' => 'Mike'
]);
Blank customer
If you're only interested in storing a payment method without any customer information, you can create a blank customer:
$result = $gateway->customer()->create();
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.
$result = $gateway->customer()->create([
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'paymentMethodNonce' => nonceFromTheClient
]);
if ($result->success) {
echo($result->customer->id);
echo($result->customer->paymentMethods[0]->token);
} else {
foreach($result->errors->deepAll() AS $error) {
echo($error->code . ": " . $error->message . "\n");
}
}
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.
$result = $gateway->customer()->create([
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'creditCard' => ['token' => 'a_token'],
'paymentMethodNonce' => nonceFromTheClient
]);
Customer with a payment method and billing address
You can also pass in a billing address when creating a customer and payment method.
$result = $gateway->customer()->create([
'paymentMethodNonce' => nonceFromTheClient,
'creditCard' => [
'billingAddress' => [
'firstName' => 'Jen',
'lastName' => 'Smith',
'company' => 'Braintree',
'streetAddress' => '123 Address',
'locality' => 'City',
'region' => 'State',
'postalCode' => '12345'
]
]
]);
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
.
$result = $gateway->customer()->create([
'paymentMethodNonce' => nonceFromTheClient,
'firstName' => 'Fred',
'lastName' => 'Jones',
'creditCard' => [
'options' => [
'verifyCard' => true
]
]
]);
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
:
$result = $gateway->customer()->create([
'firstName' => 'Bob',
'lastName' => 'Smith',
'customFields' => [
'custom_field_one' => 'custom value',
'custom_field_two' => 'another custom value'
]
]);
$result->customer->customFields['custom_field_one']
# 'custom value'
$result->customer->customFields['custom_field_two']
# 'another custom value'
See also
Transaction::sale()
usingcustomerId
PaymentMethod::create()
usingcustomerId
- Card verification
- Customer validations
- Payment method validations