Billing Logic

Billing and invoicing are two of the most important tasks that WHMCS can automate for you. It is important to understand the logic that these systems use so that you can make the best possible configuration choices.

The Billing Process

The billing and invoicing process in WHMCS follows the same general process for all orders:

  1. Ordering — A client places an order or an admin places an order on the client’s behalf.
  2. Invoicing — The system generates an invoice for the order, either through automation or when an admin generates an invoice manually.
  3. Payment — The client pays the invoice.
  4. Provisioning — If the product uses a provisioning module, WHMCS provisions the service according to the product’s settings.

WHMCS’s billing and invoicing logic also controls suspension, unsuspension, and termination for applicable services. Suspension, unsuspension, and termination can happen on request or due to lack of payment in relation to a client’s Next Due Date.

Ordering

Orders can enter your system through many methods. In the Admin Area, admins can create orders for new or existing clients. New customers and existing clients can order products through your store and the Client Area.

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

Created RecordDescriptionView At
Client RecordThis record stores the customer’s contact details and payment preferences.The client profile Summary tab.
Service or Domain RecordsThese records contain the details of the service that the client selected.The client profile Products/Services and Domains tabs.
Invoice RecordThis record includes the amount to pay, when it is due, and how to make payment.The client profile Invoices tab or Billing > Invoices.
Order RecordThis record contains all of the above information in addition to any fraud report details (if you have enabled fraud protection).
This is a static record that reflects the prices and items at the time of ordering. It will not reflect subsequent changes.
Orders > List All Orders

Invoicing

When an initial order creates an invoice, the invoice is due on the order date by default.

If you enabled Order Grace Days in the Ordering tab at Configuration () > System Settings > General Settings, the system will set the invoice due date according to this setting.

Invoice Generation and the Next Due Date

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:

  1. Analyzes the Next Due Date value for:
    • All services in the Active and Suspended statuses.
    • All domains in the Active and Pending statuses, if their Do Not Renew setting is OFF.
  2. Determines whether the date for each service is equal to or less than the number of days in the future, based on the Invoice Generation setting.
  3. Ensures that no invoice item exists for each of these services for the next due date.
  4. Generates a new invoice if the system evaluates the above points as true.
  5. Triggers the InvoiceCreation action hook point.
  6. Triggers the InvoiceCreationPreEmail action hook point.
  7. Sends the Invoice Created email to the client.
  8. Triggers the InvoiceCreated action hook point.
  9. Increments the Next Invoice Date value for the service by one billing cycle.

Using this logic, 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.

Because the system increments the Next Due Date value forward using the previous value, paying the invoice will not change the client’s renewal date, regardless of the date of payment. Services will always invoice for a contiguous period.

Continuous Invoice Generation

When you enable Continuous Invoice Generation, the system creates invoices regardless of whether unpaid invoices exist for the service.

  • The system generates invoices if the service status is Active or Suspended.
  • The system will not generate invoices if the service status is Pending, Completed, Cancelled, or Terminated.

For example, a customer might order a monthly product in January, receive their January invoice, and pay it. The system would generate their next invoice in February:

  • With Continuous Invoice Generation, the system will create a March invoice regardless of whether the customer paid the February invoice.
  • If you have disabled Continuous Invoice Generation, the system will not create a March invoice if the February invoice is unpaid.

You can enable Continuous Invoice Generation in the Invoices tab at Configuration () > System Settings > General Settings.

The Next Invoice Date value for services maintains a separate record of the due date for next invoice to generate. The Next Due Date value determines the next invoice to pay.

If you have enabled Continuous Invoice Generation, when the cron job executes the daily automation tasks, it:

  1. Analyzes the Next Invoice Date value for all Active, Pending, and Suspended services.
  2. Uses the Invoice Generation setting to determine whether the date is equal to or less than the number of days in the future.
  3. Ensures that no invoice item exists for the service on the next invoice date.
  4. Generates a new invoice if the system evaluates the above points as true.
  5. Triggers the InvoiceCreation action hook point.
  6. Triggers the InvoiceCreationPreEmail action hook point.
  7. Sends the Invoice Created email to the client.
  8. Triggers the InvoiceCreated action hook point.
  9. 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.

For more information about this setting, see Invoices.

Payment

A transaction that fully pays the balance on an invoice, reducing it to 0.00 and marking it paid, triggers automation on payment. Editing an invoice and changing the status to Paid will not trigger automation.

When a client pays an invoice for a product, service, or domain, the system:

  1. Enters a transaction into the database.
  2. Triggers the AddTransaction action hook point.
  3. Subtracts the transaction amount from the invoice balance.
    For payments that exceed the invoice amount, see Overpayments below.
  4. Marks the invoice as paid and changes the invoice status to Paid if the invoice balance is now 0.
  5. Triggers the InvoicePaidPreEmail action hook point.
  6. Sends a payment confirmation email to the client.
  7. Increments the Next Due Date of the associated service or domain by one billing cycle.
  8. Triggers the InvoicePaid action hook point.

After payment of the initial invoice, the system determines whether to provision the service automatically using the configuration in the Module Settings tab at Configuration () > System Settings > Products/Services.

Overpayments

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

  1. Records the entire transaction against the invoice, making the balance negative.
  2. Marks the invoice as paid.
  3. Credits the difference between the balance and the transaction amount to the client’s account.
  4. 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 in an invoice.

When you initiate a refund, the system:

  1. 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 #.
  2. Records a negative transaction against the invoice.
  3. Triggers the AddTransaction action hook point.
  4. Increases the invoice’s balance by the refunded amount.
  5. Changes the invoice’s status to Refunded if system refunded the full balance.
  6. Triggers the InvoiceRefunded action hook point.
  7. 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

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

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

A billing cycle is a calendar period. Due to this, a monthly billing cycle 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 shorter length of February can cause some unique behavior that does not happen for the other months of a year:

Order DateRenewal DateNumber of Days
January 29March 131 days
January 30March 231 days
January 31March 331 days
February 1March 128 days
February 2March 228 days
February 3March 328 days

Suspension, Unsuspension, and Termination

Suspension

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

  1. Analyzes the Next Due Date value of all Active and Pending services.
  2. Determines whether the date is equal to or less than the number of days in the future in the Suspension Days setting.
  3. Determines whether Automated Suspension is enabled at Configuration () > System Settings > Automation Settings.
  4. Triggers the PreModuleSuspend action hook point if the above items evaluate to true.
  5. Suspends the services.
  6. Applies a suspension reason of Overdue on Payment to the service.
  7. Triggers the AfterModuleSuspend action hook point if the module returns a success response, or 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 Payments above, the system:

  1. Analyzes the invoices for a service in the Suspended status with a Suspension Reason of Overdue on Payment.
  2. Checks whether Enable Unsuspension is enabled at Configuration () > System Settings > Automation Settings.
  3. Triggers the PreModuleUnsuspend action hook point if the points above evaluate to true.
  4. Unsuspends the service.
  5. Triggers the AfterModuleUnsuspend action hook point if the module returns a success response, or triggers the AfterModuleUnsuspendFailed action hook point if the module returns a failed response.

If you have enabled Continuous Invoice Generation, a customer could pay a more recent invoice but leave an older invoice unpaid. In this case, the system will not unsuspend the service unless the payment increments the Next Due Date forward to a date that is not within the suspension date range.

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:

  1. Analyzes the Next Due Date value of all Active, Suspended, and Pending services.
  2. Determines whether the date is equal to or less than the number of days in the future for the Termination Days setting.
  3. Checks whether you enabled Automated Termination in Configuration () > System Settings > Automation Settings.
  4. Triggers the PreModuleTerminate action hook point if the above points evaluate to true.
  5. Terminates the services.
  6. Triggers the AfterModuleTerminate action hook point if the module returns a success response, or triggers the AfterModuleTerminateFailed action hook point if the module returns a failure response.

Last modified: October 29, 2024