sensson / whmcs-moneybird

Integrates WHMCS into Moneybird 🐦
Apache License 2.0
7 stars 5 forks source link

Not getting invoices in Moneybird anymore #24

Closed ELAXXL closed 2 years ago

ELAXXL commented 2 years ago

Good morning,

We have added several clients/services to WHMCS about a week ago, the first couple of days all went as it should: domains we're synched, invoices we're created and invoices we're added (in)to moneybird. But for some reason this has stopped, the 5 invoices on jan 15th we're all added but in jan 16th one out of 2 and that was the last, no invoices from jan 18th or 19th we're added.

We have made no changes to WHMCS and/or the cronjob or whatsoever, any change you can help us out?

Thank you in advance! :)

ju5t commented 2 years ago

What is the output of the cronjob if you run it manually? Does it give an error? I assume you're on the paid package of Moneybird and not on their free tier?

ELAXXL commented 2 years ago

Hi there,

The output says "0 invoice(s) processed.

But yet we can see all invoices in WHMCS and customers receive them and are able to pay them.

And yes a paid Moneybird package.

Thanx again.

ju5t commented 2 years ago

Go to the add-on settings in WHMCS, what does it say for First invoice number? The settings can be found in the admin area of WHMCS under add-on modules. It's where you configured the access token and administration ID.

If this number is higher than zero, is it lower than your last invoice number? If not, change it to the number of the last invoice that was synced. This should ensure it's picked up by the cron.

There is a log table in the database too. It's named mod_moneybird_log. There might be something in there too.

About the error Does not exist in WHMCS, this happens if the invoice reference in Moneybird isn't a valid invoice number in WHMCS. Are you sending invoices directly from Moneybird too?

ELAXXL commented 2 years ago

The number was the number 1, which is lower then the last invoice number (last synched invoice number was 53). We changed it to the last one that was synched but still get the same error.

We dont see the logs (sorry just the general WHMCS logs, might be looking at the wrong place?)

And yes we are sending invoices directly from Moneybird as well but that was not an issues for the past 2,5 months (since we start using this). Is this something that should be changed?

ju5t commented 2 years ago

Sending invoices directly isn't a big deal. It just means it may throw an occasional error when syncing payments but that should be fine I think. Code-wise I don't see any issues. The error you're seeing is unrelated to syncing invoices and can't be solved unless you go for WHMCS only invoicing.

If you open up phpMyAdmin or any other database editor you should look into the table mod_moneybird_log. I expect some errors there. That might explain why some invoices can't be synced. It might be Moneybird doesn't accept some data but that would show in that table.

ELAXXL commented 2 years ago

Hi there! The table gives one error indeed:

Error 422: {"error":{"customer_id":["is already in use"]}}

How can this be solved?

Thanx again.

ELAXXL commented 2 years ago

Schermopname (964) To clearify (dont know if it will help you): All errors are within 2 hours on december 29th, it worked until january 15th.

ju5t commented 2 years ago

There are no errors after the 29th of December? Not on a different page in phpMyAdmin either?

If there aren't, I think this will be really difficult to solve unless you can try and debug this yourself within your own application. I would start by echo'ing out some variables with either print_r or var_dump in the cron file to see what output this gives you and see if it helps.

I would start at line 57 and 59. For example on line 57:

print_r($invoice);
die();

And run the cron.

If this returns an invoice we know the query works and it has selected invoices. The next step would be on line 59:

print($moneybird_invoice);
die();

And run the cron again. If you see output here, it means it should have synced the invoice. If it doesn't work, it should throw an exception and it that case the error should appear in the logging table.

ELAXXL commented 2 years ago

Sorry we made a mistake when checking the tables, it does give errors after 29th of december, all the same as the one mentioned earlier. We will try and debug and keep you posted.

In general how can the mentioned error be fixed? Are the mentioned ID's in WHMCS or Moneybird or do they need to have the same number (so removing all contacts in Moneybird might fix it?)

ju5t commented 2 years ago

I don't know how you can fix this. This is an edge case. Removing contacts in Moneybird is a bad idea. Don't do that.

I think the error originates from https://github.com/sensson/whmcs-moneybird/blob/f2397c08bd714909cee7e1af89dba0b72603af8c/lib/Models/Client.php#L99

If you add the following on line 95 (so inside the if ($error == 404) block:

print_r($link);
die();

This should give you some output. This should help you identify the customer. If you can share some of this (please make sure you're not sharing any private information) that might help, but to be honest I am not sure why this is happening at all.

Something is wrong but I don't know what.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We get that this might not be what you had expected but we're trying to limit stale as issues as much as possible. Thank you for your contributions.