Customer
Customer: Update
See also the Customer response object.
To update a customer, use its ID along with new attributes. The same validations apply as when creating a customer. Any attribute not passed will remain unchanged.
- Java
CustomerRequest request = new CustomerRequest()
.firstName("New First Name")
.lastName("New Last Name");
Result<Customer> updateResult = gateway.customer().update("the_customer_id", request);
Arguments
id
required, stringAdditional Parameters
.company(…)
string.company(…)
string.countryCodeAlpha2(…)
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(…)
string.firstName(…)
string.countryCode(…)
string.nationalNumber(…)
string.lastName(…)
string.locality(…)
string.updateExisting(…)
boolean.phoneNumber(…)
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(…)
string.region(…)
string.streetAddress(…)
string.billingAddressId(…)
string.cardholderName(…)
string.cvv(…)
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(…)
stringWhile we recommend using paymentMethodNonce()
when updating raw credit card data, the expiration date can be updated directly without any PCI concerns as long as you do not store, process, or transmit the raw PAN or CVV.
The expiration date, formatted MM/YY
or MM/YYYY
. May be used instead of expirationMonth and expirationYear.
.expirationMonth(…)
stringWhile we recommend using paymentMethodNonce()
when updating raw credit card data, the expiration month can be updated directly without any PCI concerns as long as you do not store, process, or transmit the raw PAN or CVV.
The expiration month of a credit card, formatted MM
. May be used with expirationYear, and instead of expirationDate.
.expirationYear(…)
stringWhile we recommend using paymentMethodNonce()
when updating raw credit card data, the expiration year can be updated directly without any PCI concerns as long as you do not store, process, or transmit the raw PAN or CVV.
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(…)
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.
.updateExistingToken(…)
string.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(…)
booleanIf 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(…)
string.fax(…)
string.firstName(…)
string.id(…)
string.countryCode(…)
string.nationalNumber(…)
string.lastName(…)
string.paymentMethodNonce(…)
string.phone(…)
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.
.taxIdentifiers(…)
array.countryCode(…)
stringThe ISO 3166-1 alpha-2 country code specified in an address. The gateway only accepts specific alpha-2 values.
.identifier(…)
string.website(…)
stringExamples
Update customer and existing credit card
To update an existing credit card when using the customer update method, you need to pass the token of the credit card under the credit card options.
- Java
CustomerRequest request = new CustomerRequest().
.paymentMethodNonce(nonceFromTheClient)
.email("new.email@example.com")
.creditCard()
.options()
.updateExistingToken("the_token")
.done()
.done();
Result<Customer> updateResult = gateway.customer().update("the_customer_id", request);
If you are only storing the customer ID in your system and using a 1:1 model of customer to credit card, then you can get the token for the credit card from the customer details.
- Java
Customer customer = gateway.customer().find("the_customer_id");
String token = customer.getCreditCards().get(0).getToken();
Update customer, credit card, and billing address
The billing address can also be updated by adding in the billing address details and setting the updateExisting option in the billing address attributes.
- Java
CustomerRequest request = new CustomerRequest()
.paymentMethodNonce(nonceFromTheClient)
.email("new.email@example.com")
.creditCard()
.options()
.updateExistingToken("the_token")
.verifyCard(true)
.done()
.billingAddress()
.streetAddress("New Street Address")
.postalCode("60622")
.options()
.updateExisting(true)
.done()
.done()
.done();
Result<Customer> updateResult = gateway.customer().update("the_customer_id", request);
If you omit the updateExisting valoption under the billing address, we will create a new address for the customer and associate it to the credit card. The old address will remain associated to the customer but no longer associated as the billing address of the credit card.
Update customer and create new payment method
You can add a new payment method to an existing customer using the customer update API.
Credit card
If you omit the updateExistingToken valoption from the examples in the previous sections, a new credit card will be created and associated to the customer.
- Java
Customer customer = gateway.customer().find("the_customer_id");
customer.getCreditCards().size();
// 1
CustomerRequest request = new CustomerRequest()
.paymentMethodNonce(nonceFromTheClient)
.done();
Customer updatedCustomer = gateway.customer().update(customer.getId(), request).getTarget();
updatedCustomer.getCreditCards().size();
// 2
Any payment method type
You can use a payment method nonce for any payment method type—not just a credit card—to associate that payment method to the customer. The example below shows adding a payment method while also updating customer details.
- Java
CustomerRequest request = new CustomerRequest()
.paymentMethodNonce(nonceFromTheClient)
.email("new.email@example.com");
Result<Customer> updateResult = gateway.customer().update("the_customer_id", request);
Update default payment method
To update a customer's default payment method, get that payment method's token and pass it as the defaultPaymentMethodToken value below:
- Java
CustomerRequest request = new CustomerRequest()
.defaultPaymentMethodToken("the_token");
Result<Customer> updateResult = gateway.customer().update("the_customer_id", 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.
- Java
CustomerRequest request = new CustomerRequest()
.paymentMethodNonce(nonceFromTheClient)
.email("new.email@example.com")
.creditCard()
.options()
.updateExistingToken("the_token")
.verifyCard(true)
.done()
.done();
Result<Customer> updateResult = gateway.customer().update("the_customer_id", request);