/* This merchant demo is published by KNET as a demonstration of the process of Online Payment Gateway Transactions. This is not a fully running demo so the merchant has to build his site according to his requirements and needs. KNET is NOT responsible for any stability or security issues of the merchant's site. This code is NOT intended for production use. */ /* * NotifyServlet.java * * Created on March 16, 2006, 9:22 AM */ import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; /** * * @author Harley L. Subido * @version */ /* NOTE: The output of this page should be in the following form: REDIRECT=https://www.arabshells.net/knet/result.jsp Where Merchant URL is his receipt page or error page according to the success/failure of the transaction processing */ public class NotifyServlet extends HttpServlet { /** Processes requests for both HTTP GET and POST methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // get message details sent from Commerce Gateway long paymentid = Long.parseLong( request.getParameter("paymentid") ); String result = request.getParameter("result"); String postdate = request.getParameter("postdate"); String details = request.getParameter("udf1"); long tranid = Long.parseLong( request.getParameter("tranid") ); String auth = request.getParameter("auth"); String trackid = request.getParameter("trackid"); /* Read up the transaction information from the Merchant's database using the Payment ID as the primary Key. Alternatively, the merchant may relay on his UNIQUE merchant tracking ID that he sent to the payment gateway in fetching the transaction details from his database. If transaction Payment ID not found in database, report error { String errURL = "https://www.arabshells.net/knet/error.jsp"; System.out.println("Could not find Order #" + paymentID); String urlStr = "REDIRECT=" + errURL; out.print(urlStr); return; } If transaction Payment ID found in database, but Merchant Tracking ID does not match the Tracking Id received from Knet, report error { String errURL = "https://www.arabshells.net/knet/error.jsp"; System.out.println("Merchant Tracking IDs mismatch"); String urlStr = "REDIRECT=" + errURL; out.print(urlStr); return; } Update the merchant database with the result of transaction Assuming Recordset is the transaction record object for simplicity Recordset.setResultCode(result); Recordset.setPostDate(postdate); Recordset.setTranID(tranid); Recordset.setAuthCode(auth); Recordset.update(order); System.out.println("Notified of Order #" + paymentID + " completion."); */ /* Respond with the URL the consumer should be redirected to, default shoud be changed */ String tempURL = "https://www.arabshells.net/knet/result.jsp" + "?paymentid=" + paymentid + "&result=" + result + "&postdate=" + postdate + "&tranid=" + tranid + "&auth=" + auth + "&trackid=" + trackid; String url = "REDIRECT=" + tempURL; System.out.println("Response: " + url); out.print(url); // print response for Knet to read out.flush(); out.close(); } // /** Handles the HTTP GET method. * @param request servlet request * @param response servlet response */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** Handles the HTTP POST method. * @param request servlet request * @param response servlet response */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** Returns a short description of the servlet. */ public String getServletInfo() { return "Short description"; } // }