<commit_before>/**
 * Wallee Magento
 *
 * This Magento extension enables to process payments with Wallee (https://wallee.com/).
 *
 * @package Wallee_Payment
 * @author customweb GmbH (http://www.customweb.com/)
 * @license http://www.apache.org/licenses/LICENSE-2.0  Apache Software License (ASL 2.0)
 * @link https://github.com/wallee-payment/magento
 */

MageWallee.Checkout.Type.MagentoOnePage = Class.create(
    MageWallee.Checkout.Type, {
    originalPaymentSave : function () {},

    initialize : function () {
        Payment.prototype.switchMethod = Payment.prototype.switchMethod.wrap(this.switchMethod.bind(this));

        this.originalPaymentSave = Payment.prototype.save.bind(payment);
        Payment.prototype.save = Payment.prototype.save.wrap(this.savePayment.bind(this));

        Review.prototype.save = Review.prototype.save.wrap(this.placeOrder.bind(this));
    },

    /**
     * Initializes the payment iframe when the customer switches the payment method.
     */
    switchMethod : function (callOriginal, method) {
        callOriginal(method);
        this.createHandler(
            method, function () {
            checkout.setLoadWaiting('payment');
            }, function (validationResult) {
            checkout.setLoadWaiting(false);
            if (validationResult.success) {
                this.originalPaymentSave();
            }
            }.bind(this), function () {
            checkout.setLoadWaiting(false);
            }
        );
    },

    /**
     * Validates the payment information when the customer saves the payment method.
     */
    savePayment : function (callOriginal) {
        if (this.isSupportedPaymentMethod(payment.currentMethod)) {
            checkout.setLoadWaiting('payment');
            this.getPaymentMethod(payment.currentMethod).handler.validate();
            return false;
        } else {
            callOriginal();
        }
    },

    /**
     * Sends the payment information to Wallee after the customer submitted the order.
     */
    placeOrder : function (callOriginal) {
        if (this.isSupportedPaymentMethod(payment.currentMethod)) {
            if (checkout.loadWaiting != false) {
                return;
            }

            checkout.setLoadWaiting('review');
            var params = Form.serialize(payment.form);
            if (review.agreementsForm) {
                params += '&' + Form.serialize(review.agreementsForm);
            }

            params.save = true;
            new Ajax.Request(
                review.saveUrl, {
                method : 'post',
                parameters : params,
                onSuccess : this.onOrderCreated.bind(this),
                onFailure : function () {
                    review.onComplete();
                    checkout.ajaxFailure();
                }
                }
            );
        } else {
            callOriginal();
        }
    },

    onOrderCreated : function (transport) {
        if (transport) {
            var response = this.parseResponse(transport);

            if (response.success) {
                this.getPaymentMethod(payment.currentMethod).handler.submit();
                return;
            } else {
                if (response.error_messages) {
                    alert(this.formatErrorMessages(response.error_messages));
                }
            }

            if (response.update_section) {
                $('checkout-' + response.update_section.name + '-load').update(response.update_section.html);
            }

            if (response.goto_section) {
                checkout.gotoSection(response.goto_section, true);
            }
        }
    }
    }
);
MageWallee.Checkout.type = MageWallee.Checkout.Type.MagentoOnePage;<commit_msg>Reenable checkout button when order creation failed.<commit_after>/**
 * Wallee Magento
 *
 * This Magento extension enables to process payments with Wallee (https://wallee.com/).
 *
 * @package Wallee_Payment
 * @author customweb GmbH (http://www.customweb.com/)
 * @license http://www.apache.org/licenses/LICENSE-2.0  Apache Software License (ASL 2.0)
 * @link https://github.com/wallee-payment/magento
 */

MageWallee.Checkout.Type.MagentoOnePage = Class.create(
    MageWallee.Checkout.Type, {
    originalPaymentSave : function () {},

    initialize : function () {
        Payment.prototype.switchMethod = Payment.prototype.switchMethod.wrap(this.switchMethod.bind(this));

        this.originalPaymentSave = Payment.prototype.save.bind(payment);
        Payment.prototype.save = Payment.prototype.save.wrap(this.savePayment.bind(this));

        Review.prototype.save = Review.prototype.save.wrap(this.placeOrder.bind(this));
    },

    /**
     * Initializes the payment iframe when the customer switches the payment method.
     */
    switchMethod : function (callOriginal, method) {
        callOriginal(method);
        this.createHandler(
            method, function () {
            checkout.setLoadWaiting('payment');
            }, function (validationResult) {
            checkout.setLoadWaiting(false);
            if (validationResult.success) {
                this.originalPaymentSave();
            }
            }.bind(this), function () {
            checkout.setLoadWaiting(false);
            }
        );
    },

    /**
     * Validates the payment information when the customer saves the payment method.
     */
    savePayment : function (callOriginal) {
        if (this.isSupportedPaymentMethod(payment.currentMethod)) {
            checkout.setLoadWaiting('payment');
            this.getPaymentMethod(payment.currentMethod).handler.validate();
            return false;
        } else {
            callOriginal();
        }
    },

    /**
     * Sends the payment information to Wallee after the customer submitted the order.
     */
    placeOrder : function (callOriginal) {
        if (this.isSupportedPaymentMethod(payment.currentMethod)) {
            if (checkout.loadWaiting != false) {
                return;
            }

            checkout.setLoadWaiting('review');
            var params = Form.serialize(payment.form);
            if (review.agreementsForm) {
                params += '&' + Form.serialize(review.agreementsForm);
            }

            params.save = true;
            new Ajax.Request(
                review.saveUrl, {
                method : 'post',
                parameters : params,
                onSuccess : this.onOrderCreated.bind(this),
                onFailure : function () {
                    review.onComplete();
                    checkout.ajaxFailure();
                }
                }
            );
        } else {
            callOriginal();
        }
    },

    onOrderCreated : function (transport) {
        if (transport) {
            var response = this.parseResponse(transport);

            if (response.success) {
                this.getPaymentMethod(payment.currentMethod).handler.submit();
                return;
            } else {
                if (response.error_messages) {
                    alert(this.formatErrorMessages(response.error_messages));
                }
                checkout.setLoadWaiting(false);
            }

            if (response.update_section) {
                $('checkout-' + response.update_section.name + '-load').update(response.update_section.html);
            }

            if (response.goto_section) {
                checkout.gotoSection(response.goto_section, true);
            }
        }
    }
    }
);
MageWallee.Checkout.type = MageWallee.Checkout.Type.MagentoOnePage;
{'fraction_non_alphanumeric': 0.10956201499408129, 'fraction_numerical': 0.0010522162304353545, 'mean_word_length': 1.869433962264151, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5554380', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1928, 'n_words': 340}