Jump to content
DennisMidjord

Run hook on specific domain order

Recommended Posts

Hi!

We've recently upgraded from v5.3, and most of our custom code obviously doesn't work.

We're trying to set the order status of any .dk domain to fraud. I have made a script that already does this:

<?php

use WHMCS\Database\Capsule;

require __DIR__ . '/init.php';

// Set all transferred domains to fraud status
$fraudTransferDomains = Capsule::table('tbldomains')
	->where('domain', 'regexp', '\.dk$')
	->where('status', 'Pending transfer')
	->orWhere('status', 'Pending')
	->where('type', 'Transfer')
	->update(
        [
			'status' => 'Fraud',
			'nextduedate' => '0000-00-00',
			'nextinvoicedate' => '0000-00-00',
			'donotrenew' => 'on',
        ]
);


// Set all registered domains to fraud status
$fraudRegisterDomains = Capsule::table('tbldomains')
	->where('domain', 'regexp', '\.dk$')
	->where('status', '!=', 'Pending')
	->where('type', 'Register')
	->update(
        [
			'status' => 'Fraud',
			'nextduedate' => '0000-00-00',
			'nextinvoicedate' => '0000-00-00',
			'donotrenew' => 'on',
        ]
);

WHMCS doesn't handle .dk domains very well. The client will always be billled by DK Hostmaster (and not us), which is why every .dk domain needs to be set to Fraud (as I don't see any way of creating a new status). We've renamed Fraud to something else so the client won't get confused.

 

Is there any way to implement this as a hook? Once a client transfers a .dk domain, $fraudTransferDomain runs, and when a client pays for a .dk registration, $fraudRegisterDomains run.

 

Edited by DennisMidjord

Share this post


Link to post
Share on other sites

I currently have this:

<?php

use WHMCS\Database\Capsule;

add_hook('AfterRegistrarTransfer', 1, function($vars) {
    if($vars['params']['tld'] == 'dk'){
		// Set all transferred domains to fraud status
		$fraudTransferDomains = Capsule::table('tbldomains')
			->where('domain', 'regexp', $vars['params']['sld'] . '\.dk$')
			->where('status', 'Pending transfer')
			->orWhere('status', 'Pending')
			->where('type', 'Transfer')
			->update(
				[
					'status' => 'Fraud',
					'nextduedate' => '0000-00-00',
					'nextinvoicedate' => '0000-00-00',
					'donotrenew' => 'on',
				]
		);
    }
});


add_hook('AfterRegistrarRegistration', 1, function($vars) {
	if($vars['params']['tld'] == 'dk'){
		// Set all registered domains to fraud status
		$fraudRegisterDomains = Capsule::table('tbldomains')
			->where('domain', 'regexp', $vars['params']['sld'] . '\.dk$')
			->where('status', '!=', 'Pending')
			->where('type', 'Register')
			->update(
				[
					'status' => 'Fraud',
					'nextduedate' => '0000-00-00',
					'nextinvoicedate' => '0000-00-00',
					'donotrenew' => 'on',
				]
		);
	}
});

as a file in includes/hooks/.

Would that be sufficient?

Edited by DennisMidjord

Share this post


Link to post
Share on other sites
2 hours ago, DennisMidjord said:

I don't see any way of creating a new status ...

You can create new Order Statuses in your Admin Area via the Setup > Other > Order Statuses section. You can find some information about this at https://docs.whmcs.com/Order_Statuses

2 hours ago, DennisMidjord said:

Is there any way to implement this as a hook?

Sure, there are a number of hook-points that you could use. Which you use depends on when you want to run these two actions.

For example, if you wanted WHMCS to mark any order containing a .dk TLD as fraudulent, then you could do something like:

<?php
use \WHMCS\Domain\Domain;

add_hook('AfterShoppingCartCheckout', 1, function($vars) {   
    foreach ($vars[Domains] as $domainID) {
        if (Domain::find($domainID)->tld === 'dk' && in_array(Domain::find($domainID)->type, array('Register', 'Transfer'))) {
            $results = localAPI('FraudOrder', array('orderid' => $vars['OrderID']));
            break;
        }
    }
});

This hook will automatically mark any order placed via the Client Area, that has a .dk TLD registration or transfer, as fraudulent.

You can read about the various elements used in this hook example at the following URLs:

https://developers.whmcs.com/hooks-reference/shopping-cart/#aftershoppingcartcheckout
https://docs.whmcs.com/classes/7.6/WHMCS/Domain/Domain.html
https://developers.whmcs.com/api-reference/fraudorder/

Share this post


Link to post
Share on other sites
8 minutes ago, WHMCS Nathan said:

You can create new Order Statuses in your Admin Area via the Setup > Other > Order Statuses section.

I don't think that'll work for us. We don't need to set the entire order as fraudulent, only the .dk domain. 

Would you care to take a quick glanse at this:

It seems to work just fine, but I'm curious whether or not it will result in any problems.

 

Share this post


Link to post
Share on other sites

Nope, can't see any immediate issues with those. If you have a development installation, then I would recommend testing them to see how they work out for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated