如何在angular2中处理razorpay的响应?

时间:2017-05-10 15:56:46

标签: angular typescript

我正在尝试使用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)函数。

3 个答案:

答案 0 :(得分:2)

这项工作适合我。

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
}

答案 1 :(得分:1)

找到解决方案

@

你的功能(orderanything);

let options:any = {
// your options
}

options.handler = ((response) => {
this.paymentId=(response.razorpay_payment_id);
this.orderanything(this.paymentId)
});

答案 2 :(得分:0)

对我有用

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)
  }