<html>
<head>
    <script src="{{ Config::get('omnipay.'.$provider.'.data')['script_api'] }}" data-error="errorCallback"
        data-cancel="cancelCallback">
    </script>
    <script type="text/javascript">
        function errorCallback(error) {
            console.log(JSON.stringify(error));
        }
        function cancelCallback() {
            window.location= '{{ env('APP_URL') }}';
        }
        function completeCallback() {
            window.location = '{{ env('APP_URL') }}/omnipay/response/success/{{ $order_id }}/';
        }
        Checkout.configure({
            session: {
                id: "{{ $session_id  }}"
            },
            transaction:{
                reference: '{{  $order_id  }}'
            },
            order: {
                description: 'Checkout for your purchase #{{ $order_id }} at {{ env('APP_NAME') }}',
                id: '{{  $order_id  }}',
                reference: '{{  $order_id  }}'
            },
            interaction: {
                merchant: {
                    name: '{{ env('APP_NAME') }}',
                    address: {
                        line1: 'test',
                        line2: 'test line 2'
                    },
                },
                displayControl: {
                    billingAddress: 'HIDE',
                    customerEmail: 'HIDE',
                    shipping: 'HIDE'
                }
            }
        });
    </script>
</head>

<body>
    <?php
if($amount == ''){
    echo '<h1>An error occured</h1>';
    exit();
}
?>
    <!DOCTYPE html>
    <html lang="en">

    <head>
        <title>{{ env('APP_NAME') }}</title>
    </head>

    <body>
        <div class="SizeHandler">
            redirecting, please be patient
            <?php

            $referer = str_replace('//www.', '//', $_SERVER['HTTP_REFERER']);
            if(isset($referer) && (str_contains($referer,'checkout/payment') || str_contains($referer,env('APP_URL')))){  ?>
            <script language="javascript">
                Checkout.showPaymentPage()
            </script>
            <?php } ?>
        </div>
    </body>

    </html>
