[英]how to handle response of razorpay in angular2?
我正在嘗試使用 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) 函數。
這對我有用。
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
}
找到解決方案
let options:any = {
// your options
}
options.handler = ((response) => {
this.paymentId=(response.razorpay_payment_id);
this.orderanything(this.paymentId)
});
你的功能(orderanything);
orderanything(paymentId) {
// define your functioin
}
它對我有用
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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.