【问题标题】:unable to integrate razorpay in angular 4无法将 razorpay 集成到 Angular 4 中
【发布时间】:2018-09-27 00:08:00
【问题描述】:

我正在尝试集成 razorPay 支付网关。

  payNow( ) { 
        
          var options = {
            "key": "rzp_test_dveDexCQKoGszl",
            "amount":((this.buyNow==1)?this.shared.totalAmountWithDisocuntBuyNow:this.shared.totalAmountWithDisocunt)*100, // 2000 paise = INR 20
            "name": " MARKET",
            "description": "Order #",
        
            "handler": function (response){
                console.log(response);
                alert(response.razorpay_payment_id);
                this.paid();
                this.shared.addOrder(this.buyNow,response.razorpay_payment_id);     
         
              
               },
            "prefill": {
                "name":  this.shared.orderDetails.billing_firstname + " " + this.shared.orderDetails.billing_lastname,
                "email": this.shared.customerData.customers_email_address,
                "contact": this.shared.customerData.customers_telephone,
           
            },
            "notes": {
                "address": this.shared.orderDetails.billing_street_address+', '+this.shared.orderDetails.billing_city+', '+this.shared.orderDetails.billing_state+' '+this.shared.orderDetails.billing_postcode+', '+this.shared.orderDetails.billing_country 
            },
            "theme": {
                "color": "blue"
            }
        };
        var rzp1 = new Razorpay(options);

       rzp1.open();
  
     // body...
   } 
   paid()
   {alert();}

我在处理程序中定义了回调函数。但问题是它成功记录了响应并发出警报,但它没有调用 this.paid() 要么 this.shared.addOrder(this.buyNow,response.razorpay_payment_id);

没有任何控制台错误。它只是不调用任何上述的methioned 函数。

【问题讨论】:

  • 您有任何控制台错误吗?
  • 函数中的 this 指的是函数中的上下文,而不是你的类。
  • @AnuradhaGunasekara 没有错误。没有调用任何函数

标签: javascript angular razorpay


【解决方案1】:

您可以通过使用以下语法将其绑定到函数来调用处理函数

"handler":this.shared.addOrder.bind(this,this.buyNow) ,

这对我有用。

【讨论】:

    猜你喜欢
    • 2016-06-17
    • 2018-05-12
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 2020-08-18
    • 2018-09-02
    相关资源
    最近更新 更多