1

I am upgrading from Magento 2.2.7 to Magento 2.3

I checked after upgrading the code, My place order button at checkout page is not working.When i clicked on Place Order button, I found the below error.

iframe.js:117 Uncaught TypeError: this.validateHandler is not a function
    at UiClass.placeOrder (iframe.js:117)
    at HTMLButtonElement.<anonymous> (knockout.js:4255)
    at HTMLButtonElement.dispatch (jquery.js:5226)
    at HTMLButtonElement.elemData.handle (jquery.js:4878)

I tried to fix the issue but it is not yet fixed.It is showing error on the below highlighted line:

define([    
'jquery',
    'Magento_Payment/js/view/payment/cc-form',
    'Magento_Ui/js/model/messageList',
    'mage/translate',
    'Magento_Checkout/js/model/full-screen-loader',
    'Magento_Checkout/js/action/set-payment-information',
    'Magento_Checkout/js/model/payment/additional-validators',
    'Magento_Ui/js/modal/alert'
], function (
    $,
    Component,
    messageList,
    $t,
    fullScreenLoader,
    setPaymentInformationAction,
    additionalValidators,
    alert
) {
    'use strict';

    return Component.extend({
        defaults: {
            template: 'Magento_Payment/payment/iframe',
            timeoutId: null,
            timeoutMessage: 'Sorry, but something went wrong.'
        },

        /**
         * @returns {String}
         */
        getSource: function () {
            return window.checkoutConfig.payment.iframe.source[this.getCode()];
        },

        /**
         * @returns {String}
         */
        getControllerName: function () {
            return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
        },

        /**
         * @returns {String}
         */
        getPlaceOrderUrl: function () {
            return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
        },

        /**
         * @returns {String}
         */
        getCgiUrl: function () {
            return window.checkoutConfig.payment.iframe.cgiUrl[this.getCode()];
        },

        /**
         * @returns {String}
         */
        getSaveOrderUrl: function () {
            return window.checkoutConfig.payment.iframe.saveOrderUrl[this.getCode()];
        },

        /**
         * @returns {String}
         */
        getDateDelim: function () {
            return window.checkoutConfig.payment.iframe.dateDelim[this.getCode()];
        },

        /**
         * @returns {String}
         */
        getCardFieldsMap: function () {
            return window.checkoutConfig.payment.iframe.cardFieldsMap[this.getCode()];
        },

        /**
         * @returns {String}
         */
        getExpireYearLength: function () {
            return window.checkoutConfig.payment.iframe.expireYearLength[this.getCode()];
        },

        /**
         * @param {Object} parent
         * @returns {Function}
         */
        originalPlaceOrder: function (parent) {
            return parent.placeOrder.bind(parent);
        },

        /**
         * @returns {Number}
         */
        getTimeoutTime: function () {
            return window.checkoutConfig.payment.iframe.timeoutTime[this.getCode()];
        },

        /**
         * @returns {String}
         */
        getTimeoutMessage: function () {
            return $t(this.timeoutMessage);
        },

        /**
         * @override
         */
        placeOrder: function () {
            if (this.validateHandler() && additionalValidators.validate()) {

                fullScreenLoader.startLoader();

                this.isPlaceOrderActionAllowed(false);

                $.when(
                    setPaymentInformationAction(
                        this.messageContainer,
                        {
                            method: this.getCode()
                        }
                    )
                ).done(this.done.bind(this))
                    .fail(this.fail.bind(this));

                this.initTimeoutHandler();
            }
        },

        /**
         * {Function}
         */
        initTimeoutHandler: function () {
            this.timeoutId = setTimeout(
                this.timeoutHandler.bind(this),
                this.getTimeoutTime()
            );

            $(window).off('clearTimeout')
                .on('clearTimeout', this.clearTimeout.bind(this));
        },

        /**
         * {Function}
         */
        clearTimeout: function () {
            clearTimeout(this.timeoutId);
            this.fail();

            return this;
        },

        /**
         * {Function}
         */
        timeoutHandler: function () {
            this.clearTimeout();

            alert(
                {
                    content: this.getTimeoutMessage(),
                    actions: {

                        /**
                         * {Function}
                         */
                        always: this.alertActionHandler.bind(this)
                    }
                }
            );

            this.fail();
        },

        /**
         * {Function}
         */
        alertActionHandler: function () {
            fullScreenLoader.startLoader();
            window.location.reload();
        },

        /**
         * {Function}
         */
        fail: function () {
            fullScreenLoader.stopLoader();
            this.isPlaceOrderActionAllowed(true);

            return this;
        },

        /**
         * {Function}
         */
        done: function () {
            this.placeOrderHandler().fail(function () {
                fullScreenLoader.stopLoader();
            });

            return this;
        }
    });
});

How can I resolve this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Prince
  • 401
  • 1
  • 7
  • 34
  • there's no indication from the code you posted that such a function exists - but, since this appears to be some sort of event handler, chances are that the issue is how you add this as an event handler ... use bind – Jaromanda X Sep 18 '19 at 09:03
  • This function exist in iframe.js file. This error shoing in this line :if (this.validateHandler() && additionalValidators.validate())` { if you have any idea then please help me. – Prince Sep 18 '19 at 09:14
  • I just did ... it's how `placeOrder` is called that is the problem - show how it is called ... if it's like `something.AddEventListener('someEvent', this.placeOrder)` you'll probably need to change that to `something.AddEventListener('someEvent', this.placeOrder).bind(this)` ... does my first comment make sense now? – Jaromanda X Sep 18 '19 at 09:17
  • sorry if it's okay if you can write my specified function using this bind() as i am not able to write it properly. – Prince Sep 18 '19 at 09:55
  • that would require you to show me *how you are calling placeOrder* – Jaromanda X Sep 18 '19 at 10:29
  • Please find the updated code and let me know if you can help on this. – Prince Sep 18 '19 at 11:32
  • so, what is the `parent` argument when calling `originalPlaceOrder` ... where are you calling that? because that's the `this` bound to `placeOrder` - does it have a `validateHandler` method? – Jaromanda X Sep 18 '19 at 11:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/199629/discussion-between-prince-and-jaromanda-x). – Prince Sep 18 '19 at 11:40

0 Answers0