#xsliii_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/1369329982190649474
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello, with our subscriptions prorations are handled per update and it is handled as if an invoice at the current quantity was already paid. So in this case I think you would need to track the most that they paid for for the subscription in a given cycle and pass us proration params based on whether or not you want proration to happen on that specific update.
Though now I'm trying to think of what you would want to do if the user changed from say qty 4 to 6 in that scenario, I'm guessing you'd want to charge them for 1 because they already paid for 5?
exactly what im trying to archive.
i want to always invoice only quantities which are more than already paid, but still want to know how much quantity is active for current running billing period.
so what would be my best approach here.
Updating existing subscription items (with proration_behavior=none) would immediately change the quantity of the running subscription. So a "retrieve" of the subscription would show me a different quantity for the current running billing period, which results in a miscalculation of the then increased quantity (more than was paid before).
1 -> 5 (4 extra paid)
5 -> 3 (nothing to be paid, but future period should also only invoice 3).
3 -> 6 (1 extra should be paid, because its known, that 5 were already paid)
is this doable with subscription update and a specific proration config or do i need to use subscription scheduling, that i can still use "stripe.subscription.items.retrieve()" with correct quantity?
or do i need to save the "canceled quantity" in my database to fit the correct usage of the next update, if the user is then increasing the quantity from the previously changed quantity (e.g. 5 -> 3 (2 canceled)-> 4 (1 canceled))?
The two main ways I can think to do this are to:
- Immediately make updates when increasing the subscription quantity, make a schedule for reducing the quantity. Release the schedule when the quantity is adjusted up to or beyond the current max that has been paid for in the cycle.
- Track the max paid for for the cycle on your side, when they want to adjust their quantity higher than that, make two updates: one to the previous max without proration, and then one to the quantity they want with proration. So in this case from 3->5 then 5->6
Unforunately its going to be a bit complicated either way. We don't have anything built in to address this use case directly
can you give me a short example of how to handle it via api correctly, to add the subscription schedule with a changed (lower) quantity than what was paid and then with releasing? all should stay on the billing period end as known in the subscription.
i use nodejs for this
Might this be correct?
// stripe quantity 5, db quantity 5, canceled 0
// reduce quantity to 3, db quantity 5, db quantity canceled 2 -> create schedule with quantity 3
// increase quantity to 4, db quantity 5, db quantity canceled 1 -> update schedule with quantity 4
// increase quantity to 6, db quantity 6, db quantity canceled 0 -> release schedule + update subscription invoice immediately
Yep that is what I was thinking. So the subscription would have two phases in that case, the first phase would have qty 5 for the first two updates and you would just update the second phase's quantity. If nothing happens when the next cycle rolls around the subscription would go down to that quantity and you can have the schedule's end behavior set to release so that it automatically detaches from the subscription at that point.
And then when you upgrade to 6, because the qty is already 5 the proration should just work and make an invoice that charges for 1 seat for the rest of the cycle
so the subscription item quantity always stays at the maximum paid, the schedule will handle then downgrading of quantity.
how do i add those phases when already having a subscription?
await this.stripeAdapter.client.subscriptionSchedules.create({
customer: stripeCustomerId,
from_subscription: existingSubscriptionId,
phases: ... // is not allowed due to from_subscription
});
first create and then update the schedule with the newly created id?
You can create a schedule on the existing subscription and then update it to add a phase https://docs.stripe.com/billing/subscriptions/subscription-schedules/use-cases#existing-subscription