Difference between revisions of "Billing Logic"

From WHMCS Documentation

Line 1: Line 1:
This document explains the billing and invoicing logic used in the WHMCS software. Having an understanding of these core elements of the software will enable years of smooth and trouble-free operation.
+
Having an understanding of WHMCS's billing and invoicing logic, core elements of the software, will enable years of smooth and trouble-free operation.
  
 
==Ordering==
 
==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:
+
When a new visitor places an order, the system creates several new records, which contain the various pieces of information on the order form:
* A client record is created to store the customer's contact details and payment preferences.
+
* A client record, which stores the customer's contact details and payment preferences.
* The service and domain record(s) are then created which contain the details of the service the client selected on the order form.
+
* The service and domain record(s), which contain the details of the service the client selected on the order form.
* 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.
+
* An invoice record, which records the amount to pay, when it is due, and how to make payment.
* 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.
+
* An order record, which ties all of the above together and records the fraud report details (if you enable them). The order is a static record which reflects the prices and items at the time of ordering. The order won't reflect subsequent changes.
  
 
==Invoicing==
 
==Invoicing==
 
===Initial Invoice===
 
===Initial Invoice===
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 [[Ordering_Tab#Order_Days_Grace|Order Grace Days setting]] is used, in which case the invoice due date will be set x days to the future.
+
When an initial order creates an invoice, the default behavior is that the invoice is due on the day of ordering. The exception to this is when you use the [[Ordering_Tab#Order_Days_Grace|Order Grace Days setting]], in which case the system will set the invoice due date <tt>x</tt> days into the future.
  
Upon payment of the initial invoice, the system checks the associated products to determine if any automation should be taken based upon the [[Module_Settings_.28aka_Provisioning.29|Module Settings]]. This could be one of the following actions:
+
Upon payment of the initial invoice, the system checks the associated products to determine whether to take action automatically, based upon the [[Module_Settings_.28aka_Provisioning.29|Module Settings]]. This could be one of the following actions:
* Automatically setup the product as soon as an order is placed
+
* Automatically set up the product as soon as a client places an order.
* Automatically setup the product as soon as the first payment is received
+
* Automatically set up the product as soon as you receive the first payment.
* Automatically setup the product when you manually accept a pending order  
+
* Automatically set up the product when you manually accept a pending order.
* Do not automatically setup this product
+
* Do not automatically set up this product.
The service's Next Due Date value is then incremented forward one billing cycle (ie. 1 month, 3 months, 6 months, 1 year, 2 years or 3 years).
+
The system then increments the service's Next Due Date value forward one billing cycle (for example, 1 month, 3 months, 6 months, 1 year, 2 years, or 3 years).
  
 
===Renewal Invoices===
 
===Renewal Invoices===
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 the service depends on the date at which the next payment is due. When the cron job executes the daily automation tasks, the system:
* 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 [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreation InvoiceCreation] Action Hook point is triggered
 
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreationpreemail InvoiceCreationPreEmail] Action Hook point is triggered
 
* The Invoice Created email is sent to the client
 
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreated 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 cancelled or deleted.
 
  
As the Next Due Date is incremented forward based upon the previous value, this means paying an invoice after the due date will not change the client's renewal date to reflect the date of payment. A service is always invoices for a contiguous period without gaps, this avoids a situation whereby a customer might hope to avoid paying for a service by intentionally paying late.
+
* Analyzes the Next Due Date of all Active, Pending and Suspended services.
 +
* Determines whether the date is equal to or less than the number of days in the future, based on the Invoice Generation setting.
 +
* Ensures no invoice item exists for the service on the next due date.
 +
* Generates a new invoice if the system evaluates the above points as true.
 +
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreation InvoiceCreation] Action Hook point.
 +
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreationpreemail InvoiceCreationPreEmail] Action Hook point.
 +
* Sends the Invoice Created email to the client.
 +
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreated InvoiceCreated] Action Hook point.
 +
* Increments the Next Invoice Date of the service 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 you have cancelled or deleted the original invoice.
 +
 
 +
As the Next Due Date is incremented forward based upon the previous value, this means paying an invoice after the due date will not change the client's renewal date to reflect the date of payment. A service always invoices for a contiguous period without gaps. This prevents a situation in which a customer might hope to avoid paying for a service by intentionally paying late.
  
 
===Continuous Invoice Generation===
 
===Continuous Invoice Generation===
When the [[Invoicing_Setup#Continuous_Invoice_Generation|Continuous Invoice Generation]] option is enabled in the general settings, the invoice generation logic is altered so that renewal invoices are created even if the previous one is unpaid.
+
When you enable the [[Invoicing_Setup#Continuous_Invoice_Generation|Continuous Invoice Generation]] option in the general settings, it alters the invoice generation logic so that the system creates renewal invoices even if the previous one is unpaid.
  
This is facilitated by a checking a hidden field in the service record called Next Invoice Date. The Next Invoice Date field maintains a separate record of the due date for next invoice to be generated. The Next Due Date value determines the next invoice to be paid.
+
Checking a hidden field in the service record, Next Invoice Date, enables this. The Next Invoice Date field maintains a separate record of the due date for next invoice to generate. The Next Due Date value determines the next invoice to be paid.
  
In this mode, when the cron executes the daily automation tasks the following actions are performed:
+
In this mode, when the cron job executes the daily automation tasks, it:
* The Next Invoice Date of all Active, Pending and Suspended services are analysed
+
* Analyzes the Next Invoice Date of all Active, Pending and Suspended services.
* Determine if the date is equal to or less than the number of days in the future specified by the Invoice Generation setting
+
* Determines whether the date is equal to or less than the number of days in the future, based on the Invoice Generation setting.
* Ensure no invoice item exists for the service on the next invoice date
+
* Ensures no invoice item exists for the service on the next invoice date.
* If the above points are evaluated to be true, then a new invoice is generated.
+
* Generates a new invoice if the system evaluates the above points as true.
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreation InvoiceCreation] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreation InvoiceCreation] Action Hook point.
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreationpreemail InvoiceCreationPreEmail] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreationpreemail InvoiceCreationPreEmail] Action Hook point.
* The Invoice Created email is sent to the client
+
* Sends the Invoice Created email to the client.
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreated InvoiceCreated] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreated InvoiceCreated] Action Hook point.
* The Next Invoice Date of the service is incremented forward by one billing cycle.
+
* Increments the Next Invoice Date of the service by one billing cycle.
  
In this way, WHMCS maintains a separate record of which invoice should be generated and which payment is due.
+
In this way, WHMCS maintains a separate record of which invoice to generate and which payment is due.
  
 
==Payments==
 
==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 that fully pays the balance on an invoice, reducing it to <tt>0.00</tt> and marking it paid, triggers automation on payment. This means that editing an invoice and changing the status to Paid will ''not'' trigger automation. Upon adding payment to an invoice for a product, service, or domain, the system:
* A transaction is entered into the database
+
* Enters a transaction into the database.
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#addtransaction AddTransaction] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#addtransaction AddTransaction] Action Hook point.
* The transaction amount is subtracted from the invoice balance
+
* Subtracts the transaction amount from the invoice balance.
* If the invoice balance is now 0, the invoice is marked as paid.
+
* Marks the invoice as paid if the invoice balance is now 0.
* The invoice status is changed to Paid
+
* Changes the invoice status to Paid.
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaidpreemail InvoicePaidPreEmail] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaidpreemail InvoicePaidPreEmail] Action Hook point.
* A payment confirmation email is sent to the client
+
* Sends a payment confirmation email to the client.
* The Next Due Date of the associated service/domain is incremented forward by one billing cycle.
+
* Increments the Next Due Date of the associated service or domain by one billing cycle.
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaid InvoicePaid] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaid InvoicePaid] Action Hook point.
  
 
===Overpayments===
 
===Overpayments===
If a transaction is applied with an amount greater than the balance of the invoice, the following actions are taken:
+
If a transaction includes an amount greater than the balance of the invoice, the system:
* The entire transaction is recorded against the invoice, thus making the balance negative
+
* Records the entire transaction against the invoice, making the balance negative.
* The invoice is marked paid
+
* Marks the invoice as paid.
* The difference between the balance and the transaction amount is credited to the client's account
+
* Credits the difference between the balance and the transaction amount to the client's account.
* The credit description will take the format ''Invoice # Overpayment''
+
* Changes the credit description format to ''Invoice # Overpayment''.
  
Sometimes, fixed payments services (such as PayPal Subscriptions and 2Checkout Recurring Payments) can send a payment when no payment is due. In these situations, the following actions occur:
+
Sometimes, fixed payments services (such as PayPal Subscriptions and 2Checkout Recurring Payments) can send a payment when no payment is due. In these situations, the system:
  
* The entire transaction is recorded against the invoice which originally created the billing agreement, thus making the balance negative
+
* Records the entire transaction against the invoice that originally created the billing agreement, making the balance negative.
* The full transaction amount is credited to the client's account
+
* Credits the full transaction amount to the client's account.
* The credit description will take the format ''Invoice # Overpayment''
+
* Changes the credit description format to ''Invoice # Overpayment''.
  
 
===Refunds===
 
===Refunds===
Transactions applied to invoices can be refunded via the Refunds tab. When a refund is initiated the following actions occur:
+
You can issue refunds on transactions for invoices via the Refunds tab. When a you initiate a refund, the system:
* The selected refund action is performed, either of the following:
+
* Performs the selected refund action, which could be either of the following actions:
** A refund command is sent to the payment gateway (if supported)
+
** It sends a refund command to the payment gateway (if it supports it).
** A credit is added to the client's account with the description ''Credit from Refund of Invoice ID #''
+
** It adds a credit to the client's account with the description ''Credit from Refund of Invoice ID #''.
* A negative transaction is recorded against the invoice
+
* Records a negative transaction against the invoice.
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#addtransaction AddTransaction Action Hook] point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#addtransaction AddTransaction Action Hook] point.
* The invoice's balance is increased by the refunded amount
+
* Increases the invoice's balance by the refunded amount.
* If the full balance is refunded, the invoice's status changes to Refunded
+
* Changes the invoice's status to Refunded if system refunded the full balance.
* The [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicerefunded InvoiceRefunded] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicerefunded InvoiceRefunded] Action Hook point.
* The Invoice Refund Confirmation email is sent to the client
+
* Sends the Invoice Refund Confirmation email to the client.
  
If the transaction being refunded resulted in a credit to the client's account, you will be required to choose how to handle the credit:
+
If the refunded transaction resulted in a credit to the client's account, you must choose how to handle the credit:
 
* Remove the refunded amount from the credit balance.
 
* Remove the refunded amount from the credit balance.
* Leave the credit untouched.
+
* Do not change the credit.
  
 
===Payment Reversals===
 
===Payment Reversals===
When issuing a [[#Refunds|refund]] there is also the option to reverse the payment. This is useful when you want to reverse the automated actions triggered by the payment, typically in the event of a payment dispute or chargeback.
+
When issuing a [[#Refunds|refund]], there is also the option to reverse the payment. This is useful when you want to reverse the automated actions that the payment triggered, typically in the event of a payment dispute or chargeback.
  
The actions which are taken when reversing a payment are context sensitive and depend upon your payment reversal settings. For an in-depth discussion of this feature, refer to the [[Payment Reversals]] page.
+
The actions that the system takes when reversing a payment are context sensitive and depend upon your payment reversal settings. For an in-depth discussion of this feature, refer to the [[Payment Reversals]] page.
  
 
===Billing Cycles===
 
===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.
+
A billing cycle is 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 determine the next due date. It adds a month and returns the date, which becomes the Next Due Date.
  
 
====February====
 
====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:
+
The shorter length of February can cause some unique behaviour that does not happen for the other 11 months of a year:
  
 
<table class="table table-striped">
 
<table class="table table-striped">
Line 141: Line 143:
 
</tr>
 
</tr>
 
</table>
 
</table>
 
  
 
==Suspension==
 
==Suspension==
The date at which services are suspended 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 for the service controls the date of service suspension. When the cron job executes the daily automation tasks, the system:
* The Next Due Date of all Active and Pending services are analysed
+
* Analyzes he Next Due Date of all Active and Pending services.
* Determine if the date is equal to or less than the number of days in the future specified by the Suspension Days setting
+
* Determines whether the date is equal to or less than the number of days in the future in the Suspension Days setting.
* Determine if Automated Suspension is enabled in [[Automation Settings]]
+
* Determines whether Automated Suspension is enabled in [[Automation Settings]].
* If this is evaluated to be true, the [https://developers.whmcs.com/hooks-reference/module/#premodulesuspend PreModuleSuspend] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#premodulesuspend PreModuleSuspend] Action Hook point if the above items evaluate to true.
* The services is suspended
+
* Suspends the services.
* If the module returns a success response, the [https://developers.whmcs.com/hooks-reference/module/#aftermodulesuspend AfterModuleSuspend] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermodulesuspend AfterModuleSuspend] Action Hook point if the module returns a success response.
* If the module returns a failed response, the [https://developers.whmcs.com/hooks-reference/module/#aftermodulesuspendfailed AfterModuleSuspendFailed] Action Hook point is triggered.
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermodulesuspendfailed AfterModuleSuspendFailed] Action Hook point If the module returns a failed response.
  
 
==Unsuspension==
 
==Unsuspension==
When payment is made against an invoice which is associated with a service in Suspended status the service can be automatically unsuspended. In addition to the actions listed in [[#Payments|Payments]], the following additional actions are performed:
+
When payment is made against an invoice for a service with the Suspended status, the system can automatically unsuspend the service. In addition to the actions in the [[#Payments|Payments]] section, the system:
  
* The invoice is associated with a service in Suspended status
+
* Associates the invoice with a service in Suspended status.
* The Enable Unsuspension option is enabled in [[Automation Settings]]
+
* Enables the Enable Unsuspension option in [[Automation Settings]].
* The service has a suspension reason of "Overdue on Payment"
+
* Applies a suspension reason of "Overdue on Payment" to the service.
* If the above points are evaluated to be true, the [https://developers.whmcs.com/hooks-reference/module/#premoduleunsuspend PreModuleUnsuspend] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#premoduleunsuspend PreModuleUnsuspend] Action Hook point if the points above evaluate to true.
* The service is unsuspended
+
* Unsuspends the service.
* If the module returns a success response, the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleunsuspend  AfterModuleUnsuspend] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleunsuspend  AfterModuleUnsuspend] Action Hook point if the module returns a success response.
* If the module returns a failed response, the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleunsuspendfailed AfterModuleUnsuspendFailed] Action Hook point is triggered.
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleunsuspendfailed AfterModuleUnsuspendFailed] Action Hook point if the module returns a failed response.
  
 
===Continuous Invoice Generation===
 
===Continuous Invoice Generation===
When used in conjunction with [[Invoicing_Setup#Continuous_Invoice_Generation|continuous invoice generation]], paying a recent invoice whilst leaving an older invoice unpaid will keep the service suspended. The exception being if 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 - in that case the service would be unsuspended.
+
When you use it in conjunction with [[Invoicing_Setup#Continuous_Invoice_Generation|continuous invoice generation]], paying a recent invoice while leaving an older invoice unpaid will keep the service suspended. The exception is if 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. In that case, the service would be unsuspended.
  
 
==Termination==
 
==Termination==
The date at which services are terminated 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 the service controls the date when the system terminates services. When the cron job executes the daily automation tasks, the system:
* The Next Due Date of all Active, Suspended and Pending services are analysed
+
* Analyzes the Next Due Date of all Active, Suspended and Pending services.
* Determine if the date is equal to or less than the number of days in the future specified by the Termination Days setting
+
* Determines whether the date is equal to or less than the number of days in the future for the Termination Days setting.
* Determine if Automated Termination is enabled in [[Automation Settings]]
+
* Determines whether you enabled Automated Termination in [[Automation Settings]].
* If this is evaluated to be true, the [https://developers.whmcs.com/hooks-reference/module/#premoduleterminate PreModuleTerminate] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#premoduleterminate PreModuleTerminate] Action Hook point if the above points evaluate to true.
* The services is terminated
+
* Terminates the services.
* If the module returns a success response, the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleterminate AfterModuleTerminate] Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleterminate AfterModuleTerminate] Action Hook point if the module returns a success response.
* If the module returns a failed response, the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleterminatefailed AfterModuleTerminateFailed] Action Hook point is triggered.
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleterminatefailed AfterModuleTerminateFailed] Action Hook point if the module returns a failure response.

Revision as of 14:11, 1 May 2020

Having an understanding of WHMCS's billing and invoicing logic, core elements of the software, will enable years of smooth and trouble-free operation.

Ordering

When a new visitor places an order, the system creates several new records, which contain the various pieces of information on the order form:

  • A client record, which stores the customer's contact details and payment preferences.
  • The service and domain record(s), which contain the details of the service the client selected on the order form.
  • An invoice record, which records the amount to pay, when it is due, and how to make payment.
  • An order record, which ties all of the above together and records the fraud report details (if you enable them). The order is a static record which reflects the prices and items at the time of ordering. The order won't reflect subsequent changes.

Invoicing

Initial Invoice

When an initial order creates an invoice, the default behavior is that the invoice is due on the day of ordering. The exception to this is when you use the Order Grace Days setting, in which case the system will set the invoice due date x days into the future.

Upon payment of the initial invoice, the system checks the associated products to determine whether to take action automatically, based upon the Module Settings. This could be one of the following actions:

  • Automatically set up the product as soon as a client places an order.
  • Automatically set up the product as soon as you receive the first payment.
  • Automatically set up the product when you manually accept a pending order.
  • Do not automatically set up this product.

The system then increments the service's Next Due Date value forward one billing cycle (for example, 1 month, 3 months, 6 months, 1 year, 2 years, or 3 years).

Renewal Invoices

The Next Due Date of the service depends on the date at which the next payment is due. When the cron job executes the daily automation tasks, the system:

  • Analyzes the Next Due Date of all Active, Pending and Suspended services.
  • Determines whether the date is equal to or less than the number of days in the future, based on the Invoice Generation setting.
  • Ensures no invoice item exists for the service on the next due date.
  • Generates a new invoice if the system evaluates the above points as true.
  • Triggers the InvoiceCreation Action Hook point.
  • Triggers the InvoiceCreationPreEmail Action Hook point.
  • Sends the Invoice Created email to the client.
  • Triggers the InvoiceCreated Action Hook point.
  • Increments the Next Invoice Date of the service 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 you have cancelled or deleted the original invoice.

As the Next Due Date is incremented forward based upon the previous value, this means paying an invoice after the due date will not change the client's renewal date to reflect the date of payment. A service always invoices for a contiguous period without gaps. This prevents a situation in which a customer might hope to avoid paying for a service by intentionally paying late.

Continuous Invoice Generation

When you enable the Continuous Invoice Generation option in the general settings, it alters the invoice generation logic so that the system creates renewal invoices even if the previous one is unpaid.

Checking a hidden field in the service record, Next Invoice Date, enables this. The Next Invoice Date field maintains a separate record of the due date for next invoice to generate. The Next Due Date value determines the next invoice to be paid.

In this mode, when the cron job executes the daily automation tasks, it:

  • Analyzes the Next Invoice Date of all Active, Pending and Suspended services.
  • Determines whether the date is equal to or less than the number of days in the future, based on the Invoice Generation setting.
  • Ensures no invoice item exists for the service on the next invoice date.
  • Generates a new invoice if the system evaluates the above points as true.
  • Triggers the InvoiceCreation Action Hook point.
  • Triggers the InvoiceCreationPreEmail Action Hook point.
  • Sends the Invoice Created email to the client.
  • Triggers the InvoiceCreated Action Hook point.
  • Increments the Next Invoice Date of the service by one billing cycle.

In this way, WHMCS maintains a separate record of which invoice to generate and which payment is due.

Payments

A transaction that fully pays the balance on an invoice, reducing it to 0.00 and marking it paid, triggers automation on payment. This means that editing an invoice and changing the status to Paid will not trigger automation. Upon adding payment to an invoice for a product, service, or domain, the system:

  • Enters a transaction into the database.
  • Triggers the AddTransaction Action Hook point.
  • Subtracts the transaction amount from the invoice balance.
  • Marks the invoice as paid if the invoice balance is now 0.
  • Changes the invoice status to Paid.
  • Triggers the InvoicePaidPreEmail Action Hook point.
  • Sends a payment confirmation email to the client.
  • Increments the Next Due Date of the associated service or domain by one billing cycle.
  • Triggers the InvoicePaid Action Hook point.

Overpayments

If a transaction includes an amount greater than the balance of the invoice, the system:

  • Records the entire transaction against the invoice, making the balance negative.
  • Marks the invoice as paid.
  • Credits the difference between the balance and the transaction amount to the client's account.
  • Changes the credit description format to Invoice # Overpayment.

Sometimes, fixed payments services (such as PayPal Subscriptions and 2Checkout Recurring Payments) can send a payment when no payment is due. In these situations, the system:

  • Records the entire transaction against the invoice that originally created the billing agreement, making the balance negative.
  • Credits the full transaction amount to the client's account.
  • Changes the credit description format to Invoice # Overpayment.

Refunds

You can issue refunds on transactions for invoices via the Refunds tab. When a you initiate a refund, the system:

  • Performs the selected refund action, which could be either of the following actions:
    • It sends a refund command to the payment gateway (if it supports it).
    • It adds a credit to the client's account with the description Credit from Refund of Invoice ID #.
  • Records a negative transaction against the invoice.
  • Triggers the AddTransaction Action Hook point.
  • Increases the invoice's balance by the refunded amount.
  • Changes the invoice's status to Refunded if system refunded the full balance.
  • Triggers the InvoiceRefunded Action Hook point.
  • Sends the Invoice Refund Confirmation email to the client.

If the refunded transaction resulted in a credit to the client's account, you must choose how to handle the credit:

  • Remove the refunded amount from the credit balance.
  • Do not change the credit.

Payment Reversals

When issuing a refund, there is also the option to reverse the payment. This is useful when you want to reverse the automated actions that the payment triggered, typically in the event of a payment dispute or chargeback.

The actions that the system takes when reversing a payment are context sensitive and depend upon your payment reversal settings. For an in-depth discussion of this feature, refer to the Payment Reversals page.

Billing Cycles

A billing cycle is 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 determine the next due date. It adds a month and returns the date, which becomes the Next Due Date.

February

The shorter length of February can cause some unique behaviour that 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

The Next Due Date for the service controls the date of service suspension. When the cron job executes the daily automation tasks, the system:

  • Analyzes he Next Due Date of all Active and Pending services.
  • Determines whether the date is equal to or less than the number of days in the future in the Suspension Days setting.
  • Determines whether Automated Suspension is enabled in Automation Settings.
  • Triggers the PreModuleSuspend Action Hook point if the above items evaluate to true.
  • Suspends the services.
  • Triggers the AfterModuleSuspend Action Hook point if the module returns a success response.
  • Triggers the AfterModuleSuspendFailed Action Hook point If the module returns a failed response.

Unsuspension

When payment is made against an invoice for a service with the Suspended status, the system can automatically unsuspend the service. In addition to the actions in the Payments section, the system:

  • Associates the invoice with a service in Suspended status.
  • Enables the Enable Unsuspension option in Automation Settings.
  • Applies a suspension reason of "Overdue on Payment" to the service.
  • Triggers the PreModuleUnsuspend Action Hook point if the points above evaluate to true.
  • Unsuspends the service.
  • Triggers the AfterModuleUnsuspend Action Hook point if the module returns a success response.
  • Triggers the AfterModuleUnsuspendFailed Action Hook point if the module returns a failed response.

Continuous Invoice Generation

When you use it in conjunction with continuous invoice generation, paying a recent invoice while leaving an older invoice unpaid will keep the service suspended. The exception is if 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. In that case, the service would be unsuspended.

Termination

The Next Due Date of the service controls the date when the system terminates services. When the cron job executes the daily automation tasks, the system:

  • Analyzes the Next Due Date of all Active, Suspended and Pending services.
  • Determines whether the date is equal to or less than the number of days in the future for the Termination Days setting.
  • Determines whether you enabled Automated Termination in Automation Settings.
  • Triggers the PreModuleTerminate Action Hook point if the above points evaluate to true.
  • Terminates the services.
  • Triggers the AfterModuleTerminate Action Hook point if the module returns a success response.
  • Triggers the AfterModuleTerminateFailed Action Hook point if the module returns a failure response.