#pedro-reis_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/1310556948755775560
đ 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.
- pedro-reis_api, 2 days ago, 35 messages
I've tried to update the subscription setting trial_end: 'now' but the subscription was being cancelled straightaway
Hi, let me help you with this.
a colleage last week suggest updating the subscription with trial_end: 'now' and get the pending_setup_intent
the subscription was being cancelled straightaway
Do you know why is this happening? If you're collecting the PaymentMethod via Subscription's client_secret it will be charged for the Subscription's Invoices.
Or is the client_secret coming from the new Subscription you're creating?
while adding the subscription to the user for the first time, these are the settings I'm passing to stripe.subscriptions.create:
{
customer: customerId,
trial_period_days: 7,
payment_behavior: 'default_incomplete',
payment_settings: {
save_default_payment_method: 'on_subscription',
},
trial_settings: {
end_behavior: {
missing_payment_method: 'cancel',
},
},
}
The last parameter explains why it's cancelled when you end the trial.
yeah, I guessed that
I need the subscription to be cancelled after the trial if the user does't add their payment details
what's the best way to achieve this?
That's already achieved, it seems. I understand that you actually need to not cancel it if the PaymentMethod is added, right?
yes, exactly
so :
- if the user does not add their payment details, the subscription is cancelled (done!);
- I need the trial to end and make the subscription Active if the user adds their payment details
Or is the client_secret coming from the new Subscription you're creating?
Where is the new PaymentMethod saved?
I'm using the stripe.confirmSetup on the frontend
I was trying to call stripe.subscriptions.update on the backend and get the client secret (from the pending_setup_intent suggested by your colleague) from that call and pass it to the stripe.confirmSetup
Could you please share and example Subscription ID?
You don't need to create/update the Subscription to get the client_secret. You can just fetch it with GET.
sorry, but what should I fetch with the get? and where should I pass it? to the Elements options?
Whenever you want to let a customer add their PaymentMethod, you can fetch the trialing Subscription by ID, grab the pending_setup_intent.client_secret and pass it to the Payment Element.
I've added this subscription to a user: sub_1QP07M2sDVri7Vid8koah8zk
ok... so get the pending_setup_intent.client_secret, pass it to the Payment Element , call stripe.confirmSetup() with that secret, and once everything is successfull, I can make the request to update the user subscription, correct?
actually, no... you said to pass the secret to the Payment Element options?
or should I pass it to the stripe.confirmSetup()?
I'm really sorry for all the questions and really appreciate your help on this!
update the user subscription
If you mean end the trial - then yes, looks good.
No worries, that's why we're here.
ok, I think I got it
last question to make sure I understand everything: the pending_setup_intent is created while creating the subscription for the first time, correct? then we just need to grab it to update the payment details before updating the subscription/ ending the trial and make it active
Yes
ok
If the auto-generated SetupIntent gets expired/cancelled for some reason during the trial, feel free to create a standalone SetupIntent yourself. Just make sure the attach the PaymentMethod created this way to the Subscriptions default_payment_method explicitly: https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements
Happy to help.
I believe there's no way to get back to this thread once closed so it's easier to recover the conversation?
in case I have further questions
You will be able to view it, but you will need to create a new one if you have more questions. I might not be around at that time anyway.
yeah, of course! thank you once again, vanya