This commit is contained in:
Hillel Coren 2016-02-17 20:59:24 +02:00
parent f5bb3d3f1b
commit 331b117189

View File

@ -733,39 +733,17 @@ class Invoice extends EntityModel implements BalanceAffecting
$invitation = $this->invitations[0]; $invitation = $this->invitations[0];
$link = $invitation->getLink(); $link = $invitation->getLink();
$key = env('PHANTOMJS_CLOUD_KEY');
$curl = curl_init(); $curl = curl_init();
if (Utils::isNinjaDev()) { if (Utils::isNinjaDev()) {
$link = env('TEST_LINK'); $link = env('TEST_LINK');
} }
$jsonEncodedData = json_encode([ $url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%22,renderType:%22html%22%7D";
'url' => "{$link}?phantomjs=true",
'renderType' => 'html',
'outputAsJson' => false,
'renderSettings' => [
'passThroughHeaders' => true,
],
// 'delayTime' => 1000,
]);
$opts = [ $pdfString = file_get_contents($url);
CURLOPT_URL => PHANTOMJS_CLOUD . env('PHANTOMJS_CLOUD_KEY') . '/', $pdfString = strip_tags($pdfString);
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $jsonEncodedData,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Content-Length: '.strlen($jsonEncodedData)
],
];
curl_setopt_array($curl, $opts);
$response = curl_exec($curl);
curl_close($curl);
$pdfString = strip_tags($response);
if ( ! $pdfString || strlen($pdfString) < 200) { if ( ! $pdfString || strlen($pdfString) < 200) {
Utils::logError("PhantomJSCloud - failed to create pdf: {$pdfString}"); Utils::logError("PhantomJSCloud - failed to create pdf: {$pdfString}");