Jump to content

add credit to specific products


Sanora Dev

Recommended Posts

Hello everyone,

I'm searching for a way to assign specific products that can use credits and products that can't. for example, if a customer has credit he or she can use it for all hosting plans, but not for google cloud plans.

Is there a hook that i can use for this or maybe a third party addon? I've search and googled for days now, but couldn't find anything about it. The only thing i found is an old topic that wanted (in general) the same as what i'm looking for.

Old topic:

Thanks,

Elias

Link to comment
Share on other sites

There're two cases where you need to check this:

  • during renewal invoice creation
    When a renewal invoice is issued, if there's available credit WHMCS will automatically apply to it
     
  • in client area, when the user can select an unpaid invoice and decide to apply credit to it
     

The second one, I guess, it's quite easy: just modify the involved .tpl with some kind of IF clause

The first one is a little more complicated: here the code of a hook that prevent automatic credit application to new invoices if the credit is not sufficient to full pay the invoice:

//
// 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);
        logactivity('Insufficient credit removed by hook: invoice id# '.$vars['invoiceid'].' - credit removed '.$invoicedata['credit'],$vars['user']);
    }  
}

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

 

You need to modify it in order to:

  • check the kind of service billed
  • set the status of the invoice back to "unpaid" if it was fully paid with credit

Hope this will be helpful to you.

 

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated