See also the PaymentMethod response object.

note

If you have card verification enabled, any updates made to credit cards are subject to those rules.

Ruby
Copy
Copied
result = gateway.payment_method.update(
  "the_token",
  :billing_address => {
    :street_address => "1 E Main St",
    :extended_address => "Suite 3",
    :locality => "Chicago",
    :region => "IL",
    :postal_code => "60622",
    :options => {
      :update_existing => true
    }
  }
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

If the payment method can't be found, it will raise a Braintree::NotFoundError.

Arguments
token required, String

The alphanumeric value that references a specific payment method stored in your Vault.

Additional Parameters
:billing_address

A billing address associated with a specific customer ID. It can be further associated with a specific payment method. The maximum number of addresses per customer is 50.

:company String

Company name. 255 character maximum.

:country_code_alpha2 String

The ISO 3166-1 alpha-2 country code specified in an address. The gateway only accepts specific alpha-2 values.

:country_code_alpha3 String

The ISO 3166-1 alpha-3 country code specified in an address. The gateway only accepts specific alpha-3 values.

:country_code_numeric String

The ISO 3166-1 numeric country code specified in an address. The gateway only accepts specific numeric values.

:country_name String

The country name specified in an address. Braintree only accepts specific country names.

:extended_address String

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

:first_name String

The first name. The first name value must be less than or equal to 255 characters.

:last_name String

The last name. The last name value must be less than or equal to 255 characters.

:locality String

The locality/city. 255 character maximum.

:options

Optional values that can be passed with a request.

:update_existing 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.

:postal_code 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.

:region String

The state or province. For PayPal addresses, the region must meet PayPal's state restrictions; for all other payment methods, it must be less than or equal to 255 characters.

:street_address String

The billing street address. 255 character maximum. Required to perform card verification when AVS rules are configured to require street address.

:billing_address_id String

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

:cardholder_name String

The cardholder name associated with the credit card. 175 character maximum.

:cvv String

Typically requires PCI SAQ D compliance

We recommend using payment_method_nonce 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 credit cards. The CVV will never be stored in the gateway, but it can be provided with one-time requests to verify the card.

:device_data String

Customer device information. Passing this value is strongly recommended when using Advanced Fraud Tools and adding credit card data to your Vault: provide the full string received from the Braintree client SDK. Not recommended when vaulting PayPal or Venmo accounts.

:expiration_date String

While we recommend using payment_method_nonce 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 expiration_month and expiration_year.

:expiration_month String

While we recommend using payment_method_nonce 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 expiration_year, and instead of expiration_date.

:expiration_year String

While we recommend using payment_method_nonce 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 expiration_month, and instead of expiration_date.

:number String

Typically requires PCI SAQ D compliance

We recommend using payment_method_nonce to avoid any PCI concerns with raw credit card data being present on your server.

The 12-19 digit value consisting of a bank identification number (BIN) and primary account number (PAN).

:options
:make_default bool

If the payment method is a CreditCard or PaypalAccount, this option makes the specified payment method the default for the customer. See example below.

:verification_amount 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.

:verification_merchant_account_id String

Specify the merchant account ID that you want to use to verify a card. See the merchant_account_id on Transaction.sale() to learn more. The merchant account can't be a marketplace sub-merchant account. See the Braintree Marketplace Guide to learn more.

:verify_card 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 CreditCardVerification result if verification runs and is unsuccessful.

:payment_method_nonce String

One-time-use reference to new card details provided by your customer. Can only be used on payment method update if the payment method type is a card; other payment method types do not allow their details to be updated. See example below.

:token String

If provided, updates the token for the payment method.

Examples

Update billing address

To update the existing billing address when updating a payment method use the update_existing option. If any other payment methods are associated with the same billing address, this will also update the billing address for those payment methods.

Ruby
Copy
Copied
result = gateway.payment_method.update(
  "the_token",
  :billing_address => {
    :street_address => "1 E Main St",
    :extended_address => "Suite 3",
    :locality => "Chicago",
    :region => "IL",
    :postal_code => "60622",
    :options => {
      :update_existing => true
    }
  }
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

If the payment method can't be found, it will raise a Braintree::NotFoundError.

New billing address

If you don't use the update_existing option, a new address will be created. The existing billing address will remain in the Vault associated with the customer.

Ruby
Copy
Copied
result = gateway.payment_method.update(
  "the_token",
  :billing_address => {
    :street_address => "1 E Main St",
    :extended_address => "Suite 3",
    :locality => "Chicago",
    :region => "IL",
    :postal_code => "60622",
  }
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Update with existing billing address

If a customer already has an address you'd like to use, you can update the payment method with that address.

Ruby
Copy
Copied
result = gateway.payment_method.update(
  "the_token",
  :billing_address_id => "the_billing_address_id"
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Updating a PayPal account token

The only fields that may be updated on a PayPal account are the token associated with that account, and setting the account as the default payment method for a customer.

Ruby
Copy
Copied
updated_result = gateway.paypal_account.update(original_token,
  :token => new_token
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Make default

If the payment method is a credit card or PayPal account, you can use this call to set the payment method as the customer's default. For all other payment method types, use default_payment_method_token on Customer.update() instead.

Ruby
Copy
Copied
result = gateway.payment_method.update(
  "the_token",
  :options => {
    :make_default => true
  }
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.
note

This only works with credit cards and PayPal accounts. We recommend updating the customer to set a default payment method.

Card verification

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

Ruby
Copy
Copied
result = gateway.payment_method.update("the_payment_method_token",
  :payment_method_nonce => nonce_from_the_client,
  :options => {
    :verify_card => true
  }
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.
important

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

Updating with a nonce and additional parameters

When updating the credit card information with a nonce, you may pass additional parameters to update as well. Here is an example of updating a payment method and explicitly verifying the card.

important

If a field is passed from the client and included in the nonce data (such as postal code) it should not be passed as an explicit argument as well.

Ruby
Copy
Copied
result = gateway.payment_method.update(
  "the_token",
  :payment_method_nonce => nonce_from_the_client,
  :billing_address => {
    :street_address => "1 E Main St",
    :extended_address => "Suite 3",
    :locality => "Chicago",
    :region => "IL",
  }
)
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.
important

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

To verify the AVS information of an existing payment method, pass the update request with an empty array and the verify_card set to "true". Note that an update will create a transaction, so if your processing options are set to reject transactions without CVV, you will need to include CVV as a parameter, or disable this rule (see below).

To disable the CVV requirement:

  1. Log into the Control Panel
  2. Navigate to Settings > Processing > CVV
  3. Click Options
  4. Uncheck CVV Not Provided (I)

Payment method nonces vs. raw card data

While it is possible to pass both raw card data and a payment method nonce in the same call, we recommend passing only a payment method nonce.

Passing both will result in a payment method that has a mix of their attributes, with precedence given to the fields individually, then to the attributes of the payment method nonce. For example, if you pass both a card number and a payment method nonce, the payment method will have the number you passed explicitly, but the rest of the attributes will be obtained through the nonce.

Still have questions?

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