#vishnu-sankar_best-practices
1 messages · Page 1 of 1 (latest)
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.
- vishnu-sankar_best-practices, 6 hours ago, 7 messages
đź‘‹ 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.
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.
They’re cancelling using the customer portal. Not using API or backend logic
Yeah in that case you would use Webhooks to charge them if they cancel.
Plus, I’ve configured the customer portal to cancel the plan immediately. I assume it charges the customer immediately based on reported usage.
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
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
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
I would still love to use customer portal. Can I disable only the cancelation?
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
Okay, for manual cancellations how the proration will work for metered billing? Will it immediately charge customer upon cancellation based on reported usage?
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Is the behaviour still the same (it charges immediately) if I use the customer portal to cancel subscription and set it to “cancel immediately”
Hi, stepping an as bismark needs to delurk. Let me catch up
You can configure this on the Customer Portal, https://docs.stripe.com/api/customer_portal/configurations/create#create_portal_configuration-features-subscription_cancel-mode. I recommend that you test this using our Test Clocks, https://docs.stripe.com/billing/testing/test-clocks that advances time so you don't need to wait days to see the epxected behavior.
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?
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.
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.
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.
But it also open doors for such abuse for basic use cases.
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.
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?
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.
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.
When typing my last reply, your response came into my mind.
For meter event summary listing how someone differentiate meter usages per subscription when multiple plans are using same meter ?
You can use our List all subscription item period summaries API, https://docs.stripe.com/api/usage_records/subscription_item_summary_list
Thank you. The total usage is same as the one showing in dashboard. Right?
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.
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?
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!
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
Does adding write to All Billing resources now work here?
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?
Sure!
Thanks a lot for waiting l, it’s showing permission error
I can share this with our team to add this permission functionality. Thank you for flagging.