#piyush_best-practices

1 messages ¡ Page 1 of 1 (latest)

gaunt grottoBOT
#

👋 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/1417586307361800303

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

raw dawn
#

Hello again

#

Update Customer API requires your secret API key so you'll need to update it via your backend/server-side code.

You could
1/ Listen to setup_intent.succeeded event and update the Customer after you've recieved the event
2/ Make an API call from the client to your server once you have the Payment Method ID -> Then from your server, you can call Update Customer API endpoint

#

Upto you on how you'd want to handle this

lethal bolt
#

Okay, this seems off the track but what i am doing is, generating setup-intent at server side, sending it to client and when it succeeds i am creating a subscription with free trial(which first checks if a customer has default payment method or not), so the webhook could be late and this could fail

raw dawn
#

Is there a reason you're creating the SetupIntent first? If you create a Subscription with Trial then we generate a SetupIntent automatically which you can confirm Client-side and attach the payment method to the Subscription automatically

lethal bolt
#

yes but customer could choose not to setup payment method after it(leaving subscription in trial and no payment method as well, which will result in cancellation of subscription - setting up missing_payment_method to result in cancel)

raw dawn
#

Ah I see.

lethal bolt
#

Do you suggest any other approaches or am i doing it wrong?

raw dawn
#

Generally, folks just use the SetupIntent generated by the Subscription and choose to cancel the subscription in a fixed duration if the SetupIntent isn't confirmed by that time.

#

But it really just depends on your flow. If you need the attach to be synchronous, then you can handle this like I described in step 2/

lethal bolt
#

Approach wise nothing wrong, right, i was afraid if i am doing something anti-pattern