Thanks for the answer Rami.
Probably I have to explain little bit more about the detail.
My team started to implement usage based payment system on Stripe for PaaS/SaaS service.
In this case, I found two ways as far as I know.
1. Using subscription (Create users. Not one time charge.)
2. Using Invoice
I decided to use both 1 and 2 to implement usage based payments. Subscriptions on Stripe are charged through invoices. Stripe generates an Invoice object that represents the amount the customer owes and then attempt to charge the customer that amount. Note that this kind of invoice isn’t actually sent to the customer but is instead paid automatically in Stripe. A successful payment of the invoice results in an active subscription, which makes my life easier because I don't need to implement additional batch system to calicurate the amount.
So I can sign customers up for a $0 base subscription and attach invoice items each month to bill them for usage. As invoice items are a one-time adjustment, I use Stripe webhooks to listen for invoice.created event on each renewal and then add your invoice item for the appropriate amount plus dealing with tax.
I already wrote the production code, and it works well.
And my additional requirement is
- Once the usage goes over the certain amount. Let's say 50 bucks. I'd love to check if the user's card has potential to pay for the amount.
I couldn't find any right answer yet, so I thought it's better to implement without capturing first because our customers are all individuals, and I can expect the usage amount is small.
As our business grows and the time to need to provide it to companies ( not individual users ) comes, maybe it could build that logic ourselves.
(Ex. Something users can shift from subscription payment to One time charge. So the capturing is supported without confusing customers )