When I update a users credit card, it adds a new card and sets it as the default, instead of replacing the customers current card. So if they update their card 5 times, there will be a list of 5 credit cards under that customer in Stripe. This just seems dirty to me.
Is this the expected behaviour? I was expecting it to replace the customers credit card info, so they only ever have a single card on file.
Here is what I'm using to update the card. Or is there another method or parameter I don't know about?
I'm having the same concern. The application I'm working on still uses laravel 4. I was wondering if you were using 4 or 5, because I'm curious if version 5 has changed this behavior. Or if you have come up with a work around?
I started on a work around:
store card id of default card
use Cashier to update card
make stripe api call to delete stored card id of original default card
Unfortunately in my app the above is wrapped in a db transaction and if there is db error, then db changes are rolled back but customer now has no credit card. I could move deletion of old card outside transaction but then the code starts getting messy. I was hoping for a cleaner solution.
I was using Laravel 5.0. Might be best to just update the card through the Stripe API (not cashier). I don't know if the behaviour would be the same though. I ended up just leaving it as is, customers don't upgrade their cards very often anyways.
I was bothered by these duplicate cards too. After I updateCard(), I also do this to remove the old versions of cards...
// updateCard actually creates a new card, causing duplicates.
// We want to delete any cards with the same fingerprint (card #), that are not the default card.
$defaultCard = $user->defaultCard();
foreach ($user->cards() as $card) {
// If this card is not the default card, but the fingerprints match...
if ( ($card->id != $defaultCard->id) and ($card->fingerprint == $defaultCard->fingerprint) ) {
// Delete it.
$card->delete();
}
}