@extends('include.dashboard')
@section('content2')

                 <div class="nk-content">
                        <div class="container-fluid">
                            <div class="nk-content-inner">
                    <br>
                        <div class="nk-block-head nk-block-head-xs text-center">
                            <h5 class="nk-block-title">Confirm Package</h5>
                            <div class="nk-block-text">
                                <div class="caption-text">You are about to make payment of <strong>{{$basic->currency_sym}}{{number_format(App\Plan::whereId(Auth::user()->plan_id)->first()->price, $basic->decimal)}}</strong>
                                  for the purchase of {{$pack->name}} Network Package<br><small> You will earn {{$pack->discount}}% for every purchase</small></div>

                            </div>
                        </div>
                        <div class="nk-block">
                            <div class="buysell-overview">
                                <ul class="buysell-overview-list">
                                    <li class="buysell-overview-item">
                                        <span class="pm-title">Package</span><span class="pm-currency"><em class="icon ni ni-$gate->val7}}"></em> <span>

                                        {{$pack->name}}.
                                         </span></span>
                                    </li>
                                    <li class="buysell-overview-item"><span class="pm-title">Price</span><span class="pm-currency">{{$basic->currency_sym}}{{number_format($pack->price, $basic->decimal)}}</span></li>
                                </ul>

                            </div>





                           <!-- <div class="buysell-field form-action text-center">

                              <div class="nk-block nk-block-lg">
                                <div class="nk-block-head">
                                    <h5 class="nk-block-title">Package Matrix Details</h5>
                                </div>
                                <div class="card card-bordered">
                                    <table class="table table-iv-tnx">
                                        <thead class="thead-light">
                                            <tr>
                                                <th class="tb-col-type"><span class="overline-title">Level</span></th>
                                                <th class="tb-col-date"><span class="overline-title">Downlines</span></th>
                                                <th class="tb-col-date"><span class="overline-title">Commission</span></th>
                                                <th class="tb-col-time tb-col-end"><span class="overline-title">Total</span></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($plans as $data)
                                        @php $totalreturn = 0; @endphp
                                        @php $totalusers = 0; @endphp
                                        @foreach($data->plan_level as $key => $lv)
                                        @if($key+1 <= $basic->matrix_height)
                                            <tr>
                                                <td class="tb-col-type"><span class="sub-text">@lang('Level'.$lv->level.' ')</span></td>
                                                <td class="tb-col-date"><span class="sub-text">{{pow($basic->matrix_width,$key+1)}} Users</span></td>
                                                <td class="tb-col-date"><span class="sub-text">{{$basic->currency_sym}} {{number_format($lv->amount,2)}}</span></td>
                                                <td class="tb-col-time tb-col-end"><span class="lead-text text-primary"> {{$basic->currency_sym}}@php $ret = $lv->amount*pow($basic->matrix_width,$key+1) @endphp {{number_format($ret, 2)}}</span></td>
                                            </tr>
                                        @php $totalreturn += $lv->amount*pow($basic->matrix_width,$key+1); @endphp
                                        @php $totalusers += 1*pow($basic->matrix_width,$key+1); @endphp
                                        @endif
                                        @endforeach
                                        @endforeach


                                        </tbody>
                                    </table>


                                     <table class="table table-iv-tnx">
                                        <thead class="thead-light">
                                            <tr>
                                                <th class="tb-col-type"><span class="overline-title">Total Downlines</span></th>
                                                <th class="tb-col-date"><span class="overline-title">Total Earnings</span></th>
                                                <th class="tb-col-time tb-col-end"><span class="overline-title">Percentage Earning</span></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td class="tb-col-type"><span class="sub-text">{{$totalusers}} Downlines</span></td>
                                                <td class="tb-col-date"><span class="sub-text text-primary"> {{$basic->currency_sym}} {{number_format($totalreturn,2)}}</span></td>
                                                <td class="tb-col-time tb-col-end"><span class="lead-text text-info">{{intval($totalreturn/$data->price*100)}}%</span></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div><!-- .card -->
                          


<br>
<div class="pay-buttons"><div class="pay-button">

@if($gate->id == 100)
@section('scripts')
<script src="https://api.ravepay.co/flwv3-pug/getpaidx/api/flwpbf-inline.js"></script>

    <script>
			const API_publicKey = "{{ $gate->val1 }}";
			function payWithRave() {
			var x = getpaidSetup({
			PBFPubKey: API_publicKey,
			customer_email: "{{ Auth::user()->email }}",
			amount: "{{ round(App\Plan::whereId(Auth::user()->plan_id)->first()->price, 2)}}",
			customer_phone: "{{ Auth::user()->mobile }}",
			currency: "NGN",
			txref: "rave-123456",
		    payment_options: "card",
			meta: [{
			metaname: "flightID",
			metavalue: "AP1234"
			}],
			onclose: function() {},
			callback: function(response) {
			var txref = response.tx.txRef; // collect txRef returned and pass to a 					server page to complete status check.
			console.log("This is the response returned after a charge", response);
			if (
			response.tx.chargeResponseCode == "00" ||
			response.tx.chargeResponseCode == "0"
			) {

			  swal("Payment successful",{

                closeOnClickOutside: false,
                title: 'Successful!',
                     icon: 'success',
                }).then(function() {
                   window.location='javascript: submitform()';
                });


			} else {
			// redirect to a failure page.
			}

			x.close(); // use this to close the modal immediately after payment.
			}
			});
			}
			</script>
@endsection

<badge  onClick="payWithRave()" class="btn btn-primary btn-lg">Buy Plan With Flutterwave<em class="ti ti-wallet"></em></badge>
@elseif($gate->id == 107)

<badge onclick="payWithPaystack()" class="btn btn-primary btn-lg">Buy Plan With Paystack <em class="ti ti-wallet"></em></badge>

@section('scripts')
 <script>
						function payWithPaystack(){
						var handler = PaystackPop.setup({
						key: "{{ $gate->val1 }}",
						email: "{{ Auth::user()->email }}",
						amount: "{{ round(App\Plan::whereId(Auth::user()->plan_id)->first()->price, 2)*100 }}",
						currency: "NGN",
						ref: ''+Math.floor((Math.random() * 1000000000) + 1), // generates a pseudo-unique reference. Please replace with a reference you generated. Or remove the line entirely so our API will generate one for you
						firstname: '',
						lastname: '',
						// label: "Optional string that replaces customer email"
						metadata: {
						custom_fields: [
						{
						display_name: "Mobile Number",
						variable_name: "",
						value: "+2348012345678"
						}
						]
						},
						callback: function(response){
						alert('Payment successful. transaction reference number is ' + response.reference);
						 document.getElementById("code").value = response.reference;
						window.location='javascript: submitform()';
						},
						onClose: function(){
						alert('window closed');
						}
						});
						handler.openIframe();
						}
						</script>



<script src="https://js.paystack.co/v1/inline.js"></script>
@endsection
                </div>
                </div>
                </div>
@endif</div>
<br>
 <div class="sub-text-sm center">* Payment gateway may charge you . <a href="#">transaction fee</a></div>                           </div>
                        </div>
                    </div>
                </div>

 <script type="text/javascript">
			function submitform()
			{
			document.forms["myform"].submit();
			}
			</script>
			<form id="myform"  action="{{route('activate-plan-pay')}}" method="post">
			{{csrf_field()}}
			<input type="hidden" name="plan" value="{{ $pack->id }}" />
			<input type="hidden" name="amount" value="{{ $pack->price }}" />
			<input type="hidden" name="code" id="code" />
			</form>
@endsection
