#netic_api

1 messages ยท Page 1 of 1 (latest)

reef apexBOT
#

๐Ÿ‘‹ 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.

twilit ingot
#

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

hollow valley
#

Hey, thanks for answering so fast.

Are we talking about using

payment_method_collection: 'always',

twilit ingot
#

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

hollow valley
#

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

twilit ingot
#

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

hollow valley
#

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

twilit ingot
reef apexBOT
twilit ingot
#

Are you suggesting that when you use payment_method_collection: 'always', that it is not setting the default_payment_method on the sub/customer?

hollow valley
#

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

twilit ingot
#

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

hollow valley
hollow valley
twilit ingot
#

Do you have an example customer/session where you saw this happen that i can look at?

hollow valley
#

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);
twilit ingot
#

the session for the customer is complete/expired. Can you create a new one i can access?

twilit ingot
#

this at least shows apple pay for me in desktop chrome

hollow valley
#

I dont understand?

twilit ingot
#

What do you observe

hollow valley
twilit ingot
#

Oh sorry, crossed my threads ๐Ÿ˜…

hollow valley
twilit ingot
#

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

#

This will guarantee the PM is set as the default, then you can create subsequent subscriptions that will it by default

hollow valley
#

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?

twilit ingot
#

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

#

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

hollow valley
#

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

twilit ingot
#

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

twilit ingot
#

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

hollow valley
#

Aha I understand, that is a good point thanks.

#

I believe that is all I needed, thanks.

twilit ingot
#

awesome, happy to help, thanks for your patience!

hollow valley
#

Thanks for your patience as well

#

Have a great day