dpgthing Posted December 14, 2020 Share Posted December 14, 2020 Hello, I'd like to get an E-Mail notification whenever a client adds a new card on file. I have been directed to use the CCUpdate Hook, however I'm not sure what code to put in for the hook to function. Please assist. <?php add_hook('CCUpdate', 1, function($vars) { // Perform hook code here... }); 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted December 14, 2020 Share Posted December 14, 2020 (edited) Have not tested it, but this should work: <?php /** @author @steven99 * @version 0.1 * * Get an admin email when card updates are done */ use WHMCS\User\Client; add_hook('CCUpdate', 1, function ($vars) { /** @var Client $Client */ $Client = Client::find($vars['userid']); if ($Client) { $command = 'SendAdminEmail'; $postData = array( 'customsubject' => 'Credit card Updated - '.$Client->email, 'custommessage' => 'Client '. $Client->firstName . " ".$Client->lastName . " updated their card info", 'type' =>'account', ); $results = localAPI($command, $postData); } }); Edited December 14, 2020 by steven99 0 Quote Link to comment Share on other sites More sharing options...
dpgthing Posted December 14, 2020 Author Share Posted December 14, 2020 Awesome, thank you, it did in fact work! 0 Quote Link to comment Share on other sites More sharing options...
dpgthing Posted December 14, 2020 Author Share Posted December 14, 2020 Would there be a way to add an exception to the code to where it will ignore sending the email on a 'new' order? And only send email if client already exists? 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted December 15, 2020 Share Posted December 15, 2020 Could maybe go off of age of account. Would that work for you? 0 Quote Link to comment Share on other sites More sharing options...
dpgthing Posted December 15, 2020 Author Share Posted December 15, 2020 Yes, any that are more than 1 day old would work I think. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted December 15, 2020 Share Posted December 15, 2020 See below <?php /** @author @steven99 * @version 0.2 * * Get an admin email when card updates are done */ use WHMCS\User\Client; add_hook('CCUpdate', 1, function ($vars) { /** @var Client $Client */ $Client = Client::find($vars['userid']); if ($Client) { //Are we older then 1 day? Hook fires on new clients . if ( $Client->dateCreated->diff(new DateTime())->days > 1) { $command = 'SendAdminEmail'; $postData = array( 'custommessage' => 'Credit card Updated - '.$Client->email, 'customsubject' => 'Client '. $Client->firstName . " ".$Client->lastName . " updated their card info", 'type' =>'account', ); $results = localAPI($command, $postData); } } }); 0 Quote Link to comment Share on other sites More sharing options...
dpgthing Posted December 15, 2020 Author Share Posted December 15, 2020 8 minutes ago, steven99 said: See below <?php /** @author @steven99 * @version 0.2 * * Get an admin email when card updates are done */ use WHMCS\User\Client; add_hook('CCUpdate', 1, function ($vars) { /** @var Client $Client */ $Client = Client::find($vars['userid']); if ($Client) { //Are we older then 1 day? Hook fires on new clients . if ( $Client->dateCreated->diff(new DateTime())->days > 1) { $command = 'SendAdminEmail'; $postData = array( 'custommessage' => 'Credit card Updated - '.$Client->email, 'customsubject' => 'Client '. $Client->firstName . " ".$Client->lastName . " updated their card info", 'type' =>'account', ); $results = localAPI($command, $postData); } } }); Steve, I just tried that, gave me an "oops...something went wrong" error on Submission of card, however, the card info DID change after a refresh...but it did not send any email. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted December 15, 2020 Share Posted December 15, 2020 Under General settings -> other, enable debug and try then. Then note down the error and post here. Then disable debug. Docs say dateCreated is a DateTime but again haven't tested the above. 😉 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.