0

1.lets assume placeOrderClick function is called.within this there is a eprotect API success callback function called submitAfterEprotect.

i'm trying to call placeorder function using self in submitAfterEprotect callback function.

but it is throwing an error. cannot read property of undefined placeorder. Could you please help me on this?

It is related to Knockout js. but i don't know how to deal with this.

   /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    /*browser:true*/
    /*global define*/
    define(
        [
            'underscore',
            'jquery',
            'Magento_Payment/js/view/payment/cc-form',                
            'Magento_Checkout/js/model/quote',
            'Sivaji_Worldpay/js/validator',
            'Magento_Ui/js/model/messageList',
            'Sivaji_Worldpay/js/view/payment/validator-handler',        
            'Sivaji_Worldpay/js/view/payment/kount',
            'mage/translate',
            'prototype',
            'eprotectTestUrl',
            'domReady!'
        ],
        function (
            _,
            $,
            Component,
            quote,
            validator,
            globalMessageList,
            validatorManager,
            kount,
            $t
        ) {
            'use strict';
    
            return Component.extend({
                defaults: {
                    template: 'Sivaji_Worldpay/payment/form',
                    active: false,
                    code: 'worldpaycnp',
                    lastBillingAddress: null,
                  
                    selectorsMapper: {
                        'expirationMonth': 'expirationMonth',
                        'expirationYear': 'expirationYear',
                        'number': 'cc_number',
                        'cvv': 'cc_cid'
                    },
                    paymentPayload: {
                        nonce: null
                    },
                    additionalData: {}
                },
    
                /**
                 * @returns {exports.initialize}
                 */
                initialize: function () {
                    var self = this;
                    self._super();             
    
                    kount.getDeviceData()
                        .then(function (deviceData) {
                            self.additionalData['device_data'] = deviceData;
                        });
    
                    return self;
                },
    
                setEprotectResponseFields:  function(response){
            document.getElementById('response$code').value = response.response;             
        },
        submitAfterEprotect: function (response) {
                    var self = this;
            document.getElementById('response$code').value = response.response;
            document.getElementById('response$message').value = response.message;        
                  // self.setPaymentPayload(payload);
                   self.placeOrder();
        },
    
         timeoutOnEprotect :function() 
        { 
            alert("error");
        },
         onErrorAfterEprotect :function(response) {
                            var self = this;
                document.getElementById('response$code').value = response.response;
            document.getElementById('response$lastFour').value = response.lastFour;
                    alert(response.response);
                if(response.response == '871') {
                    alert("Invalid card number. Check and retry. (Not Mod10)");
                }                       
                
                return false;
                },
        
    
    
                /**
                 * Set list of observable attributes
                 *
                 * @returns {exports.initObservable}
                 */
                initObservable: function () {
                    validator.setConfig(window.checkoutConfig.payment[this.getCode()]);
                    this._super()
                        .observe(['active']);
    
                    return this;
                },
    
                /**
                 * Get payment name
                 *
                 * @returns {String}
                 */
                getCode: function () {
                    return this.code;
                },
    
                /**
                 * Check if payment is active
                 *
                 * @returns {Boolean}
                 */
                isActive: function () {
                    var active = this.getCode() === this.isChecked();
                    this.active(active);
                    return active;
                },        
              
                /**
                 * Action to place order
                 * @param {String} key
                 */
                placeOrder: function (key) {
                    var self = this;
    
                    if (key) {
                        return self._super();
                    }
                    return self.placeOrder('parent');
    
                    return false;
                },
    
               
    
                /**
                 * Trigger order placing
                 */
                placeOrderClick: function () {
                            var self = this;
                if(typeof new eProtect() != 'object') {
                    alert("We are experiencing technical difficulties. Please try again later or call 555-555-1212 (API unavailable)" );
                                     return false;
            }
            // clear test fields
            self.setEprotectResponseFields({"response":"", "message":""});
            var eProtectRequest = {
                "paypageId" : document.getElementById("request$paypageId").value,
                "reportGroup" : document.getElementById("request$reportGroup").value,
                "orderId" : document.getElementById("request$orderId").value,
                "id" : document.getElementById("request$merchantTxnId").value,
                "url" : "https://request.eprotect.vantivprelive.com"
            };
            var formFields = {
                    "accountNum" :document.getElementById('ccNum'),
                    "cvv2" :document.getElementById('cvv2Num'),
                    "paypageRegistrationId":document.getElementById('response$paypageRegistrationId'),
                    "bin" :document.getElementById('response$bin')
                    };
            new eProtect().sendToEprotect(eProtectRequest, formFields, self.submitAfterEprotect,
            self.onErrorAfterEprotect, self.timeoutOnEprotect, 15000);
                    return false;
                },
    
               
    
                /**
                 * Get full selector name
                 *
                 * @param {String} field
                 * @returns {String}
                 * @private
                 */
                getSelector: function (field) {
                    return '#' + this.getCode() + '_' + field;
                },
    
              
                /**
                 * Sets payment payload
                 *
                 * @param {Object} paymentPayload
                 * @private
                 */
                setPaymentPayload: function (paymentPayload) {
                    this.paymentPayload = paymentPayload;
                }, 
    
               /**
                 * Returns state of place order button
                 *
                 * @returns {Boolean}
                 */
                isButtonActive: function () {
                    return this.isActive() && this.isPlaceOrderActionAllowed();
                },
    
                /**
                 * Show error message
                 *
                 * @param {String} errorMessage
                 * @private
                 */
                showError: function (errorMessage) {
                    globalMessageList.addErrorMessage({
                        message: errorMessage
                    });
                }
            });
        }
    );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.