From 25d2af48919a5dacca2489e6aca3f1850f0e9624 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 17 Feb 2016 17:50:01 +0200 Subject: [PATCH] Working on download PDF route --- app/Http/Controllers/AccountController.php | 8 +++++++- app/Http/Controllers/PublicClientController.php | 15 +++++++++++++++ app/Http/routes.php | 1 + app/Models/Invoice.php | 10 +++++++--- app/Models/User.php | 5 +++++ app/Ninja/Mailers/ContactMailer.php | 4 ++-- 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 56a7d1a82b43..4b12b6802e90 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -958,7 +958,13 @@ class AccountController extends BaseController 'text' => $reason, ]; - $this->userMailer->sendTo(CONTACT_EMAIL, $email, $name, 'Invoice Ninja Feedback [Canceled Account]', 'contact', $data); + $subject = 'Invoice Ninja - Canceled Account'; + + if (Auth::user()->isPaidPro()) { + $subject .= ' [PRO]'; + } + + $this->userMailer->sendTo(CONTACT_EMAIL, $email, $name, $subject, 'contact', $data); } $user = Auth::user(); diff --git a/app/Http/Controllers/PublicClientController.php b/app/Http/Controllers/PublicClientController.php index 834a89beac59..f52e850e5826 100644 --- a/app/Http/Controllers/PublicClientController.php +++ b/app/Http/Controllers/PublicClientController.php @@ -162,6 +162,21 @@ class PublicClientController extends BaseController return $paymentTypes; } + public function download($invitationKey) + { + if (!$invitation = $this->invoiceRepo->findInvoiceByInvitation($invitationKey)) { + return response()->view('error', [ + 'error' => trans('texts.invoice_not_found'), + 'hideHeader' => true, + ]); + } + + $invoice = $invitation->invoice; + $pdfString = $invoice->getPDFString(); + + dd($pdfString); + } + public function dashboard() { if (!$invitation = $this->getInvitation()) { diff --git a/app/Http/routes.php b/app/Http/routes.php index 848d22bcdd05..347060fcb728 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -37,6 +37,7 @@ Route::post('/get_started', 'AccountController@getStarted'); // Client visible pages Route::get('view/{invitation_key}', 'PublicClientController@view'); +Route::get('download/{invitation_key}', 'PublicClientController@download'); Route::get('view', 'HomeController@viewLogo'); Route::get('approve/{invitation_key}', 'QuoteController@approve'); Route::get('payment/{invitation_key}/{payment_type?}', 'PaymentController@show_payment'); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 626f4db6475d..8c34b40deed1 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -735,6 +735,10 @@ class Invoice extends EntityModel implements BalanceAffecting $link = $invitation->getLink(); $curl = curl_init(); + if (Utils::isNinjaDev()) { + $link = env('TEST_LINK'); + } + $jsonEncodedData = json_encode([ 'url' => "{$link}?phantomjs=true", 'renderType' => 'html', @@ -761,11 +765,11 @@ class Invoice extends EntityModel implements BalanceAffecting $response = curl_exec($curl); curl_close($curl); - $encodedString = strip_tags($response); - $pdfString = Utils::decodePDF($encodedString); + $pdfString = strip_tags($response); if ( ! $pdfString || strlen($pdfString) < 200) { - Utils::logError("PhantomJSCloud - failed to create pdf: {$encodedString}"); + Utils::logError("PhantomJSCloud - failed to create pdf: {$pdfString}"); + return false; } return $pdfString; diff --git a/app/Models/User.php b/app/Models/User.php index f62e4a5846c6..9f66f0d2af8f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -107,6 +107,11 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $this->account->isPro(); } + public function isPaidPro() + { + return $this->isPro() && ! $this->isTrial(); + } + public function isTrial() { return $this->account->isTrial(); diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index dc513c3e8822..6d588de3439e 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -56,7 +56,7 @@ class ContactMailer extends Mailer $sent = false; if ($account->attatchPDF() && !$pdfString) { - $pdfString = $invoice->getPDFString(); + $pdfString = Utils::decodePDF($invoice->getPDFString()); } foreach ($invoice->invitations as $invitation) { @@ -184,7 +184,7 @@ class ContactMailer extends Mailer ]; if ($account->attatchPDF()) { - $data['pdfString'] = $invoice->getPDFString(); + $data['pdfString'] = Utils::decodePDF($invoice->getPDFString()); $data['pdfFileName'] = $invoice->getFileName(); }