#florian-ruen_billing-webhook-events

1 messages ยท Page 1 of 1 (latest)

merry pawnBOT
#

๐Ÿ‘‹ 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/1277663883254829087

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

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.

rustic hound
#

Hello there,

for more details:

  • i'm using checkout session as setup mode for my customers add billing details and credit card ;
  • the eevent checkout.session.completed will create a subscription, only using the schedulling feature here ;
  • when the invoice.created is fired, I'll add recorded usage (in my DB) to the invoice ;

but when my customer upgrade/downgrade/cancel, I want to charge now, the previous usage
i means if my customer sent 3 transactions, downgrade to free offer, i want to charge now for the 3 transactions, so i'm expected the invoice.created event
i guess using InvoiceNow from cancellation should fire this no ?

lean sonnet
#

Hi ๐Ÿ‘‹

Can you share an example API request ID for when a customer updated their subscription and an event was not fired?

rustic hound
#

for cancellation, this one: req_HP6IEAa5wkhvJv

#

for update, maybe this one: req_4eyHuBe0CM6pQw

#

maybe the event is not invoice.created for this, but something similar ?

lean sonnet
#

For the invoice that was canceled, the subscription was created with a 0 price

#

So the first invoice was created and marked as paid

#

there wasn't anything to invoice for

rustic hound
#

Yes, but maybe in my own DB, I've usage to report for the final invoice (i'm not using billing meters here)

#

If the customer subscribe to premium on 3rd - then send 3 transactions - then cancel - i want to report the price for the 3 transactions for the final invoice

#

today when the billing period is finished, the invoice.created is fired, and I report the 3 transactions, but not working with cancel/update it seems

lean sonnet
#

but the quantites are still 0 so nothing to bill

#

Nowhere do you ever provide any data that would generate an Invoice

#

So there is nothing to Invoice a customer for

rustic hound
#

so here, if i want to create an invoice, I need to manually create it right ?

#

using API call create invoice, will fire the event I think

#

because 0 quantity is normal, I'm using this to not bill for subscriptions fees, only usage (reported on invoice.created event actually)

#

if I put quantity 1, will generate an invoice, but the customer will pay fees (in my case 0.25 and 0.03), and I don't want this
only usage * 0.03 or usage * 0.25 (computation in my backend)

lean sonnet
#

so here, if i want to create an invoice, I need to manually create it right ?
Not necessarily. Sorry your logic here makes absolutely no sense to me

#

You create a Subscription for a Customer but set thee quantity for two Subscription Items to 0.

#

Then you delete those items to replace them with two other Subscription Items, both with a quantity of 0.

#

What are you trying to bill your customer for?

rustic hound
#

Between the create and the update, the customer send 5 transactions.
The price for the 5 transactions will depend on the two subscriptions items unit price (which is 0.03 โ‚ฌ and 0.25 โ‚ฌ, will do computation based on this)
And before the update (= upgrade from one offer to another), I want to generate an invoice for the 5 transactions

lean sonnet
#

Okay but there is no record with that Subscription of any of this

rustic hound
#

The records are in my own DB, because the computation for the price is way too complex to use billing meters for this

#

So to report this to the invoice, I'm using webhook events (invoice.created when billing cycle end)

lean sonnet
#

Okay so we won't fire an Invoice created on these susbcriptions because there is nothing to bill a customer for

rustic hound
#

I see

lean sonnet
#

And then generate an Invoice for the Customer identified.

#

Same thing for the updated request. Use the customer.subscription.updated event

#

Then the logic of examining the Subscription object will work for both

rustic hound
#

I see
And is it better to use these 2 events, or to create an invoice before the cancellation / update, passing only the subscription and customer ID, to generate the invoice.created event?

lean sonnet
#

That would depend on how you want to model the scenario. Personally, it makes more sense to me to rely on the two customer.subscription.* events then generate an empty Invoice just to create the invoice.created event.

rustic hound
#

I will do this way, seems good!
Thanks for your help!

lean sonnet
#

Sure thing! Happy to shed what ๐Ÿ’ก I can ๐Ÿ™‚