fork download
  1. /*
  2. This merchant demo is published by KNET as a demonstration of the process of
  3. Online Payment Gateway Transactions. This is not a fully running demo so the
  4. merchant has to build his site according to his requirements and needs.
  5.  
  6. KNET is NOT responsible for any stability or security issues of the merchant's
  7. site. This code is NOT intended for production use.
  8. */
  9.  
  10. /*
  11.  * NotifyServlet.java
  12.  *
  13.  * Created on March 16, 2006, 9:22 AM
  14.  */
  15.  
  16. package knet;
  17.  
  18. import java.io.*;
  19. import java.net.*;
  20.  
  21. import javax.servlet.*;
  22. import javax.servlet.http.*;
  23.  
  24. /**
  25.  *
  26.  * @author Harley L. Subido
  27.  * @version
  28.  */
  29.  
  30. /*
  31. NOTE: The output of this page should be in the following form:
  32. REDIRECT=<Merchant URL>
  33. Where Merchant URL is his receipt page or error page according to the
  34. success/failure of the transaction processing
  35. */
  36.  
  37. public class NotifyServlet extends HttpServlet {
  38.  
  39. /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  40.   * @param request servlet request
  41.   * @param response servlet response
  42.   */
  43. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  44. throws ServletException, IOException {
  45. response.setContentType("text/html;charset=UTF-8");
  46. PrintWriter out = response.getWriter();
  47.  
  48. // get message details sent from Commerce Gateway
  49. long paymentid = Long.parseLong( request.getParameter("paymentid") );
  50. String result = request.getParameter("result");
  51. String postdate = request.getParameter("postdate");
  52. String details = request.getParameter("udf1");
  53. long tranid = Long.parseLong( request.getParameter("tranid") );
  54. String auth = request.getParameter("auth");
  55. String trackid = request.getParameter("trackid");
  56.  
  57. /* Read up the transaction information from the Merchant's database
  58.   using the Payment ID as the primary Key. Alternatively, the merchant
  59.   may relay on his UNIQUE merchant tracking ID that he sent to the payment
  60.   gateway in fetching the transaction details from his database.
  61.  
  62.   If transaction Payment ID not found in database, report error
  63.   {
  64.   String errURL = "http://w...content-available-to-author-only...e.com/error.jsp";
  65.   System.out.println("Could not find Order #" + paymentID);
  66.   String urlStr = "REDIRECT=" + errURL;
  67.   out.print(urlStr);
  68.   return;
  69. }
  70.  
  71. If transaction Payment ID found in database, but Merchant Tracking
  72.   ID does not match the Tracking Id received from Knet, report error
  73. {
  74.   String errURL = "http://w...content-available-to-author-only...e.com/error.jsp";
  75.   System.out.println("Merchant Tracking IDs mismatch");
  76.   String urlStr = "REDIRECT=" + errURL;
  77.   out.print(urlStr);
  78.   return;
  79.   }
  80.  
  81. Update the merchant database with the result of transaction
  82.   Assuming Recordset is the transaction record object for simplicity
  83. Recordset.setResultCode(result);
  84. Recordset.setPostDate(postdate);
  85. Recordset.setTranID(tranid);
  86. Recordset.setAuthCode(auth);
  87. Recordset.update(order);
  88.   System.out.println("Notified of Order #" + paymentID + " completion.");
  89.   */
  90.  
  91. /* Respond with the URL the consumer should be redirected to, default
  92.   shoud be changed */
  93. String tempURL = "https://w...content-available-to-author-only...e.com/knet/result.jsp" +
  94. "?paymentid=" + paymentid + "&result=" + result + "&postdate=" +
  95. postdate + "&tranid=" + tranid + "&auth=" + auth + "&trackid=" + trackid;
  96. String url = "REDIRECT=" + tempURL;
  97. System.out.println("Response: " + url);
  98. out.print(url); // print response for Knet to read
  99.  
  100. out.flush();
  101. out.close();
  102. }
  103.  
  104. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  105. /** Handles the HTTP <code>GET</code> method.
  106.   * @param request servlet request
  107.   * @param response servlet response
  108.   */
  109. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  110. throws ServletException, IOException {
  111. processRequest(request, response);
  112. }
  113.  
  114. /** Handles the HTTP <code>POST</code> method.
  115.   * @param request servlet request
  116.   * @param response servlet response
  117.   */
  118. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  119. throws ServletException, IOException {
  120. processRequest(request, response);
  121. }
  122.  
  123. /** Returns a short description of the servlet.
  124.   */
  125. public String getServletInfo() {
  126. return "Short description";
  127. }
  128. // </editor-fold>
  129. }
  130.  
Success #stdin #stdout 0.02s 25752KB
stdin
Standard input is empty
stdout
/*
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
 */

package knet;

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=<Merchant URL>
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 <code>GET</code> and <code>POST</code> 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 = "http://w...content-available-to-author-only...e.com/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 = "http://w...content-available-to-author-only...e.com/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://w...content-available-to-author-only...e.com/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();
    }
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> 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 <code>POST</code> 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";
    }
    // </editor-fold>
}