I am trying to prevent user from going back if done any payment. If the payment is successfully done then redirecting to success page and showing some message there. Now, I want if user clicks on back button then, he should not be able to redirect to checkout page, instead of that I want to redirect them to dashboard. Below is my javascript function to check payment status and then if successful, redirect to success page.
function checkStatus(status){
switch(status){
case "succeeded":
showmessage("Payment succeeded!");
break;
case "processing":
showmessage("Your payment is processing.");
break;
case "requires_payment_method":
showmessage("Your payment was not successful, please try again.");
break;
default:
showmessage("Something went wrong.");
break;
}
}
function showmessage(response){
if(response == "Payment succeeded!"){
window.location.href = 'success';
}else{
window.location.href = 'failed';
}
}
Below is controller for success function:
@RequestMapping(value= {WebUrl.success},method= {RequestMethod.GET,RequestMethod.POST})
public @ResponseBody ModelAndView success(HttpServletRequest request, HttpSession session) {
logger.info("Payment Success Page is called ");
ModelAndView modelAndView;
User loginuser = (User)session.getAttribute("user");
if(loginuser == null || !loginuser.getRoles().toString().equalsIgnoreCase("[ROLE_CUSTOMER]")) {
modelAndView = new ModelAndView("redirect:.."+ WebUrl.login);
}else {
modelAndView = new ModelAndView(WebUrl.success);
modelAndView.addObject("loginuser", loginuser);
}
return modelAndView;
}
How to get this in spring boot?