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.
CreditCardRequest updateRequest = new CreditCardRequest().
number("4111111111111111").
expirationDate("12/2012");
Result<CreditCard> result = gateway.creditCard().update("the_token", updateRequest);
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.
CreditCardRequest updateRequest = new CreditCardRequest().
billingAddress().
streetAddress("100 Maple Lane").
options().
updateExisting(true).
done().
done();
Result result = gateway.creditCard().update("the_token", updateRequest);
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.
CreditCardRequest updateRequest = new CreditCardRequest().
billingAddress().
firstName("Drew").
lastName("Smith").
streetAddress("100 Maple Lane").
locality("Chicago").
region("IL").
postalCode("60622").
done();
Result result = gateway.creditCard().update("the_token", updateRequest);
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 getMakeDefault() option.
CreditCardRequest updateRequest = new CreditCardRequest().
number("4111111111111111").
expirationDate("12/2012").
options().
makeDefault(true).
done();
Result<CreditCard> result = gateway.creditCard().update("the_token", updateRequest);