Mechanic Posted August 13, 2023 Share Posted August 13, 2023 (edited) 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 August 13, 2023 by Mechanic 0 Quote Link to comment Share on other sites More sharing options...
Ankit70 Posted August 13, 2023 Share Posted August 13, 2023 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 0 Quote Link to comment Share on other sites More sharing options...
Mechanic Posted August 16, 2023 Author Share Posted August 16, 2023 @Ankit70 Thank you for the offer. Please let me know how much it would cost. 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 16, 2023 Share Posted August 16, 2023 (edited) 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 August 16, 2023 by leemahoney3 0 Quote Link to comment Share on other sites More sharing options...
Mechanic Posted August 27, 2023 Author Share Posted August 27, 2023 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? 0 Quote Link to comment Share on other sites More sharing options...
Mechanic Posted August 27, 2023 Author Share Posted August 27, 2023 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? 0 Quote Link to comment Share on other sites More sharing options...
Mechanic Posted August 27, 2023 Author Share Posted August 27, 2023 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? 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted August 28, 2023 Share Posted August 28, 2023 What version of PHP and WHMCS are you using? I only tested that on my setup (PHP 8 and WHMCS 8.7) Correct, by default it will disallow admins from suspending. Your method is correct however to rectify this. 0 Quote Link to comment Share on other sites More sharing options...
Mechanic Posted August 29, 2023 Author Share Posted August 29, 2023 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 0 Quote Link to comment Share on other sites More sharing options...
Mechanic Posted September 10, 2023 Author Share Posted September 10, 2023 I ended up directly querying the database to find out which services to suspend. This has been working as expected so far. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.