DennisHermannsen Posted August 30, 2018 Share Posted August 30, 2018 (edited) 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 August 30, 2018 by DennisMidjord 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 30, 2018 Author Share Posted August 30, 2018 (edited) 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 August 30, 2018 by DennisMidjord 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Developer WHMCS Nathan Posted August 30, 2018 WHMCS Developer Share Posted August 30, 2018 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/#aftershoppingcartcheckouthttps://docs.whmcs.com/classes/7.6/WHMCS/Domain/Domain.htmlhttps://developers.whmcs.com/api-reference/fraudorder/ 1 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 30, 2018 Author Share Posted August 30, 2018 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. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Developer WHMCS Nathan Posted August 30, 2018 WHMCS Developer Share Posted August 30, 2018 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. 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.