Difference between revisions of "Billing Logic"

From WHMCS Documentation

Line 36: Line 36:
 
* The InvoicePaid Action Hook point is triggered
 
* The InvoicePaid Action Hook point is triggered
  
 +
===Billing Cycles===
 +
A billing cycle is considered a calendar period, so "1 month" is not a consistent period of days. When you agree to bill by the month, you are charging the same amount of money for different amounts of service. WHMCS uses the php date function's computation to figure out the next due date. We tell it to add a month and return the date, which we set as the Next Due Date.
  
===February===
+
====February====
A billing cycle is considered a calendar period, so "1 month" is not a consistent period of days. When you agree to bill by the month, you are charging the same amount of money for different amounts of service. We use the php date function's computation to figure out the next renewal date. We tell it to add a month and return the date, which we set as the Next Due Date. Due to the shorter length of Febuary this can cause some unquie behaviour which does not happen for the other 11 months of a year:
+
Due to the shorter length of February this can cause some unique behaviour which does not happen for the other 11 months of a year:
  
 
<table class="table table-striped">
 
<table class="table table-striped">
 
<tr>
 
<tr>
<td>'''Field Title'''</td>
+
<td>'''Order Date'''</td>
<td>'''Another Field'''</td>
+
<td>'''Renewal Date'''</td>
 +
<td>'''Number of Days'''</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td>Row 1</td>
+
<td>January 29</td>
<td>Some value</td>
+
<td>March 1</td>
 +
<td>31 days</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td>Row 2</td>
+
<td>January 30 </td>
<td>Another value</td>
+
<td>March 2</td>
 +
<td>31 days</td>
 +
</tr>
 +
<tr>
 +
<td>January 31</td>
 +
<td>March 3</td>
 +
<td>31 days</td>
 +
</tr>
 +
<tr>
 +
<td>February 1</td>
 +
<td>March 1</td>
 +
<td>28 days</td>
 +
</tr>
 +
<tr>
 +
<td>February 2</td>
 +
<td>March 2</td>
 +
<td>28 days</td>
 +
</tr>
 +
<tr>
 +
<td>February 3</td>
 +
<td>March 3</td>
 +
<td>28 days</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
* Order placed on February 1, renewal date will be March 1 = 28 days
 
* Order placed on February 2, renewal date will be March 2 = 28 days
 
In WHMCS when an order is placed on February 3, renewal date will be set at March 3, so 28 days
 
In WHMCS when an order is placed on February 4, renewal date will be set at March 4, so 28 days
 
In WHMCS when an order is placed on February 5, renewal date will be set at March 5, so 28 days
 
In WHMCS when an order is placed on February 6, renewal date will be set at March 6, so 28 days
 
....etc
 
========== BUT ==========
 
When an order is made on January 29 the renewal date will be March 1 , so 31 days
 
When an order is made on January 30 the renewal date will be March 2nd , so 31 days
 
When an order is made on January 31 the renewal date will be March 3rd , so 31 days
 
  
  

Revision as of 17:45, 26 April 2017

This document explains the billing and invoicing logic used in the WHMCS software. Having an understanding of these core elements of the software will

Ordering

When a new visitor places an order a number of new records are created which contain the various pieces of information captured on the order form: 1. A client record is created to store the customer's contact details and payment preferences. 2. The service and domain record(s) are then created which contain the details of the service the client selected on the order form. 3. Next an invoice record is created which records the amount to be paid, when it is due to be paid and how payment should be made. 4. Finally, an order record is created which ties all of the above together and records the fraud report details (if enabled). The order is a static record which reflects the prices and items at the time of ordering, subsequent changes will not be reflected on the order.

Invoicing

When an invoice is created by an initial order, the default behaviour is that the invoice is due on the day of ordering. The exception being if the Order Grace Days setting is used, in which case the invoice due date will be set x days to the future.

Upon payment of the initial invoice, the automation is triggered which executes the module Create function and the service's Next Due Date value is incremented forward one billing cycle (ie. 1 month, 3 months, 6 months, 1 year, 2 years or 3 years).

The date at which the next payment is due is controlled by the Next Due Date of the service. When the cron executes the daily automation tasks the following actions are performed:

  • The Next Due Date of all Active, Pending and Suspended services are analysed
  • Determine if the date is equal to or less than the number of days in the future specified by the Invoice Generation setting
  • Ensure no invoice item exists for the service on the next due date
  • If the above points are evaluated to be true, then a new invoice is generated.
  • The InvoiceCreation Action Hook point is triggered
  • The InvoiceCreationPreEmail Action Hook point is triggered
  • The Invoice Created email is sent to the client
  • The InvoiceCreated Action Hook point is triggered
  • The Next Invoice Date of the service is incremented forward by one billing cycle.

In this way, WHMCS will never generate two invoices for a given product, service or domain with the same due date - even if the original invoice has been deleted.

Payments

Automation upon payment is triggered by a transaction applied to an invoice which fully pays the balance, reducing it to 0.00 and marking an invoice paid. This means that editing an invoice and changing the status to Paid will not trigger automation. Upon adding payment to an invoice which is associated with a product/service or domain, the following actions occur:

  • A transaction is entered into the database
  • The transaction amount is subtracted from the invoice balance
  • If the invoice balance is now 0, the invoice is marked as paid.
  • The invoice status is changed to Paid
  • The InvoicePaidPreEmail Action Hook point is triggered
  • A payment confirmation email is sent to the client
  • The Next Due Date of the associated service/domain is incremented forward by one billing cycle.
  • The InvoicePaid Action Hook point is triggered

Billing Cycles

A billing cycle is considered a calendar period, so "1 month" is not a consistent period of days. When you agree to bill by the month, you are charging the same amount of money for different amounts of service. WHMCS uses the php date function's computation to figure out the next due date. We tell it to add a month and return the date, which we set as the Next Due Date.

February

Due to the shorter length of February this can cause some unique behaviour which does not happen for the other 11 months of a year:

Order Date Renewal Date Number of Days
January 29 March 1 31 days
January 30 March 2 31 days
January 31 March 3 31 days
February 1 March 1 28 days
February 2 March 2 28 days
February 3 March 3 28 days


Suspension/Termination

Unsuspension

When used with continuous invoice generation, paying a recent invoice whilst leaving an older invoice will keep the service suspended. Unless the payment were to increment the Next Due Date forward to a date at which the service was no longer within the Suspension date range.