feat: Render all available payment gateways from controller

This commit is contained in:
IceToast 2023-01-14 23:34:10 +01:00
parent 69dd7a6855
commit 1f79a19943

View file

@ -10,8 +10,7 @@
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<ol class="breadcrumb float-sm-right"> <ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a class="" <li class="breadcrumb-item"><a class="" href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a class="text-muted" <li class="breadcrumb-item"><a class="text-muted"
href="{{ route('store.index') }}">{{ __('Store') }}</a> href="{{ route('store.index') }}">{{ __('Store') }}</a>
</li> </li>
@ -23,13 +22,15 @@
<!-- END CONTENT HEADER --> <!-- END CONTENT HEADER -->
<!-- MAIN CONTENT --> <!-- MAIN CONTENT -->
<section x-data="serverApp()" x-init="$watch('paymentMethod', value => setPaymentRoute(value))" class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<form action="{{ route('payment.pay') }}" method="POST">
@csrf
@method('post')
<!-- Main content --> <!-- Main content -->
<div class="invoice p-3 mb-3"> <div class="invoice p-3 mb-3">
<!-- title row --> <!-- title row -->
@ -67,6 +68,7 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<input type="hidden" name="product_id" value="{{ $product->id }}">
</div> </div>
<!-- /.col --> <!-- /.col -->
</div> </div>
@ -75,33 +77,19 @@
<div class="row"> <div class="row">
<!-- accepted payments column --> <!-- accepted payments column -->
<div class="col-6"> <div class="col-6">
@if($total!=0)
<p class="lead">{{ __('Payment Methods') }}:</p> <p class="lead">{{ __('Payment Methods') }}:</p>
<div> <div>
@if (config('SETTINGS::PAYMENTS:PAYPAL:SECRET') || config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET')) @foreach ($paymentGateways as $gateway)
<label class="text-center " for="paypal"> <label class="text-center" for="{{ $gateway->name }}">
<img class="mb-3" height="50" <img class="mb-3" height="50" src="{{ $gateway->image }}"></br>
src="{{ url('/images/paypal_logo.png') }}"></br> <input x-model="payment_method" type="radio" id="{{ $gateway->name }}"
value="{{ $gateway->name }}" name="payment_method">
<input x-model="paymentMethod" type="radio" id="paypal" value="paypal"
name="payment_method">
</input> </input>
</label> </label>
@endif @endforeach
@if (config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') || config('SETTINGS::PAYMENTS:STRIPE:SECRET'))
<label class="ml-5 text-center " for="stripe">
<img class="mb-3" height="50"
src="{{ url('/images/stripe_logo.png') }}" /></br>
<input x-model="paymentMethod" type="radio" id="stripe" value="stripe"
name="payment_method">
</input>
</label>
@endif
</div> </div>
@else
<p class="lead" style="text-align: center">{{ __('This product is free for you') }}.</p>
@endif
</div> </div>
<!-- /.col --> <!-- /.col -->
<div class="col-6"> <div class="col-6">
@ -110,10 +98,10 @@
<div class="table-responsive"> <div class="table-responsive">
<table class="table"> <table class="table">
@if($discountpercent&&$discountvalue) @if ($discountpercent && $discountvalue)
<tr> <tr>
<th>{{ __('Discount') }} ({{ $discountpercent }}%):</th> <th>{{ __('Discount') }} ({{ $discountpercent }}%):</th>
<td>{{$product->formatToCurrency($discountvalue)}}</td> <td>{{ $product->formatToCurrency($discountvalue) }}</td>
</tr> </tr>
@endif @endif
<tr> <tr>
@ -138,42 +126,19 @@
<!-- this row will not appear when printing --> <!-- this row will not appear when printing -->
<div class="row no-print"> <div class="row no-print">
<div class="col-12"> <div class="col-12">
<a type="button" :href="paymentRoute" :disabled="!paymentRoute" <button x-on="console.log('Method', paymentMethod)" :disabled="!paymentMethod"
:class="!paymentRoute ? 'disabled' : ''" class="btn btn-success float-right"><i :class="!paymentMethod ? 'disabled' : ''" class="btn btn-success float-right"><i
class="far fa-credit-card mr-2"></i> class="far fa-credit-card mr-2"></i>
{{ __('Submit Payment') }} {{ __('Submit Payment') }}
</a> </button>
</div> </div>
</div> </div>
</div> </div>
</form>
<!-- /.invoice --> <!-- /.invoice -->
</div><!-- /.col --> </div><!-- /.col -->
</div><!-- /.row --> </div><!-- /.row -->
</div> </div>
</section> </section>
<!-- END CONTENT --> <!-- END CONTENT -->
<script>
function serverApp() {
return {
//loading
paymentMethod: '',
paymentRoute: ({{ $total }} == 0)?('{{ route('payment.FreePay', $product->id) }}'):'',
setPaymentRoute(provider) {
switch (provider) {
case 'paypal':
this.paymentRoute = '{{ route('payment.PaypalPay', $product->id) }}';
break;
case 'stripe':
this.paymentRoute = '{{ route('payment.StripePay', $product->id) }}';
break;
default:
this.paymentRoute = '{{ route('payment.PaypalPay', $product->id) }}';
}
},
}
}
</script>
@endsection @endsection