<?php $__env->startSection('content'); ?>

    <!-- Begin: Main Slider -->
    <div class="innerBan">
        <img src="<?php echo e(asset('front/images/innerbnr1.png')); ?>" class="w-100" alt="">
        <div class="overlay">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-md-12">
                        <h2>Payment</h2>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End: Main Slider -->

    <section class="check-out-section">
        <div class="container">
            <div class="check-out-form check-out-3">
                <h2 class="primary-heading">Payment Methods</h2>
                
                <form
                    role="form"
                                        action="<?php echo e(route('admin.payment.process')); ?>"
                    method="post"
                    class="stripe-payment"
                    data-cc-on-file="false"
                    data-stripe-publishable-key="<?php echo e('pk_test_51PlWzBDNtMzulUkx5U2yDJU8kMt6BaBsfDW0TMtMGWtfrRWY8FNEAWPZ1rU8W4SdkwIwjYSmxzF41eHwiBFlP0Db00q1dWTubc'); ?>"
                    id="stripe-payment">
                    <?php echo csrf_field(); ?>

                    <div class="col-12 offset-lg-1 col-lg-10">
                        <div class="row tabs-row fields-row">
                            <div class="col-12 text-center mb-4">
                                <img src="images/card-img.png" alt="">
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label>CARD NUMBER</label>
                                    <input autocomplete='off' class='form-control card-number'>
                                    <div id="card-errors" role="alert" style="color: red;"></div>
                                    <!-- Error messages -->
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label>NAME ON CARD</label>
                                    <input type="text" class="form-control" placeholder="NAME ON CARD"> required>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label>CVV</label>
                                    <input type="text" size="4" autocomplete='off' class='form-control card-cvc'
                                           placeholder='ex. 311'
                                           required>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>EXPIRATION MONTH</label>
                                    <input class='form-control card-expiry-month' placeholder='MM' size='2' type="text">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Expiration Year</label>
                                    <input class='form-control card-expiry-year' placeholder='YYYY' size='4'
                                           type='text'>
                                </div>
                            </div>
                            <div class="col-md-6 mt-25">
                                <div class="col-md-12 checkbox">
                                    <input type="checkbox" id="box-2">
                                    <label for="box-2">
                                        <h5>Save Card</h5>
                                        Information is encrypted and securely stored.
                                    </label>
                                </div>
                            </div>
                            <div class="col-12 mt-20">
                                <button class="themeBtn w-100" id="submit">Place Order</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>

    



    <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
    <script src="https://js.stripe.com/v3/"></script>

    <script>
        history.pushState(null, null, location.href);
        window.onpopstate = function () {
            history.go(1);
        };
    </script>

    <script type="text/javascript">

        $(function () {

            /*------------------------------------------
            --------------------------------------------
            Stripe Payment Code
            --------------------------------------------
            --------------------------------------------*/
            var $form = $(this);

            $('.stripe-payment').on('submit', function (e) {
                e.preventDefault();

                $('#loader-container').css('display', 'block');
                // $('#order-submit').prop('disabled', true);

                let cardNumber = $('.card-number').val();
                let cardCVC = $('.card-cvc').val();
                let cardExpMonth = $('.card-expiry-month').val();
                let cardExpYear = $('.card-expiry-year').val();

                var $form = $(this); // Use $(this) to reference the current form
                var $errorMessage = $form.find('div.error');
                $errorMessage.addClass('hide');

                $('.has-error').removeClass('has-error');

                if (cardNumber === '' || cardCVC === '' || cardExpMonth === '' || cardExpYear === '') {
                    // Handle validation errors here, if needed
                    return;
                }

                var $form = $(this),
                    inputSelector = ['input[type=email]', 'input[type=password]',
                        'input[type=text]', 'input[type=file]',
                        'textarea'].join(', '),
                    $inputs = $form.find('.required').find(inputSelector),
                    $errorMessage = $form.find('div.error'),
                    valid = true;
                $errorMessage.addClass('hide');

                $('.has-error').removeClass('has-error');
                $inputs.each(function (i, el) {
                    var $input = $(el);
                    if ($input.val() === '') {
                        $input.parent().addClass('has-error');
                        $errorMessage.removeClass('hide');
                        e.preventDefault();
                    }
                });

                if (!$form.data('cc-on-file')) {
                    e.preventDefault();

                    let stripePublishableKey = $form.data('stripe-publishable-key');
                    console.log('stripePublishableKey', stripePublishableKey);

                    Stripe.setPublishableKey(stripePublishableKey);
                    Stripe.card.createToken({
                        number: cardNumber,
                        cvc: cardCVC,
                        exp_month: cardExpMonth,
                        exp_year: cardExpYear,
                    }, function (status, response) {
                        console.log('Tokenization response:', response);

                        if (response.error) {
                            // Inform the user if there was an error
                            $('.error')
                                .removeClass('hide')
                                .removeAttr('style')
                                .find('.alert')
                                .text(response.error.message);
                            $('#loader-container').css('display', 'none');

                        } else {

                            // Send the token to your server
                            console.log(response);
                            // document.getElementById('stripeToken').val() = response.id;
                            $form.find('input[type=text]').val(''); // Clear text inputs

                            // Add the token as a hidden input in the form
                            $form.append("<input type='hidden' name='stripe_token' value='" + response.id + "'/>");

                            // Optionally, clear sensitive card data from the form
                            $('.card-number').val('');
                            $('.card-cvc').val('');
                            $('.card-expiry-month').val('');
                            $('.card-expiry-year').val('');

                            $form.get(0).submit();
                        }
                    });
                }
                $('#loader-container').css('display', 'block');

            });
        });
    </script>


    

<?php $__env->stopSection(); ?>

<?php echo $__env->make('front.include.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/vagrant/projects/upsence/resources/views/front/payment.blade.php ENDPATH**/ ?>