File: /var/www/html/fb-order-invoice/index.php
<?php
$invoice_pdf = isset($_GET['invoice_pdf']) ? $_GET['invoice_pdf'] : '';
if($invoice_pdf){
$pos = strrpos($invoice_pdf, '/');
$pdfname_orderid = $pos === false ? $invoice_pdf : substr($invoice_pdf, $pos + 1);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.pdfshift.io/v3/convert/pdf",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(array("source" => $invoice_pdf, "landscape" => false, "use_print" => true)),
CURLOPT_HTTPHEADER => array('Content-Type:application/json'),
CURLOPT_USERPWD => 'api:2971bbb159f44c919a10cca268e28fc6'
));
$response2 = curl_exec($curl);
$pdfname = $pdfname_orderid.'.pdf';
$ok = file_put_contents('invoice/'.$pdfname, $response2);
$response = array();
if($ok)
{
$response['errorcode'] = '200';
$response['errormessage'] = 'success';
$response['response'] = $response2;
$response['pdf_url'] = 'http://172.105.42.62/fb-order-invoice/invoice/'.$pdfname;
}
else
{
$response['errorcode'] = '201';
$response['errormessage'] = 'failed';
$response['pdf_url'] = '';
$response['response'] = $response2;
}
echo json_encode($response);
}
// We even made a GIST for you at:
// https://gist.github.com/cnicodeme/f2c73d89ac49313d023d738b5cdb7046
?>