From 6e7b9d6964e6398abc578b3e6d65a0f0fee76b54 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Sat, 18 Nov 2017 15:23:20 +0300 Subject: [PATCH] refs #78 --- app/Http/Controllers/Customers/Invoices.php | 15 ++++--- app/Utilities/Modules.php | 40 ++++++++++++++----- .../Events/Handlers/OfflinePaymentConfirm.php | 6 +-- .../Http/Controllers/Settings.php | 4 ++ .../Resources/lang/en-GB/offlinepayment.php | 1 + .../Resources/views/edit.blade.php | 14 ++++++- public/css/app.css | 18 +++++++++ .../views/customers/invoices/show.blade.php | 15 +++---- routes/web.php | 6 +-- 9 files changed, 86 insertions(+), 33 deletions(-) diff --git a/app/Http/Controllers/Customers/Invoices.php b/app/Http/Controllers/Customers/Invoices.php index e561d44f0..014f80262 100644 --- a/app/Http/Controllers/Customers/Invoices.php +++ b/app/Http/Controllers/Customers/Invoices.php @@ -102,14 +102,12 @@ class Invoices extends Controller * * @return Response */ - public function printInvoice($invoice_id) + public function printInvoice(Invoice $invoice) { $sub_total = 0; $tax_total = 0; $paid = 0; - $invoice = Invoice::where('id', $invoice_id)->first(); - foreach ($invoice->items as $item) { $sub_total += ($item->price * $item->quantity); $tax_total += ($item->tax * $item->quantity); @@ -136,14 +134,12 @@ class Invoices extends Controller * * @return Response */ - public function pdfInvoice($invoice_id) + public function pdfInvoice(Invoice $invoice) { $sub_total = 0; $tax_total = 0; $paid = 0; - $invoice = Invoice::where('id', $invoice_id)->first(); - foreach ($invoice->items as $item) { $sub_total += ($item->price * $item->quantity); $tax_total += ($item->tax * $item->quantity); @@ -177,10 +173,13 @@ class Invoices extends Controller * * @return Response */ - public function payment(PaymentRequest $request) + public function payment(Invoice $invoice, PaymentRequest $request) { - $invoice = Invoice::where(['id' => $request['invoice_id'], 'customer_id' => Auth::user()->customer->id])->first(); + if (!$invoice) { + return response()->json( + ); + } // Fire the event to extend the menu $result = event(new PaymentGatewayConfirm($request['payment_method'], $invoice)); diff --git a/app/Utilities/Modules.php b/app/Utilities/Modules.php index 3f2f6acfd..3c0b1eed3 100644 --- a/app/Utilities/Modules.php +++ b/app/Utilities/Modules.php @@ -13,37 +13,55 @@ class Modules public static function getPaymentMethods() { - $payment_methods = Cache::get('payment_methods'); + + $payment_methods = Cache::get('payment_methods.admin'); + + $customer = auth()->user()->customer; + + if ($customer) { + $payment_methods = Cache::get('payment_methods.customer'); + } if (!empty($payment_methods)) { return $payment_methods; } - $gateways = array(); + $gateways = []; + $methods = []; // Fire the event to extend the menu $results = event(new PaymentGatewayListing($gateways)); foreach ($results as $gateways) { foreach ($gateways as $gateway) { + if ($customer && empty($gateway['customer'])) { + continue; + } + $methods[] = $gateway; } } - $sort_order = array(); + $sort_order = []; - foreach ($methods as $key => $value) { - $sort_order[$key] = $value['order']; + if ($methods) { + foreach ($methods as $key => $value) { + $sort_order[$key] = $value['order']; + } + + array_multisort($sort_order, SORT_ASC, $methods); + + foreach ($methods as $method) { + $payment_methods[$method['code']] = $method['name']; + } } - array_multisort($sort_order, SORT_ASC, $methods); - - foreach ($methods as $method) { - $payment_methods[$method['code']] = $method['name']; + if ($customer) { + Cache::put('payment_methods.customer', $payment_methods, Date::now()->addHour(6)); + } else { + Cache::put('payment_methods.admin', $payment_methods, Date::now()->addHour(6)); } - Cache::put('payment_methods', $payment_methods, Date::now()->addHour(6)); - return $payment_methods; } } diff --git a/modules/OfflinePayment/Events/Handlers/OfflinePaymentConfirm.php b/modules/OfflinePayment/Events/Handlers/OfflinePaymentConfirm.php index 84a96580a..9f2b1637d 100644 --- a/modules/OfflinePayment/Events/Handlers/OfflinePaymentConfirm.php +++ b/modules/OfflinePayment/Events/Handlers/OfflinePaymentConfirm.php @@ -14,8 +14,8 @@ class OfflinePaymentConfirm */ public function handle(PaymentGatewayConfirm $event) { - /*if (strpos($event->gateway, 'offlinepayment') === false) { - return false; + if (strpos($event->gateway, 'offlinepayment') === false) { + return []; } return [ @@ -23,6 +23,6 @@ class OfflinePaymentConfirm 'name' => $event->gateway, 'redirect' => false, 'html' => true, - ];*/ + ]; } } diff --git a/modules/OfflinePayment/Http/Controllers/Settings.php b/modules/OfflinePayment/Http/Controllers/Settings.php index 32f632fca..9e3c8587d 100644 --- a/modules/OfflinePayment/Http/Controllers/Settings.php +++ b/modules/OfflinePayment/Http/Controllers/Settings.php @@ -40,6 +40,7 @@ class Settings extends Controller $offlinepayment[$key]['code'] = 'offlinepayment.' . $request['code'] . '.' . $method[2]; $offlinepayment[$key]['name'] = $request['name']; + $offlinepayment[$key]['customer'] = $request['customer']; $offlinepayment[$key]['order'] = $request['order']; $offlinepayment[$key]['description'] = $request['description']; } @@ -48,6 +49,7 @@ class Settings extends Controller $offlinepayment[] = array( 'code' => 'offlinepayment.' . $request['code'] . '.' . (count($offlinepayment) + 1), 'name' => $request['name'], + 'customer' => $request['customer'], 'order' => $request['order'], 'description' => $request['description'] ); @@ -83,6 +85,8 @@ class Settings extends Controller $method['code'] = $code[1]; $data = $method; + + break; } } diff --git a/modules/OfflinePayment/Resources/lang/en-GB/offlinepayment.php b/modules/OfflinePayment/Resources/lang/en-GB/offlinepayment.php index 58253673e..9b702ed82 100644 --- a/modules/OfflinePayment/Resources/lang/en-GB/offlinepayment.php +++ b/modules/OfflinePayment/Resources/lang/en-GB/offlinepayment.php @@ -6,6 +6,7 @@ return [ 'add_new' => 'Add New', 'edit' => 'Edit: :method', 'code' => 'Code', + 'customer' => 'Show to Customer', 'order' => 'Order', 'payment_gateways' => 'Offline Payment Methods', diff --git a/modules/OfflinePayment/Resources/views/edit.blade.php b/modules/OfflinePayment/Resources/views/edit.blade.php index da6dc4fa6..99305c2f1 100644 --- a/modules/OfflinePayment/Resources/views/edit.blade.php +++ b/modules/OfflinePayment/Resources/views/edit.blade.php @@ -20,7 +20,9 @@ {{ Form::textGroup('code', trans('offlinepayment::offlinepayment.code'), 'key', ['required' => 'required'], null, 'col-md-12') }} - {{ Form::textGroup('order', trans('offlinepayment::offlinepayment.order'), 'sort', [], 0, 'col-md-12') }} + {{ Form::radioGroup('customer', trans('offlinepayment::offlinepayment.customer'), '', ['required' => 'required'], 0, 'col-md-12') }} + + {{ Form::textGroup('order', trans('offlinepayment::offlinepayment.order'), 'sort', [], null, 'col-md-12') }} {{ Form::textareaGroup('description', trans('general.description')) }} @@ -109,6 +111,9 @@ @push('scripts')