Fixed Offline Payment method for Customer

This commit is contained in:
Cüneyt Şentürk
2017-11-19 02:52:01 +03:00
parent 994998dc0b
commit 021b853127
14 changed files with 212 additions and 146 deletions

View File

@ -28,6 +28,7 @@ class OfflineFile extends Migration
$offlinepayment[] = array(
'code' => 'offlinepayment.' . $code[1] . '.' . $code[2],
'name' => $offline_payment['name'],
'customer' => 0,
'order' => $offline_payment['order'],
'description' => $offline_payment['description']
);

View File

@ -29,6 +29,7 @@ class OfflinePaymentDatabaseSeeder extends Seeder
$methods[] = array(
'code' => 'offlinepayment.cash.1',
'name' => 'Cash',
'customer' => '0',
'order' => '1',
'description' => null,
);
@ -36,6 +37,7 @@ class OfflinePaymentDatabaseSeeder extends Seeder
$methods[] = array(
'code' => 'offlinepayment.bank_transfer.2',
'name' => 'Bank Transfer',
'customer' => '0',
'order' => '2',
'description' => null,
);

View File

@ -1,45 +0,0 @@
<?php
namespace Modules\OfflinePayment\Events\Handlers;
use App\Events\PaymentGatewayConfirm;
class OfflinePaymentConfirm
{
/**
* Handle the event.
*
* @param PaymentGatewayConfirm $event
* @return void
*/
public function handle(PaymentGatewayConfirm $event)
{
if (strpos($event->gateway, 'offlinepayment') === false) {
return [];
}
$invoice = $event->invoice;
$gateway = [];
$payment_methods = json_decode(setting('offlinepayment.methods'), true);
foreach ($payment_methods as $payment_method) {
if ($payment_method['code'] == $event->gateway) {
$gateway = $payment_method;
break;
}
}
$html = view('offlinepayment::confirm', compact('gateway', 'invoice'))->render();
return [
'code' => $gateway['code'],
'name' => $gateway['name'],
'description' => $gateway['description'],
'redirect' => false,
'html' => $html,
];
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace Modules\OfflinePayment\Http\Controllers;
use App\Events\InvoicePaid;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use App\Http\Requests\Customer\InvoicePayment as PaymentRequest;
use App\Http\Requests\Customer\InvoiceConfirm as ConfirmRequest;
use App\Models\Income\Invoice;
class OfflinePayment extends Controller
{
/**
* Show the form for editing the specified resource.
* @param Invoice
* @param PaymentRequest
* @return Response
*/
public function show(Invoice $invoice, PaymentRequest $request)
{
$gateway = [];
$payment_methods = json_decode(setting('offlinepayment.methods'), true);
foreach ($payment_methods as $payment_method) {
if ($payment_method['code'] == $request['payment_method']) {
$gateway = $payment_method;
break;
}
}
$html = view('offlinepayment::show', compact('gateway', 'invoice'))->render();
return response()->json([
'code' => $gateway['code'],
'name' => $gateway['name'],
'description' => $gateway['description'],
'redirect' => false,
'html' => $html,
]);
}
public function confirm(Invoice $invoice, ConfirmRequest $request)
{
$result = event(new InvoicePaid($invoice, $request));
return response()->json($result);
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Modules\OfflinePayment\Http\Requests;
use App\Http\Requests\Request;
class Show extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'payment_method' => 'required|string',
];
}
}

View File

@ -6,3 +6,8 @@ Route::group(['middleware' => ['web', 'auth', 'language', 'adminmenu', 'permissi
Route::post('settings/get', 'Settings@get');
Route::post('settings/delete', 'Settings@delete');
});
Route::group(['prefix' => 'customers', 'namespace' => 'Modules\OfflinePayment\Http\Controllers'], function () {
Route::get('invoices/{invoice}/offlinepayment', 'OfflinePayment@show');
Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm');
});

View File

@ -11,9 +11,6 @@ use Modules\OfflinePayment\Events\Handlers\OfflinePaymentAdminMenu;
use App\Events\PaymentGatewayListing;
use Modules\OfflinePayment\Events\Handlers\OfflinePaymentGateway;
use App\Events\PaymentGatewayConfirm;
use Modules\OfflinePayment\Events\Handlers\OfflinePaymentConfirm;
class OfflinePaymentServiceProvider extends ServiceProvider
{
/**
@ -39,7 +36,6 @@ class OfflinePaymentServiceProvider extends ServiceProvider
$this->app['events']->listen(AdminMenuCreated::class, OfflinePaymentAdminMenu::class);
$this->app['events']->listen(PaymentGatewayListing::class, OfflinePaymentGateway::class);
$this->app['events']->listen(PaymentGatewayConfirm::class, OfflinePaymentConfirm::class);
}
/**

View File

@ -0,0 +1,39 @@
<h2>{{ $gateway['name'] }}</h2>
@if ($gateway['description'])
<div class="well well-sm">
{{ $gateway['description'] }}
</div>
@endif
<div class="buttons">
<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') }}" />
</div>
</div>
<script type="text/javascript"><!--
$('#button-confirm').on('click', function() {
$.ajax({
url: '{{ url("customers/invoices/" . $invoice->id . "/offlinepayment/confirm") }}',
type: 'POST',
dataType: 'JSON',
data: {payment_method: '{{ $gateway['code'] }}'},
cache: false,
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
beforeSend: function() {
$('#button-confirm').button('loading');
},
complete: function() {
$('#button-confirm').button('reset');
},
success: function(data) {
if (data['error']) {
alert(data['error']);
}
if (data['success']) {
location.reload();
}
}
});
});
//--></script>