Difference between revisions of "Billing Logic"

From WHMCS Documentation

m (Termination)
(Renewal Invoices)
 
(20 intermediate revisions by 3 users not shown)
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.
+
Billing and invoicing are two of the most important tasks that WHMCS can automate for you. It is important to understand these systems as you configure them so that you can make the best available choices.
  
 
==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:
+
 
* A client record is created to store the customer's contact details and payment preferences.
+
When a new visitor places an order, the system creates several new records, which contain the various pieces of information on the order form:
* The service and domain record(s) are then created 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.
+
* A client record, which stores the customer's contact details and payment preferences.
* 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.
+
* 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==
 
==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 [[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.
 
  
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:
+
===Initial Invoice===
* Automatically setup the product as soon as an order is placed
+
 
* Automatically setup the product as soon as the first payment is received
+
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.
* Automatically setup the product when you manually accept a pending order
+
 
* Do not automatically setup this product
+
Upon payment of the initial invoice, the system checks the associated products to determine whether to take action automatically, based on the configuration in the '''[[Products_and_Services|Module Settings]]''' tab at  '''Configuration (<i class="fa fa-wrench" aria-hidden="true"></i>) > System Settings > [[Products and Services|Products/Services]]''' or, prior to WHMCS 8.0, '''Setup > Products/Services'''.  
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===
 +
 
 +
<div class="docs-alert-info">
 +
In WHMCS 8.8 and later, you can enable and configure on-demand renewals to allow customers to renew services early, before invoice generation, from within the Client Area. For more information, see [[On-Demand Renewals]].
 +
</div>
 +
 
 +
The Next Due Date of the service determines 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'' and ''Suspended'' services.
 +
* Analyzes the '''Next Due Date''' value for all ''Active'' and ''Pending'' domains for which '''Do Not Renew''' is ''Off''.
 +
* 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.
  
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:
+
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.
* 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 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.
+
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.
 
  
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.
+
When you enable the '''[[Invoicing_Setup#Continuous_Invoice_Generation|Continuous Invoice Generation]]''' option in the '''[[Invoice Tab|Invoice]]''' tab at '''Configuration (<i class="fa fa-wrench" aria-hidden="true"></i>) > System Settings > General Settings''' or, prior to WHMCS 8.0, '''Setup > 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 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 InvoiceCreation Action Hook point is triggered
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreation InvoiceCreation] Action Hook point.
* The 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 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 is entered into the database
 
* The AddTransaction Action Hook point is triggered
 
* 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
 
  
===Overpayments===
+
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.
If a transaction is applied with an amount greater than the balance of the invoice, the following actions are taken:
+
 
* The entire transaction is recorded against the invoice, thus making the balance negative
+
Upon adding payment to an invoice for a product, service, or domain, the system:
* The invoice is marked paid
 
* The difference between the balance and the transaction amount is credited to the client's account
 
* The credit description will take the format ''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:
+
* Enters a transaction into the database.
 +
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#addtransaction 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 [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaidpreemail 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 [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaid InvoicePaid] Action Hook point.
  
* The entire transaction is recorded against the invoice which originally created the billing agreement, thus making the balance negative
+
===Overpayments===
* The full transaction amount is credited to the client's account
+
* The credit description will take the format ''Invoice # Overpayment''
+
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 (like [[2CheckOut]] and some [[PayPal]]® 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===
 
===Refunds===
Transactions applied to invoices can be refunded via the Refunds tab. When a refund is initiated the following actions occur:
+
* The selected refund action is performed, either of the following:
+
You can issue refunds on transactions for invoices via the '''Refunds''' tab.  
** A refund command is sent to the payment gateway (if supported)
+
 
** A credit is added to the client's account with the description ''Credit from Refund of Invoice ID #''
+
When a you initiate a refund, the system:
* A negative transaction is recorded against the invoice
+
* The AddTransaction Action Hook point is triggered
+
* Performs the selected refund action, which could be either of the following actions:
* The invoice's balance is increased by the refunded amount
+
** It sends a refund command to the payment gateway if it supports it.
* If the full balance is refunded, the invoice's status changes to Refunded
+
** It adds a credit to the client's account with the description ''Credit from Refund of Invoice ID #''.
* The InvoiceRefunded Action Hook point is triggered
+
* Records a negative transaction against the invoice.
* The Invoice Refund Confirmation email is sent to the client
+
* Triggers the [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#addtransaction 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 [https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicerefunded 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:
  
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:
 
 
* 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===
 +
 +
When you issue a [[#Refunds|refund]], you have the option to reverse the payment. This is useful when you want to reverse the automated actions that the payment triggered, typically due to a [[Disputes|dispute]].
 +
 +
The actions that the system takes when reversing a payment are context sensitive and depend on your payment reversal settings. For more information, see [[Payment Reversals]].
 +
 +
===Affiliate Commission Reversals=== 
 +
 +
When you issue a [[#Refunds|refund]], you can also reverse any affiliate commissions. This helps you ensure that you do not pay commissions to affiliates unless you also received payment for the transaction.
 +
 +
When you refund a transaction, one of the following scenarios will occur:
 +
 
 +
* If you are giving a full refund, WHMCS will perform the reversal automatically.
 +
* If you are giving a partial refund, you can choose whether to perform the reversal.
 +
 +
For more information on affiliate commission reversals and delays, see [[Affiliates]].
 +
 
 +
===Billing Cycles===
  
===Payment Reversals===
+
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.
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.
 
  
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 following billing cycles are available for products or services and product addons:
  
===Billing Cycles===
+
* One Time
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.
+
* Monthly
 +
* Quarterly
 +
* Semi-Annually
 +
* Annually
 +
* Biennially
 +
* Triennially
  
 
====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 140: Line 189:
 
</table>
 
</table>
  
 +
==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:
  
==Suspension==
+
* Analyzes the Next Due Date of all Active and Pending services.
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:
+
* Determines whether the date is equal to or less than the number of days in the future in the Suspension Days setting.
* The Next Due Date of all Active and Pending services are analysed
+
* Determines whether Automated Suspension is enabled in [[Automation Settings]].
* Determine if the date is equal to or less than the number of days in the future specified by the Suspension Days setting
+
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#premodulesuspend PreModuleSuspend] Action Hook point if the above items evaluate to true.
* Determine if Automated Suspension is enabled
+
* Suspends the services.
* If this is evaluated to be true, the PreModuleSuspend Action Hook point is triggered
+
* Applies a suspension reason of "Overdue on Payment" to the service.
* The services is suspended
+
* 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 success response, the AfterModuleSuspend 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.
* If the module returns a failed response, the AfterModuleSuspendFailed Action Hook point is triggered.
 
  
 
==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], the following additional actions are performed:
 
  
* Check if the invoice is associated with a service in Suspended status
+
When payment is made against an invoice for a service with the Suspended status, the system can automatically unsuspend the service.
* Check if the Enable Unsuspension option is enabled in Automation Settings
+
 
* Check if the service has a suspension reason of "Overdue on Payment"
+
In addition to the actions in the [[#Payments|Payments]] section, the system:
* If the above points are evaluated to be true, the PreModuleUnsuspend Action Hook point is triggered
+
 
* The service is unsuspended
+
* Analyzes the invoices associated with a service in Suspended status and a Suspension Reason matching "Overdue on Payment".
* If the module returns a success response, the AfterModuleUnsuspend Action Hook point is triggered
+
* Asserts the Enable Unsuspension option is enabled in [[Automation Settings]].
* If the module returns a failed response, the AfterModuleUnsuspendFailed 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.
 +
* Unsuspends the service.
 +
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleunsuspend  AfterModuleUnsuspend] Action Hook point if the module returns a success response.
 +
* 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 all Active, Suspended and Pending services are analysed
+
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:
* Determine if the date is equal to or less than the number of days in the future specified by the Termination Days setting
+
 
* Determine if Automated Termination is enabled in [[Automation Settings]]
+
* Analyzes the Next Due Date of all Active, Suspended and Pending services.
* If this is evaluated to be true, the PreModuleTerminate Action Hook point is triggered
+
* Determines whether the date is equal to or less than the number of days in the future for the Termination Days setting.
* The services is terminated
+
* Determines whether you enabled Automated Termination in [[Automation Settings]].
* If the module returns a success response, the AfterModuleTerminate 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.
* If the module returns a failed response, the AfterModuleTerminateFailed Action Hook point is triggered.
+
* Terminates the services.
 +
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleterminate AfterModuleTerminate] Action Hook point if the module returns a success response.
 +
* Triggers the [https://developers.whmcs.com/hooks-reference/module/#aftermoduleterminatefailed AfterModuleTerminateFailed] Action Hook point if the module returns a failure response.

Latest revision as of 11:36, 6 February 2024

Billing and invoicing are two of the most important tasks that WHMCS can automate for you. It is important to understand these systems as you configure them so that you can make the best available choices.

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 on the configuration in the Module Settings tab at Configuration () > System Settings > Products/Services or, prior to WHMCS 8.0, Setup > Products/Services.

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

In WHMCS 8.8 and later, you can enable and configure on-demand renewals to allow customers to renew services early, before invoice generation, from within the Client Area. For more information, see On-Demand Renewals.

The Next Due Date of the service determines 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 and Suspended services.
  • Analyzes the Next Due Date value for all Active and Pending domains for which Do Not Renew is Off.
  • 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 Invoice tab at Configuration () > System Settings > General Settings or, prior to WHMCS 8.0, Setup > 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 (like 2CheckOut and some PayPal® 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 you issue a refund, you have the option to reverse the payment. This is useful when you want to reverse the automated actions that the payment triggered, typically due to a dispute.

The actions that the system takes when reversing a payment are context sensitive and depend on your payment reversal settings. For more information, see Payment Reversals.

Affiliate Commission Reversals

When you issue a refund, you can also reverse any affiliate commissions. This helps you ensure that you do not pay commissions to affiliates unless you also received payment for the transaction.

When you refund a transaction, one of the following scenarios will occur:

  • If you are giving a full refund, WHMCS will perform the reversal automatically.
  • If you are giving a partial refund, you can choose whether to perform the reversal.

For more information on affiliate commission reversals and delays, see Affiliates.

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.

The following billing cycles are available for products or services and product addons:

  • One Time
  • Monthly
  • Quarterly
  • Semi-Annually
  • Annually
  • Biennially
  • Triennially

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 the 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.
  • Applies a suspension reason of "Overdue on Payment" to the service.
  • 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:

  • Analyzes the invoices associated with a service in Suspended status and a Suspension Reason matching "Overdue on Payment".
  • Asserts the Enable Unsuspension option is enabled in Automation Settings.
  • 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.