Billable Event Hook

Nico Baumgarten's Avatar

Nico Baumgarten

31 Mar, 2016 10:28 AM

I need to add some charges prior to an invoice being issued. The idea is to use a hook to get notified when an invoice is about to be issued. During the hook handling I would add the required charges and then issue the run-outstanding api call to complete the invoice.

The question is, how can I debug this? I am setting the next-invoice date to "now" and a new invoice is issued immediately - since it is essentially empty (amount=0) it is immediately put into the paid state, the hook is never executed and I have no chance to try running my code.
I do get a "transaction" hook, however. So how can I dry run my code, I don't really want to wait a month until the regular cycle is up?

Also the documentation is a bit unclear:
There is a add-custom-charge API call. What happens if I call this twice for the same charge? does it get overwritten? do I need run delete a charge first in this case - the scenario is probably unlikely but a hook might get called twice, or one of the add-charges calls may fail (if I have multiple charges) and then on the next attempt, I'd have a duplicate.

Thanks in advance

  1. 1 Posted by Drew Songer on 01 Apr, 2016 03:48 PM

    Drew Songer's Avatar

    Hi Nico,

    The billable hook doesn't fire when you set a pending invoice billdate to "now". Testing can be accomplished by setting the bill date of the pending invoice to 1 second from now, then wait for the next recurring run. This could take up to 3 hours under normal circumstances, which is much better than a month.

    Because there is potential for retries, you will want to be sure that any logic performed in your hook listener is idempotent. This is alluded to in our webhooks article here: http://support.cheddargetter.com/kb/api-8/web-hooks-service-hooks-a...

    Best,
    Drew

  2. Drew Songer closed this discussion on 05 Apr, 2016 01:38 PM.

Discussions are closed to public comments.
If you need help with Cheddar please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac