{"size": 3432, "ext": "js", "max_stars_repo_path": "src/js/Afterpay/checkout/awesomecheckout.js", "max_stars_repo_name": "magescale/afterpay-magento1", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/js/Afterpay/checkout/awesomecheckout.js", "max_issues_repo_name": "magescale/afterpay-magento1", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/js/Afterpay/checkout/awesomecheckout.js", "max_forks_repo_name": "magescale/afterpay-magento1", "max_forks_repo_forks_event_min_datetime": "2020-02-20T05:08:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T05:08:43.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 40.8571428571, "max_line_length": 103, "alphanum_fraction": 0.3234265734}
(function() {
    if (typeof window.Review !== "undefined" && window.Afterpay.paymentAction == 'authorize_capture') {
        /**
         * Override save on order review function
         */
        var reviewSave = window.Review.prototype.save;
        window.Review.prototype.save = function() {
            // check payment method
            if (payment.currentMethod == 'afterpaypayovertime') {
                if (checkout.loadWaiting != false) return;
                checkout.setLoadWaiting('review');
                /**
                 * Override on complete to do afterpay payment
                 *
                 * @param transport
                 */
                // Run ajax to process Afterpay payment using Protorype
                var request = new Ajax.Request(
                    window.Afterpay.saveUrl, // use Afterpay controller
                    {
                        method: 'post',
                        onSuccess: function (transport) {
                            var response = {};

                            // Parse the response - lifted from original method
                            try {
                                response = eval('(' + transport.responseText + ')');
                            }
                            catch (e) {
                                response = {};
                            }

                            // if the order has been successfully placed
                            if (response.success) {

                                //modified to suit API V1
                                if( window.afterpayReturnUrl === false ) {
                                    AfterPay.init(); 
                                }
                                else {
                                    AfterPay.init({
                                        relativeCallbackURL: window.afterpayReturnUrl
                                    });
                                }

                                switch (window.Afterpay.redirectMode) {
                                    case 'lightbox':
                                        AfterPay.display({
                                            token: response.token
                                        });

                                        break;

                                    case 'redirect':
                                        AfterPay.redirect({
                                            token: response.token
                                        });

                                        break;
                                }
                            } else {
                                if (response.redirect) {
                                    this.isSuccess = false;
                                    location.href = response.redirect;
                                } else {
                                    alert(response.message);
                                }
                            }

                        }.bind(this),
                        onFailure: function () {
                            alert('Afterpay Gateway is not available.');
                        }
                    }
                );
            } else {
                /**
                 * Call original function
                 */
                reviewSave.apply(this, arguments);
            }
        };
    }
})();