#sam-customer-cards
1 messages · Page 1 of 1 (latest)
via Code
gotcha so I recommend looking at https://stripe.com/docs/billing/subscriptions/payment-methods-setting
basically either you set it globally on the customer and it applies to all subscriptions and invoices
or you do it per subscription
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!
In this article: https://stripe.com/docs/billing/subscriptions/payment-methods-setting I am not sure how to provide my selected Card ID i.e. card_xxxxxxxxxxxxx
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?
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!
Sure, can you give me a concrete example? That way I can show you what you are doing wrong
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
],
],
]
);
sorry I need a concrete example not generic code
Please give me an exact subscription id sub_123 that you just updated
sub_1Kzl3xGvtfUGWiicJBFIRkHw
perfect, looking
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)
okay so https://dashboard.stripe.com/test/logs/req_miVacRbNESqpzH this is your most recent call. You passed "default_payment_method": "card_1Kzl3tGvtfUGWiicgn488wg2" explicitly. That's the 4242
that's your own code doing that
you likely mixed up the card ids here, nothing is wrong with the code/API itself