I have called a function inside a function but inner function is not working please help me out
below my code
pay() {
console.log(this.total_ammount)
var options = {
description: 'Payment To View Seller Profile',
image: 'url',
currency: 'INR',
key: 'rzp_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',// this key need to chage for every app
amount: this.total_ammount,
name: 'appname',
prefill: {
email: this.email,
contact: this.mobile,
name: this.name
},
theme: {
color: '#F37254'
},
modal: {
ondismiss: function() {
alert('dismissed')
}
}
};
var successCallback = function(payment_id) {
alert(payment_id);
**here i want to call a function**
let postParams ={
userid:'1',
ammount:'100',
payment_valid:'5',
}
alert(JSON.stringify(postParams));
};
var cancelCallback = function(error) {
alert(error.description + ' (Error ' + error.code + ')');
};
RazorpayCheckout.open(options,successCallback,cancelCallback);
}
I want to call a function inside the successCallback payment id show in alert(payment_id); box
when while i called a function this function is not working or fire
please help me out
Thanks in advace
Didn’t completely get it. Can you a show demo code of how you are trying to call a function and why functions inside a function which is actually a callback to be called in the first place?
Ok, I read the docs but there seems to be no way of detecting whether the checkout went through success or the user cancelled it.
You could just copy paste code inside paymentsave() to successCallback, but the context of this will be lost.
However, can you check with whether the RazorpayCheckout uses any storage of ionic? If yes, then probably, you could just add some key as success in storage and then check that in your current file and call paymentsave() accordingly. Something like below:
var successCallback = function(success) {
alert('payment_id: ' + success.razorpay_payment_id)
var orderId = success.razorpay_order_id
var signature = success.razorpay_signature
this.storage.set('payment_success',true); // here, storage must be an instance variable of RazorpayCheckout
}
and then afterRazorpayCheckout.open(options), you could something like below:
RazorpayCheckout.open(options);
// here, storage is your current class's instance variable
this.storage.get('payment_success').then((has_paid) => {
if(has_paid !== null && has_paid === true){
this.paymentsave();
}
});
Thanks for you effort i have solved just i use arrow functions like this
var successCallback = (success) =>{
alert('payment_id: ' + success.razorpay_payment_id)
var orderId = success.razorpay_order_id
var signature = success.razorpay_signature
this.storage.set('payment_success',true); // here, storage must be an instance variable of RazorpayCheckout
}
its working fine
really i appreciate for your effors
Thanks again
Yes, this should work with the use of arrow functions itself. I too was concerned with the code properly referring to the type of this. Hence, I went with storage. It(arrow functions) properly binds this with it’s enclosing scope as explained in the MDN docs.
var options = {
description: 'Credits towards consultation',
image: 'https://i.imgur.com/3g7nmJC.png',
currency: "INR", // your 3 letter currency code
key: "rzp_test_1DP5mmOlF5G5ag", // your Key Id from Razorpay dashboard
amount: 100, // Payment amount in smallest denomiation e.g. cents for USD
name: 'Razorpay',
prefill: {
email: 'test@razorpay.com',
contact: '9990009991',
name: 'Razorpay'
},
theme: {
color: '#F37254'
},
modal: {
ondismiss: function () {
alert('dismissed')
}
}
};
var successCallback = function (payment_id)
{
alert('payment_id: ' + payment_id);
this.navCtrl.push(OrderConfirmPage) // i want call this function but its fails
}