Jump to content

how to suspend some services on the due date while allowing extensions on others?


Mechanic

Recommended Posts

I need to suspend some services on the due date while allowing a 5 day extension on others.

For example, all shared hosting packages will get a 5 day extension by default after their invoice due date. This feature is available in WHMCS.

What I need is to suspend other packages, e.g., software license, VPS, server (products with and without configurable options and addons), etc., on the invoice due date.

Can anyone help in doing that? paid offers are welcome, too!

Edited by Mechanic
Link to comment
Share on other sites

2 hours ago, Mechanic said:

I need to suspend some services on the due date while allowing a 5 day extension on others.

For example, all shared hosting packages will get a 5 day extension by default after their invoice due date. This feature is available in WHMCS.

What I need is to suspend other packages, e.g., software license, VPS, server (products with and without configurable options and addons), etc., on the invoice due date.

Can anyone help in doing that? paid offers are welcome, too!

Hi @Mechanic

We can create a daily cron file for that.

I can help you with it. But it will be paid task.

Thank you 

Link to comment
Share on other sites

The below hook should do the job. Better ways of doing this if you go down the paid route (e.g. an addon where you can configure suspension rules) but it might give you a start and will work fine if you don't plan on changing products frequently.

You will first need to set the automatic suspension days in WHMCS to 0 (System Settings > Automation Settings > Suspend Days) so that all services are suspended on their due date by default and then add the product ID's you want to override this on and their allowed grace period (how many days after the due date before they will be suspended) to the $suspensionOverrides array in the hook below.

e.g. I've two products, one with an ID of 5 and one with an ID of 6. As I've not added product ID 5 to the array, all services using that product will be suspended immediately on their due date.

However as I've added product ID 6 to the array and defined 10 days, all services using this product will not get suspended until 10 days past their due date. (mapped in the array as 'productId' => days

<?php

use Carbon\Carbon;

add_hook(
    'PreModuleSuspend', 1, function ( array $params ) : array {
        // Mapped as productId => days after next due before suspension
        // Products not in this array will use the default suspension config set in your whmcs automation settings
        $suspensionOverrides = [
            '6' => 10,
        ];

        $params = $params['params'];
        $productId = $params['pid'];

        // If the product doesnt exist in our array above, carry on with the suspension
        if (!array_key_exists($productId, $suspensionOverrides)) {
            return [];
        }
      
        $service = $params['model'];
        $allowedDays = $suspensionOverrides[$productId];
        $parsedNextDueDate = Carbon::createFromFormat('Y-m-d', $service->nextduedate);

        // If the modified due date is todays date or in the past, carry on with the suspension
        if (Carbon::now()->startOfDay()->greaterThanOrEqualTo($parsedNextDueDate->startOfDay()->addDays($allowedDays))) {
            return [];
        }

        // Abort the suspension this time around
        return ['abortcmd' => true];
    }
);

 

Edited by leemahoney3
Link to comment
Share on other sites

  • 2 weeks later...
On 8/17/2023 at 4:51 AM, leemahoney3 said:
        $service = $params['model'];

 

My apologies for the delay.

I added the hook and force ran the cron in a test install. It didn't suspend any services. Due days were 1 day in the past, Suspend Days is 0.

Was the above line correct, or is there something else?

 

Link to comment
Share on other sites

On 8/17/2023 at 4:51 AM, leemahoney3 said:
function ( array $params ) : array {

This seems to be the issue.

I have modified it to

function ( array $params ) {

and it is working.

But I get an error "Function Aborted by Action Hook Code" when I manually suspend a service from the admin interface. 

How do I exclude admins/manual suspensions from the admin area?

 

Link to comment
Share on other sites

Alright, I have solved the manual suspension issue using this:

use WHMCS\Authentication\CurrentUser;

$currentUser    = new CurrentUser;

if ($currentUser->isAuthenticatedAdmin()) {
    return [];
}

 

The other issue seems to be addons. All addons are getting suspended on the due date.

'model' or 'params' does not have any information about addons. How do I solve this issue now?

Link to comment
Share on other sites

2 hours ago, leemahoney3 said:

What version of PHP and WHMCS are you using? I only tested that on my setup (PHP 8 and WHMCS 8.7)

It is PHP 7.4 and WHMCS 8.7.3

The addon I am referring to is a dedicated IP added to a reseller hosting, with the following details:

[*] Prorata Billing
Module Name: None
Product Type: Other
Server Group: None

 

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