【问题标题】:Angular 2 custom function not getting called from razorpay options property未从 razorpay 选项属性调用 Angular 2 自定义函数
【发布时间】:2018-08-01 21:36:16
【问题描述】:

我有一个具有处理函数的选项属性。 我想从此属性调用自定义方法,但似乎没有调用该方法。

基本上我试图在 checkOutorder() 中创建一个新订单,该订单应该在成功付款时创建

component.ts

options = {
  //Redirect on success order
  if (typeof response.razorpay_payment_id == "undefined" ||response.razorpay_payment_id < 1) 
  {
    console.log("failure page");
  } else
  {
    console.log("success page");
   /*How to call the checkOutorder function from this property*/
    this.checkOutorder   //Doesnt call !
 },
};


checkOutorder() {
    ...
    ...
  console.log('Order Placed SuccessFully')
}

 public initPay(): void {
    this.options.amount = this.getTotal() * 100;
    this.rzp1 = new this.winRef.nativeWindow.Razorpay(this.options);
    /* If i put the contents of checkOutorder() here, it works , but "Order Placed SuccessFully" message appears even before the payment is made*/
    this.rzp1.open();
}

component.html

<button id="rzp-button1" class="razorpay-payment-button" (click)="initPay();">Pay</button>

【问题讨论】:

    标签: javascript angular2-forms razorpay


    【解决方案1】:

    从语法上讲,你不会在 JS 对象中编写 if-else 块。

    你可以试试下面的,

    options = {
       handler: function(response) {
         // Control comes here only in case of success. In case of failure,  razorpay form shows "Retry button"
         console.log('Payment Success');
         // Your custom logic
       }
    }
    

    有关处理函数的更多信息,请参考示例代码here

    【讨论】:

    • 请给出调用 checkOutorder() 的方法的答案...您在 Angular1 中指定的链接
    【解决方案2】:

    试试这个

    "handler": function (response) {
          console.log(response)
          this.callbackRazor(response) // your function
        }.bind(this),
    

    【讨论】:

      猜你喜欢
      • 2018-01-14
      • 2020-02-15
      • 2017-08-26
      • 1970-01-01
      • 2017-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多