From 7889350fd8455866a9506c977198ca639e17ab9f Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 7 Nov 2017 12:56:42 +0200 Subject: [PATCH] Improve invoice getPDFString --- app/Models/Invoice.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 1cc9e9022665..9c1aa6832d26 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1203,7 +1203,7 @@ class Invoice extends EntityModel implements BalanceAffecting } $invitation = $this->invitations[0]; - $link = $invitation->getLink('view', true); + $link = $invitation->getLink('view', true, true); $pdfString = false; $phantomjsSecret = env('PHANTOMJS_SECRET'); $phantomjsLink = $link . "?phantomjs=true&phantomjs_secret={$phantomjsSecret}"; @@ -1213,8 +1213,10 @@ class Invoice extends EntityModel implements BalanceAffecting // we see occasional 408 errors for ($i=1; $i<=5; $i++) { $pdfString = CurlUtils::phantom('GET', $phantomjsLink); - if ($pdfString) { + if (strpos($pdfString, 'data') === 0) { break; + } else { + $pdfString = false; } } } @@ -1239,7 +1241,7 @@ class Invoice extends EntityModel implements BalanceAffecting if ($pdf = Utils::decodePDF($pdfString)) { return $pdf; } else { - Utils::logError("PhantomJS - Unable to decode {$phantomjsLink}: {$pdfString}"); + Utils::logError("PhantomJS - Unable to decode {$phantomjsLink}"); return false; } } else {