So I ran into an interesting problem trying to write a script that renews subscriptions.
I'm writing a site wherein users can pay monthly to gain access to certain features. I was trying to scheme up the cron job that would renew these subscriptions and, using Authorize.net's CIM profiles, would automagically bill any accounts that have not paid in a month.
My first impulse was to query for accounts whose last payment was over a month ago:
SELECT * FROM accounts WHERE last_payment_date <= DATE_SUB(NOW(), INTERVAL 1 MONTH);
The problem with this code is for accounts last paid on January 30 or 31. When we get to February 29th, everything's fine, but then Mar 1 rolls around and we'll have a few days worth of subscriptions to renew.
I guess technically speaking that Mar 1 is "over a month" past Jan 30/31, but just thought it was interesting. Over time this would have the effect of moving all subscription renewal dates off the 29, 30, or 31 of a given month into the first of the month.
Any thoughts about a cron job to automatically charge for subscription renewal are much appreciated.