See also the Braintree_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.

PHP
$updateResult = Braintree_Customer::update(
    'a_customer_id',
    [
      'firstName' => 'New First',
      'lastName' => 'New Last',
      'company' => 'New Company',
      'email' => 'new.email@example.com',
      'phone' => 'new phone',
      'fax' => 'new fax',
      'website' => 'http://new.example.com'
    ]
);

$updateResult->success
# true if update was successful

If the customer cannot be found, you'll receive a Braintree_Exception_NotFound exception.

Arguments
id required, string

A string value representing an existing customer in your Vault.

Additional Parameters
'company' string

Company name. 255 character maximum.

'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. 255 character maximum.

'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. Braintree only accepts specific country names.

'extendedAddress' string

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

'firstName' string

The first name. 255 character maximum.

'lastName' string

The last name. 255 character maximum.

'locality' string

The locality/city. 255 character maximum.

'options'

Optional values that can be passed with a request.

'updateExisting' bool

Update the billing address associated with the payment method token specified. Other payment methods associated with the same billing address will have their addresses updated, as well.

'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. 255 character maximum.

'streetAddress' string

The credit card billing street address. 255 character maximum. Only required if using card verification when AVS rules are configured to require street address.

'billingAddressId' string

The two-letter value for an address associated with a specific credit card. The maximum number of addresses per customer is 50.

'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

While 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' string

While 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' string

While 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' 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.

'updateExistingToken' string

Update the payment method token specified.

'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 Braintree_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 Braintree_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.

'defaultPaymentMethodToken' string

Update the customer's default payment method to the specified token.

'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 comprised of ASCII characters.

'fax' string

Fax number. 255 character maximum.

'firstName' string

The first name. 255 character maximum.

'id' string

If specified, will replace the customer's existing ID. 36 character maximum; must be unique within your Vault; valid characters are letters, numbers, -, and _; the words "all" and "new" currently cannot be used.

'lastName' string

The last name. 255 character maximum.

'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 updating a customer, a new payment method will be added based on the nonce passed in.

'phone' string

Phone number. Phone must be 10-14 characters and can only contain numbers, dashes, parentheses and periods.

'riskData'

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

'customerBrowser' string

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

'customerIp' string

The customer's IP address.

'website' string

Website URL. 255 character maximum. Website must be well-formed. The URL scheme is optional.

Examples

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.

note

Credit cards are the only payment method type that you can update using the customer update method. To update other payment method types, use Braintree_PaymentMethod::update().

PHP
$result = Braintree_Customer::update(
  'a_customer_id',
  [
    'firstName' => 'New First',
    'lastName' => 'New Last',
    'creditCard' => [
        'paymentMethodNonce' => nonceFromTheClient,
        'options' => [
            'updateExistingToken' => 'a_creditcard_token'
        ]
     ]
  ]
);

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.

PHP
$customer = Braintree_Customer::find('a_customer_id');
$token = $customer->creditCards[0]->token;

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.

note

Using this method, you can update any of the credit card parameters listed above, but some parameters have been deprecated to avoid any PCI concerns with raw credit card data being present on your server.

PHP
$result = Braintree_Customer::update(
  'a_customer_id',
  [
    'firstName' => 'New First',
    'creditCard' => [
        'paymentMethodNonce' => nonceFromTheClient,
        'options' => [
            'updateExistingToken' => 'a_creditcard_token'
        ],
        'billingAddress' => [
            'firstName' => 'New First Billing',
            'lastName' => 'New Last Billing',
            'options' => [
                'updateExisting' => true
            ]
        ]
    ]
  ]
);

If you omit the updateExisting option 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 option from the examples in the previous sections, a new credit card will be created and associated to the customer.

PHP
$customer = Braintree_Customer::find('a_customer_id');
sizeof($customer->creditCards)
# 1

$result = Braintree_Customer::update(
  $customer->id, [
    'firstName' => 'New Customer First',
    'lastName' => 'New Customer Last',
    'creditCard' => [
      'paymentMethodNonce' => nonceFromTheClient
    ]
  ]
);

sizeof($result->customer->creditCards)
# 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.

PHP
$result = Braintree_Customer::update(
  'a_customer_id',
  [
    'firstName' => 'New First',
    'lastName' => 'New Last',
    'paymentMethodNonce' => nonceFromTheClient,
  ]
);

Card verification

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

PHP
$updateResult = Braintree_Customer::update(
  'a_customer_id',
  [
    'creditCard' => [
      'paymentMethodNonce' => nonceFromTheClient,
      'options' => [
          'updateExistingToken' => 'a_creditcard_token',
          'verifyCard' => true
      ]
    ]
  ]
);
important

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

See also

Still have questions?

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