Jump to content

CCUpdate Hook (Code?)


dpgthing

Recommended Posts

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...
});
Link to comment
Share on other sites

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 by steven99
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

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