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.
- Ruby
result = gateway.customer.create(
:first_name => "Jen",
:last_name => "Smith",
:company => "Braintree",
:email => "jen@example.com",
:phone => "312.555.1234",
:fax => "614.555.5678",
:website => "www.example.com"
)
if result.success?
puts result.customer.id
else
p result.errors
end
Parameters
:company
String:company
String:country_code_alpha2
String:country_code_alpha3
String:country_code_numeric
String:country_name
String:extended_address
String:first_name
String:last_name
String:locality
String:postal_code
String:region
String:street_address
String:cardholder_name
String:cvv
StringTypically requires PCI SAQ D compliance
We recommend using
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.
:expiration_date
StringTypically requires PCI SAQ D compliance
We recommend using
The expiration date of a credit card, formatted MM/YY
or MM/YYYY
. May be used instead of
:expiration_month
StringTypically requires PCI SAQ D compliance
We recommend using
The expiration month of a credit card, formatted MM
. May be used with
:expiration_year
StringTypically requires PCI SAQ D compliance
We recommend using
The two or four digit year associated with a credit card, formatted YYYY
or YY
. May be used with
:number
StringTypically requires PCI SAQ D compliance
We recommend using
The 12-19 digit value on a credit card consisting of a bank identification number (BIN) and primary account number (PAN).
:make_default
bool:verification_amount
String:verify_card
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.
: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
:ds_transaction_id
StringTransaction identifier resulting from 3D Secure 2 authentication. This field must be supplied for Mastercard Identity Check.
:eci_flag
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
:three_d_secure_version
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
StringA 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.
:device_data
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
String:fax
String:first_name
String:id
String:last_name
String:payment_method_nonce
String:phone
StringCustomer 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.
:customer_browser
String:customer_ip
String:tax_identifiers
array:country_code
String:identifier
String:website
StringExamples
Specify your own customer ID
You can optionally choose what you would like the ID to be. Customer IDs are case insensitive.
- Ruby
result = gateway.customer.create(
:id => "customer_123",
:first_name => "Katrina"
)
Blank customer
If you're only interested in storing a payment method without any customer information, you can create a blank customer:
- Ruby
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.
- Ruby
result = gateway.customer.create(
:first_name => "Charity",
:last_name => "Smith",
:payment_method_nonce => nonce_from_the_client
)
if result.success?
puts result.customer.id
puts result.customer.payment_methods[0].token
else
p result.errors
end
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.
- Ruby
result = gateway.customer.create(
:credit_card => {
:token => "credit_card_123"
},
:payment_method_nonce => nonce_from_the_client
)
Customer with a payment method and billing address
You can also pass in a billing address when creating a customer and payment method.
- Ruby
result = gateway.customer.create(
:payment_method_nonce => nonce_from_the_client,
:credit_card => {
:billing_address => {
:first_name => "Jen",
:last_name => "Smith",
:company => "Braintree",
:street_address => "123 Address",
:locality => "City",
:region => "State",
:postal_code => "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 verify_card to true.
- Ruby
result = gateway.customer.create(
:payment_method_nonce => nonce_from_the_client,
:first_name => "Fred",
:last_name => "Jones",
:credit_card => {
:options => {
:verify_card => 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
:
- Ruby
result = gateway.customer.create(
:first_name => "Bob",
:last_name => "Smith",
:custom_fields => {
:custom_field_one => "value one",
:custom_field_two => "value two"
}
)
if result.success?
result.customer.custom_fields
#=> {:custom_field_one => "value one", :custom_field_two => "value two"}
end