Some of our customers have auto-direct debit with us, this means we collect all invoices automatically via direct debit, when the invoice is created via a recurring profile quickfile does it automatically and we do not have any issue with this, but when we create single invoices we had to remember which customers were on auto-collection or not.
So we created an app that connected to the API and checked all client invoices and send a request if we were meant to do it.
This caused issues because of the number of API calls we were doing so we changed our approach to use Webhooks instead and that’s were we found some issues.
As there is no webhook for “InvoiceStatusChanged”, we do this when the invoice is created, but the direct debit request is sent when the invoice is still a draft, and if we are building an invoice and saving it (e.g. Create an invoice, add item 1 save, add item 2 save), it do the direct debit collection with the value of the item 1.
If we copy an invoice from a customer that is meant to be used for a different client, the direct debit collection is done for the client where the invoice was copied from.
Do you currently have a workaround this or can we have a new hook done for “InvoiceStatusChanged”?
I just want to clarify the query here if that’s OK?
Is it the case that you’re triggering the direct debit request on an InvoiceCreated webhook? But because of this, the direct debit is being requested for the original client (rather than the one that it’s changed to), and only for partial lines rather than the complete invoice, because of the timing?
We use the trigger “InvoiceCreated” to fire a direct debit collection if the client has requested auto-collection.
On normal situations we create a new invoice from scratch and when we save it, it requests which is okay.
If we save the invoice as draft so we can add more stuff, it creates the request straight away when we save it as draft, and then when we amend the invoice it doesn’t trigger again, because the invoice was already created. (that was obvious but we haven’t thought about it).
If we do copy an invoice from a different client, it creates the request of this client, not to the one we changed it to.
I think the only solution is to have a trigger when “InvoiceStatusChanged” like we have for the estimates, this will allow us to only trigger this when the invoice status is changed to sent.
Appreciate it’s not ideal, but perhaps checking the invoice details when you receive an invoice created or invoice updated webhook would be the best way to handle this for you.
For example:
Receive an InvoiceCreated or InvoiceUpdated webhook
Grab the Id from the payload
Use the Invoice_Get endpoint to get the invoice details
Check the “STATUS” field, and only act if the status is set to “SENT”
Or, add a delay to trigger the direct debit collection (e.g. set up a scheduled task/cron job)
That’s similar to what we had before and we been contacted by Glen because of the amount of API requests we were doing.
When an invoice is created (even as a draft) it will trigger an InvoiceCreated, if I grab the ID here, I will need to be querying the invoice every now and again increasing the amount of requests I do.
If I do it on InvoiceUpdated, this update can be a description update, and I will be querying the API again for no reason on this cases.
Hence why I think the best solution would be a similar webhook to “EstimatesStatusChange”, this would allow us not only to only act when invoice status is changed to “Sent” but also to act on different status providing more functionality and flexibility.
I can also delay the direct debit collection request, but it will be a margin for error, as sometimes draft invoices are created and they stay as draft for days.