<?php
/**
 * Worldpay 2 checkout "part3" include
 * This file is only included if WORLDPAY setting is set to true
 * @author Rihards Siliņš
 * @version 1 12/07/2016
 */
?>
<script src="https://cdn.worldpay.com/v1/worldpay.js"></script>
<script type="text/javascript">
    var worldpay_variables = {
        client_key: '<?= WORLDPAY_CLIENT_KEY ?>',
        server_http_accept: '<?= $_SERVER["HTTP_ACCEPT"] ?>'
    };
</script>


<?php if (config('app.env') !== 'production'): ?>

    <div class="alertBlue">
        Docs:
        <a href="https://developer.worldpay.com/docs/wpop/template-form" target="_blank">
            https://developer.worldpay.com/docs/wpop/template-form
        </a>
        <br /></br />

        Test Cards: <br />
        <a href="http://support.worldpay.com/support/kb/bg/testandgolive/tgl5103.html" target="_blank">
            http://support.worldpay.com/support/kb/bg/testandgolive/tgl5103.html
        </a>
        <br />
        e.g.: Visa 4444333322221111 (123) <br />
    </div>

<?php endif ?>


<div id='paymentSection'></div>

<div id="worldpayContainer">
    <?php
    if (!empty($_GET['worldpay_error']) && $_GET['worldpay_error'] === "failed_3ds") {
        ?><div class="error cardFailedToAuthorize worldpayErrorMsg">
            Your payment wasn't successfully authorized. Please try a different payment method.
        </div><?php
    }
    ?>
    <div class="error cardDeclined worldpayErrorMsg" style="display:none">
        Your card was declined. Please try a different payment method. Reason given: "<span class="reason"></span>"
    </div>
    <div class="error paymentError worldpayErrorMsg" style="display:none">
        Something went wrong with the payment, please try again later. Error given: "<span class="reason"></span>"
    </div>
    <div id='worldpayPaymentSection' style="display:none__"></div>
    <form id='worldpayPaymentForm' method="post">
        <input type="hidden" name="order_id" value="<?=$newbasket->order_id?>">
        <input type="hidden" name="token" value="">
        <input type="hidden" name="name" value="">
        <input type="hidden" name="PaReq" value="">
        <input type="hidden" name="TermUrl" value="<?= SITE_URL ?>/shop/checkout/worldpay/3ds_response_check.php?resend=y&order_id=<?= $newbasket->order_id ?>">
        <input type="hidden" name="MD" value="<?= $newbasket->order_id ?>">
    </form>
    <button type="button" name="worldPayPay" class="checkoutButton worldPayPay">
        Make payment securely <i class="fa fa-lock"></i>
    </button>
</div>
