Jump to content

Update addons status using invoicepaid hook and api


dixonjoseph.k

Recommended Posts

Hi,

 

It seems that when a user does not pay their addons, and they become overdue, they have their status changed to suspended followed by terminated, and when they are paid by the client they do not go to active, they stay with the terminated status although their due date is changed as if its paid, so that means it goes undetected and next month he will not be invoiced for it, meaning they receive it for free.

 

We developed a script and it is give below. Please check and let us know that is it correct or not?. Please advise if any changes needed?

 

function hook_activate_paid_addons($vars)
{
$invoiceid = $vars['invoiceid'];

$query = "SELECT addon.id as addon_id FROM tblinvoiceitems itms inner join tblinvoices invc on itms.invoiceid = invc.id inner join tblhosting host on host.id=itms.relid  inner join tblhostingaddons addon on host.id=addon.hostingid where itms.invoiceid = $invoiceid and addon.status='Terminated' and invc.status = 'Paid' and (itms.type = 'Addon' or itms.type = 'DomainAddonDNS' or itms.type = 'DomainAddonEMF' or itms.type = 'DomainAddonIDP')" ;


if(!mysql_query($query))
{
  echo("Error description: " . mysql_error());
}
else
{
	$result = mysql_query($query);
}

$cnt = mysql_num_rows($result);

$url = "https://example.com/includes/api.php"; # URL to WHMCS API file	
$postfields["username"] ="test";
$postfields["password"] = md5("test");

if($cnt > 0)
{
	while( $row = mysql_fetch_assoc( $result ) )
	{			
		$addon_id = $data['addon_id'];
		$postfields["action"] = "updateclientaddon";
		$postfields["addonid "] = $addon_id; 
		$postfields["status "] = "active";

		$query_string = "";
		foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";

		$chh = curl_init();
		curl_setopt($chh, CURLOPT_URL, $url);
		curl_setopt($chh, CURLOPT_POST, 1);
		curl_setopt($chh, CURLOPT_TIMEOUT, 30);
		curl_setopt($chh, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($chh, CURLOPT_POSTFIELDS, $query_string);
		curl_setopt($chh, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($chh, CURLOPT_SSL_VERIFYPEER, 0);
		$xmldata = curl_exec($chh);
	}		
}
}

add_hook("InvoicePaid",1,"hook_activate_paid_addons");

 

Also please let us know that "relid" field in the table tblinvoiceitems is the value of tblhosting.id?

 

Hope that anybody can help us.

 

Thanks.

Link to comment
Share on other sites

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