#vishnu-sankar_best-practices

1 messages · Page 1 of 1 (latest)

dark skyBOT
tardy warrenBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

dark skyBOT
#

đź‘‹ 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/1238128308651167774

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

gritty barn
#

Hey there

#

Yeah mostly you need to handle this with your integration

#

So if they attempt to cancel you could charge them immediately for their current usage and then cancel.

pulsar yacht
#

They’re cancelling using the customer portal. Not using API or backend logic

gritty barn
#

Yeah in that case you would use Webhooks to charge them if they cancel.

pulsar yacht
#

Plus, I’ve configured the customer portal to cancel the plan immediately. I assume it charges the customer immediately based on reported usage.

gritty barn
#

Hmm what proration_behavior do you use?

#

Do you have an example I can look at?

#

Ah wait doh. We don't do proration with metered

#

So yeah that is expected

#

So what you would need to do is listen for Webhooks and if they cancel then you would create a separate Invoice for the amount, based on the previous usage, and charge the collected payment method

pulsar yacht
#

That’s a bit confusing, how does it prevent free usage? The user can again create another subscription and use it to consume first free x number of items

gritty barn
#

Yes if you are going to use this set up then you would build your own logic here.

#

If they are only using the first x amount free then you need to aggregate Subscriptions per Customer

#

Mostly this is up to you to handle as you desire, or to not allow cancellation via the Customer Portal

pulsar yacht
#

I would still love to use customer portal. Can I disable only the cancelation?

gritty barn
#

Yep

#

So you would just set it to enabled: false

#

If you are just using the default config from your Dashboard then you can turn it off there as well

pulsar yacht
#

Okay, for manual cancellations how the proration will work for metered billing? Will it immediately charge customer upon cancellation based on reported usage?

tardy warrenBOT
gritty barn
#

There is no proration with metered billing

#

That isn't how metered billing works, as you pay at the end of the period, not the beginning.

#

However

#

If you cancel you can immediately invoice for the current usage

pulsar yacht
#

Is the behaviour still the same (it charges immediately) if I use the customer portal to cancel subscription and set it to “cancel immediately”

cobalt osprey
#

Hi, stepping an as bismark needs to delurk. Let me catch up

pulsar yacht
#

Yes, I did test it using Test clock and it created a “draft” invoice pending charges.

I want to know how it will behave when customer cancels through portal. Will it charge the saved card for reported usage immediately if I set the cancellation behaviour to “cancel immediately”.

Also what’s the best way to prevent metered billing abuse just by cancelling and resubscribe the same plan to rest the meter?

cobalt osprey
#

I see, yeah if you tested this you know that setting features.subscription_cancel.mode to 'immediately' will cancel the subscription immediately. You would need to track this on your end. For instance, if you see the same email/ customer trying to resubscribe/ abuse the free usage, you need to invoice them and then allow cancellation for instance.

pulsar yacht
#

Since the meter events usages are tied to customer, I think stripe should auto apply unpaid meters when someone creates a new subscription with same meter.

#

Otherwise it’s just too much of a work to prevent such abuse.

cobalt osprey
#

That prevents a lot of valid use cases where merchants do want that behavior. As an example, a customer might want to subscribe to the same metered price for two separate subscriptions on a customer and they need to keep them separately.

pulsar yacht
#

But it also open doors for such abuse for basic use cases.

cobalt osprey
#

In this case, you can track this on your end and choose not to offer the option to cancel until they pay for the usage so far.

pulsar yacht
#

Okay, but I want to know how it will behave when customer cancels through portal. Will it charge the saved card for reported usage immediately if I set the cancellation behaviour to “cancel immediately”.

#

Say, if I only allow users to visit customer portal after the free tier consumption, and user plan to cancel the plan. Will they get billed immediately?

cobalt osprey
#

Yes, as long as you've reported the usage from your end on that customer, it should.

#

I think you should still test this on your end ensure that it exactly what you want.

pulsar yacht
#

Yes, I’m testing multiple scenarios. One last thing I want to ask is there any way to get summary of meters per month. So that I could only allow users to visit customer portal only after x number of usage.

pulsar yacht
cobalt osprey
pulsar yacht
cobalt osprey
#

I'm unsure what you're referring to on the DB, but yeah for the subscription item, it will return the usage data up to that point.

pulsar yacht
#

The stripe dashboard subscription details page shows a quantity. I assume it’s same the value in summary list.

#

Anyways, I think this should work for now and thanks a lot for your support so far.

#

One last thing, may I?

cobalt osprey
#

yeah, I do not know personally know the code behind the Dashboard but it sounds like it should match for the same subscription item.

Sure!

pulsar yacht
#

Is it possible to have restricted api keys to send metered billing events. I see no option to write metered events through restricted api keys. So I’m resorted to full access api keys which I’m not comfortable using in production

cobalt osprey
#

Does adding write to All Billing resources now work here?

pulsar yacht
#

I didn’t tried that way! I tried with write access to “usage record” option but still no luck. Do you mind waiting for 5 mins so that I could try with write access to all billing resources and report back?

cobalt osprey
#

Sure!

pulsar yacht
#

Thanks a lot for waiting l, it’s showing permission error

cobalt osprey
#

I can share this with our team to add this permission functionality. Thank you for flagging.