Working on download PDF route

This commit is contained in:
Hillel Coren 2016-02-17 17:50:01 +02:00
parent 34b3501842
commit 25d2af4891
6 changed files with 37 additions and 6 deletions

View File

@ -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();

View File

@ -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()) {

View File

@ -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');

View File

@ -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;

View File

@ -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();

View File

@ -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();
}