Offlinepayment compability invoice unique link feature

This commit is contained in:
cuneytsenturk 2018-10-15 16:44:43 +03:00
parent 3ba1dcbf51
commit 12aa503cf0
3 changed files with 79 additions and 0 deletions

View File

@ -12,6 +12,7 @@ use App\Http\Requests\Customer\InvoicePayment as PaymentRequest;
use App\Http\Requests\Customer\InvoiceConfirm as ConfirmRequest;
use App\Models\Income\Invoice;
use SignedUrl;
class OfflinePayment extends Controller
{
@ -45,6 +46,38 @@ class OfflinePayment extends Controller
'html' => $html,
]);
}
/**
* Show the form for editing the specified resource.
* @param Invoice
* @param PaymentRequest
* @return Response
*/
public function link(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;
}
}
$confirm_action = SignedUrl::sign(url('links/invoices/' . $invoice->id . '/offlinepayment/confirm'), 1);
$html = view('offlinepayment::link', compact('gateway', 'invoice', 'confirm_action'))->render();
return response()->json([
'code' => $gateway['code'],
'name' => $gateway['name'],
'description' => $gateway['description'],
'redirect' => false,
'html' => $html,
]);
}
public function confirm(Invoice $invoice, Request $request)
{

View File

@ -11,3 +11,10 @@ Route::group(['middleware' => ['web', 'auth', 'language', 'customermenu', 'permi
Route::get('invoices/{invoice}/offlinepayment', 'OfflinePayment@show');
Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm');
});
Route::group(['middleware' => ['web', 'language'], 'prefix' => 'links', 'namespace' => 'Modules\OfflinePayment\Http\Controllers'], function () {
Route::group(['middleware' => 'signed-url'], function () {
Route::post('invoices/{invoice}/offlinepayment', 'OfflinePayment@link');
Route::post('invoices/{invoice}/offlinepayment/confirm', 'OfflinePayment@confirm');
});
});

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: '{!! urldecode($confirm_action) !!}',
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>