Merge pull request #683 from cuneytsenturk/offlinepayment-dev

Offline Payment re-factoring
This commit is contained in:
Cüneyt Şentürk 2018-12-18 13:01:25 +03:00 committed by GitHub
commit 76aa41f8fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 107 additions and 91 deletions

View File

@ -1,7 +0,0 @@
<?php
return [
'name' => 'OfflinePayment',
];

View File

@ -4,7 +4,6 @@ namespace Modules\OfflinePayment\Http\Controllers;
use App\Events\InvoicePaid; use App\Events\InvoicePaid;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -16,11 +15,12 @@ use SignedUrl;
class OfflinePayment extends Controller class OfflinePayment extends Controller
{ {
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
* @param Invoice * @param Invoice
* @param PaymentRequest * @param PaymentRequest
* @return Response * @return JSON
*/ */
public function show(Invoice $invoice, PaymentRequest $request) public function show(Invoice $invoice, PaymentRequest $request)
{ {
@ -46,11 +46,12 @@ class OfflinePayment extends Controller
'html' => $html, 'html' => $html,
]); ]);
} }
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
* @param $invoice * @param $invoice
* @param $request * @param $request
* @return Response * @return JSON
*/ */
public function link(Invoice $invoice, PaymentRequest $request) public function link(Invoice $invoice, PaymentRequest $request)
{ {

View File

@ -12,6 +12,7 @@ use Modules\OfflinePayment\Http\Requests\SettingDelete as DRequest;
class Settings extends Controller class Settings extends Controller
{ {
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
* *
@ -66,7 +67,7 @@ class Settings extends Controller
Artisan::call('cache:clear'); Artisan::call('cache:clear');
return redirect('apps/offlinepayment/settings'); return redirect()->route('offlinepayment.edit');
} }
/** /**

View File

@ -1,18 +1,30 @@
<?php <?php
Route::group(['middleware' => ['web', 'auth', 'language', 'adminmenu', 'permission:read-admin-panel'], 'prefix' => 'apps/offlinepayment', 'namespace' => 'Modules\OfflinePayment\Http\Controllers'], function () { Route::group([
Route::get('settings', 'Settings@edit'); 'middleware' => 'admin',
Route::post('settings', 'Settings@update'); 'prefix' => 'apps/offlinepayment',
Route::post('settings/get', 'Settings@get'); 'namespace' => 'Modules\OfflinePayment\Http\Controllers'
Route::post('settings/delete', 'Settings@delete'); ], function () {
Route::get('settings', 'Settings@edit')->name('offlinepayment.edit');
Route::post('settings', 'Settings@update')->name('offlinepayment.update');
Route::post('settings/get', 'Settings@get')->name('offlinepayment.get');
Route::post('settings/delete', 'Settings@delete')->name('offlinepayment.delete');
}); });
Route::group(['middleware' => ['web', 'auth', 'language', 'customermenu', 'permission:read-customer-panel'], 'prefix' => 'customers', 'namespace' => 'Modules\OfflinePayment\Http\Controllers'], function () { Route::group([
'middleware' => ['web', 'auth', 'language', 'customermenu', 'permission:read-customer-panel'],
'prefix' => 'customers',
'namespace' => 'Modules\OfflinePayment\Http\Controllers'
], function () {
Route::get('invoices/{invoice}/offlinepayment', 'OfflinePayment@show'); Route::get('invoices/{invoice}/offlinepayment', 'OfflinePayment@show');
Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm'); Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm');
}); });
Route::group(['middleware' => ['web', 'language'], 'prefix' => 'links', 'namespace' => 'Modules\OfflinePayment\Http\Controllers'], function () { Route::group([
'middleware' => ['web', 'language'],
'prefix' => 'links',
'namespace' => 'Modules\OfflinePayment\Http\Controllers'
], function () {
Route::group(['middleware' => 'signed-url'], function () { Route::group(['middleware' => 'signed-url'], function () {
Route::post('invoices/{invoice}/offlinepayment', 'OfflinePayment@link'); Route::post('invoices/{invoice}/offlinepayment', 'OfflinePayment@link');
Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm'); Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm');

View File

@ -1,12 +1,13 @@
<?php <?php
namespace Modules\OfflinePayment\Events\Handlers; namespace Modules\OfflinePayment\Listeners;
use App\Events\AdminMenuCreated;
use Auth; use Auth;
use App\Events\AdminMenuCreated;
class OfflinePaymentAdminMenu class OfflinePaymentAdminMenu
{ {
/** /**
* Handle the event. * Handle the event.
* *
@ -22,7 +23,7 @@ class OfflinePaymentAdminMenu
// Add child to existing item // Add child to existing item
$item = $event->menu->whereTitle(trans_choice('general.settings', 2)); $item = $event->menu->whereTitle(trans_choice('general.settings', 2));
$item->url('apps/offlinepayment/settings', trans('offlinepayment::offlinepayment.offlinepayment'), 4, ['icon' => 'fa fa-angle-double-right']); $item->url('apps/offlinepayment/settings', trans('offlinepayment::general.title'), 4, ['icon' => 'fa fa-angle-double-right']);
} }
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Modules\OfflinePayment\Events\Handlers; namespace Modules\OfflinePayment\Listeners;
use App\Events\PaymentGatewayListing; use App\Events\PaymentGatewayListing;

View File

@ -3,13 +3,12 @@
namespace Modules\OfflinePayment\Providers; namespace Modules\OfflinePayment\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use App\Events\AdminMenuCreated; use App\Events\AdminMenuCreated;
use Modules\OfflinePayment\Events\Handlers\OfflinePaymentAdminMenu; use Modules\OfflinePayment\Listeners\OfflinePaymentAdminMenu;
use App\Events\PaymentGatewayListing; use App\Events\PaymentGatewayListing;
use Modules\OfflinePayment\Events\Handlers\OfflinePaymentGateway; use Modules\OfflinePayment\Listeners\OfflinePaymentGateway;
class OfflinePaymentServiceProvider extends ServiceProvider class OfflinePaymentServiceProvider extends ServiceProvider
{ {
@ -28,14 +27,10 @@ class OfflinePaymentServiceProvider extends ServiceProvider
public function boot() public function boot()
{ {
$this->registerTranslations(); $this->registerTranslations();
$this->registerConfig();
$this->registerViews(); $this->registerViews();
$this->registerFactories(); $this->registerMigrations();
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); $this->registerEvents();
$this->app['events']->listen(AdminMenuCreated::class, OfflinePaymentAdminMenu::class);
$this->app['events']->listen(PaymentGatewayListing::class, OfflinePaymentGateway::class);
} }
/** /**
@ -48,21 +43,6 @@ class OfflinePaymentServiceProvider extends ServiceProvider
// //
} }
/**
* Register config.
*
* @return void
*/
protected function registerConfig()
{
$this->publishes([
__DIR__.'/../Config/config.php' => config_path('offlinepayment.php'),
], 'config');
$this->mergeConfigFrom(
__DIR__.'/../Config/config.php', 'offlinepayment'
);
}
/** /**
* Register views. * Register views.
* *
@ -99,15 +79,15 @@ class OfflinePaymentServiceProvider extends ServiceProvider
} }
} }
/** public function registerMigrations()
* Register an additional directory of factories.
* @source https://github.com/sebastiaanluca/laravel-resource-flow/blob/develop/src/Modules/ModuleServiceProvider.php#L66
*/
public function registerFactories()
{ {
if (! app()->environment('production')) { $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
app(Factory::class)->load(__DIR__ . '/Database/factories'); }
}
public function registerEvents()
{
$this->app['events']->listen(AdminMenuCreated::class, OfflinePaymentAdminMenu::class);
$this->app['events']->listen(PaymentGatewayListing::class, OfflinePaymentGateway::class);
} }
/** /**

View File

@ -0,0 +1,21 @@
<?php
return [
'title' => 'Offline Payments',
'add_new' => 'Add New',
'edit' => 'Edit: :method',
'form' => [
'code' => 'Code',
'customer' => 'Show to Customer',
'order' => 'Order'
],
'payment_gateways' => 'Offline Payment Methods',
'confirm' => 'Confirm',
'loading' => 'Loading',
];

View File

@ -1,16 +0,0 @@
<?php
return [
'offlinepayment' => 'Offline Payments',
'add_new' => 'Add New',
'edit' => 'Edit: :method',
'code' => 'Code',
'customer' => 'Show to Customer',
'order' => 'Order',
'payment_gateways' => 'Offline Payment Methods',
'confirm' => 'Confirm',
'loading' => 'Loading',
];

View File

@ -4,4 +4,4 @@
<div class="well well-sm"> <div class="well well-sm">
{{ $gateway['description'] }} {{ $gateway['description'] }}
</div> </div>
@endif @endif

View File

@ -1,29 +1,29 @@
@extends('layouts.admin') @extends('layouts.admin')
@section('title', trans('offlinepayment::offlinepayment.offlinepayment')) @section('title', trans('offlinepayment::general.title'))
@section('content') @section('content')
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<div class="box box-success"> <div class="box box-success">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ trans('offlinepayment::offlinepayment.add_new') }}</h3> <h3 class="box-title">{{ trans('offlinepayment::general.add_new') }}</h3>
<!-- /.box-tools --> <!-- /.box-tools -->
</div> </div>
<!-- /.box-header --> <!-- /.box-header -->
{!! Form::open(['url' => 'apps/offlinepayment/settings', 'files' => true, 'role' => 'form']) !!} {!! Form::open(['route' => 'offlinepayment.update', 'files' => true, 'role' => 'form', 'class' => 'form-loading-button']) !!}
<div class="box-body"> <div class="box-body">
<div id="install-loading"></div> <div id="install-loading"></div>
{{ Form::textGroup('name', trans('general.name'), 'id-card-o', ['required' => 'required'], null, 'col-md-12') }} {{ Form::textGroup('name', trans('general.name'), 'id-card-o', ['required' => 'required'], null, 'col-md-12') }}
{{ Form::textGroup('code', trans('offlinepayment::offlinepayment.code'), 'key', ['required' => 'required'], null, 'col-md-12') }} {{ Form::textGroup('code', trans('offlinepayment::general.form.code'), 'key', ['required' => 'required'], null, 'col-md-12') }}
{{ Form::radioGroup('customer', trans('offlinepayment::offlinepayment.customer'), '', ['required' => 'required'], 0, 'col-md-12') }} {{ Form::radioGroup('customer', trans('offlinepayment::general.form.customer'), '', ['required' => 'required'], 0, 'col-md-12') }}
{{ Form::textGroup('order', trans('offlinepayment::offlinepayment.order'), 'sort', [], null, 'col-md-12') }} {{ Form::textGroup('order', trans('offlinepayment::general.form.order'), 'sort', [], null, 'col-md-12') }}
{{ Form::textareaGroup('description', trans('general.description')) }} {{ Form::textareaGroup('description', trans('general.description')) }}
</div> </div>
@ -38,22 +38,25 @@
</div> </div>
<!-- /.box --> <!-- /.box -->
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
<!-- Default box --> <!-- Default box -->
<div class="box box-success"> <div class="box box-success">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ trans('offlinepayment::offlinepayment.payment_gateways') }}</h3> <h3 class="box-title">{{ trans('offlinepayment::general.payment_gateways') }}</h3>
<!-- /.box-tools --> <!-- /.box-tools -->
</div> </div>
<!-- /.box-header --> <!-- /.box-header -->
<div class="box-body"> <div class="box-body">
<div id="delete-loading"></div>
<div class="table table-responsive"> <div class="table table-responsive">
<table class="table table-striped table-hover" id="tbl-items"> <table class="table table-striped table-hover" id="tbl-items">
<thead> <thead>
<tr> <tr>
<th class="col-md-3">{{ trans('general.name') }}</th> <th class="col-md-3">{{ trans('general.name') }}</th>
<th class="col-md-4">{{ trans('offlinepayment::offlinepayment.code') }}</th> <th class="col-md-4">{{ trans('offlinepayment::general.form.code') }}</th>
<th class="col-md-2 text-center">{{ trans('offlinepayment::offlinepayment.order') }}</th> <th class="col-md-2 text-center">{{ trans('offlinepayment::general.form.order') }}</th>
<th class="col-md-3">{{ trans('general.actions') }}</th> <th class="col-md-3">{{ trans('general.actions') }}</th>
</tr> </tr>
</thead> </thead>
@ -86,13 +89,14 @@
@push('stylesheet') @push('stylesheet')
<style type="text/css"> <style type="text/css">
.install-loading-bar { #install-loading.active, #delete-loading.active {
font-size: 35px; font-size: 35px;
position: absolute; position: absolute;
z-index: 500; z-index: 500;
top: 0px; top: 0px;
left: 0px; left: 0px;
width: 100%; width: 100%;
height: 100%;
background: rgb(136, 136, 136); background: rgb(136, 136, 136);
opacity: 0.2; opacity: 0.2;
-moz-border-radius-bottomleft: 1px; -moz-border-radius-bottomleft: 1px;
@ -106,7 +110,11 @@
position: absolute; position: absolute;
margin: auto; margin: auto;
color: #fff; color: #fff;
padding: 28% 40%; padding: 45% 40%;
}
#delete-loading .install-loading-spin {
padding: 8% 40%;
} }
</style> </style>
@endpush @endpush
@ -115,22 +123,25 @@
<script type="text/javascript"> <script type="text/javascript">
var text_yes = '{{ trans('general.yes') }}'; var text_yes = '{{ trans('general.yes') }}';
var text_no = '{{ trans('general.no') }}'; var text_no = '{{ trans('general.no') }}';
var code = '';
var tr = '';
$(document).ready(function() { $(document).ready(function() {
$('.method-edit').on('click', function() { $('.method-edit').on('click', function() {
var code = $(this).attr('id').replace('edit-', ''); code = $(this).attr('id').replace('edit-', '');
$.ajax({ $.ajax({
url: '{{ url("apps/offlinepayment/settings/get") }}', url: '{{ route("offlinepayment.get") }}',
type: 'post', type: 'post',
dataType: 'json', dataType: 'json',
data: {code: code}, data: {code: code},
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' }, headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
beforeSend: function() { beforeSend: function() {
$('#install-loading').addClass('active');
$('#install-loading').html('<span class="install-loading-bar"><span class="install-loading-spin"><i class="fa fa-spinner fa-spin"></i></span></span>'); $('#install-loading').html('<span class="install-loading-bar"><span class="install-loading-spin"><i class="fa fa-spinner fa-spin"></i></span></span>');
$('.install-loading-bar').css({"height": $('.col-md-4.no-padding-left').height() - 23});
}, },
complete: function() { complete: function() {
$('#install-loading').removeClass('active');
$('#install-loading .install-loading-bar').remove(); $('#install-loading .install-loading-bar').remove();
}, },
success: function(json) { success: function(json) {
@ -160,20 +171,30 @@
}); });
$('.method-delete').on('click', function() { $('.method-delete').on('click', function() {
var code = $(this).attr('id').replace('delete-', ''); code = $(this).attr('id').replace('delete-', '');
tr = $(this).parent().parent();
$.ajax({ $.ajax({
url: '{{ url("apps/offlinepayment/settings/delete") }}', url: '{{ route("offlinepayment.delete") }}',
type: 'post', type: 'post',
dataType: 'json', dataType: 'json',
data: {code: code}, data: {code: code},
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' }, headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
beforeSend: function() {
$('#delete-loading').addClass('active');
$('#delete-loading').html('<span class="install-loading-bar"><span class="install-loading-spin"><i class="fa fa-spinner fa-spin"></i></span></span>');
},
complete: function() {
//$('#delete-loading').removeClass('active');
//$('#delete-loading .install-loading-bar').remove();
},
success: function(json) { success: function(json) {
if (json['error']) { if (json['error']) {
} }
if (json['success']) { if (json['success']) {
$('#method-' + code).remove(); $('#method-' + code).remove();
location.reload();
} }
} }
}); });

View File

@ -5,9 +5,10 @@
{{ $gateway['description'] }} {{ $gateway['description'] }}
</div> </div>
@endif @endif
<div class="buttons"> <div class="buttons">
<div class="pull-right"> <div class="pull-right">
<input type="button" value="{{ trans('offlinepayment::offlinepayment.confirm') }}" id="button-confirm" class="btn btn-success" data-loading-text="{{ trans('offlinepayment::offlinepayment.loading') }}" /> <input type="button" value="{{ trans('offlinepayment::general.confirm') }}" id="button-confirm" class="btn btn-success" data-loading-text="{{ trans('offlinepayment::general.loading') }}" />
</div> </div>
</div> </div>
<script type="text/javascript"><!-- <script type="text/javascript"><!--

View File

@ -5,9 +5,10 @@
{{ $gateway['description'] }} {{ $gateway['description'] }}
</div> </div>
@endif @endif
<div class="buttons"> <div class="buttons">
<div class="pull-right"> <div class="pull-right">
<input type="button" value="{{ trans('offlinepayment::offlinepayment.confirm') }}" id="button-confirm" class="btn btn-success" data-loading-text="{{ trans('offlinepayment::offlinepayment.loading') }}" /> <input type="button" value="{{ trans('offlinepayment::general.confirm') }}" id="button-confirm" class="btn btn-success" data-loading-text="{{ trans('offlinepayment::general.loading') }}" />
</div> </div>
</div> </div>
<script type="text/javascript"><!-- <script type="text/javascript"><!--

View File

@ -2,8 +2,8 @@
"name": "OfflinePayment", "name": "OfflinePayment",
"alias": "offlinepayment", "alias": "offlinepayment",
"description": "", "description": "",
"version": "1.0.0", "version": "1.0.1",
"category": "payment-gateways", "category": "payment-gateway",
"keywords": [], "keywords": [],
"active": 1, "active": 1,
"order": 0, "order": 0,