#sam-customer-cards

1 messages · Page 1 of 1 (latest)

tender fiber
#

Hello!

#

Are you trying to do this manually in the Dashboard or via code?

thin herald
#

via Code

tender fiber
#

basically either you set it globally on the customer and it applies to all subscriptions and invoices

#

or you do it per subscription

thin herald
#

I need it for Per Subscription Because on my site I have option to change the existing Card while updating the Subscription like Price or Frequency.

#

In simple words I have Card Ids to provide while updating a Subscription i.e. card_xxxxxxxxxxxxxxxx Now where to set this?

#

Here is my Code:

$subscription = \Stripe\Subscription::retrieve('sub_xxxxxxxxxxxxxx');

$sub_updated = \Stripe\Subscription::update(
'sub_xxxxxxxxxxxxxxxx', [
'cancel_at_period_end' => false,
'default_source' => 'card_xxxxxxxxxxxxx',
'proration_behavior' => 'none',
'items' => [
[
'id' => $subscription->items->data[0]->id,
'plan' => $plan->id
],
],
]
);

#

@jagged totem Please help me for this! as per your last suggestion, I used default_payment_method instead of default_source but still it is taking the default card not the card that I selected!

tender fiber
#

I mean both the options should just work

#

So I need you to be a bit more explicit about what exactly isn't working. Can you give me a concrete example?

thin herald
#

Well when I am trying to update a subscription where I am updating the Amount, Frequency, and a Card (i.e. card_xxxxx) then amount and frequency is updating in the subscription But for the payment it is always using my Default Card and not the Selected Card. FYI I have 2 cards attached with a stripe customer and all the time default is working and not the other card!

tender fiber
#

Sure, can you give me a concrete example? That way I can show you what you are doing wrong

thin herald
#

Here is my Code:

$subscription = \Stripe\Subscription::retrieve('sub_xxxxxxxxxxxxxx');

$sub_updated = \Stripe\Subscription::update(
'sub_xxxxxxxxxxxxxxxx', [
'cancel_at_period_end' => false,
'default_source' => 'card_xxxxxxxxxxxxx',
'proration_behavior' => 'none',
'items' => [
[
'id' => $subscription->items->data[0]->id,
'plan' => $plan->id
],
],
]
);

tender fiber
#

sorry I need a concrete example not generic code

#

Please give me an exact subscription id sub_123 that you just updated

thin herald
#

sub_1Kzl3xGvtfUGWiicJBFIRkHw

tender fiber
#

perfect, looking

thin herald
#

in this subscription you can see that the customer have 2 cards and when I am trying to provide card id for Discover Card (1117) it is always taking Visa Card (4242)

tender fiber
#

that's your own code doing that

#

you likely mixed up the card ids here, nothing is wrong with the code/API itself

thin herald
#

Ohh I see!

#

Let me check this

#

Yes you are correct! my code is always giving same card id!