Skip to content

Commit

Permalink
Offlinepayment compability invoice unique link feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Oct 15, 2018
1 parent 3ba1dcb commit 12aa503
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
33 changes: 33 additions & 0 deletions modules/OfflinePayment/Http/Controllers/OfflinePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Http\Requests\Customer\InvoiceConfirm as ConfirmRequest;

use App\Models\Income\Invoice;
use SignedUrl;

class OfflinePayment extends Controller
{
Expand Down Expand Up @@ -45,6 +46,38 @@ public function show(Invoice $invoice, PaymentRequest $request)
'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)
{
Expand Down
7 changes: 7 additions & 0 deletions modules/OfflinePayment/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@
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');
});
});
39 changes: 39 additions & 0 deletions modules/OfflinePayment/Resources/views/link.blade.php
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 12aa503

Please sign in to comment.