FreshBooks and Mikrotik Automatic Non-Payment Script

by Jim Bouse 9. October 2012 11:12

I have a WISP that has more customers that I would like to keep up with.  Most of the time is spent chasing down late payments.

I wrote the following combination of files to handle automating handling of Non-Payment customers.


  • Web server on a public IP address.
  • Domain Name.
  • FreshBooks account.
  • Simple Queue with a name EXACTLY matching the Last Name, First Name of the customer from FreshBooks.
  • Mikrotik Router with API access enabled.


  • In the Readme.txt



Zip File (v1.0)

From the Readme.txt:

Mikrotik Freshbooks Intergration Script v1.0

Jim Bouse
October 9, 2012

License: None... Feel free to use, modify, butcher, whatever, this code. I ask that if you add features, you send me a copy.

Plug: I own and operate an WISP that uses Ubiquiti and Mikrotik equipment. I also do consulting work and onsite assistance.


I needed to automatically block customers with overdue invoices. This is what I came up with.


config.php <-- all PHP variables set here
create_callback.php <-- creates callbacks on FreshBooks.com
email.php <-- queries FreshBooks for customers matching names in Simple Queues
index.php <-- responds to callback requests from FreshBooks.com
AND is the page the customer is redirected to on non-payment.
Readme.txt <-- This file.
routeros_api.class.php <-- API class downloaded from http://wiki.mikrotik.com/wiki/API_PHP_class


1. Setup a sub-domain for your files to reside on. (http://payments.example.com)
Place all files from zip there.

2. (OPTIONAL) Enable port 800 on web server.
This is needed if you don't have a dedicated IP for your payment server.
Also edit the PaymentServerPort to match in the Mikrotik Script at the bottom.

3. Setup the web server to redirect all 404 errors to index.php

4. Verify that the webserver can write to the directory of these files.
This is used for logging.

5. Modify config.php to match your environment.

6. Add the "Late Payment Fees" add-on in FreshBooks

7. Modify the default behavior of the late payment email to send a notice on day 20
and another notice on day 30. (FreshBooks ->Settings -> Emails)

8. Use create_callback.php to create the following Invoice "Past Due 2" and "Payment Create"

9. Run The script at the bottom on each of your Mikrotiks

Currently, the index.php script only responds to:


You can use the existing code as an example to create more.
Reminder: If you add new features, please send me the code so I can update the files for others.


Mikrotik Script:

:global PaymentServerIP "XXX.XXX.XXX.XXX"
:global PaymentServerPort "80"

/ip firewall nat add action=dst-nat chain=dstnat comment="Redirect Non-Payment HTTP"\
port=80 protocol=tcp src-address-list=NonPayment to-addresses=$PaymentServerIP\
/ip firewall filter add chain=forward comment="Allow Non-Payment HTTPS to FreshBooks"\
dst-port=443 protocol=tcp src-address-list=NonPayment
/ip firewall filter add chain=forward comment="Allow Non-Payment HTTP to Payment Server"\
dst-address=$PaymentServerIP port=800 protocol=tcp src-address-list=NonPayment
/ip firewall filter add chain=forward comment="Allow DNS" port=53 protocol=udp
/ip firewall filter add chain=forward comment="Allow DNS" port=53 protocol=tcp
/ip firewall filter add action=drop chain=forward comment="Drop Non-Payment tcp traffic"\
protocol=tcp src-address-list=NonPayment
/ip firewall filter add action=drop chain=forward comment="Drop Non-Payment udp traffic"\
protocol=udp src-address-list=NonPayment
:put "Done"

FreshBooks-And-Mikrotik-Automatic-Non-Payment-Scripts-v1.0.zip (26.49 kb)

Tags: , , ,

FreshBooks | Mikrotik | WISP

Powered by BlogEngine.NET
Original Design by Laptop Geek, Adapted by onesoft