You can configure your WHMCS in order to automatically apply any available credit on a user's account to new recurring invoices immediately upon generation.
(For further details about usual WHMCS management of prepaid credit: https://docs.whmcs.com/Credit/Prefunding

Usually it works fine, and it's useful for current service management: the user does a prepaid credit refill, and then just waits for his services and domains going to automatically renew when necessary, using this available prepaid credit.

But an issue occurs when the available is not sufficient to fully pay an invoice; even more, in such a case many different issues may occur.

Example:

  • the user has a domain going to be renewed; the renewal cost is 15.00
  • the user has just 14.90 of available prepaid credit
  • the system issues an invoice for the renewal of the invoice; total invoice amount 15.00, the system applies the available credit (14.90), total due 0.10
  • at the best, the user will log in, and pay the missing 0.10 (and PayPal will apply 0.35 to you for this single transaction: so you'll have a loss of 0.25 ...)
  • If the user does not pay, the domain will expire; the invoice will be canceled, but the applied credit will not be refunded to the user (who, when will discover it, will legitly claim)

This is just an example: many other issues may occur, even more difficult than this...

In order to fix this issue, and allow WHMCS to apply credit only when it's sufficient to fully pay an invoice, it's sufficient this hook:

//
// remove applied credit to invoices, when credit applied is not sufficient to fully pay
//
function remove_credit_from_new_invoice($vars) {
   if ($vars['status']=="Paid") { return; }
   $postData=array('invoiceid' => $vars['invoiceid'], );
   $invoicedata = localAPI('GetInvoice', $postData);
   if ( $invoicedata['credit'] != 0 AND $invoicedata['balance'] != 0 ) {
      $postData = array(
         'invoiceid' => $vars['invoiceid'],
         'amount' => - $invoicedata['credit'],
      );
      $res = localAPI('ApplyCredit', $postData);
   }
}

add_hook('InvoiceCreationPreEmail', 5, "remove_credit_from_new_invoice" );

Found this article interesting?
Subscribe to DomainRegister´s newsletter!

You can unsubscribe at any time by simply clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp s privacy practices here.

  • WHMCS
  • 1 uporabniku/om je bi članek v pomoč
Vam je bil odgovor v pomoč?

Povezani članki

 How to add a favicon in WHMCS

To add a favicon to your WHMCS install: copy your favicon (es. myfavicon.ico) in WHMCS folder...

 How to comment in template (.tpl) files

If you need to insert a comment in a .tpl file, or comment a block of code to disable it, you...

 How to insert a Youtube video in WHMCS knowledgebase article

To insert a YouTube video in an article of the WHMCS knowledge base, you need to insert following...

 How to disable a customer to pay invoices partly with credit balance

in WHMCS if a customer has not enough credit balance for full payment of an invoice, WHMCS allows...

 How to add a cookie bar to WHMCS

In order to add a cookie bar to your own installation of WHMCS: copy somewhere on your WHMCS...