From 9b13321a7f5ada22e764d9fbe388bc1365716c77 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 2 Jan 2017 14:47:39 +0200 Subject: [PATCH] Store that invoice was authorized in the session #1230 --- .../Controllers/ClientPortalController.php | 10 ++++++--- .../Controllers/OnlinePaymentController.php | 5 +++++ app/Models/Account.php | 2 +- resources/views/invoices/view.blade.php | 22 +++++++++---------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 99c183012c..7cefa6e1e1 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -209,9 +209,13 @@ class ClientPortalController extends BaseController return RESULT_FAILURE; } - $invitation->signature_base64 = Input::get('signature'); - $invitation->signature_date = date_create(); - $invitation->save(); + if ($signature = Input::get('signature')) { + $invitation->signature_base64 = $signature; + $invitation->signature_date = date_create(); + $invitation->save(); + } + + session(['authorized:' . $invitation->invitation_key => true]); return RESULT_SUCCESS; } diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php index c1b6fe81ec..ae596b89ea 100644 --- a/app/Http/Controllers/OnlinePaymentController.php +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -77,6 +77,11 @@ class OnlinePaymentController extends BaseController $invitation = $invitation->load('invoice.client.account.account_gateways.gateway'); $account = $invitation->account; + + if ($account->requiresAuthorization($invitation->invoice) && ! session('authorized:' . $invitation->invitation_key)) { + return redirect()->to('view/' . $invitation->invitation_key); + } + $account->loadLocalizationSettings($invitation->invoice->client); if ( ! $gatewayTypeAlias) { diff --git a/app/Models/Account.php b/app/Models/Account.php index 072a99b68f..ba33cea144 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1881,7 +1881,7 @@ class Account extends Eloquent return $this->enabled_modules & static::$modules[$entityType]; } - public function showAuthenticatePanel($invoice) + public function requiresAuthorization($invoice) { return $this->showAcceptTerms($invoice) || $this->showSignature($invoice); } diff --git a/resources/views/invoices/view.blade.php b/resources/views/invoices/view.blade.php index c4bc12133c..02956ae090 100644 --- a/resources/views/invoices/view.blade.php +++ b/resources/views/invoices/view.blade.php @@ -203,7 +203,7 @@ refreshPDF(); @endif - @if ($account->showAuthenticatePanel($invoice)) + @if ($account->requiresAuthorization($invoice)) $('#paymentButtons a').on('click', function(e) { e.preventDefault(); window.pendingPaymentHref = $(this).attr('href'); @@ -246,17 +246,17 @@ var data = { signature: $('#signature').jSignature('getData', 'svgbase64')[1] }; - $.ajax({ - url: "{{ URL::to('sign/' . $invitation->invitation_key) }}", - type: 'PUT', - data: data, - success: function(response) { - redirectToPayment(); - } - }); @else - redirectToPayment(); + var data = false; @endif + $.ajax({ + url: "{{ URL::to('sign/' . $invitation->invitation_key) }}", + type: 'PUT', + data: data, + success: function(response) { + redirectToPayment(); + } + }); } function redirectToPayment() { @@ -313,7 +313,7 @@ @endif - @if ($account->showAuthenticatePanel($invoice)) + @if ($account->requiresAuthorization($invoice))