3

I have integrated a payment gateway with a Java based Web-App Now, After a successful and failure transaction, PG accordingly redirect to respectively html pages failure.html,success.html with form data. How can i read and use this data. I have no clue,, need help guys.

   General
    Request URL:http://www.educationxpress.in/failure.html
    Request Method:POST
    Status Code:200 OK
    Remote Address:43.242.215.132:80
  Response Headers
   view source
   Accept-Ranges:bytes
   Connection:Keep-Alive
   Content-Encoding:gzip
   Content-Length:2461
   Content-Type:text/html
   Date:Mon, 21 Mar 2016 11:44:23 GMT
   ETag:W/"7124-1458556448000"
   Last-Modified:Mon, 21 Mar 2016 10:34:08 GMT
   Server:Apache-Coyote/1.1
   Vary:Accept-Encoding
  Request Headers
   view source
   Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.     8
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8
    Cache-Control:max-age=0
    Connection:keep-alive
    Content-Length:1087
    Content-Type:application/x-www-form-urlencoded
    Host:www.xywevbsite.in
    Origin:null
    Upgrade-Insecure-Requests:1
    User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36    (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
  Form Data
    view source
    view URL encoded
    mihpayid:550690310 
    mode:DC
    status:failure
     unmappedstatus:failed

    txnid:f63fdb227b24393099dc
    amount:45.0
    addedon:2016-03-21 17:12:37
    productinfo:Rabbit 
    firstname:Mohit

Need help on how to read this response????

mohit sharma
  • 1,050
  • 10
  • 20

3 Answers3

1

When Integrating with payment gateways or in general when you receive a
redirection URL based on server response.Simply map your URL in controller or in Servlet.

This way you can access the request parameters and based on parameter and other
information you can redirect the page.

Example: I've provided http://www.localhost.in/failure
Map above url in your controller

  @RequestMapping(value = "/failure.do", method = RequestMethod.POST)
public void pgResponse(@RequestBody ResonseBean bean, HttpServletRequest request, HttpServletResponse response )
{
  try
  {
   // Here you can extract the parameters from POST request.
  String amount = (String) request.getParameter("amount");
  String addedon = (String) request.getParameter("addedon");
  String productinfo = (String) request.getParameter("productinfo");
  String firstname = (String) request.getParameter("firstname");

  // Do you business here
  //  Redirect when you're done


  }
  catch ( Exception e )
  {

  }

}

Or You can simply bind a Servlet in your not using Spring MVC, Spring Boot.

In JSP Environment,
Simply use scriptlet in jsp page.For Example:

<%

 String amount = (String) request.getParameter("amount");
 String addedon = (String) request.getParameter("addedon");
 String productinfo = (String) request.getParameter("productinfo");
 String firstname = (String) request.getParameter("firstname");

%>
<script type="javascipt">
// Get java variable value in js
var amount = <%=amount %>;
var addedon  = <%=addedon%>;
var productinfo = <%=productinfo %>;
var firstname = <%=firstname %>;
</script>

There are multiple way for this problem and it's subject to stack that you're using.

mohit sharma
  • 1,050
  • 10
  • 20
0

Client side code has no access to most of the data in the request that was used to load the page the client side code is being executed in, including POST data.

You'll need to use server side code instead.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I am using Java,so how can i get this data to servlet. how can i sent request to servlet – mohit sharma Mar 21 '16 at 12:29
  • @mohitsharma — The payment provider is already sending the data to your server. You just need to make sure that the URL they are using is handled by a servlet and then handle the data as with any other form submission. That's Servlets 101 (and outside my experience as I've never felt the need to use Java as a server side programming language). – Quentin Mar 21 '16 at 12:58
-2

You can't read POST data in client side but you can save it locally when submitting the form using localStorage:

<form onSubmit="formSubmitted()">
    <input type="text" id="firstname" name="firstname" />
    ...
</form>
<script type="text/javascript>
    function formSubmitted() {
        localStorage.setItem('firstname', document.getElementById('firstname').value);
    }
</script>

Also you can use any server side language to get it:

var firstname = "<?php echo $_POST['firstname']; ?>";
campsjos
  • 1,275
  • 15
  • 22
  • The data is coming from the payment provider. You can't add JavaScript to the payment provider's pages. – Quentin Mar 21 '16 at 12:56
  • Yes, you're right, so the only way to do it is using a server side code language. Normally payment providers let the users configure the response URL's, so it should be possible to change the redirects from `failure.html` to `failure.php` (for example) – campsjos Mar 21 '16 at 15:04
  • @campsjos that's exactly want i wanted to know... I 'll just try server side code – mohit sharma Mar 22 '16 at 05:35
  • People downvoting me, please write your reasons, so anyone who comes here will know why they shouldn't use this code. – campsjos Jul 11 '17 at 09:59