#mattwoberts
1 messages ยท Page 1 of 1 (latest)
Hi there. How can we help?
Hi there ...
We have a customer, cus_Iunj3sOHVX5fby. They had an invoice on the 11th Feb which failed payment, because they have a failing card attached to the customer (and set for the subscription). On the 15th Feb, they entered a new card, via the hosted invoice page - evt_0MbhB3EHSdXPilfDbgoFY3ET is the event they added that card. Payment was successful, but that card was not set as the new default for the subscription - it was left at the old one (that had previously failed). So when they were invoiced again in March, it failed.
My question - why did that new card that was added via the hosted invoice page not get set as the default for the subscription for future invoices?
Got it. So yeah unless you explicitly make the api call to set the payment method as the default, it won't get set as the default
However if there is no previous default PM for that subscription, in that case it DOES set that PM as the default - it's just confusing me because the customer has added a new card (via hosted invoice page) to sort the payment, and it's not going to be used the next time .... have I got that right?
Yeah
It looks like your code is setting the default for that subscription though
This request was a while ago, but: https://dashboard.stripe.com/logs/req_exyO3ovTRJXBhm
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
However if there is no previous default PM for that subscription, in that case it DOES set that PM as the default
I actually wasn't aware that this was the case
Are you seeing this behavior?
Sure are... what happens is that if you have a sub with no default PM, and you add a card.. and then an invoice is created and the first payment on that card goes through - when that happens, that PM then becomes the default for that sub.
Although now that you've shown me that our code is setting the PM for the sub, I'm wondering - could it be OUR code that did that ๐ค
I think it may be
Do you have a recent example of this happening?
Like a request ID so I can take a look
I'll just take a look
I need to just check our code, and if it's not that I can find you an example - can I leave this for a while and I'll get back to you?
Yeah that's fine
We archive threads after some inactivity though, so if it's closed by then you can just post again in the main channel
OK thanks for your help
I've just looked through the code, and I don't think I can see anywhere we set the default PM on the sub. We set it on the customer (when you add a card, we check if there is no default for the customer and if not we add this one as the default), but not for the sub
I'll just create a test scenario now that shows you what i mean about one getting set - hang on 2 mins...
Ok
Also something important to note is there are several sources default payment method
Which can be confusing
We mention this on the subscription object in the docs here: https://stripe.com/docs/api/subscriptions/object#subscription_object-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I believe default_source actually is set automatically on first invoice payment if it hasn't been set yet
But the subscription you shared has the default set on the actual subscription, which take priority
But yeah let's take a look at your test example so I can fully understand what's happening here
Oh ok ... right so I've created a new subscription
sub_0MmIDwEHSdXPilfD4zKOG6tS
It has no default PM, I've just added a test card for it
So now I'm going to advance 30 days and let the invoice happen and get paid (it's in a trial)
I'll do that now...
Ok so that's happened now, so now the first invoice has been paid, and the default_payment_method for that sub is now set to the PM
Oh hello.. .I found something...
Ah
Yeah that setting will do this: https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_settings-save_default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So we set that, and it makes the PM the default the first time it's used, and that means that once this has been set, and the customer updates (for example via the hosted invoice page) to another card, the default remains at the one that was wrong!
Yeah. Default payment method isn't changed unless you explicitly say so
I wonder why I set that... ๐ฌ Not a question for you though, at least now I understand what's happening! Thanks a lot for your help here !
No problem
I'm wondering if I should unset that option, so that the default PM isn't set for the subscription - but yeah I think I need to read up on what happens in that case
So if you don't set default payment method on the Sub at all, then we'll attempt to charge invoice_settings.default_payment_method if that's set. And if that isn't set we'll attempt to charge default_source on the customer. If all the above aren't set, then payment will just fail
Right that makes sense, since we're using the customer portal for customers to manage this themselves it makes more sense for us to unset this and let customers manage it
Yeah up to you
Thank you again, that's been really helpful - awesome assistance ๐
No problem!
Argh - one more question if you don't mind
The docs say "With on_subscription Stripe updates subscription.default_payment_method when a subscription payment succeeds."
that implies to me that when a new card is added and succeeds, then the default PM would change to that, but this isn't the case - is that correcT?
i.e it seems to set it the first time, but then when you change to another PM - as was the case with the original customer I shared, it "stuck" on the old PM
Yeah it's only for the first payment
You'd need to manually specify the default PM if you want it changed in the future
Gotcha, thanks