John182 Posted March 1, 2015 Share Posted March 1, 2015 Hi All, When a user decides to upgrade from Trial Package to Paid Package, I am trying get WHMCS to register the domain (the action hook i am using is: AfterProductUpgrade). NOTE: I have configured WHMCs such that it does not register the domain on sign up of free package. i have created an action hook as per below but it is not working at all. Am i missing something obvious? Thanks!! <?php function register_domain_upgrade($vars) { $command = "domainregister"; $adminuser = "admin"; $values["domainid"] = "1"; $results = localAPI($command,$values,$adminuser); return $results; } add_hook("AfterProductUpgrade",1,"register_domain_upgrade"); 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted March 1, 2015 Share Posted March 1, 2015 print_r($results) so that you can see where's the error. Anyway can you confim that "admin" is a valid admin user with API access permissions? And also can you confirm that $values["domainid"] is not null when you localAPI()? 0 Quote Link to comment Share on other sites More sharing options...
John182 Posted March 2, 2015 Author Share Posted March 2, 2015 Klan thanks for your reply. I have added the print_r($results) to the end of my code but i still do not see any errors printed anywhere after i run the upgrade and make payment for the invoice - it's' like the action hook is not beeing "called" at all... Not sure how to confirm if domainid is null? Not sure how to confirm if "admin" is a valid admin user with API access - forgive me but i am new to this. thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted March 2, 2015 Share Posted March 2, 2015 @John182 your action hook code is incomplete, "AfterProductUpgrade" contain "upgradeid" only in $vars so you will need to get the information from Database using this variable to complete what you need to do 0 Quote Link to comment Share on other sites More sharing options...
John182 Posted March 2, 2015 Author Share Posted March 2, 2015 @sentq - thanks very much. would it be better if I use this action hook then: AfterModuleChangePackage ? It seems like it has domainid parsed to it which means I don't have to get it from the database? Im just not sure what to change in my code in order to get the domain register command to work? Any chance that you can lead me in the right direction with this one? Thanks! 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted March 2, 2015 Share Posted March 2, 2015 AfterModuleChangePackage doesn't seem to include "domainid" only "domain" that looks like something.com, try this: <?php function hook_upgradeFromTrial($vars){ # Get Upgrade Info $getUpgradeInfo = full_query("SELECT * FROM `tblupgrades` WHERE `id`='".$vars['upgradeid']."'"); $getUpgradeInfo = mysql_fetch_assoc($getUpgradeInfo); # Get Order Info $getOrderInfo = full_query("SELECT * FROM `tblhosting` WHERE `orderid`='".$getUpgradeInfo['orderid']."'"); $getOrderInfo = mysql_fetch_assoc($getOrderInfo); # Get Domain Info $getDomainInfo = full_query("SELECT * FROM `tbldomains` WHERE `orderid`='".$getUpgradeInfo['orderid']."' AND `domain`='".$getOrderInfo['domain']."'"); $getDomainInfo = mysql_fetch_assoc($getDomainInfo); $command = "domainregister"; $adminuser = "admin"; $values = array("domainid", $getDomainInfo['id']); $results = localAPI($command, $values, $adminuser); if ($results['result']=='error'){ logActivity("Upgrade Error: " . $results['message']); } } ?> 0 Quote Link to comment Share on other sites More sharing options...
John182 Posted March 2, 2015 Author Share Posted March 2, 2015 @sentq - wow! thanks so much for your time! I used you code and tried to simulate the condition but the following error occurred (as seen in activity log) "Upgrade Error: No matching admin user found" Any ideas on how to solve this? Thanks again 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted March 2, 2015 Share Posted March 2, 2015 in $adminuser = "admin"; change "admin" with valid administrator username with "Full Administrator" role and try 0 Quote Link to comment Share on other sites More sharing options...
John182 Posted March 2, 2015 Author Share Posted March 2, 2015 @sentq - thanks very much. This is the error I am getting now - "Upgrade Error: Domain Not Found" - any ideas now? Once again please forgive me in asking these rudimentary questions - I am new to this thanks 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted March 2, 2015 Share Posted March 2, 2015 you're welcome, you need to track the process from the beginning, is the domain already added to Database with the Trial signup? from PHPMyAdmin check the following tables and try to simulate the hook action process, "tblupgrades", "tblhosting", "tbldomains" I'm unable to check this from my side as i don't know what is happening in your side from the start, but the action hook code i made should work with what you need.. 0 Quote Link to comment Share on other sites More sharing options...
John182 Posted March 2, 2015 Author Share Posted March 2, 2015 Sentq thanks very much ! Ill give it a bash and let you know! - - - Updated - - - The domain does get added to WHMCS in the trial version, btw. It just doesn't get registered.... 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted March 2, 2015 Share Posted March 2, 2015 we may improve it to track info we get: <?php function hook_upgradeFromTrial($vars){ $errors = array(); # Get Upgrade Info $getUpgradeInfo = full_query("SELECT * FROM `tblupgrades` WHERE `id`='".$vars['upgradeid']."'"); $getUpgradeInfo = mysql_fetch_assoc($getUpgradeInfo); if (!is_array($getUpgradeInfo) || count($getUpgradeInfo)=='0'){ $errors[] = 'Upgrade Info Empty!'; $errors[] = "Getting Upgrade: SELECT * FROM `tblupgrades` WHERE `id`='".$vars['upgradeid']."'"; } # Get Order Info $getOrderInfo = full_query("SELECT * FROM `tblhosting` WHERE `orderid`='".$getUpgradeInfo['orderid']."'"); $getOrderInfo = mysql_fetch_assoc($getOrderInfo); if (!is_array($getOrderInfo) || count($getOrderInfo)=='0'){ $errors[] = 'Order Info Empty!'; $errros[] = "Getting Order: SELECT * FROM `tblhosting` WHERE `orderid`='".$getUpgradeInfo['orderid']."'"; } # Get Domain Info $getDomainInfo = full_query("SELECT * FROM `tbldomains` WHERE `orderid`='".$getUpgradeInfo['orderid']."' AND `domain`='".$getOrderInfo['domain']."'"); $getDomainInfo = mysql_fetch_assoc($getDomainInfo); if (!is_array($getDomainInfo) || count($getDomainInfo)=='0'){ $errors[] = 'Domain Info Empty!'; $errors[] = "Getting Domain: SELECT * FROM `tbldomains` WHERE `orderid`='".$getUpgradeInfo['orderid']."' AND `domain`='".$getOrderInfo['domain']."'"; } $command = "domainregister"; $adminuser = "admin"; $values = array("domainid", $getDomainInfo['id']); $results = localAPI($command, $values, $adminuser); if ($results['result']=='error'){ logActivity("Upgrade Error: " . $results['message']); } elseif (count($errors)>'0'){ logActivity("Upgrade Error: " . join(" \n", $errors)); } } ?> check the activity log 0 Quote Link to comment Share on other sites More sharing options...
John182 Posted March 2, 2015 Author Share Posted March 2, 2015 Senq - thank you so much again! I updated the PHP code and simulated the condition, but once again it returned the error "Upgrade Error: Domain Not Found". I will look through the DBs like you had suggested in your earlier post and then ill get back to you thanks!! 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted March 2, 2015 Share Posted March 2, 2015 ok change the condition to this: if ($results['result']=='error'){ logActivity("Upgrade Error: " . $results['message']); } if (count($errors)>'0'){ logActivity("Upgrade Error: " . join(" \n", $errors)); } 0 Quote Link to comment Share on other sites More sharing options...
John182 Posted March 2, 2015 Author Share Posted March 2, 2015 Senq - that seemed to have helped - thanks! The error code is much more detailed now: 02/03/2015 20:48 Module Change Package Successful - Service ID: 182 shopon 105.210.11.182 02/03/2015 20:48 Upgrade Error: Order Info Empty! Domain Info Empty! Getting Domain: SELECT * FROM `tbldomains` WHERE `orderid`='217' AND `domain`='' shopon 105.210.11.182 02/03/2015 20:48 Upgrade Error: Domain Not Found I don't quite understand though, because when I go and look in WHMCS (before the package is upgraded), the domain name is definitely there! Thanks so so much again for all of your time! 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.