0

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

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

组件.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();
}

组件.html

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

2 回答 2

0

从语法上讲,您不会在 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
   }
}

有关处理函数的更多信息,请参阅此处的示例代码:

于 2018-02-22T13:33:56.027 回答
0

尝试这个

"handler": function (response) {
      console.log(response)
      this.callbackRazor(response) // your function
    }.bind(this),
于 2020-11-29T05:54:49.213 回答