Best monthly billing template

I wrote code for my new billing system. The goal is to bill the customer on the same day every month. (not the first or last day of the month)

static bool NeedToBill(DateTime planLastBilled, DateTime cycleDate) { // is today the same date as the cycleDate AND is was the planLastBilled not the same day as today? if (DateTime.UtcNow.Day.Equals(cycleDate.Day) && !DateTime.UtcNow.Day.Equals(planLastBilled)) return true; else return false; } 

2 traps:

  • If its cycleDate.Day is 31 and the current month is 29 days
  • cycleDate - February 29, 2012 - it will only receive leap years.

Is there a general practice here?

so it seems that there is something to check

  • Has this invoice been billed this month?
  • is there a cycle day in the current month
  • is the day of the cycle that is greater than or equal to the current date (this is ideal if the transaction failed the day before)

Thanks!

+6
c # datetime billing
source share
4 answers

Well, I think I was completely over thinking about it. It is simple and covers everything:

 bool NeedToBill = ((DateTime.UTCNow – LastBillDate) >= 30 Days) 

On the same day he will not necessarily be billed, however he is close enough. It also adds flexibility if the transaction was rejected within a day or if the scheduled task was not completed within 1 day, the next time it is launched, it will raise it.

0
source share

Allow only billing day between 1 - 28 . In my experience, this is how most credit card / credit companies deal with this when given a choice.

+6
source share

What does it mean the same day every month?

If I am a customer, I want him to be on the 16th every month. No problems. If I want to be billed on the 31st every month, the obvious problem is not all the months that are 31 months, as you indicated in your question.

Why not check the current month for the number of days. If it has less than 31 days, make the last day of the month the invoice date.

Are there any other problems?

+2
source share

I would say that he made a choice between 1-28 or a day, but charged a fee on the last day of the month if the current month has fewer days than the selected day of the month.

0
source share

All Articles