#staunch_best-practices
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1488032834068152492
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
In particular, a problem we want to avoid is a customer that currently has a default_source set adding a new card (and setting invoice_settings.default_payment_source to the new card) then deleting that new card making us think "they've deleted the default payment method so they don't have one set" when in fact they do still have one set in the default_source
hello! gimme a while to think about this
No problem, would appreciate and advice/help you can give
Basically what we want to do is a big cleanup of the data we have in Stripe before we start syncing it again in a new way - the big thing we're doing is fixing up duplicate payment methods that were made due to the way we handled some invoicing but it would also be nice to move completely away from the legacy source API and not have to think about it, but we can't just remove the sources on file for the customers that have that set as the default.
Another approach I was going to try was cloning the source, setting the new one as the default payment method under invoice settings then deleting the original to clear out default_source but the clone call gave me an error as well, I think you can only clone to a different account
hmmmm, you can't unset default_source itself (as you've probably already noticed). The Customer Update API doesn't support clearing that field while keeping the card attached.
I think the best path forward here would be to set the existing card_ or src_ ID directly as the invoice_settings.default_payment_method on the Customer Update call, and then simply stop reading from default_source altogether. Would that work for your use case?
It kind of works, but doesn't really cover the case of being able to unset the default source if it's a new payment method (as we can't set the new payment method to the default_source field) - it would revert the default back to the one set in default_source unless we also completely detach that one
e.g. Customer cus_KKERZsHZs78hAf currently has a default_source of src_1MGvo3GC4EC4DnRhoHjfPCCq and invoice_settings.default_payment_method of pm_1LyuqLGC4EC4DnRhgdnNYRZo. If pm_1LyuqLGC4EC4DnRhgdnNYRZo is deleted, their default payment method now becomes src_1MGvo3GC4EC4DnRhoHjfPCCq even though in the Stripe dashboard, we deleted the one that says "Default". We'd need to refresh the dashboard to see the new default and also remove that one to remove the default. It would be nice if we were able to retain src_1MGvo3GC4EC4DnRhoHjfPCCq on file, just not the default, in case they want to use it in the future.
If that's not really possible it's fine, we'll just need to continue supporting the default_source field in our logic to determine if they have a payment method set.
ah okay, i see what you're trying to say now.
If the customer sets a new payment method and the old legacy source is still attached, default_source would still exist, and Stripe would fallback to the default_source if it still exists.
I think the cleanest solution there is to just delete the old source at that point. If the customer is actively choosing a new payment method, the old one isn't really needed anymore, and deleting it will clear out default_source so you don't have to worry about the fallback. Having said that, you may need to warn the user if you're deleting the source i guess
but yeah, the core of the issue here is unfortunately, it's just not possible to only unset the default_source, while still having the source be attached to the customer.
Yeah that's what I was trying to get around, having to delete the original payment method, since they might still choose to use that for other things in the future