#netic_api
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/1450856479920885760
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
hey there, do you have an example where this didnt happen like you expect? in my test of this the payment method collected was saved both to the subscription default and the customer default
We also have options to enable more saved payment method behaviour within checkout: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=checkout#save-payment-methods-to-prefill-them-in-checkout
Hey, thanks for answering so fast.
Are we talking about using
payment_method_collection: 'always',
I don't think that should change the behaviour, but if it does we can explore that
Using the saved payment method options i linked to would also give the customer some control over this
I dont think I understand, so what I am trying to achive it
User signs up for the subscription -> User want to add a new seubscription. ->. Stripe doesnt need to create a new checkout session
So my question is, can i pass payment_method_collection: 'always' to the stripe.checkout.create() so that I do not get the "This customer has no attached payment source or default payment method" error
Do you need that checkout session for your business flow? If you already have a saved payment method, you could create the second subscription directly without a checkout session
But, if you do want the session flow, then the saved payment methods feature will be how you can have that existing payment method resurfaced in Checkout
The only checkout that we would like to have is the first checkout for the subscription, and after that we would like to use the default payment method to create and assign new subscriptions to the user. That is what I am asking, if there is a way to tell the stripe.checkout.sessions.create to assign that payment method as the default payment method
https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=checkout#save-payment-methods-to-prefill-them-in-checkout
If the payment method was not originally collected using the saved payment methods feature, you may need to modify the allow_redisplay property to always before it can be prefilled
This sounds like what i was suggesting, just creating the subscription directly without checkout
Are you suggesting that when you use payment_method_collection: 'always', that it is not setting the default_payment_method on the sub/customer?
No I am not asking about prefilling the stripe hosted checkout session. I would just like to know, if there is a way to tell the stripe hosted checkout session (that is created using stripe.checkout.sessions.create) to save the payment that the user used, as the default payment. Because currently, if I fill in the stripe hosted checkout session. And then look at the user in stripe dashboard, that payment method is not set as default.
So when i try to attach a new subscription to the user, the user will not need to be directed to the checkout but will be automaticaly assigned a new subscription
So when i try to attach a new subscription to the user, the user will not need to be directed to the checkout but will be automaticaly assigned a new subscription
I dont understand what you mean here, you need to manage this by creating a checkout session or creating a subscription without a session
If you're asking if you can use just the checkout session api to have stripe determine if there is a default PM, and if so use that automatically to create a subscription without the session, then no thats not possible
you need ot build that part of the logic
Yes, i have added the payment_method_collection: 'always' and the payment method is still not being set as default
I would just like to have the payment the user used in the checkout, to be set as the default payment.
Do you have an example customer/session where you saw this happen that i can look at?
This one
url: https://dashboard.stripe.com/acct_1QGKexLiGzfLlQtt/test/customers/cus_Tcc2Ib9EqRtUwu
account: acct_1QGKexLiGzfLlQtt
customer: cus_Tcc2Ib9EqRtUwu
And just for reference, this is how we are setting up the stripe checkout
const sessionConfig: Stripe.Checkout.SessionCreateParams = { customer: customerId, payment_method_types: ['card'], line_items: lineItems, mode: 'subscription', custom_text: { submit: { message: submitMessage }, }, ...discountConfig, subscription_data: { description, metadata, ...(shouldApplyTrial && { trial_period_days: 3 }), }, success_url: successUrl, cancel_url: cancelUrl, ...(clientReferenceId && { client_reference_id: clientReferenceId }), payment_method_collection: 'always', }; const session = await stripe.checkout.sessions.create(sessionConfig);
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
the session for the customer is complete/expired. Can you create a new one i can access?
I dont understand?
What do you observe
Oh sorry, crossed my threads ๐
Yeah, sorry that this is taking so long ๐
Ok i suspect that because there is not a payment happening in this flow at first, the PM doesnt end up as the customer invoice default
I think all you need to do here is take that collected PM (on the session, attached to the customer) and update the customer to set the invoice default:
https://docs.stripe.com/api/customers/update?lang=curl&api-version=2025-02-24.acacia#update_customer-invoice_settings-default_payment_method
This will guarantee the PM is set as the default, then you can create subsequent subscriptions that will it by default
So add this code in the subscription created webhook
if (subscription.default_payment_method && subscription.customer) { await stripe.customers.update(subscription.customer as string, { invoice_settings: { default_payment_method: subscription.default_payment_method as string, }, }); }
Or is there a more elegant solution?
Yep that would work, though I would suggest doing it in the checkout.session.completed event instead, because you'd also get subscription created events for those second sub cases
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
This doesn't have the PM in it directly, though, so you'd need to retrieve the subscription/customer PM first, then set the default
second sub cases? I might have missunderstod you or missrepresented my situation.
The first time the checkout session is created, the user can select only one subscription. And then they can, at a later date, add new ones. But at this point we should already have the default payment
so when i try to attach a new subscription to the user, the user will not need to be directed to the checkout but will be automaticaly assigned a new subscription
im referring to this, when you go to create those additional subscriptions after the first one via checkout
yes, exactly
my point is this would generate an additional subscription.created event, and setting the customer default is not necessary here
you only need to do this after the initial checkout session completion
its harmless to set the default again to the same value, so if its simpler for you to do it on subscription created events then thats fine
Aha I understand, that is a good point thanks.
I believe that is all I needed, thanks.
awesome, happy to help, thanks for your patience!