【问题标题】:how to handle response of razorpay in angular2?如何在angular2中处理razorpay的响应?
【发布时间】:2017-05-10 15:56:46
【问题描述】:

我正在尝试使用 RazorPay 支付网关完成我的支付交易,我尝试如下:

var options = {

   "key": "XXX",

   "amount": 100, // 2000 paise = INR 20
   "name": "Ezshipp",
   "description": this.itemName,
   "image": "../images/logo-blue-1.png",
   "handler": function (response) {
              this.paymentId = response.razorpay_payment_id;
       console.log("payment id "+this.paymentId);
       this.orderanything(this.paymentId);

   },

   "prefill": {
       "name": this.UserName
   },
   "notes": {
       "address": this.pickAddress
   },
   "theme": {
       "color": "#12a6f1"
   }

}; 

当我试图在处理程序响应中调用另一个方法时,我收到如下错误:

this.orderanything 不是函数

但我在我的组件中声明了 orderanything(paymentId) 函数。

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    这对我有用。

    payment() {
    
      //TODO
    
      var options = {
              'key': environment.RAZORPAY,
              'amount': data.attributes.amount,
              'name': 'mydemoApp',
              'description': 'Payment portal',
              'image': '../images/payment-logo.jpg',
              'handler': this.paymentCapture.bind(this),
              'prefill': {
                'name': this.auxiliaryUserName,
              },    
              'theme': {
                'color': '#BB070A'
              },
              'order_id': data.attributes.id,
              'modal': {
                'ondismiss': this.closePop.bind(this)
              }
            };
    }
    
    paymentCapture(response) {
       this.loadingProgress = true;
    
       this.paymentId = response.razorpay_payment_id;
       console.log("payment id "+this.paymentId);
       //TODO
    }
    

    【讨论】:

      【解决方案2】:

      找到解决方案

      let options:any = {
      // your options
      }
      
      options.handler = ((response) => {
      this.paymentId=(response.razorpay_payment_id);
      this.orderanything(this.paymentId)
      });
      

      你的功能(orderanything);

      orderanything(paymentId) {
      // define your functioin
      }
      

      【讨论】:

        【解决方案3】:

        它对我有用

        preparePaymentDetails(order){
        
            var ref = this;
            return  {
              "key": environment.RAZORPAY_KEY_ID, // Enter the Key ID generated from the Dashboard
              "amount": this.payableAmount, // Amount is in currency subunits. Default currency is INR. Hence, 29935 refers to 29935 paise or INR 299.35.
              "name": 'Pay',
              "currency": order.currency,
              "order_id": order.id,//This is a sample Order ID. Create an Order using Orders API. (https://razorpay.com/docs/payment-gateway/orders/integration/#step-1-create-an-order). Refer the Checkout form table given below
              "image": 'https://angular.io/assets/images/logos/angular/angular.png',
              "handler": function (response){
                ref.handlePayment(response);
              },
              "prefill": {
                  "name": `Angular Geeks`
              },
              "theme": {
                  "color": "#2874f0"
              }
             };
           }
        
           handlePayment(response) {
        
            console.log('payment_id:', response.razorpay_payment_id)
          }
        

        【讨论】:

          猜你喜欢
          • 2016-02-29
          • 2017-09-28
          • 1970-01-01
          • 2019-08-02
          • 1970-01-01
          • 1970-01-01
          • 2017-07-20
          • 2021-05-06
          • 2016-12-23
          相关资源
          最近更新 更多