Re: How to programmatically send a form (Dev WO)
Re: How to programmatically send a form (Dev WO)
- Subject: Re: How to programmatically send a form (Dev WO)
- From: Dev WO <email@hidden>
- Date: Mon, 23 Jan 2006 20:59:42 +0100
Hi James and Joseph,
I'm actually trying to finish this "sending a form", but when using
the string generated by the method provided by the bank in the
example you James provided, I got some sort of a loop and finally a:
" The web server closed the connection without sending any response "
No crash, only this...
I assume the setUrl should only get a URL and not an entire html form?
I probably go the wrong way. And really start to get a headache;)
So I'm going to try to be "clear".
The bank provided me with 4 java Classes:
-CyberMut1_2openLib.java which is abstract and got all the method to
generate a string from the values (amount, etc)
-YourTpeInstance.java which extends CyberMut1_2... with the personal
codes for the shop
-YourServlet1.java which extends HttpServlet, and handle the first
part of the process which is sending the user to the bank server with
all the data (amount, etc)
-YourServlet2.java which extends HttpServlet, and handle both the
verification of the bank answer (to check if the request is not fake)
and send a confirmation.
So it seems pretty much all done, except that I don't know how to
integrate this with my WOApplication:(
I understand I have to call a method in YourServlet1 from my order
page, and then use a direct action to call YourServlet2 from the bank
answer.
Here are the relevant method I have to call (I think):
-YourServlet1:
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println( "<title>CyberMUT-P@iement™ /
P@iementCIC™"
+ " Phase Aller </title>");
out.println("</head>");
out.println("<body>");
out.println( "<h2>CyberMUT-P@iement™ / P@iementCIC™"
+ " -- YourServlet1 1.03</h2>CyberMUT compliance
test:"
+ "<hr size=1>");
try {
YourTpeInstance YourTpe = new YourTpeInstance("", "", "");
out.println("<tt>TPE CM-CIC : " + YourTpe.getTPE() );
out.println(" - Bank Server : " + YourTpe.getBankServer
() );
out.println("<br> Interface Version : "
+ YourTpe.getVersion() );
out.println(" - Hash Method : " + YourTpe.getHash() );
out.println("<br> " + YourTpe.getCtlHmac() +
" -");
out.println("</tt><hr size=1>End of CyberMUT compliance
test.<br>"
+ "First, check that the CtlHmac value obtained above
is the "
+ "same as the one you got from extract2HmacSha1.htm. "
+ "If it is equal and you are rejected from the bank
test "
+ "server with a message saying that the security
requirements "
+ "have not been met, then copy the compliance test
above and "
+ "send it to <a href=mailto:centrecom@e-
i.com>CENTRECOM</a>."
+ "<br><b>BUT DO *NEVER* SEND YOUR SECRET KEY TO
ANYBODY !</b>"
+ "<p><font color=blue>Before clicking on the button, "
+ "you should have edited the code of this Servlet and "
+ "changed it according to your personnal parameters"
+ "</font></p>" + "Payment button : <br>");
// test-only pseudoRandom reference generator
String Reference = Integer.toHexString(YourTpe.hashCode());
// You must fill the parameters below with your own values
String Formulaire = YourTpe.CreerFormulaireHmac(
"123.45EUR", Reference, "infos libres utiles",
"http://www.domain.com/",
"http://www.domain.com/TransactionOK?ref=facture00000001",
"http://www.domain.com/TransactionKO?ref=facture00000001",
"FR", //EN DE IT ES (*)
"Company", // Site code-societe (*)
"Paiement CB"); // payment button text
// (*) according to CentreCom's settings for your
merchant account
out.println(Formulaire);
out.println( "<br>Information : Form source :<hr
size=1><xmp>"
+ Formulaire + "</xmp><hr size=1>End of form
source.");
} catch (Exception e) { // log ... e ...
out.println("CyberMUT-P@iement failed.");
// Here you may use 'e' to get more information about the
// incident, but be careful not showing it to the user
since
// it may contain confidential informations.
}
out.println("<h2>CyberMUT-P@iement™ /
P@iementCIC™</h2>");
out.println("</body>");
out.println("</html>");
out.close();
}
-YourServlet2:
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException {
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
String ChampMac = request.getParameter("MAC");
String TPE = request.getParameter("TPE");
String DateCommande = request.getParameter("date");
String Montant = request.getParameter("montant");
String Reference = request.getParameter("reference");
String TexteLibre = request.getParameter("texte-libre");
String CodeRetour = request.getParameter("code-retour");
String RetourPLUS = request.getParameter("retourPLUS");
if(RetourPLUS==null) {
RetourPLUS = "";
}
try {
YourTpeInstance YourTpe = new YourTpeInstance(TPE, "", "");
String MacOk = YourTpe.TesterHmac(ChampMac,
DateCommande,
Montant,
Reference,
TexteLibre,
CodeRetour,
RetourPLUS);
if (YourTpe.isMsgAuth(MacOk)) { // Message authenticated
// ... log ...
// Payment Ok ?
if (YourTpe.isPayment(CodeRetour)) {
// ... send congratulation mail ...
// ... update (DB) Order Status ...
// ... initiate delivery process ...
}
// Payment test enabled ?
else if (YourTpe.isTestPayment(CodeRetour)) {
// out.println(" [" + MacOk + "]-[" + CodeRetour
+"]- ");
// ...
} else {
// No payment now
// (but a succesfull trial may happen thereafter).
// ...
}
// ...
}
else { // Message not authenticated
// ... log alert with MacOk content
}
out.println(YourTpe.CreerAccuseReception(MacOk));
// warning: no extra out.println() allowed
} catch (Exception e) { // log ... e ...
out.println("CyberMUT-P@iement failed");
// Here you may use 'e' to get more information about the
// incident, but be careful not showing it to the user
since
// it may contain confidential informations.
}
out.close();
}
Basically, I know how to complete the method to update the order
validation, etc. What I don't know is:
1-How to call the doPost() in YourServlet1 from my WO method that
will "validate the order", and return the bank page (which is in the
action parameter of the generated form string)
2-How to process the bank server answer through a direct action
Can someone help me to get back on track?
Thanks a lot
Xavier
Xavier,
I wrote a similar app a couple years ago for PayFlowLink using
WORedirect:
public WOComponent sendToVerisign() {
WORedirect nextPage;
nextPage = new WORedirect(context());
nextPage.setUrl (yourTargetUrlAsString()); <-- use your banks
method here
return nextPage;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden