In this section, you will learn about advanced topics.
Automatic Cancellation of Pending Cashback #
Since in the WHMCS invoice refunding mechanism, it is not possible to accurately specify the service that the operator intends to return, it is not possible to automatically cancel the cashback at the time of the invoice refunding in a technically precise manner. But if you would like to cancel the pending cashback when the invoice is refunded fully or partially, you can use the following method.
Since in the WHMCS invoice refunding mechanism, it is not possible to accurately specify the service that the operator intends to return, it is not possible to automatically cancel the cashback at the time of the invoice refunding in a technically precise manner. But if you would like to cancel the pending cashback when the invoice is refunded fully or partially, you can use the following hook.
Create a WHMCS hook file in the following path:
/includes/hooks/auto-cancel-pending-cashback.php
Then paste the following snippet inside it:
<?php function cancelPendingCashback($invoice_id){ Capsule::table("mod_cashback_logs") ->join("tblinvoiceitems", 'invoice_item_id', '=', 'tblinvoiceitems.id') ->join("tblinvoices", 'tblinvoices.id', '=', 'tblinvoiceitems.invoiceid') ->where("tblinvoices.id", $invoice_id) ->where("mod_cashback_logs.status", 'pending') ->update([ 'mod_cashback_logs.status'=> 'cancelled' ]); } // Handle refund by credit add_hook('UpdateInvoiceTotal', 1, function ($vars) { $invoice = localAPI('GetInvoice', array( 'invoiceid' => $vars['invoiceid'], )); if ($invoice['Refunded'] != false || $invoice['credit'] != 0 || $invoice['balance'] != $invoice['total']) return; cancelPendingCashback($vars['invoiceid']); }); // Handle manual refund and refund through Gateway add_hook('InvoiceRefunded', 1, function ($vars) { cancelPendingCashback($vars['invoiceid']); }); ?>