<!doctype html>
<html lang="en">
<head>
    <?php
//     header("Access-Control-Allow-Origin: *");
// header("Access-Control-Allow-Credentials: true ");
// header("Access-Control-Allow-Methods: OPTIONS, GET, POST");
// header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
    ?>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Infolink Limited Payment">
    <meta name="author" content="Infolink Limited">
    
    <link rel="shortcut icon" href="{{ asset('public/favicon.png') }}" type="image/x-icon">
    
    <title>iPay | Infolink Limited</title>

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
          integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <style>
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }
        .container{
            border:2px solid green;
            border-radius:20px;
        }
        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }
    </style>
</head>
<body class="bg-light">
<div class="container">
    <br/>
    <div class="text-center">
        <img src="{{ asset('public/infolink_logo.jpg') }}" alt="Infolink Limited" width="200">
    </div>
    
    <div class="row">
        <div class="col-md-3">
            &nbsp;
        </div>
        <div class="col-md-6">
            <hr class="mb-4">
            <form action="{{ url('/pay') }}" method="POST" class="needs-validation">
                <input type="hidden" value="{{ csrf_token() }}" name="_token" />
                
                    
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="client_id">Client ID (IL-C):</label>
                            <input type="number" class="form-control" name="client_id_check" id="client_id_check" placeholder="Enter Client ID">
                            <div class="invalid-feedback">
                                Please enter your client ID.
                            </div>
                        </div> 
                        <div class="col-md-6 mb-3">
                            <label for="btn2_id"></label>
                            <br style="display: block;margin: 6px 0;">
                            <button type="button" id="button">Check Details</button>
                            <div class="invalid-feedback">
                                
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="firstName">Name: <b style="color:red">*</b></label>
                            <input type="text" class="form-control firstName" id="firstName" name="fname" placeholder="Full Name" required readonly>
                            <div class="invalid-feedback">
                                Please enter your fullname.
                            </div>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label for="phone">Phone: <b style="color:red">*</b></label>
                            <input type="text" class="form-control phone" id="phone" name="phone" placeholder="Enter Phone Number" required readonly>
                            <input type="hidden" class="form-control phone" id="cus_phone" name="cus_phone" placeholder="Enter Phone Number" required >
                            <div class="invalid-feedback">
                                Please enter your valid phone number.
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="email">Email:<b style="color:red">*</b></label>
                            <input type="email" class="form-control email" id="email" name="email" placeholder="Enter Valid Email" required readonly>
                            <input type="hidden" class="form-control email" id="cus_email" name="cus_email" placeholder="Enter Valid Email" required>
                            <div class="invalid-feedback">
                                Please enter your email.
                            </div>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label>Amount: <b style="color:red">*</b></label>
                            <input type="text" class="form-control amount" id="amount" name="amount" placeholder="Enter Amount" required readonly>
                            <div class="invalid-feedback">
                                Please enter your amount.
                            </div>
                        </div>
                        
                    </div>
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="client_id">Client ID (IL-C):</label>
                            <input type="number" class="form-control" name="client_id" id="client_id" placeholder="Enter Client ID" readonly>
                            <div class="invalid-feedback">
                                Please enter your client ID.
                            </div>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label>Invoice ID (IL-):</label>
                            <input type="text" class="form-control" name="invoice_id" id="invoice_id" placeholder="Enter Invoice ID" readonly> 
                            <div class="invalid-feedback">
                                Please enter invoie id.
                            </div>
                        </div>
                        
                    </div>
                    <div class="row">
                        <div class="col-md-12 mb-6">
                            <label for="address">Address: <b style="color:red">*</b></label>
                            <input type="text" class="form-control address" id="add1" name="add1" placeholder="Enter Your Address" required readonly> 
                            <div class="invalid-feedback">
                                Please enter your valid address.
                            </div>
                        </div>
                    </div>
                    <br/>
                    <div class="row">
                        <div class="col-md-12 mb-6">
                            <label for="address">Reason of Payment: <b style="color:red">*</b></label>
                            <input type="text" class="form-control address" id="reason" name="reason" placeholder="Reason of Payment" required readonly>
                            <div class="invalid-feedback">
                                Please enter payment reason.
                            </div>
                        </div>
                    </div>
                    <br/>
                
                <button class="btn btn-primary btn-lg btn-block" type="submit">Pay Now</button>
                <div class="row">
                    <div class="col-md-12">
                        <img src="{{ asset('public/ssl_s2.png') }}" alt="SSL Commerz" width="100%">
                    </div>
                </div>
            </form>
        </div>
        <div class="col-md-3">
            &nbsp;
        </div>
    </div>

</div>
<script type="text/javascript">
  $("#button").click( function(){
    var guest_id = $('#client_id_check').val();
    //alert(guest_id);
    //var value = $(this).val();
    //var url = 'https://db.infolinkbd.com/admin/index.php/cron/get_connection_details_amount';
    var url = 'https://infolinkbd.com/ipay/info_details';
    $.ajaxSetup({
      headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
    });
    $.ajax({
         url : url,
         type: "post",
         data: {"guest_id":guest_id},
         success:function(data12)
         {
            var datas = JSON.parse(data12);
             //alert(datas['due'][0]['due']);
             var email_client = datas['client_id'][0]['client_email1'];
            //  email_client.replace(/@|_/g,'');
            //  alert(email_client.replace(/@|_/g,'#'));
            var new_email1 = email_client.substr(0, 2);
            var new_email2 = email_client.substr(-3, 3);
            var new_email = new_email1.concat("******", new_email2);
            
            var phone_client = datas['client_id'][0]['client_phone1'];
            var new_phone1 = phone_client.substr(0, 5);
            var new_phone2 = phone_client.substr(-2, 2);
            var new_phone = new_phone1.concat("******", new_phone2);
            
            var address = datas['client_address'][0]['house'].concat(", ", datas['client_address'][0]['road']);
            var address = address.concat(", ", datas['client_address'][0]['police_station']);
            var address = address.concat(", ", datas['client_address'][0]['post_office']);
            var address = address.concat(", ", datas['client_address'][0]['district']);
            var address = address.concat(" - ", datas['client_address'][0]['post_code']);
            
            let text = "";
            let il = "";
            for (let i = 0; i < datas['invoice_list'].length; i++) {
                if(i!=0){text += ", ";il += ", ";}
                var amount = 0.00+datas['invoice_list'][i]['bill']-datas['invoice_list'][i]['paid'];
              text += "IL-"+datas['invoice_list'][i]['invoice_id'] + "( Due:"+amount+" BDT )";
              il += "IL-"+datas['invoice_list'][i]['invoice_id'] ;
            } 
            
             $("#amount").val(datas['due'][0]['due']);
             $("#client_id").val(datas['client_id'][0]['client_id']);
             $("#email").val(new_email);
             $("#phone").val(new_phone);
             $("#firstName").val(datas['client_id'][0]['client_title']);
             $("#add1").val(address);
             $("#reason").val(text);
             $("#invoice_id").val(il);
             
         },
    //   error: function (xhr, ajaxOptions, thrownError) {
    //       alert(guest_id);
    //     alert(xhr.status);
    //     alert(thrownError);
    //   }
    });
});
</script>
<!--<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"-->
<!--        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"-->
<!--        crossorigin="anonymous"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>
</html>
