#VisionADdyOP
1 messages · Page 1 of 1 (latest)
hello! give me a while to get back to oyu
Ok
If a customer upgrades their plan for metered usage, you would want to do something like this:
- Add a new subscription item for the new metered price (do not update the existing subscription item)
- Stop reporting usage for the original subscription item, and report all new usage for the new subscription item
- After the period is over and the invoice has been generated, delete the original subscription item
you mean old metered item right?
which specific bit are you refering to?
but my subscription is combination of two prices flat price and metered price
yes, what i'm explaining for metered price specifically. For flat price, it's fairly straightforward - you can just update the subscription item since proration would work as per what you expect
i don't understand what you mean by which event you need to remove old price item id?
you said once invoice is created we need to remove original price id right
is their any chance to charge immidietly for metred price and generate new invoice as usal
beacuse may be customer upgrade multiple times
to maintain that flow it will be complex may be give me suggestion
if (plan.plan_id === companyactiveplan.plan_id && plan.feature_id === companyactiveplan.feature_id) {
return CommonFunctions.response(true, Messages.Error.Plans.SAMEPLANACTIVATED, 0, {}, Constants.ResponseStatus.OK);
}
const stripesubscription = await stripe.subscriptions.retrieve(companyactiveplan.stripe_subscription_id);
if (stripesubscription.cancel_at) {
await stripe.subscriptions.update(stripesubscription.id, {
cancel_at_period_end: false,
});
}
const flat_rate_item_id = stripesubscription.items.data[0].id;
const metered_rate_item_id = stripesubscription.items.data[1].id;
await stripe.subscriptions.update(companyactiveplan.stripe_subscription_id, {
items: [
{
id: flat_rate_item_id,
price: plan.stripe_price_flat_rate,
},
{
id: metered_rate_item_id,
price: plan.stripe_price_metered_rate,
clear_usage: false,
},
],
}); i am doing this
when you upgrade the subscription, you're changing the flat price also right? If that's the case and you set the proration_behavior=always_invoice that should generate an invoice immediately
along with metered price?
with this code change will new invoice is old metred price usages + new prorated flat fee?
hrm, the proration for the flat fee won't cause the metered usage to be charged
let me test something out
please test and update
i think the easiest way to go about things would really be to cancel the existing subscription with prorate=true, invoice_now=true and then create a new subscription
if you cancel the existing subscription with prorate=true, invoice_now=true, it'll charge for existing usage of the metered plan and also prorate the flat fee
then subsequently the customer should just sign up for a new Subscription
is their any other way
not that i can think of
i want some solution without canceling subscription actully
are you okay to change the billing cycle anchor?
if you're okay with that, then you can update the subscription with the new flat fee, add in the new metered price, then set billing_cycle_anchor=now, prorate=true and that will charge the existing metered price usage
subsequently after payment is made, remove the old metered price from the subscription
the anchor should not change actully
there's not really many other options left here really - you could manually calculate how much to charge the customer and then create your own invoice, but that defeats the purpose of using Subscriptions. At this point, with your requirements and the level of complexity your logic would need to handle, you would maybe want to consider building your own recurring payment logic
to summarize, there's two options here :
- cancel the existing subscription and then create a new one
- update the Subscription with the new Prices and then set billing_cycle_anchor (so that the Subscription will bill immediately)
if neither works for you, i can't think of any other great option that doesn't involve a great deal of manual calculation / implementation work
you could try tinkering with some other ideas and see if you can come up with anything else
can we edit upcoming invoice?
is their any way some how will add the previous metered usges starightaway and this will be charged in upcoming invoice
can we edit upcoming invoice?
Sure, you can try. What do you want to edit?
is their any way some how will add the previous metered usges starightaway and this will be charged in upcoming invoice
I've already shared the available options with you
what i am thinking will add new item of metred price by keeping old metred item as it is and once the invoice is created i will remove the old item from subscription for upcoming month will this work?
that's originally what i suggested, but your requirement was that you wanted to invoice immediately right?
i.e. what i mentioned originally
If a customer upgrades their plan for metered usage, you would want to do something like this:
1. Add a new subscription item for the new metered price (do not update the existing subscription item)
2. Stop reporting usage for the original subscription item, and report all new usage for the new subscription item
3. After the period is over and the invoice has been generated, delete the original subscription item