Jump to content

Module Terminating service to early?


phuber

Recommended Posts

HI, so my module is having an issue where it terminates the service on the day of non payment and that's all working great. 

The problem is I end up with a list of Failed Module actions due to either the module or maybe whmcs not being able to find the account as it's already been removed.

I'm wondering if there's a way to one find out which is failing ( module or whmcs ) and then to either slow down execution or even better would be to only have one handle the accounts.

My initial thought is that it's caused by the module running termination as a curl request instead of whmcs running it's termination command?

function plex_TerminateAccount($params)
{
    $useremail = $params["customfields"]["plex_email"];
    $plexDetails = Illuminate\Database\Capsule\Manager::table("plex_clients")->where("useremail", $useremail)->first();
    $is_nonremoveable = $params["configoption8"];
    $apiurl = $params["configoption2"];
    $endpoint = $apiurl . "servers/" . $params["configoption3"] . "/shared_servers/" . $plexDetails->shared_id;
    if ($plexDetails) {
        $id = get_query_val("plex_clients", "id", array("useremail" => $useremail, "status" => 1));
        if ($id) {
            $fields = array("X-Plex-Product" => $params["configoption4"], "X-Plex-Version" => $params["configoption5"], "X-Plex-Client-Identifier" => $params["configoption6"], "X-Plex-Token" => $params["configoption7"]);
            $return = Plex_CurlFunction($endpoint, $fields, "unshareLibraries");
            $response = $return->data;
            if ($return->intCode == 200) {
                if ($is_nonremoveable == "on") {
                    Illuminate\Database\Capsule\Manager::table("plex_clients")->where("useremail", $useremail)->update(array("status" => 0));
                } else {
                    if (isset($plexDetails->user_id) && !empty($plexDetails->user_id)) {
                        $endpoint2 = $apiurl . "friends/" . $plexDetails->user_id;
                        Plex_CurlFunction($endpoint2, $fields, "removeFriend");
                    }
                    Illuminate\Database\Capsule\Manager::table("plex_clients")->where("useremail", $useremail)->delete();
                    Illuminate\Database\Capsule\Manager::table("plex_schedule")->where("useremail", $useremail)->delete();
                }
                return "success";
            }
            if ($response["@attributes"]["status"]) {
                return $response["@attributes"]["status"];
            }
            if ($response["error"]) {
                return $response["error"];
            }
            return "error";
        }
        if ($is_nonremoveable == "on") {
            Illuminate\Database\Capsule\Manager::table("plex_clients")->where("useremail", $useremail)->update(array("status" => 0));
        } else {
            Illuminate\Database\Capsule\Manager::table("plex_clients")->where("useremail", $useremail)->delete();
            Illuminate\Database\Capsule\Manager::table("plex_schedule")->where("useremail", $useremail)->delete();
        }
        return "success";
    }
    return "There isn't active service with this user";
}

 

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