Jump to content

Action Hook - register domain on upgrade (not working :( )


John182

Recommended Posts

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");

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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!

Link to comment
Share on other sites

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']);
   }
}

?>

Link to comment
Share on other sites

@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 :)

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

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! :)

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