# Billing clients automatically

**URL:** <https://www.ruby-forum.com/t/billing-clients-automatically/113128>\
**Category:** Rails\
**Created:** [August 27, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/billing-clients-automatically/113128 "2007-08-27T22:14:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [August 27, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/billing-clients-automatically/113128/1 "2007-08-27T22:14:25Z")

</div>

Hello,

I’m in the process of implementing invoce functionality to my Rails app.  
The  
service is monthly billed. I already have an [Authorize.NET](http://Authorize.NET) test account.

What I would like to do is bill the customers automatically after a  
certain  
interval has passed after the last payment, sending them the invoice to  
pay  
for it again and perform some action if the invoice has not been paid in  
time.

What would be the best way to do this? A rails controller running as a  
cron  
job?

Any help would be much appreciated!

Thanks in advance,

Marcelo.

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [August 27, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/billing-clients-automatically/113128/2 "2007-08-27T23:17:32Z")

</div>

Take a look at BackgroundRb. Its a great solution for off-line or  
background tasks.

[http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

On Aug 27, 2:13 pm, “Marcelo de Moraes S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [August 27, 2007, 11:20pm UTC](https://www.ruby-forum.com/t/billing-clients-automatically/113128/3 "2007-08-27T23:20:31Z")

</div>

Marcelo de Moraes S. wrote:

> What would be the best way to do this? A rails controller running as a  
> cron job?

The best way I’ve found is just to add an OfflineProcessController with  
the functionality I need. I use a before\_filter to validate only the IP  
address on which I’m running cron, so nobody else can access these  
methods.

I use a little shell script like this:

#!/bin/sh

WGET=/usr/bin/wget  
BASEURL=http://my\_site.com/offline\_process/  
LOGFILE=  
OPTS=’-q --no-check-certificate -O -’

if [! -f $LOGFILE]; then  
touch $LOGFILE  
fi

${WGET} ${OPTS} ${BASEURL}do\_something | cat \>\> $LOGFILE  
${WGET} ${OPTS} ${BASEURL}do\_something\_else | cat \>\> $LOGFILE

…and a crontab entry like…

1,31 \* \* \* \* /complete/path/to/script/for/offline\_process.sh

I’ve done this several different ways, and this is my favorite at the  
moment.

–Al Evans

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [August 27, 2007, 11:44pm UTC](https://www.ruby-forum.com/t/billing-clients-automatically/113128/4 "2007-08-27T23:44:35Z")

</div>

just to correct some spelling errors:

- worked better, not best
- approach, not appreach 😛

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [September 10, 2007, 8:53am UTC](https://www.ruby-forum.com/t/billing-clients-automatically/113128/5 "2007-09-10T08:53:07Z")

</div>

You can get ARB from [Authorize.net](http://Authorize.net) ($10/mo) and let them charge the  
customer each period instead of sending them a bill. Does the amount  
change each month? Then you can use Billing Orchard and load invoices  
via a simple API. It stores the credit card and bills [a.net](http://a.net) each  
month or it can send an invoice via email to your customer. BO has an  
interface for your customer, too.

- [Online Invoicing and Electronic Billing Software | Time Tracking Billing Software | BillingOrchard](http://www.billingorchard.com/default.cfm?pid=a2de1a17)

Fred

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [August 27, 2007, 11:43pm UTC](https://www.ruby-forum.com/t/billing-clients-automatically/113128/6 "2007-08-27T23:43:34Z")

</div>

rbaldwin, Al Evans - Thank you very much for the help, I really  
appreaciate  
it!

@Al Evans: You appreach seems simple and flexible, I’ll definetly try it  
out, thanks for the tip!  
@rbaldwin: BackgroundRb also seems to be great, as simple as Al Evans  
approach… I’ll try it too.

Once I get everything set up and working, I’ll let you know which one  
worked  
best for me.

Thanks!

Marcelo.

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [September 10, 2007, 12:47pm UTC](https://www.ruby-forum.com/t/billing-clients-automatically/113128/7 "2007-09-10T12:47:17Z")

</div>

> I use a little shell script like this:

If you prefer to write ruby instead of a shell script, you could also  
write a custom rake task ( [#66 Custom Rake Tasks - RailsCasts](http://railscasts.com/episodes/66) ), and call  
that using cron.

Regards,

Chris
