我将用Ionic 3应用程序实现Razorpay Everything Works Find,我获得了带有支付ID的成功回调,但之后没有任何事情发生,如重定向到其他页面或路由或任何其他活动或调用函数等。
我指的是以下链接,
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);
    })

最佳答案

您应该像这样使用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属性)。

09-25 18:10