<?PHP
// We don't want someone getting crafy and calling this manually without using the WHMCS API authentications
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
// Borrowed from http://bobcares.com/blog/extend-whmcs-create-your-own-whmcs-api-functions/
function buildParams($vars)
{
$param = array(
'action' => array(),
'params' => array()
);
// Is cmd set? If so we're being used as Local API
if (isset($vars['cmd'])) {
$param['action'] = $vars['cmd'];
$param['params'] = (object) $vars['apivalues1'];
$param['adminuser'] = $vars['adminuser'];
} else {
// Nope, then we're in remote API mode..
// Fix for WHMCS > 7.x
if (!isset($vars['_POST']) && isset($vars['_POSTbackup'])) {
$vars['_POST'] = $vars['_POSTbackup'];
}
$param['action'] = $vars['_POST']['action'];
// Just cleaning up a bit, so these don't go into the params sub array..
unset($vars['_POST']['username']);
unset($vars['_POST']['password']);
unset($vars['_POST']['action']);
$param['params'] = (object) $vars['_POST'];
}
return (object) $param;
}
try {
// Get the arguments
$vars = get_defined_vars();
$postFields = buildParams($vars);
// Include the WHMCS invoicefunctions
if (!function_exists('pdfInvoice')) {
require_once('invoicefunctions.php');
}
// And build an invoice PDF for the given invoiceID - Note, if this invoice ID is invalid, it will return a blank PDF..
$pdfdata = pdfInvoice($postFields->params->invoiceid);
// Base64 encode it so it doesn't break the xml or json return
$doc = base64_encode($pdfdata);
// And return. WHMCS takes care of the json/xml encoding
$apiresults = array(
"result" => "success",
"pdf" => $doc,
"message" => "Success Message"
);
}
catch (Exception $e) {
// Return with an error!
$apiresults = array(
"result" => "error",
"message" => $e->getMessage()
);
}