WHMCS操作钩未传递$ vars

问题描述 投票:1回答:1

根据WHMCS文档,动作挂钩'AddInvoicePayment'应该传递$ vars变量,其中$vars['invoiceid']等于刚刚收到付款的任何发票。

但是,我的动作挂钩似乎没有在$vars变量中接收任何内容。我在下面包含了我的代码:

add_hook('AddInvoicePayment', 5, function($vars) {
// $vars['invoiceid'] is the only var passed into this hook.

// 1. Get the invoice information from WHMCS
function get_invoice_info($invoice_id) {
    //Define the paramaters
    $command = 'GetInvoice';
    $values = array(
        'invoiceid' => $invoice_id
    );
    $adminUsername = 'admin';

    // Call the Local API
    $invoice_info = localAPI($command, $values, $adminUsername);

    // Make it an object
    return json_decode($invoice_info);
}

// 2. Get the Client email from WHMCS
function get_client_email($client_id) {
    //Define the paramaters
    $command = 'GetClientsDetails';
    $values = array(
        'clientid' => $client_id,
        'stats' => false,
    );
    $adminUsername = 'admin';

    // Call the local API
    $client_info = localAPI($command, $values, $adminUsername);

    //Make it pretty
    $client_array = json_decode($client_info, true);
    return $client_array['client[email]'];
}

// 3. Create LeadDyno Purchase
function create_leaddyno_purchase($vars){
    $invoiceinfo = get_invoice_info($vars['invoiceid']);
    $clientemail = get_client_email($invoiceinfo->userid);

    // Gather all the info for the curl request
    $url = 'https://api.leaddyno.com/v1/purchases';
    $req = '&email=' . $clientemail;
    $req .= '&purchase_amount=' . $invoiceinfo->total;

    // Actually make the curl request
    make_curl_request( $url, $req );
}

// 4. Get the Client info from WHMCS
function get_client_info($client_id) {
    //Define the paramaters
    $command = 'GetClientsDetails';
    $values = array(
        'clientid' => $client_id,
        'stats' => false,
    );
    $adminUsername = 'admin';

    // Call the local API
    $client_info = localAPI($command, $values, $adminUsername);

    //Make it pretty
    $client_array = json_decode($client_info, true);

    return $client_array;
}

// 5. Create a LeadDyno affiliate. If they already exists, it ignores our request
function create_a_leaddyno_affiliate($vars){
    $clientinfo = get_client_info(get_invoice_info($vars['invoiceid'])->userid);

    // Gather the children for the trip
    $url = 'https://api.leaddyno.com/v1/affiliates';
    $req = '&email=' . urlencode($clientinfo['client[email]']);
    $req .= '&first_name=' . $clientinfo['client[firstname]'];
    $req .= '&last_name=' . $clientinfo['client[lastname]'];

    // Send the children on the trip
    make_curl_request( $url, $req );
}
create_leaddyno_purchase($vars);
create_a_leaddyno_affiliate($vars);
});
php hook action whmcs
1个回答
0
投票

尝试此代码:

if(!defined('API_ADMIN_USERNAME')) {
    define('API_ADMIN_USERNAME', 'admin');
}

// 1. Get the invoice information from WHMCS
function get_invoice_info($invoice_id) {
    // Call the Local API
    $invoice_info = localAPI('GetInvoice', ['invoiceid' => $invoice_id], API_ADMIN_USERNAME);
    // Make it an object
    return json_decode($invoice_info);
}

// 2. Create LeadDyno Purchase
function create_leaddyno_purchase($total, $clientemail){
    // Gather all the info for the curl request
    $url = 'https://api.leaddyno.com/v1/purchases';
    $req = '&email=' . $clientemail;
    $req .= '&purchase_amount=' . $total;

    // Actually make the curl request
    make_curl_request( $url, $req );
}

// 3. Get the Client info from WHMCS
function get_client_info($client_id) {
    // Call the local API
    $client_info = localAPI('GetClientsDetails', ['clientid' => $client_id, 'stats' => false], API_ADMIN_USERNAME);

    //Make it pretty
    $client_array = json_decode($client_info, true);

    return $client_array;
}

// 4. Create a LeadDyno affiliate. If they already exists, it ignores our request
function create_a_leaddyno_affiliate($clientinfo){
    // Gather the children for the trip
    $url = 'https://api.leaddyno.com/v1/affiliates';
    $req = '&email=' . urlencode($clientinfo['client[email]']);
    $req .= '&first_name=' . $clientinfo['client[firstname]'];
    $req .= '&last_name=' . $clientinfo['client[lastname]'];

    // Send the children on the trip
    make_curl_request( $url, $req );
}

add_hook('AddInvoicePayment', 5, function($vars) {
    $invoice = get_invoice_info($vars['invoiceid']);
    $client = get_client_info($invoice->userid);
    create_leaddyno_purchase($invoice->total, $client['client[email]']);
    create_a_leaddyno_affiliate($client);
});

重要注意:没有make_curl_request函数的声明

© www.soinside.com 2019 - 2024. All rights reserved.