How to test webhooks locally during the development phase?

During development, I want to test the ChargeBee webhooks. How do I setup the webhook, to call my development machine, even though I do not have a public IP or URL?


Are there any tools that can help me test webhooks locally?


2 people like this idea

Webhooks can also be tested locally using ngrok


1) Download ngrok.


2) Start ngrok with your local server port number which you would like to test.

    Ex : ./ngrok 8000   (In Linux)


3) A URL will be generated. Update this URL as your webhook URL in ChargeBee under Settings -> API & Webhooks > Webhook Settings.


Now your local server can receive the webhook sent from ChargeBee.


5 people like this
Assuming I configured webhook URL how can I trigger event pending_invoice_created to be fired on my URL?


By a way, page https://www.chargebee.com/docs/metered_billing.html says an "invoice_created" event will be fired. I gues it's typo, should be pending_invoice_created

Hey Pirozhkov,


The "invoice_created" event {in API V1} has been updated to "pending_invoice_created" event in our API V2 release. Both have the same functionality, and if you'd like to trigger a Webhook, you would need to enable "Notify and wait to close invoices" option from under Site Settings and try creating a subscription. The invoice {on renewal} would be generated in a pending state and corresponding Webhook would get triggered to hit your URL server.


Also, thanks for bringing the text error to our notice, and I've forwarded it to our documentation team to implement the change :)


Please let us know if you need any clarification.


1 person likes this

 Thanks,


>you would need to enable "Notify and wait to close invoices" option from under Site Settings

I've already done this.


>try creating a subscription. The invoice would be generated in a pending state and corresponding Webhook would get triggered to hit your URL server.


Well, I created V2 Webhook URL and tried out, but I got following event sequence for:


[Sat Jun  4 13:54:29 2016] invoice_generated
[Sat Jun  4 13:54:29 2016] subscription_created


or

[Sat Jun  4 13:51:21 2016] subscription_created
[Sat Jun  4 13:52:06 2016] invoice_generated
[Sat Jun  4 13:52:06 2016] subscription_started


depending on activation date (immediately or one minute in future ).


May be event pending invoice will be fired on next billing day (next month), but it's not option for development ))

Hey Pirozhkov,


Yes that's right.


When the subscription is created, an invoice_generated event is triggered immediately, and the pending_invoice_created event gets triggered only during subscription's renewal. So, if you'd like to test this webhook event, you could change the next billing date {to present time} using "Change Next Billing" option present on the right side panel of the particular subscription's page. The invoice would get generated in a 'pending' state and the webhook event is triggered immediately.


Here's a screenshot for your reference:




1 person likes this
Thanks, I'll try!

Another question:

docs say "If we don't receive 200 response code, we retry calling your webhook with exponential time interval for next 2 days"

So what happens to invoice is webhook is still unavailable/returns error/doesn't close invoice?


 

Hey Pirozhkov,


Thanks for your response.


So you mean to say, you are attempting to close a pending invoice and the subsequent webhook fails, what would happen if the same event is fired using the webhook in the next attempt?


In this case, as the event is associated with the webhook will be the same, when you try to close the invoice from the webhook call, you could retrieve the invoice from the invoice id that is present in the event, and use retrieve invoice API call and check for the correct invoice state.


Please let us know if you need any clarification.


No, may question is what happens is there is no reply from Webhook at all (assume web-server is down for more than two days).  What happens to invoice? Does it remain in pending state forever or will be closed automatically after two days?

 

I mean pending_invoice_created event. On this event invoice in pending state and webhook should call close_invoice. And what it doesn't do it?

 

Hey Pirozhkov,


In that case, automatic closure of invoice will not happen and it would still be in a pending state unless there is an initialization from your end {to close the invoice}.


1 person likes this
By a way, Webhook settings page says "we will retry calling your webhook with exponential time intervals over the next 3 days.", while docs say two days.

Which is right?

 

Hey Pirozhkov,


In the web interface, it is mentioned - "Chargebee expects a 2xx HTTP response to the POST, otherwise the event notification will be retried. If we do not receive a 2xx response code, we will retry calling your webhook with exponential time intervals over the next 3 days."


So, this 3 days duration is split up in two - {1+2}, where the attempt is made on the first day and next attempt is made after 2 days from that point of time.


Here's a screenshot for your reference:



Hi,

I created a webhook of 'subscription_changed' but it automatically turns into subscription_created.

Why is this happening everytime. Need help regarding this.

Thanks!!

Hi Anamica


While we support configuring multiple webhooks, this is done so that you could configure webhooks for different platforms or applications. All the events would be triggered for each of the webhooks configured.


When you receive the webhooks, you could filter them at your end based on the event, and trigger necessary actions. You can read more about webhooks here


The subscription_changed option you selected below on the Webhook configuration window is only for testing the webhooks and it won't work as a filter when your webhooks are actually triggered. You can use the drop-down option to select a different event and test them with your configured webhook URL to understand how each event is received at your end. 


Here's an example of how event listening can be handled on your end. Let me know if that helps and if you have more questions.

Login or Signup to post a comment
×