Stripe update customer default card (PHP)

tim peterson picture tim peterson · Apr 20, 2015 · Viewed 18.2k times · Source

I'd like to update the default card for a customer using Stripe.

In the update customer API docs it is not clear what to feed in for the card parameter.

In PHP, I've tried setting the card based on the retrieve card method like this:

$customer->card=$card['id']

but that doesn't appear to work. Nor does using the token like this:

$customer->source=$_POST['stripe_token]

so I'm a bit at a loss. Thoughts?

Answer

tim peterson picture tim peterson · Apr 20, 2015

I was able to answer my own question with Stripe's support on IRC #stripe channel:

The card parameter is specified by default_source like this:

Stripe::setApiKey($stripe_private_key);
$customer = Stripe_Customer::retrieve($stripe_cus_id);
$customer->default_source=$card['id'];
$customer->save();