Jump to content

Automatically close fraud accounts (CRON)


KuJoe

Recommended Posts

I wrote this quick cron job to automatically close accounts that had products/services marked as fraud (currently runs every other minute). I considered doing a hook but since this job only runs for a few seconds and requires no CPU resources I figured it's just as effective. Plus, I am still learning the hooks. :D

 

With this code I created a new table in the WHMCS database called "fraudclose" to keep track of the UserIDs that are closed by the script. I am no developer by any means so please feel free to point out any flaws or if you know of a better more efficient way to handle this I am all ears. :D

 

(I keep the file above my public_html directory so it is not web accessible.)

 

<?php
$db_host = "localhost";
$db_username = "user";
$db_password = "password";
$db_name = "database";

$con = mysql_connect("$db_host","$db_username","$db_password");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }
mysql_select_db("$db_name", $con);

$query = "SELECT tblclients.id ".
"FROM tblclients, tblorders ".
"WHERE tblclients.id = tblorders.userid AND tblclients.status = 'Active' AND tblorders.status = 'Fraud'";
$result = mysql_query($query) or die(mysql_error());

// Print out the contents of each row into a table 
while($row = mysql_fetch_array($result)){
$userid = $row['id']; 
$updateq = "UPDATE tblclients SET status='Closed' WHERE id='$userid'";
$insertq = "INSERT fraudclose VALUES ($userid)";
mysql_query($updateq) or die(mysql_error());
mysql_query($insertq) or die(mysql_error());
}
mysql_close($con);
?>

Edited by KuJoe
Link to comment
Share on other sites

  • 3 weeks later...

I have re-wrote this to be an action hook and have removed the fraudclose table as most of us keep track of frauds using the already built in whmcs accounts search feature.

 

<?php

function close_fraud_accounts_hook($args) {

$query = "SELECT tblclients.id FROM tblclients, tblorders WHERE tblclients.id = tblorders.userid AND tblclients.status = 'Active' AND tblorders.status = 'Fraud'";
$result = full_query($query);

while($record = mysql_fetch_array($result)) {
	update_query("tblclients",array("status"=>"Closed"),array("id"=>$record['id']));
}
}

add_hook("DailyCronJob",1,"close_fraud_accounts_hook","");

?>

Link to comment
Share on other sites

  • 11 months later...
  • 4 months later...

Expanded it a bit more to use the built-in API rather than the raw SQL queries. (This is untested)

 

function close_fraud_accounts_hook($args) { 
   $adminuser = "apiuser"; // Set to a valid admin user with API access
   $data = select_query("tblorders o, tblclients c", "c.id", array(
                            "c.id"=>"o.userid",
                            "c.status"=>"Active",
                            "o.status"=>"Fraud"));

   while ($res = mysql_fetch_array($data)) {
       $val = array("clientid"=>$res[0]);
       localAPI("closeclient", $val, $adminuser);
   }
}
add_hook("DailyCronJob",1,"close_fraud_accounts_hook",""); 

Link to comment
Share on other sites

  • 3 months later...

Can you make another of these that will look for cancelled / terminated products and cancel any add ons for them?

 

We have an ongoing issue with WHMCS leaving add ons active even after the products are terminated or cancelled which means clients who have left are still sent invoices for the add on products.

 

It's become a huge issue to the point where the owner refuses to use add ons and creates additonal products instead which leads to even more confusion.

 

I don't know why WHMCS doesn't do this automatically but we really, really could use a solution for this.

 

Another version that looks for clients with no active products and closes their accounts would be great too. Even if the system automatically terminates a client for non payment the account is left "active" which means they will still get any emails sent out to all active clients. This is yet another source of complaints for us we'd like to solve.

 

Thanks for the fraud closing script, it's helped me save a lot of time on one of our services which gets a ton of fraud sign ups.

Link to comment
Share on other sites

  • 5 months 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