<commit_before><script type="text/javascript">
    if ((typeof jQuery === 'undefined') && ! window.jQuery) {

        if (typeof $ == 'function') {
            var dlSignIsUsing = true;
        } else {
            var dlSignIsUsing = false;
        }

        function getScript(url, success) {
            var script     = document.createElement('script');
                script.src = url;

            var head = document.getElementsByTagName('head')[0],
                done = false;

            // Attach handlers for all browsers
            script.onload = script.onreadystatechange = function() {
                if (! done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
                    done = true;

                    // callback function provided as param
                    success();

                    script.onload = script.onreadystatechange = null;
                    head.removeChild(script);
                };
            };

            head.appendChild(script);
        };

        getScript('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', function() {
            $nj = jQuery.noConflict();
            hookPaymentSave($nj);
        });
    } else {
        $nj = jQuery.noConflict();
        hookPaymentSave($nj);
    }

    function hookPaymentSave(jQuery) {
        Payment.prototype.save = Payment.prototype.save.wrap(function(superMethod) {
            var paymentMethod = jQuery("#co-payment-form").find("input[name='payment[method]']:checked").val();

            if (typeof paymentMethod == "undefined") {
                alert('Please select one method');

                return false;
            } else if (paymentMethod == "omise_gateway") {
                var omiseValidation = new Validation('co-payment-form');

                // If validate pass
                if (omiseValidation.validate()) {
                    jQuery.getScript("https://cdn.omise.co/omise.min.js.gz", function() {

                        // Set Omise key
                        Omise.setPublicKey("<?php echo $this->getOmiseKeys('public_key'); ?>");

                        var form                = jQuery("#payment_form_omise_gateway"),
                            formValidation      = form.find('.omise-validation-advice'),
                            formValidationMsg   = formValidation.find('.validation-advice');

                        jQuery("#payment-buttons-container").find("button").prop("disabled", true);

                        // Serialize the form fields into a valid card object.
                        var card = {
                            "name": form.find("[data-omise=holder_name]").val(),
                            "number": form.find("[data-omise=number]").val(),
                            "expiration_month": form.find("[data-omise=expiration_month]").val(),
                            "expiration_year": form.find("[data-omise=expiration_year]").val(),
                            "security_code": form.find("[data-omise=security_code]").val()
                        };

                        formValidation.css({'opacity': 0, 'display': 'none'});

                        // Send a request to create a token
                        // then trigger the callback function once a response is received from Omise.
                        // * Note that the response could be an error and this needs to be handled
                        // * within the callback.
                        Omise.createToken("card", card, function (statusCode, response) {
                            // If has an error (can not create a card's token).
                            if (response.object == "error") {
                                // Display an error message - "Omise Response: "+response.message.
                                formValidation.css({'opacity': 1, 'display': 'block'});
                                formValidationMsg.html("Omise Response: "+response.message);

                                jQuery("#payment-buttons-container").find("button").prop("disabled", false);
                            } else if (typeof response.card != 'undefined' && !response.card.security_code_check) {
                                // Display an error message - "Omise Response: Card authorization failure.".
                                formValidation.css({'opacity': 1, 'display': 'block'});
                                formValidationMsg.html("Omise Response: Card authorization failure.");

                                jQuery("#payment-buttons-container").find("button").prop("disabled", false);
                            } else {
                                form.find("[data-omise=holder_name]").prop("disabled", true);
                                form.find("[data-omise=number]").prop("disabled", true);
                                form.find("[data-omise=expiration_month]").prop("disabled", true);
                                form.find("[data-omise=expiration_year]").prop("disabled", true);
                                form.find("[data-omise=security_code]").prop("disabled", true);

                                form.find("[data-omise=omise_token]").val(response.id);

                                return superMethod();
                            };
                        });

                    });

                    return false;
                }
            } else {
                return superMethod();
            }
        }, jQuery);
    }
</script>

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php $_code=$this->getMethodCode() ?>
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">

    <li class="omise-validation-advice"><div class="validation-advice"></div></li>

    <li>
        <label for="<?php echo $_code ?>_cc_type" class="required"><em>*</em><?php echo $this->__('Credit Card Type') ?></label>
        <div class="input-box">
            <select id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" class="required-entry validate-cc-type-select">
                <option value=""><?php echo $this->__('--Please Select--')?></option>
            <?php $_ccType = $this->getInfoData('cc_type') ?>
            <?php foreach ($this->getCcAvailableTypes() as $_typeCode => $_typeName): ?>
                <option value="<?php echo $_typeCode ?>"<?php if($_typeCode==$_ccType): ?> selected="selected"<?php endif ?>><?php echo $_typeName ?></option>
            <?php endforeach ?>
            </select>
        </div>

        <input data-omise="omise_token" type="hidden" name="payment[omise_token]">
    </li>

    <!-- Credit Card Holder Name -->
    <li>
        <label for="<?php echo $_code ?>_cc_owner" class="required"><em>*</em><?php echo $this->__('Credit Card Holder Name') ?></label>
        <div class="input-box">
            <input type="text" data-omise="holder_name" id="<?php echo $_code ?>_cc_name" name="payment[cc_name]" title="<?php echo $this->__('Credit Card Holder Name') ?>" class="input-text required-entry" value="<?php echo $this->escapeHtml($this->getInfoData('cc_owner')) ?>" /><commit_msg>Remove jQuery lib from the checkout form by implementing pure js function instead.<commit_after><script type="text/javascript">
    function getScript(url, success) {
        var script     = document.createElement("script");
            script.src = url;

        var head = document.getElementsByTagName("head")[0],
            done = false;

        // Attach handlers for all browsers
        script.onload = script.onreadystatechange = function() {
            if (! done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
                done = true;

                // callback function provided as param
                success();

                script.onload = script.onreadystatechange = null;
                head.removeChild(script);
            };
        };

        head.appendChild(script);
    };

    // Hook Payment.save function by wrapping Omise logic on top of the 'Payment.prototype.save'
    Payment.prototype.save = Payment.prototype.save.wrap(function(superMethod) {
        var omisePayment = document.getElementById("p_method_omise_gateway");

        if (! omisePayment.checked) {
            return superMethod();
        }

        var validator = new Validation("co-payment-form");

        if (validator.validate()) {
            checkout.setLoadWaiting('payment');

            getScript("https://cdn.omise.co/omise.min.js.gz", function() {
                // Set Omise key
                Omise.setPublicKey("<?php echo $this->getOmiseKeys('public_key'); ?>");

                var form                  = document.getElementById("payment_form_omise_gateway"),
                    formInput             = {
                        "name"             : document.getElementById("omise_gateway_cc_name"),
                        "number"           : document.getElementById("omise_gateway_cc_number"),
                        "expiration_month" : document.getElementById("omise_gateway_expiration"),
                        "expiration_year"  : document.getElementById("omise_gateway_expiration_yr"),
                        "security_code"    : document.getElementById("omise_gateway_cc_cid"),
                        "omise_token"      : document.getElementById("omise_gateway_token")
                    },
                    omiseValidationAdvice = document.getElementById("omise-validation-advice");

                var card = {
                    "name"             : formInput.name.value,
                    "number"           : formInput.number.value,
                    "expiration_month" : formInput.expiration_month.value,
                    "expiration_year"  : formInput.expiration_year.value,
                    "security_code"    : formInput.security_code.value
                };

                /** 
                 * Send a request to create a token then trigger the callback function once
                 * a response is received from Omise.
                 *
                 * Note that the response could be an error and this needs to be handled within
                 * the callback.
                 */
                Omise.createToken("card", card, function(statusCode, response) {
                    if (response.object == "error") {
                        omiseValidationAdvice.innerHTML = response.message;
                        checkout.setLoadWaiting(false);
                    } else if (typeof response.card != 'undefined' && !response.card.security_code_check) {
                        omiseValidationAdvice.innerHTML = 'This card cannot authorize, please contact our support.';
                        checkout.setLoadWaiting(false);
                    } else {
                        formInput.omise_token.value         = response.id;

                        formInput.name.disabled             = true;
                        formInput.number.disabled           = true;
                        formInput.expiration_month.disabled = true;
                        formInput.expiration_year.disabled  = true;
                        formInput.security_code.disabled    = true;

                        checkout.setLoadWaiting(false);
                        return superMethod();
                    };
                });
            });
        }
    });
</script>

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php $_code=$this->getMethodCode() ?>
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">

    <li><div id="omise-validation-advice" class="validation-advice"></div></li>

    <li>
        <label for="<?php echo $_code ?>_cc_type" class="required"><em>*</em><?php echo $this->__('Credit Card Type') ?></label>
        <div class="input-box">
            <select id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" class="required-entry validate-cc-type-select">
                <option value=""><?php echo $this->__('--Please Select--')?></option>
            <?php $_ccType = $this->getInfoData('cc_type') ?>
            <?php foreach ($this->getCcAvailableTypes() as $_typeCode => $_typeName): ?>
                <option value="<?php echo $_typeCode ?>"<?php if($_typeCode==$_ccType): ?> selected="selected"<?php endif ?>><?php echo $_typeName ?></option>
            <?php endforeach ?>
            </select>
        </div>

        <input id="<?php echo $_code ?>_token" data-omise="omise_token" type="hidden" name="payment[omise_token]">
    </li>

    <!-- Credit Card Holder Name -->
    <li>
        <label for="<?php echo $_code ?>_cc_owner" class="required"><em>*</em><?php echo $this->__('Credit Card Holder Name') ?></label>
        <div class="input-box">
            <input type="text" data-omise="holder_name" id="<?php echo $_code ?>_cc_name" name="payment[cc_name]" title="<?php echo $this->__('Credit Card Holder Name') ?>" class="input-text required-entry" value="<?php echo $this->escapeHtml($this->getInfoData('cc_owner')) ?>" />
{'fraction_non_alphanumeric': 0.13181573999462798, 'fraction_numerical': 0.002753156056943325, 'mean_word_length': 1.8767626038246088, 'pattern_counts': {'":': 5, '<': 106, '<?xml version=': 0, '>': 128, 'https://': 3, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2406374', 'n_tokens_mistral': 3936, 'n_tokens_neox': 3756, 'n_words': 925}