#daniele_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1255104099234349159
đ Have more to share? Add details, code, screenshots, videos, etc. below.
The logic I'm using is that if I see the user already has a subscriptionItem - I'll try to update it to support different subscriptions plans.
const product = await stripeClient.products.retrieve(product_id);
const subscriptionItems = (await stripeClient.subscriptionItems.list({
subscription: subscription_id,
})).data;
// Last item
const subscriptionItem = subscriptionItems[subscriptionItems.length - 1];
subscription = await stripeClient.subscriptions.update(subscription_id, {
items: [
{ id: subscriptionItem.id, price: product.default_price as string },
],
expand: ["latest_invoice.payment_intent"],
proration_behavior: "always_invoice",
payment_behavior: "pending_if_incomplete",
});
The bug happens when the user dismissed the payment sheet - the subscription is left in an incomplete state
This is expected
and breaks if I try to update the subscription again.
What breaks exactly? what is the expected behavior ?
It basically runs the update code above. And it fails with the following error:
Error: A canceled subscription can only update its cancellation_details.
You need to not udpate the subscription update code then if the user cancel the payment sheet.
I'm not updating it when the user cancels, I'm doing it when a user starts the payment for another subscription plan. I'm doing it because I want only one active plan at a time.
Sorry, but I'm not sure I udnerstand the issue you are facing exactly here. I'm trying to understand the use case first, despite the Flutter SDK is maintained by the community and not Stripe.
That's fine, the issue is happening on the server - I just gave the flutter sdk as context.
I understand the root cause. How should I manage the incomplete subscription then, if a user starts a new one?
can I delete the subscription upon user dismissing the payment sheet?
How should I manage the incomplete subscription then, if a user starts a new one?
can I delete the subscription upon user dismissing the payment sheet?
Why not re-using the same subscription even if the customer cancels the payment sheet ?
that's what I was going for - but since they might have clicked on a separate subscription plan - I need to update the product information attached to the subscription. When I try to do that on the incomplete subscription i get the Error: A canceled subscription can only update its cancellation_details. error
When I try to do that on the incomplete subscription i get the Error: A canceled subscription can only update its cancellation_details. error
Can you share the ID (req_xxx) of the failing API request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
What makes the subscription canceled ? PaymentSheet shouldn't canceling the Stripe Subscription
Subscriptions are generally immutable in an incomplete state. If you're looking to reflect some changes a customer may make to their plan choice etc, then you just need to create a new subscription
Alright, so summing it all up, I think I should do the following:
- If user clicked on the same, I use the incomplete subscription.
- If the user clicks on a separate plan, I create a new one.
Last question - how do I safely update plan and price for a users and avoid them being billed for two different plans?
Seems logical yep!
how do I safely update plan and price for a users and avoid them being billed for two different plans?
Not sure I understand the question
I'm using the same logic for having users change their plan. By updating the subscription, I can easily move them from one plan to another. If I stop updating the subscription, what's is the best way to migrate their plan gonna be?
Well if they have an active ongoing subscription you should still update that sub_xxxx
Actually, correct me if I'm wrong, I think I can update the subscription if it's in an active state. Therefore I could keep the same logic and just check for the state
It's only when it's incomplete (i.e. in the initial 'checkout' flow) that you'd need to create a new subscription
Yep!
How would I check for the subscription state?
or, even better, if it's in an immutable state?
It's right there on the object: https://docs.stripe.com/api/subscriptions/object#subscription_object-status
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
is the incomplete the only immutable state? Could this happen for any more states?
canceled and incomplete_expired are immutable too. The others you'd need to test but might not even be relevant (trialing, paused)
alright, thanks a lot for the help!