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.
$updateResult = Braintree_CreditCard::update(
'the_token',
array(
'number' => '4111111111111111',
'expirationDate' => '07/14'
)
);
Credit Card and Existing Billing Address
To update the existing billing address when updating a credit card use the updateExisting 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',
array(
'billingAddress' => array(
'streetAddress' => '100 Maple Lane',
'options' => array(
'updateExisting' => true
)
)
));
Credit Card and New Billing Address
If you don’t use the updateExisting 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',
array(
'billingAddress' => array(
'firstName' => 'Drew',
'lastName' => 'Smith',
'company' => 'Smith Co.',
'streetAddress' => '1 E Main St',
'region' => 'IL',
'postalCode' => '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 makeDefault option.
$updateResult = Braintree_CreditCard::update(
'the_token',
array(
'number' => '4111111111111111',
'expirationDate' => '07/14',
'options' => array(
'makeDefault' => true
)
)
);