Offline payment method for customer
This commit is contained in:
parent
6e7b9d6964
commit
994998dc0b
@ -4,9 +4,12 @@ namespace App\Http\Controllers\Customers;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Customer\InvoicePayment as PaymentRequest;
|
use App\Http\Requests\Customer\InvoicePayment as PaymentRequest;
|
||||||
|
use App\Http\Requests\Customer\InvoiceConfirm as ConfirmRequest;
|
||||||
use App\Models\Banking\Account;
|
use App\Models\Banking\Account;
|
||||||
use App\Models\Income\Customer;
|
use App\Models\Income\Customer;
|
||||||
use App\Models\Income\Invoice;
|
use App\Models\Income\Invoice;
|
||||||
|
use App\Models\Income\InvoicePayment;
|
||||||
|
use App\Models\Income\InvoiceHistory;
|
||||||
use App\Models\Income\InvoiceStatus;
|
use App\Models\Income\InvoiceStatus;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
use App\Models\Setting\Currency;
|
use App\Models\Setting\Currency;
|
||||||
@ -14,7 +17,7 @@ use App\Traits\Currencies;
|
|||||||
use App\Traits\DateTime;
|
use App\Traits\DateTime;
|
||||||
use App\Traits\Uploads;
|
use App\Traits\Uploads;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Jenssegers\Date\Date;
|
use Date;
|
||||||
|
|
||||||
use App\Events\PaymentGatewayConfirm;
|
use App\Events\PaymentGatewayConfirm;
|
||||||
|
|
||||||
@ -176,13 +179,73 @@ class Invoices extends Controller
|
|||||||
public function payment(Invoice $invoice, PaymentRequest $request)
|
public function payment(Invoice $invoice, PaymentRequest $request)
|
||||||
{
|
{
|
||||||
if (!$invoice) {
|
if (!$invoice) {
|
||||||
return response()->json(
|
return response()->json([
|
||||||
|
'error' => trans('You can not pay this invoice. Because it is not yours')
|
||||||
);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire the event to extend the menu
|
// Fire the event to extend the menu
|
||||||
$result = event(new PaymentGatewayConfirm($request['payment_method'], $invoice));
|
$responses = event(new PaymentGatewayConfirm($request['payment_method'], $invoice));
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'name' => null,
|
||||||
|
'code' => null,
|
||||||
|
'description' => null,
|
||||||
|
'redirect' => false,
|
||||||
|
'html' => null,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($responses as $response) {
|
||||||
|
if ($response) {
|
||||||
|
$result = $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json($result);
|
return response()->json($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function confirm(Invoice $invoice, ConfirmRequest $request)
|
||||||
|
{
|
||||||
|
$request['invoice_id'] = $invoice->id;
|
||||||
|
$request['account_id'] = setting('general.default_account');
|
||||||
|
|
||||||
|
if (!isset($request['amount'])) {
|
||||||
|
$request['amount'] = $invoice->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request['currency_code'] = $invoice->currency_code;
|
||||||
|
$request['currency_rate'] = $invoice->currency_rate;
|
||||||
|
|
||||||
|
$request['paid_at'] = Date::parse('now')->format('Y-m-d');
|
||||||
|
|
||||||
|
if ($request['amount'] > $invoice->amount) {
|
||||||
|
$message = trans('messages.error.added', ['type' => trans_choice('general.payment', 1)]);
|
||||||
|
|
||||||
|
return response()->json($message);
|
||||||
|
} elseif ($request['amount'] == $invoice->amount) {
|
||||||
|
$invoice->invoice_status_code = 'paid';
|
||||||
|
} else {
|
||||||
|
$invoice->invoice_status_code = 'partial';
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoice->save();
|
||||||
|
|
||||||
|
InvoicePayment::create($request->input());
|
||||||
|
|
||||||
|
$request['status_code'] = $invoice->invoice_status_code;
|
||||||
|
|
||||||
|
$request['notify'] = 0;
|
||||||
|
|
||||||
|
$desc_date = Date::parse($request['paid_at'])->format($this->getCompanyDateFormat());
|
||||||
|
|
||||||
|
$desc_amount = money((float) $request['amount'], $request['currency_code'], true)->format();
|
||||||
|
|
||||||
|
$request['description'] = $desc_date . ' ' . $desc_amount;
|
||||||
|
|
||||||
|
InvoiceHistory::create($request->input());
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
30
app/Http/Requests/Customer/InvoiceConfirm.php
Normal file
30
app/Http/Requests/Customer/InvoiceConfirm.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Customer;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
|
||||||
|
class InvoiceConfirm 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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -18,11 +18,28 @@ class OfflinePaymentConfirm
|
|||||||
return [];
|
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 [
|
return [
|
||||||
'code' => $event->gateway,
|
'code' => $gateway['code'],
|
||||||
'name' => $event->gateway,
|
'name' => $gateway['name'],
|
||||||
|
'description' => $gateway['description'],
|
||||||
'redirect' => false,
|
'redirect' => false,
|
||||||
'html' => true,
|
'html' => $html,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,4 +10,7 @@ return [
|
|||||||
'order' => 'Order',
|
'order' => 'Order',
|
||||||
'payment_gateways' => 'Offline Payment Methods',
|
'payment_gateways' => 'Offline Payment Methods',
|
||||||
|
|
||||||
|
'confirm' => 'Confirm',
|
||||||
|
'loading' => 'Loading',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
35
modules/OfflinePayment/Resources/views/confirm.blade.php
Normal file
35
modules/OfflinePayment/Resources/views/confirm.blade.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<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 . "/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['success']) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
//--></script>
|
4
public/css/app.css
vendored
4
public/css/app.css
vendored
@ -241,10 +241,10 @@ div.required .control-label:not(span):after, td.required:after {
|
|||||||
left: 40%;
|
left: 40%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.confirm #loading {
|
#confirm #loading {
|
||||||
position: inherit;
|
position: inherit;
|
||||||
top: 40%;
|
top: 40%;
|
||||||
left: 40%;
|
left: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#payment-modal .form-group.col-md-6 .help-block {
|
#payment-modal .form-group.col-md-6 .help-block {
|
||||||
|
@ -151,15 +151,17 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-2">
|
<div class="col-md-2">
|
||||||
@if ($payment_methods)
|
@if($invoice->invoice_status_code != 'paid')
|
||||||
{!! Form::select('payment_method', $payment_methods, null, array_merge(['id' => 'payment-method', 'class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.payment_methods', 1)])])) !!}
|
@if ($payment_methods)
|
||||||
{!! Form::hidden('invoice_id', $invoice->id, []) !!}
|
{!! Form::select('payment_method', $payment_methods, null, array_merge(['id' => 'payment-method', 'class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.payment_methods', 1)])])) !!}
|
||||||
@else
|
{!! Form::hidden('invoice_id', $invoice->id, []) !!}
|
||||||
|
@else
|
||||||
|
|
||||||
|
@endif
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="confirm"></div>
|
<div id="confirm" class="col-md-12"></div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
@ -170,21 +172,29 @@
|
|||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$(document).on('change', '#payment-method', function (e) {
|
$(document).on('change', '#payment-method', function (e) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '{{ url("customers/invoices/" . $invoice->id . "payment") }}',
|
url: '{{ url("customers/invoices/" . $invoice->id . "/payment") }}',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
data: $('.box-footer input, .box-footer select'),
|
data: $('.box-footer input, .box-footer select'),
|
||||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||||
beforeSend: function() {
|
beforeSend: function() {
|
||||||
$('.confirm').append('<div id="loading" class="text-center"><i class="fa fa-spinner fa-spin fa-5x checkout-spin"></i></div>');
|
$('#confirm').append('<div id="loading" class="text-center"><i class="fa fa-spinner fa-spin fa-5x checkout-spin"></i></div>');
|
||||||
},
|
},
|
||||||
complete: function() {
|
complete: function() {
|
||||||
$('#loading').remove();
|
$('#loading').remove();
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$("#payment-modal").modal('hide');
|
if (data['erorr']) {
|
||||||
|
|
||||||
//location.reload();
|
}
|
||||||
|
|
||||||
|
if (data['redirect']) {
|
||||||
|
location = data['redirect'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data['html']) {
|
||||||
|
$('#confirm').append(data['html']);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function(data){
|
error: function(data){
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ Route::group(['middleware' => 'language'], function () {
|
|||||||
Route::get('invoices/{invoice}/print', 'Customers\Invoices@printInvoice');
|
Route::get('invoices/{invoice}/print', 'Customers\Invoices@printInvoice');
|
||||||
Route::get('invoices/{invoice}/pdf', 'Customers\Invoices@pdfInvoice');
|
Route::get('invoices/{invoice}/pdf', 'Customers\Invoices@pdfInvoice');
|
||||||
Route::post('invoices/{invoice}/payment', 'Customers\Invoices@payment');
|
Route::post('invoices/{invoice}/payment', 'Customers\Invoices@payment');
|
||||||
|
Route::post('invoices/{invoice}/confirm', 'Customers\Invoices@confirm');
|
||||||
Route::resource('invoices', 'Customers\Invoices');
|
Route::resource('invoices', 'Customers\Invoices');
|
||||||
Route::resource('payments', 'Customers\Payments');
|
Route::resource('payments', 'Customers\Payments');
|
||||||
Route::resource('transactions', 'Customers\Transactions');
|
Route::resource('transactions', 'Customers\Transactions');
|
||||||
@ -161,4 +162,4 @@ Route::group(['middleware' => 'language'], function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user