【发布时间】:2017-05-16 20:04:10
【问题描述】:
根据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);
});
【问题讨论】: