I am losing session data when being redirected from Payment GateWay using java

2.6k views Asked by At

I am setting some values using java session. After calling the Payment gateway, all me stored session values are losing. Please help me how to get those session values.

i set the some values to session like session.setAttribute("id", 120). After redirect the paymeny gateway. I try to get the id using session.getAttribute("id"). Here it returns the null value.

2

There are 2 answers

0
nanofarad On BEST ANSWER

From chat, you had stated that you are keeping the JSP session ID in a URL parameter rather than a cookie. This will cause an issue with the callback from the payment gateway, if the callback URL does not specify the same session ID.

This means that you need to put the session ID in the callback URL. I am not familiar with CCAvenue as a payment gateway, but I can tell you this much:

When you set the callback URL, you need to encode the session ID onto it using HttpServletResponse#encodeURL

You would pass the URL of the callback (i.e. your homepage) to this method, and it will return the callback URL with the session ID encoded within it, if necessary. You can then use this URL as the user redirect (callback) on your gateway and when the redirect completes, the page will be loaded with a valid session.

0
Mahmoud Saleh On

You need to add the JSESSIONID in the callback url something like the following :

HttpSession session = request.getSession();
session.setAttribute("someName", someObject);

String callbackURL = "http://yourapplicationserver.com/callback.jsp;JSESSIONID=" + session.getId();
String redirectURL = "http://paymentgateway.com/process?callbackURL=" + URLEncoder.encode(callbackURL, "UTF-8");

response.sendRedirect(redirectURL);