#VisionADdyOP

1 messages · Page 1 of 1 (latest)

viscid cryptBOT
trail lintel
#

hello! give me a while to get back to oyu

worn zinc
#

Ok

trail lintel
#

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
vital pivot
#

you mean old metered item right?

trail lintel
#

which specific bit are you refering to?

vital pivot
#

but my subscription is combination of two prices flat price and metered price

trail lintel
#

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

vital pivot
#

yes

#

but i which event we need to remove old price item id

trail lintel
#

i don't understand what you mean by which event you need to remove old price item id?

vital pivot
#

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
trail lintel
#

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

vital pivot
#

along with metered price?

#

with this code change will new invoice is old metred price usages + new prorated flat fee?

trail lintel
#

hrm, the proration for the flat fee won't cause the metered usage to be charged

#

let me test something out

vital pivot
#

please test and update

trail lintel
#

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

vital pivot
#

is their any other way

trail lintel
#

not that i can think of

vital pivot
#

i want some solution without canceling subscription actully

trail lintel
#

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

viscid cryptBOT
vital pivot
#

the anchor should not change actully

trail lintel
#

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

vital pivot
#

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

trail lintel
#

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

vital pivot
#

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?

trail lintel
#

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
vital pivot
#

Yes this i can try

#

can you share the doc how to add item and remove