Updating Credit Cards
You can update a credit card by itself, a credit card along with an existing billing address, or a credit card with adding a new billing address. If you also want to update customer information when doing any of this see the customer update API. Examples on this page use the server-to-server API, but credit cards can also be updated using transparent redirect.
Only the Credit Card
To update a credit card use its token along with new attributes. Any attribute not passed will remain unchanged.
result = Braintree::CreditCard.update(
"the_token",
:number => "5105105105105105100",
:expiration_date => "06/2012"
)
Credit Card and Existing Billing Address
To update the existing billing address when updating a credit card use the update_existing option. If any other credit cards are associated to the same billing address this will also update the billing address for those credit cards.
result = Braintree::CreditCard.update(
"the_token",
:billing_address => {
:street_address => "1 E Main St",
:extended_address => "Suite 3",
:locality => "Chicago",
:region => "Illinois",
:postal_code => "60622",
:options => {
:update_existing => true
}
}
)
Credit Card and 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 to the customer.
result = Braintree::CreditCard.update(
"the_token",
:billing_address => {
:street_address => "1 E Main St",
:extended_address => "Suite 3",
:locality => "Chicago",
:region => "Illinois",
:postal_code => "60622",
}
)
Setting a new Default
If a customer has multiple credit cards, the first card created will be the customer’s default card. The default card is used when creating transactions from vault customers. To set a new card as the default, use the make_default option.
result = Braintree::CreditCard.update(
"the_token",
:number => "5105105105105105100",
:expiration_date => "06/2012",
:options => {
:make_default => true
}
)