mfoland Posted March 11, 2019 Share Posted March 11, 2019 So I'm working with the licensing addon, and attempting to figure out the hook part.. add_hook('LicensingAddonVerify', 1, function($vars) { return [ 'Hash' => 'Hash Here', ]; } ); The hash actually shows in the license how it should, but I'm trying to do it since I make several softwares, and not only one, so what I'm trying to do is something like if ($productid == "prodID number") { add_hook('LicensingAddonVerify', 1, function($vars) { return [ 'Hash' => 'Hash Here', ]; } ); } else -- run get different product It doesn't retrieve the product id at all.. What am I missing here? The hash is basically there to tell the system if a new version has been released. Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 11, 2019 Share Posted March 11, 2019 i'd move that IF statement inside the hook instead of leaving it outside of it, and then return the various hash responses inside each of the IF statements. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Peter Posted March 11, 2019 Share Posted March 11, 2019 Hi @mfoland, Based on your description, it sounds like something like the following may be useful for your needs: <?php use WHMCS\Service\Service; add_hook('LicensingAddonVerify', 1, function($vars) { try { $service = Service::findorFail($vars['serviceid']); $productID = $service->packageId; } catch (\Exception $e) { $productID = 0; } switch ((int)$productID) { case 0: return [ 'Hash' => 'error', ]; break; case 1: return [ 'Hash' => '1', ]; break; case 2: return [ 'Hash' => '2', ]; break; case 3: return [ 'Hash' => '3', ]; break; } }); Naturally, in the switch you'd need to replace 1, 2, 3 with your actual Product ID's. In my example, I use 0 to return an error (Product ID not found). This sample is provided as-is with no guarantee or warranty however, I trust it provides you with the information you require for your customisations. The documentation I used in this example was: https://developers.whmcs.com/hooks-reference/addon/#licensingaddonverifyhttps://docs.whmcs.com/classes/7.6/WHMCS/Service/Service.htmlhttp://php.net/manual/en/control-structures.switch.phphttps://docs.whmcs.com/Using_Models I hope this helps! 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 11, 2019 Author Share Posted March 11, 2019 40 minutes ago, WHMCS Peter said: Hi @mfoland, Based on your description, it sounds like something like the following may be useful for your needs: <?php use WHMCS\Service\Service; add_hook('LicensingAddonVerify', 1, function($vars) { try { $service = Service::findorFail($vars['serviceid']); $productID = $service->packageId; } catch (\Exception $e) { $productID = 0; } switch ((int)$productID) { case 0: return [ 'Hash' => 'error', ]; break; case 1: return [ 'Hash' => '1', ]; break; case 2: return [ 'Hash' => '2', ]; break; case 3: return [ 'Hash' => '3', ]; break; } }); Naturally, in the switch you'd need to replace 1, 2, 3 with your actual Product ID's. In my example, I use 0 to return an error (Product ID not found). This sample is provided as-is with no guarantee or warranty however, I trust it provides you with the information you require for your customisations. The documentation I used in this example was: https://developers.whmcs.com/hooks-reference/addon/#licensingaddonverifyhttps://docs.whmcs.com/classes/7.6/WHMCS/Service/Service.htmlhttp://php.net/manual/en/control-structures.switch.phphttps://docs.whmcs.com/Using_Models I hope this helps! @WHMCS Peter could I assign multiple cases so I can do it for multiple product ID's since some are Owned and Monthly? Thanks for your help! 🙂 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Peter Posted March 11, 2019 Share Posted March 11, 2019 Hi @mfoland, Sure thing! As documented in the PHP Manual, this can be achieved like so: Let's say you wanted cases 1, 2 and 3 to do the same thing: switch ((int)$productID) { case 0: return [ 'Hash' => 'error', ]; break; case 1: case 2: case 3: return [ 'Hash' => 'MySecretHash', ]; break; } Here's that link again for reference 🙂 - http://php.net/manual/en/control-structures.switch.php 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 11, 2019 Author Share Posted March 11, 2019 Perfect. I was thinking it could do this: switch ((int)$productID) { case 0: return [ 'Hash' => 'error', ]; break; case 31 - 32: return [ but then I got to looking on that! Thanks so much! 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 11, 2019 Author Share Posted March 11, 2019 @WHMCS Peter While on the licensing topic... I have this code: //--Check Addons validity $addonarray = array(); $addonslist = explode('|',$results['addons']); foreach ($addonslist as $addons){ $addondata = explode(';',$addons); $addonname = $addonnextduedate = $addonstatus = ""; foreach ($addondata as $addon){ $addonnvp = explode('=',$addon); if($addonnvp[0] == 'name') $addonname = $addonnvp[1]; if($addonnvp[0] == 'nextduedate') $addonnextduedate = $addonnvp[1]; if($addonnvp[0] == 'status') $addonstatus = $addonnvp[1]; } $addonarray[$addonname] = array("nextduedate"=>$addonnextduedate,"status"=>$addonstatus); $hisAddon = array("$addonname"); $arrlength = count($hisAddon); for($x = 0; $x < $arrlength; $x++) { $addonFinal[] = $hisAddon[$x]; $addonStat[] = $addonstatus[$x]; $hisAddon[$x] = $hisAddons; //$hisAddons = "$hisAddon"; }} //-- Branding Option Force 9/6/18.. Completed 9/8/2018. $astat = str_replace("A", "Active", $addonStat[0]); $bname = "Branding Removal"; $badd = $addonFinal[0]; if ($badd == $bname && $astat == "Active") { $bReq2 = "N"; $brandRemov2 = "Yes"; } else { $bReq2 = "Y"; $brandRemov2 = "No"; }*/ //--Ends Force Branding //--Do we have Support and Updates Allowed? $lkey = $license_key; $key = explode("-", $lkey); $bstat = str_replace("A", "Active", $addonStat[0]); $cname = "SupportAccess"; $cadd = $addonFinal[0]; if ($cadd == $cname && $astat == "Active") { $supportUpdates = "Yes"; } else { $supportUpdates = "No"; } What's going on, is If I suspend one of the addons they both show Not Allowed, and if I have one of them enabled, both are enabled. I was working with the license key portion to automatically say Monthly has Support Access (which would of been what the hash was for to get the updates). But why in the world would both be active or suspended, if one of them were and the other was an opposite status? This is so mind boggoling Thanks! 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Peter Posted March 11, 2019 Share Posted March 11, 2019 Hi, The first thing that stands out to me is this line: $addonname = $addonnextduedate = $addonstatus = ""; That to me looks like it's reassigning more than 1 variable. I'd recommend stepping through your code, making sure each variable is returning exactly as you expect it to. You can use something like die(var_dump($variable)); to achieve that. 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 11, 2019 Author Share Posted March 11, 2019 (edited) 8 minutes ago, WHMCS Peter said: Hi, The first thing that stands out to me is this line: $addonname = $addonnextduedate = $addonstatus = ""; That to me looks like it's reassigning more than 1 variable. I'd recommend stepping through your code, making sure each variable is returning exactly as you expect it to. You can use something like die(var_dump($variable)); to achieve that. @WHMCS Peter Changed the lining to $addonarray = array(); $addonslist = explode('|',$results['addons']); foreach ($addonslist as $addons){ $addondata = explode(';',$addons); $addonname = $addonnextduedate = $addonstatus = ""; die(var_dump($results[status])); foreach ($addondata as $addon){ $addonnvp = explode('=',$addon); if($addonnvp[0] == 'name') $addonname = $addonnvp[1]; if($addonnvp[0] == 'nextduedate') $addonnextduedate = $addonnvp[1]; if($addonnvp[0] == 'status') $addonstatus = $addonnvp[1]; } I went to do $addonname and it gave a 0 string. For the results[status] i'm getting Active, and when I try to do $addonstatus there's no data. Not sure why it's giving an issue. Here's what my Addon Array looks like: string(117) "name=SupportAccess;nextduedate=2019-09-09;status=Active|name=Branding Removal;nextduedate=0000-00-00;status=Suspended" Edited March 11, 2019 by mfoland Added addon array 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 11, 2019 Author Share Posted March 11, 2019 10 minutes ago, mfoland said: @WHMCS Peter Changed the lining to $addonarray = array(); $addonslist = explode('|',$results['addons']); foreach ($addonslist as $addons){ $addondata = explode(';',$addons); $addonname = $addonnextduedate = $addonstatus = ""; die(var_dump($results[status])); foreach ($addondata as $addon){ $addonnvp = explode('=',$addon); if($addonnvp[0] == 'name') $addonname = $addonnvp[1]; if($addonnvp[0] == 'nextduedate') $addonnextduedate = $addonnvp[1]; if($addonnvp[0] == 'status') $addonstatus = $addonnvp[1]; } I went to do $addonname and it gave a 0 string. For the results[status] i'm getting Active, and when I try to do $addonstatus there's no data. Not sure why it's giving an issue. Here's what my Addon Array looks like: string(117) "name=SupportAccess;nextduedate=2019-09-09;status=Active|name=Branding Removal;nextduedate=0000-00-00;status=Suspended" Here's what the actual Array looks like when I var dump addon array.. Array ( [SupportAccess] => Array ( [nextduedate] => 2019-09-09 [status] => Active ) ) Array ( [SupportAccess] => Array ( [nextduedate] => 2019-09-09 [status] => Active ) [Branding Removal] => Array ( [nextduedate] => 2019-03-12 [status] => Suspended ) ) That part knows what it's suppose to do, based on the above script, so not sure why I would be having the issue 😞 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Peter Posted March 12, 2019 Share Posted March 12, 2019 Hi @mfoland, I'm seeing two array keys called "SupportAccess". If one is expired but another is Active, it's possible that one is overwriting the other. Array ( [SupportAccess] => Array ( [nextduedate] => 2019-09-09 [status] => Active ) ) Array ( [SupportAccess] => Array ( [nextduedate] => 2019-09-09 [status] => Active ) [Branding Removal] => Array ( [nextduedate] => 2019-03-12 [status] => Suspended ) ) 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 12, 2019 Author Share Posted March 12, 2019 3 hours ago, WHMCS Peter said: Hi @mfoland, I'm seeing two array keys called "SupportAccess". If one is expired but another is Active, it's possible that one is overwriting the other. Array ( [SupportAccess] => Array ( [nextduedate] => 2019-09-09 [status] => Active ) ) Array ( [SupportAccess] => Array ( [nextduedate] => 2019-09-09 [status] => Active ) [Branding Removal] => Array ( [nextduedate] => 2019-03-12 [status] => Suspended ) ) @WHMCS Peter Array ( [SupportAccess] => Array ( [nextduedate] => 2019-03-12 [status] => Active ) ) Now I have Branding Removal gone out of the license.. but it still shows ENABLED in my script 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Peter Posted March 12, 2019 Share Posted March 12, 2019 Hi @mfoland, At this point, you would need to step through each part of your code performing var_dump($var) along the way. By doing this, you can ensure each part of your script is working as expected. When you reach a point where a variable is returning one thing but should in fact be another, you'll narrow down the area in which the defect lies. I'd recommend reaching out to a qualified PHP Developer if you are still uncertain. Unfortunately, our support scope is fairly limited. 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 13, 2019 Author Share Posted March 13, 2019 Well here's the array... array(3) { [0]=> string(18) "name=SupportAccess" [1]=> string(22) "nextduedate=2019-03-12" [2]=> string(13) "status=Active" } array(3) { [0]=> string(21) "name=Branding Removal" [1]=> string(22) "nextduedate=0000-00-00" [2]=> string(13) "status=Active" } It's weird because for Active it still says Branding is required, and if suspended it's still showing required. So I'm not sure what the heck is going on. I find this REALLY ODD! I use to name my products the original product name.. so in the case of the radio CMS, it would be Monthly WaveCMS Standard or Owned WaveCMS Standard . I use to do Unbranded or Branded at the end. I'm thinking of possibly going back to that! This is really weird haha. I'm going to continue to figure this one out. 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 15, 2019 Author Share Posted March 15, 2019 @WHMCS Peter Any ideas? It seems like it wants to rely on one of the statuses. Not sure what else is going on. Even though the status is in the loop right, and the array, I'm not sure what else could be going on here. I'm at a loss. This one is tricky! 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted March 18, 2019 Author Share Posted March 18, 2019 I found a solution that works by using the $addonarray part of my code! if (in_array("Active", $addonarray[BrandingRemoval])) { $bReq = "N"; $brandRemov = "Yes"; } else{ $bReq = "Y"; $brandRemov = "No"; } It works 🙂 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.