#daniele_code

1 messages ¡ Page 1 of 1 (latest)

hushed thornBOT
#

👋 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.

odd zealot
#

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",
    });
tribal zephyr
#

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 ?

odd zealot
#

It basically runs the update code above. And it fails with the following error:

Error: A canceled subscription can only update its cancellation_details.

tribal zephyr
#

You need to not udpate the subscription update code then if the user cancel the payment sheet.

odd zealot
#

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.

tribal zephyr
#

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.

odd zealot
#

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?

tribal zephyr
#

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 ?

odd zealot
#

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

tribal zephyr
#

What makes the subscription canceled ? PaymentSheet shouldn't canceling the Stripe Subscription

hushed thornBOT
glacial drift
#

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

odd zealot
#

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?

glacial drift
#

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

odd zealot
#

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?

glacial drift
#

Well if they have an active ongoing subscription you should still update that sub_xxxx

odd zealot
#

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

glacial drift
#

It's only when it's incomplete (i.e. in the initial 'checkout' flow) that you'd need to create a new subscription

odd zealot
#

How would I check for the subscription state?

#

or, even better, if it's in an immutable state?

glacial drift
hushed thornBOT
odd zealot
#

is the incomplete the only immutable state? Could this happen for any more states?

glacial drift
#

canceled and incomplete_expired are immutable too. The others you'd need to test but might not even be relevant (trialing, paused)

odd zealot
#

alright, thanks a lot for the help!