Improve invoice getPDFString

This commit is contained in:
Hillel Coren 2017-11-07 12:56:42 +02:00
parent 8f409bf889
commit 7889350fd8

View File

@ -1203,7 +1203,7 @@ class Invoice extends EntityModel implements BalanceAffecting
} }
$invitation = $this->invitations[0]; $invitation = $this->invitations[0];
$link = $invitation->getLink('view', true); $link = $invitation->getLink('view', true, true);
$pdfString = false; $pdfString = false;
$phantomjsSecret = env('PHANTOMJS_SECRET'); $phantomjsSecret = env('PHANTOMJS_SECRET');
$phantomjsLink = $link . "?phantomjs=true&phantomjs_secret={$phantomjsSecret}"; $phantomjsLink = $link . "?phantomjs=true&phantomjs_secret={$phantomjsSecret}";
@ -1213,8 +1213,10 @@ class Invoice extends EntityModel implements BalanceAffecting
// we see occasional 408 errors // we see occasional 408 errors
for ($i=1; $i<=5; $i++) { for ($i=1; $i<=5; $i++) {
$pdfString = CurlUtils::phantom('GET', $phantomjsLink); $pdfString = CurlUtils::phantom('GET', $phantomjsLink);
if ($pdfString) { if (strpos($pdfString, 'data') === 0) {
break; break;
} else {
$pdfString = false;
} }
} }
} }
@ -1239,7 +1241,7 @@ class Invoice extends EntityModel implements BalanceAffecting
if ($pdf = Utils::decodePDF($pdfString)) { if ($pdf = Utils::decodePDF($pdfString)) {
return $pdf; return $pdf;
} else { } else {
Utils::logError("PhantomJS - Unable to decode {$phantomjsLink}: {$pdfString}"); Utils::logError("PhantomJS - Unable to decode {$phantomjsLink}");
return false; return false;
} }
} else { } else {