Jump to content

Get domainid instead of domain


Linuc82

Recommended Posts

Hi Guys,

I am writing a hook that uses "AfterModuleCreate" point.  This point will only return the actual domain name parameter "domain" as per https://developers.whmcs.com/provisioning-modules/module-parameters/

I actually need the domainid parameter.

Any ideas?  I cannot find a function for the local API to get the domainid from a domain parameter.

Link to comment
Share on other sites

SELECT t1.id FROM tbldomains AS t1 LEFT JOIN tblhosting AS t2 ON t1.domain = t2.domain AND t1.userid = t2.userid WHERE t2.domain = '{DOMAIN_NAME}' LIMIT 1

Replace {DOMAIN_NAME} with domain name. The reason why I'm joining by userid is to avoid situations where two customers have the same domain name (one Active and the other Pending). This way you don't risk to get the ID of the "Pending" domain that is owned by a different customer.

I think that you should consider also the status of the domain in question. In fact a customer can have following configuration:

  • Pending example.com (abandoned cart)
  • Transfered Away example.com (he registered the domain with you but he switched to another provider 3 years ago)
  • Active example.com (he's now back with you)

Here we have the same domain name with 3 different IDs and the one that you want to get is the Active one. That's why you should probably filter by tbldomains.status.

Edited by Kian
Link to comment
Share on other sites

Perhaps I should give you some more information here.

See, our company situation is a bit unique.

All new domains registered on our system has "Auto Renew" Disabled by default.  BUT when a hosting service is ordered, we want the associated domain to have Auto Renew Enabled.

To accomplish this, I have created the following hook:

<?php

#WHMCS DB Connection Manager
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('AfterModuleCreate', 1, function ($vars) 
{    
    $domain = $vars['params']['domain'];

    try {
        $updateAutorenew = Capsule::table('tbldomains')
            ->where('domain', $domain)
            ->update(
                [
                    'donotrenew' => 0,
                ]
            );

        echo "Updated {updateAutorenew} domain renewal status";
    } catch (\Exception $e) {
        echo "I was unable to update the domain renewal status. {$e->getMessage()}";
    }
    
});

 

This issue we have is that when a manual payment is added to an order, the page hangs on "Unpaid" and does not forward to "Paid".  I've narrowed the issue down to this hook, but cannot determine why it is doing that.

Link to comment
Share on other sites

9 hours ago, Linuc82 said:

All new domains registered on our system has "Auto Renew" Disabled by default.  BUT when a hosting service is ordered, we want the associated domain to have Auto Renew Enabled.

"auto renew" in this sense (with WHMCS) is really a do not generate a renewal invoice and not auto renew in the sense of automatically renewing it with the registrar - so for domains, are you not wanting to generate renewal invoices, but when purchased with a product, you want them to generate an invoice.... or are you assuming that the auto renew option is about renewing with the registrar ??

Link to comment
Share on other sites

13 hours ago, brian! said:

Since we have Domain Resellers on our system with credit on their accounts, who do not want to renew domains unless their clients pay them, we cannot have the system generate invoices for them automatically, then subsequently renew at the registrar.  As mentioned, our situation is unique and requires that Auto Renewal (Invoice Generation) be disabled by default for all domains registered on the system, except if someone orders a Hosting Plan, then the domain linked to that Hosting Plan must have Auto Renewal (Invoice Generation) Enabled.

 

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