From 8b9c83da1eb0d413a8938a0d829fd7908044d067 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 4 Aug 2020 21:29:22 +1000 Subject: [PATCH] Polish for Phantom JS implementation --- app/Utils/PhantomJS/Phantom.php | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/app/Utils/PhantomJS/Phantom.php b/app/Utils/PhantomJS/Phantom.php index a93588ce6d50..3a5a6e32a69a 100644 --- a/app/Utils/PhantomJS/Phantom.php +++ b/app/Utils/PhantomJS/Phantom.php @@ -55,24 +55,13 @@ class Phantom $file_path = $path . $entity_obj->number . '.pdf'; - $url = rtrim(config('ninja.app_url'), "/") . 'phantom/' . $entity . '/' . $invitation . '?phantomjs_secret='. config('ninja.phantomjs_secret'); + $url = config('ninja.app_url') . 'phantom/' . $entity . '/' . $invitation->key . '?phantomjs_secret='. config('ninja.phantomjs_secret'); - $json_payload = new \stdClass; - $json_payload->url = $url; - $json_payload->renderType = "pdf"; + $key = config('ninja.phantomjs_key'); + $secret = config('ninja.phantomjs_key'); - $url = "http://PhantomJScloud.com/api/browser/v2/" . config('ninja.phantomjs_key'); - $payload = json_encode($json_payload); - $options = array( - 'http' => array( - 'header' => "Content-type: application/json\r\n", - 'method' => 'POST', - 'content' => $payload - ) - ); - $context = stream_context_create($options); - $pdf = file_get_contents($url, false, $context); - if ($pdf === FALSE) { /* Handle error */ info("i did not make the PDF from phantom"); } + $phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$url}%22,renderType:%22pdf%22%7D"; + $pdf = \App\Utils\CurlUtils::get($phantom_url); Storage::makeDirectory($path, 0755); @@ -80,7 +69,6 @@ class Phantom return $file_path; - } public function displayInvitation(string $entity, string $invitation_key)