hi i am using razorpay payment integration and i have implemented when my payment success it returns to same page but i want to navigate to success page so how to achive this i am using ionic 4 angular 8
Whatever you get as the results of the payment is what you use to determine what route to follow next which can be done simply using ifelse and routerlink
if(success){
// Go to success page
routerLink='link to the success page';
} else {
// Go to failed page
routerLink='link to failed page';
}
async payWithRazor() {
console.log(“invoice details=”,this.invoiceDetails.InvoiceMst_Id);
let data;
await this.storage.getObject(“userData”).then(res=>{
data=res;
})//do u have username and password whre u can use ur mobile number
var options = {
description: ‘MedV’,
image: ‘https://i.imgur.com/3g7nmJC.png’,
currency: this.currency,
key: this.razor_key,
amount: this.paymentAmount,
name: ‘MedV’,
// OrderID:this.invoiceDetails.InvoiceMst_Id,
Notes:‘tytyu’,
prefill: {
email: ‘’,
contact: data.mobNo,
name:data.customerName,
},
theme: {
color: '#004a8e'
},
modal: {
ondismiss: function () {
alert('dismissed')
}
}
};
let incId=this.invoiceDetails.InvoiceMst_Id;
var successCallback = (payment_id) => {
alert(‘payment_id: ’ + payment_id);//only payment id will show if success means?yes this code shows payment id
console.log(“invoide id=”,incId.InvoiceMst_Id);
console.log(“payment id=”,payment_id);
this.account.successPayment(incId,1,payment_id).subscribe(res=>{
let data=JSON.parse(res[’_body’]);
console.log(“data=”,data);
})
this.router.navigateByUrl(’/pages/razor’);
}
var cancelCallback = (error) =>{
alert(error.description + ’ (Error ‘+error.code+’)’)
}
RazorpayCheckout.open(options, successCallback, cancelCallback)
}
this our code let me know where to call router
Sorry but i can barely figure out what your code is doing but here is what i can suggest.
You need to have separation of tasks.
- Create a service that handles all related authentication issues this will code away the need to call storage requests here plus username and password issues.
- Create a service to handle payment tasks. This will help deal with successful and failed payment and help to give feedback in order to route to desired locations
- Create service to deal with invoices and related tasks like pending invoices, payment status et al
thank you soo much for your response…