I am using Paytm for payment gateway integration, and I am using the sample kit which is an example of the JSP implementation.
What I am doing is putting this code inside my servlet method as follows:
int appointmentId = rst_appnt.getInt(1);//unique id
TreeMap< String, String> parameters = new TreeMap<String, String>();
parameters.put("ORDER_ID", String.valueOf(appointmentId));
parameters.put("CUST_ID", "CUST001");
parameters.put("INDUSTRY_TYPE_ID", "Retail");
parameters.put("CHANNEL_ID", "WEB");
//parameters.put("TXN_AMOUNT", String.valueOf(rst_appnt.getDouble(3)));
parameters.put("TXN_AMOUNT", "10");
parameters.put("MID", "WorldP64425807474247");
parameters.put("CHANNEL_ID", "WEB");
parameters.put("INDUSTRY_TYPE_ID", "Retail");
parameters.put("WEBSITE", "worldpressplg");
parameters.put("MOBILE_NO", "9876543210");
parameters.put("EMAIL", "[email protected]");
parameters.put("CALLBACK_URL", "http://localhost:8080/Test/pgResponse.jsp");
String checkSum = CheckSumServiceHelper.getCheckSumServiceHelper().genrateCheckSum(PaytmConstants.MERCHANT_KEY, parameters);
StringBuilder outputHtml = new StringBuilder();
outputHtml.append("<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
outputHtml.append("<html>");
outputHtml.append("<head>");
outputHtml.append("<title>Merchant Check Out Page</title>");
outputHtml.append("</head>");
outputHtml.append("<body>");
outputHtml.append("<center><h1>Please do not refresh this page...</h1></center>");
outputHtml.append("<form method='post' action='https://pguat.paytm.com/oltp-web/processTransaction' name='f1'>");
outputHtml.append("<table border='1'>");
outputHtml.append("<tbody>");
for (Map.Entry<String, String> entry : parameters.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
outputHtml.append("<input type='hidden' name='" + key + "' value='" + value + "'>");
}
outputHtml.append("<input type='hidden' name='CHECKSUMHASH' value='" + checkSum + "'>");
outputHtml.append("</tbody>");
outputHtml.append("</table>");
outputHtml.append("<script type='text/javascript'>");
outputHtml.append("document.f1.submit();");
outputHtml.append("</script>");
outputHtml.append("</form>");
out.print(outputHtml);
Here it is submitting using form submission in JavaScript as seen in the below code:
outputHtml.append("<script type='text/javascript'>");
outputHtml.append("document.f1.submit();");
outputHtml.append("</script>");
But it seems to be not executing the script sometimes inside the servlet.
So I referred to the Paytm Java example.
But, unfortunately, it does not have any code to call service to Paytm.
Am I doing correct by using JavaScript inside the servlet, or should I use Java API instead of the sample JSP kit?