2017-06-30 66 views
1

我將實現與離子3個應用程序一切正常razorpay發現,我與payment_id successcallback了,但之後沒有happenig喜歡重定向到其他網頁或路由或任何其它活動或打電話等多種功能Razorpay離子3回調問題

我是指下面的鏈接,

https://github.com/razorpay/razorpay-cordova-sample-app/tree/master/rzp-ionic2-example

這裏是我的代碼,

var options = { 
     description: 'Credits towards consultation', 
     image: 'https://i.imgur.com/3g7nmJC.png', 
     currency: 'INR', 
     key: 'rzp_test_1DP5mmOlF5G5ag', 
     amount: '5000', 
     name: 'foo', 
     prefill: { 
     email: '[email protected]', 
     contact: '8879524924', 
     name: 'Pranav Gupta' 
     }, 
     theme: { 
     color: '#F37254' 
     }, 
     modal: { 
     ondismiss: function() { 
      alert('dismissed') 
     } 
     } 
    }; 

    var successCallback = function(payment_id) { 
     alert('payment_id: ' + payment_id); 
     this.navCtrl.push("ThankyouPage",{ 
       status: this.status 
      }); 
    }; 

    var cancelCallback = function(error) { 
     alert(error.description + ' (Error ' + error.code + ')'); 
    }; 

    this.platform.ready().then(() => { 
     RazorpayCheckout.open(options, successCallback, cancelCallback); 
    }) 

回答

2

你應該ü SE arrow functions這樣的:

var options = { 
    description: 'Credits towards consultation', 
    image: 'https://i.imgur.com/3g7nmJC.png', 
    currency: 'INR', 
    key: 'rzp_test_1DP5mmOlF5G5ag', 
    amount: '5000', 
    name: 'foo', 
    prefill: { 
    email: '[email protected]', 
    contact: '8879524924', 
    name: 'Pranav Gupta' 
    }, 
    theme: { 
    color: '#F37254' 
    }, 
    modal: { 
    ondismiss:() => { // <- Here! 
     alert('dismissed') 
    } 
    } 
}; 

var successCallback = (payment_id) => { // <- Here! 
    alert('payment_id: ' + payment_id); 
    this.navCtrl.push("ThankyouPage",{ 
      status: this.status 
     }); 
}; 

var cancelCallback = (error) => { // <- Here! 
    alert(error.description + ' (Error ' + error.code + ')'); 
}; 

this.platform.ready().then(() => { 
    RazorpayCheckout.open(options, successCallback, cancelCallback); 
}) 

當使用常規功能,this關鍵字引用本身的功能,但使用箭頭功能時,this屬性不被覆蓋,仍引用組件實例(如你所定義的navCtrl屬性)

1

這個問題的另一種解決方案可以分配此變量以某些其他變量和在回調使用它像 -

let me = this; 

var successCallback = function(payment_id) { 
    alert('payment_id: ' + payment_id); 
    me.navCtrl.push("ThankyouPage",{ 
     status: me.status 
    }); 
};