|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/3/2003 Posts: 9 Location: ,
|
I'm using this code that I basically cut and pasted from your code samples and I keep getting an invalid response from the server. Any ideas?
<html>
<head>
<title>
ProcessPayment
</title>
</head>
<body>
<%@ page import="java.util.*,java.net.*,java.io.*,java.sql.*,javax.mail.*,javax.mail.internet.*" %>
<%@ page session="false" %>
<%
// read post from PayPal system and add 'cmd'
Enumeration en = request.getParameterNames();
String str = "cmd=_notify-validate";
while(en.hasMoreElements()){
String paramName = (String)en.nextElement();
String paramValue = request.getParameter(paramName);
str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue);
}
// post back to PayPal system to validate
// NOTE: change http: to https: in the following URL to verify using SSL (for increased security).
// using HTTPS requires either Java 1.4 or greater, or Java Secure Socket Extension (JSSE) installed
// and configured for older versions.
URL u = new URL("http://www.paypal.com/cgi-bin/webscr");
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
PrintWriter pw = new PrintWriter(uc.getOutputStream());
pw.println(str);
pw.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(uc.getInputStream()));
String res = in.readLine();
in.close();
// assign posted variables to local variables
String FirstName = request.getParameter("first_name");
String LastName = request.getParameter("last_name");
String Address = request.getParameter("address_name");
String AddressStreet = request.getParameter("address_street");
String AddressCity = request.getParameter("address_city");
String AddressState = request.getParameter("address_state");
String AddressZip = request.getParameter("address_zip");
String AddressCountry = request.getParameter("address_country");
String Email = request.getParameter("receiver_email");
String itemNumber = request.getParameter("item_number");
String invoice = request.getParameter("invoice");
String paymentStatus = request.getParameter("payment_status");
String paymentGross = request.getParameter("payment_gross");
String txnId = request.getParameter("txn_id");
String payerEmail = request.getParameter("payer_email");
String SubscriptionStartDate = request.getParameter("subscr_date");
String PaypalID = request.getParameter("paypal_id");
String PaymentType = request.getParameter("payment_type");
boolean txnIdError = false;
// check notification validation
if(res.equals("VERIFIED")) {
if(paymentStatus.equals("COMPLETED") && Email.equals("someone@hotmail.com")){
try{
Class.forName("org.gjt.mm.mysql.Driver");
}catch(ClassNotFoundException e){}
try{
Properties props = new Properties();
props.put("mail.smtp.host","localhost");
Session S = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(S);
InternetAddress from = new InternetAddress("Someone@hotmail.com");
message.setFrom(from);
InternetAddress to = new InternetAddress("Someone@hotmail.com");
message.addRecipient(Message.RecipientType.TO,to);
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:xxxx/website?user=xx&password=xxxx");
Statement s = con.createStatement();
String sql = "INSERT INTO ProcessedTxnId"+" (PaypalIds)"+ " VALUES"+ " ('" + txnId+ "')";
String trans = "INSERT INTO StoredTransactionInfo" + " (id, FirstName, LastName, AddressName, AddressStreet, AddressCity, AddressState, AddressZip, AddressCountry, PaypalID, PaymentType, DateTime)" + " VALUES" +
" (null,'" + FirstName + "'," + " '" + LastName + "'," +
" '" + Address + "'," + " '" + AddressStreet + "'," +
" '"+ AddressCity + "'," + " '"+ AddressState + "'," +
" '"+ AddressZip + "'," + " '"+ AddressCountry + "'," +
" '"+ PaypalID + "'," + " '"+ PaymentType + "'," + " '" +
"Now()" + "')";
ResultSet rs = s.executeQuery(sql);
if(rs.next()){
rs.close();
// The txnId is a duplicate.
txnIdError = true;
}else {
rs.close();
int i = s.executeUpdate(sql);
if (i==1) {
//txnId insert was successful
//Transaction has completed successfully
txnIdError = false;
s.executeUpdate(trans);
message.setSubject("Subscription Complete Notice from JJC_Industries");
message.setText("This email is confirmation of successful completion of payment and signup of a new user."
+"The new user is: "+ payerEmail);
Transport.send(message);
%>
<jsp:forward page="registrationservlet" >
<jsp:param name="payerEmail" value="<%=payerEmail%>" />
</jsp:forward>
<%
}
}
}catch(SQLException e){%>
<jsp:forward page="error.jsp" >
<jsp:param name="ErrorCode" value="<%=e.toString()%>" />
</jsp:forward>
<%
}
catch(Exception e){%>
<jsp:forward page="error.jsp" >
<jsp:param name="ErrorCode" value="<%=e.toString()%>" />
</jsp:forward>
<%
}
if(txnIdError){
%>
<jsp:forward page="error.jsp" >
<jsp:param name="ErrorCode" value="<%=" First Name: "+FirstName+" LastName: "+LastName+" Address: "+Address+" Address Street: "+AddressStreet+" Address City: "+AddressCity+" Address State: "+AddressState+" Address Zip: "+AddressZip+" AddressCountry: "+AddressCountry+" Email: "+Email+" ItemNumber: "+itemNumber+" Invoice: "+invoice+" payment status: "+paymentStatus+" payment Gross: "+paymentGross+" txnid: "+txnId+" payerEmail: "+payerEmail+" subscription start date: "+SubscriptionStartDate+" paypal id: "+PaypalID+" payment type: "+PaymentType+" txniderror: "+txnIdError+" res: "+res+" str: "+str%>" /> </jsp:forward>
<%
}
}
}
else if(res.equals("INVALID")) {
// log for investigation, create some log to handle all of the errors for further reviewing
%>
<jsp:forward page="error.jsp" >
<jsp:param name="ErrorCode" value="<%=" First Name: "+FirstName+" LastName: "+LastName+" Address: "+Address+" Address Street: "+AddressStreet+" Address City: "+AddressCity+" Address State: "+AddressState+" Address Zip: "+AddressZip+" AddressCountry: "+AddressCountry+" Email: "+Email+" ItemNumber: "+itemNumber+" Invoice: "+invoice+" payment status: "+paymentStatus+" payment Gross: "+paymentGross+" txnid: "+txnId+" payerEmail: "+payerEmail+" subscription start date: "+SubscriptionStartDate+" paypal id: "+PaypalID+" payment type: "+PaymentType+" txniderror: "+txnIdError+" res: "+res+" str:"+str%>" /> </jsp:forward>
<%
}
else {
// error, something else besides verified or completed was sent.
%>
<jsp:forward page="error.jsp" >
<jsp:param name="ErrorCode" value="<%=" First Name: "+FirstName+" LastName: "+LastName+" Address: "+Address+" Address Street: "+AddressStreet+" Address City: "+AddressCity+" Address State: "+AddressState+" Address Zip: "+AddressZip+" AddressCountry: "+AddressCountry+" Email: "+Email+" ItemNumber: "+itemNumber+" Invoice: "+invoice+" payment status: "+paymentStatus+" payment Gross: "+paymentGross+" txnid: "+txnId+" payerEmail: "+payerEmail+" subscription start date: "+SubscriptionStartDate+" paypal id: "+PaypalID+" payment type: "+PaymentType+" txniderror: "+txnIdError+" res: "+res+" str: "+str%>" /> </jsp:forward>
<%
}
%>
</body>
</html>
I put a couple of xx's in there to keep system info secure.
|
|
|
|
|
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 9/16/2002 Posts: 2,960 Location: ,
|
Do you have an example of the error message your script generates? Patrick Breitenbach PayPal, Inc. Dev Net: https://www.paypal.com/pdn
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/3/2003 Posts: 9 Location: ,
|
all i get is an INVALID response from the server. My programming teacher and I think we've figured it out. We suspect that the jsp is not getting the first post. I'm gonna write a servlet to handle it instead.
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 9/16/2002 Posts: 2,960 Location: ,
|
You can use this form for quick testing. Set the action to your script's URL. <form method="post" action="http://www.mysite.com/ipn.cfm"> <input type="submit" name="" value="Test IPN"> <input type="hidden" name="payment_date" value="17:53:45 Nov 5, 2002 PST"> <input type="hidden" name="txn_type" value="web_accept"> <input type="hidden" name="last_name" value="Breitenbach"> <input type="hidden" name="item_name" value=""> <input type="hidden" name="payment_gross" value="0.01"> <input type="hidden" name="mc_currency" value="USD"> <input type="hidden" name="payment_type" value="instant"> <input type="hidden" name="verify_sign" value="AlWncXKLadIepzMosHhM.VWxC0Z6AZYI0ynXRnEUma0d3RMC.TXWaJro"> <input type="hidden" name="payer_status" value="unverified"> <input type="hidden" name="payer_email" value="pb-test@paypal.com"> <input type="hidden" name="txn_id" value="01G32341KC3727119"> <input type="hidden" name="first_name" value="Patrick"> <input type="hidden" name="quantity" value="1"> <input type="hidden" name="receiver_email" value="pb-sell@paypal.com"> <input type="hidden" name="payer_id" value="QGVDAFGZ9XHLJ"> <input type="hidden" name="payment_method" value="non_cc"> <input type="hidden" name="item_number" value=""> <input type="hidden" name="payment_status" value="Completed"> <input type="hidden" name="mc_gross" value="0.01"> <input type="hidden" name="custom" value=""> <input type="hidden" name="notify_version" value="1.4"> </form> Patrick Breitenbach PayPal, Inc. Dev Net: https://www.paypal.com/pdn
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/3/2003 Posts: 9 Location: ,
|
I'll give you script a try. My servlet is not giving the correct response either. It seems like i'm missing the first post still.
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/3/2003 Posts: 9 Location: ,
|
The servlet is telling me that it's recieving a get request. What can you tell my from your side? I tried the script twice to make sure I was getting the same response.
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 9/16/2002 Posts: 2,960 Location: ,
|
When you use the HTML FORM from this thread? It's clearly a POST: <form method="post" action="http://www.mysite.com/ipn.cfm"> Patrick Breitenbach PayPal, Inc. Dev Net: https://www.paypal.com/pdn
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/3/2003 Posts: 9 Location: ,
|
It's still giving me a get response. I think the problem may be with Internet Explorer itself. My post's work fine when I post from a jsp page to the servlet but when I use internet explorer it sends me a get response. The guys on the java.sun.com forums said that netscape doesn't produce this same behavior. Do you have any knowledge of this happening?
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 9/16/2002 Posts: 2,960 Location: ,
|
I haven't heard anything about that. Browsers are generally pretty reliable in sending a GET or a POST. Patrick Breitenbach PayPal, Inc. Dev Net: https://www.paypal.com/pdn
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/3/2003 Posts: 9 Location: ,
|
I fixed it finally. I was using a url that redirects to my original url and that was generating a get request. Wow, that was some ordeal.
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/3/2003 Posts: 9 Location: ,
|
At this point I have the servlet getting the info from the post object. The test button that you sent me is giving me an invalid response still. I'm not sure why though.
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/3/2003 Posts: 9 Location: ,
|
Could you give that test script again with the reciever email as JJC_Industries@hotmail.com? I want to test it as it'll work.
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 3/22/2003 Posts: 8 Location: ,
|
xfactor973 --
Did you ever get this to work? I'm having similar problems. I have converted mine to a servlet as well. When I test it I always get a "INVALID" response and it say's my script isn't responding. I dont have a doGet or doPost issue like you had, mine just doesn't work.
Maybe you could point me in some direction? Or did you give up on this?
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 9/10/2003 Posts: 2 Location: ,
|
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Originally posted by xfactor973 [br]I'm using this code that I basically cut and pasted from your code samples and I keep getting an invalid response from the server. Any ideas? <html> <head> <title> ProcessPayment </title> </head> <body> <%@ page import="java.util.*,java.net.*,java.io.*,java.sql.*,javax.mail.*,javax.mail.internet.*" %> <%@ page session="false" %> <% // read post from PayPal system and add 'cmd' Enumeration en = request.getParameterNames(); String str = "cmd=_notify-validate"; while(en.hasMoreElements()){ String paramName = (String)en.nextElement(); String paramValue = request.getParameter(paramName); str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue); } // post back to PayPal system to validate // NOTE: change http: to https: in the following URL to verify using SSL (for increased security). // using HTTPS requires either Java 1.4 or greater, or Java Secure Socket Extension (JSSE) installed // and configured for older versions. URL u = new URL("http://www.paypal.com/cgi-bin/webscr"); URLConnection uc = u.openConnection(); uc.setDoOutput(true); uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); PrintWriter pw = new PrintWriter(uc.getOutputStream()); pw.println(str); pw.close();
BufferedReader in = new BufferedReader( new InputStreamReader(uc.getInputStream())); String res = in.readLine(); in.close();
// assign posted variables to local variables String FirstName = request.getParameter("first_name"); String LastName = request.getParameter("last_name"); String Address = request.getParameter("address_name"); String AddressStreet = request.getParameter("address_street"); String AddressCity = request.getParameter("address_city"); String AddressState = request.getParameter("address_state"); String AddressZip = request.getParameter("address_zip"); String AddressCountry = request.getParameter("address_country"); String Email = request.getParameter("receiver_email"); String itemNumber = request.getParameter("item_number"); String invoice = request.getParameter("invoice"); String paymentStatus = request.getParameter("payment_status"); String paymentGross = request.getParameter("payment_gross"); String txnId = request.getParameter("txn_id"); String payerEmail = request.getParameter("payer_email"); String SubscriptionStartDate = request.getParameter("subscr_date"); String PaypalID = request.getParameter("paypal_id"); String PaymentType = request.getParameter("payment_type"); boolean txnIdError = false; // check notification validation
if(res.equals("VERIFIED")) { if(paymentStatus.equals("COMPLETED") && Email.equals("someone@hotmail.com")){ try{ Class.forName("org.gjt.mm.mysql.Driver"); }catch(ClassNotFoundException e){} try{ Properties props = new Properties(); props.put("mail.smtp.host","localhost"); Session S = Session.getInstance(props,null); MimeMessage message = new MimeMessage(S); InternetAddress from = new InternetAddress("Someone@hotmail.com"); message.setFrom(from); InternetAddress to = new InternetAddress("Someone@hotmail.com"); message.addRecipient(Message.RecipientType.TO,to); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:xxxx/website?user=xx&password=xxxx"); Statement s = con.createStatement(); String sql = "INSERT INTO ProcessedTxnId"+" (PaypalIds)"+ " VALUES"+ " ('" + txnId+ "')"; String trans = "INSERT INTO StoredTransactionInfo" + " (id, FirstName, LastName, AddressName, AddressStreet, AddressCity, AddressState, AddressZip, AddressCountry, PaypalID, PaymentType, DateTime)" + " VALUES" + " (null,'" + FirstName + "'," + " '" + LastName + "'," + " '" + Address + "'," + " '" + AddressStreet + "'," + " '"+ AddressCity + "'," + " '"+ AddressState + "'," + " '"+ AddressZip + "'," + " '"+ AddressCountry + "'," + " '"+ PaypalID + "'," + " '"+ PaymentType + "'," + " '" + "Now()" + "')"; ResultSet rs = s.executeQuery(sql); if(rs.next()){ rs.close(); // The txnId is a duplicate. txnIdError = true; }else { rs.close(); int i = s.executeUpdate(sql); if (i==1) { //txnId insert was successful //Transaction has completed successfully txnIdError = false; s.executeUpdate(trans); message.setSubject("Subscription Complete Notice from JJC_Industries"); message.setText("This email is confirmation of successful completion of payment and signup of a new user." +"The new user is: "+ payerEmail);
Transport.send(message); %> <jsp:forward page="registrationservlet" > <jsp:param name="payerEmail" value="<%=payerEmail%>" /> </jsp:forward> <% } } }catch(SQLException e){%> <jsp:forward page="error.jsp" > <jsp:param name="ErrorCode" value="<%=e.toString()%>" /> </jsp:forward> <% } catch(Exception e){%> <jsp:forward page="error.jsp" > <jsp:param name="ErrorCode" value="<%=e.toString()%>" /> </jsp:forward> <% } if(txnIdError){ %> <jsp:forward page="error.jsp" > <jsp:param name="ErrorCode" value="<%=" First Name: "+FirstName+" LastName: "+LastName+" Address: "+Address+" Address Street: "+AddressStreet+" Address City: "+AddressCity+" Address State: "+AddressState+" Address Zip: "+AddressZip+" AddressCountry: "+AddressCountry+" Email: "+Email+" ItemNumber: "+itemNumber+" Invoice: "+invoice+" payment status: "+paymentStatus+" payment Gross: "+paymentGross+" txnid: "+txnId+" payerEmail: "+payerEmail+" subscription start date: "+SubscriptionStartDate+" paypal id: "+PaypalID+" payment type: "+PaymentType+" txniderror: "+txnIdError+" res: "+res+" str: "+str%>" /> </jsp:forward> <% } } } else if(res.equals("INVALID")) { // log for investigation, create some log to handle all of the errors for further reviewing %> <jsp:forward page="error.jsp" > <jsp:param name="ErrorCode" value="<%=" First Name: "+FirstName+" LastName: "+LastName+" Address: "+Address+" Address Street: "+AddressStreet+" Address City: "+AddressCity+" Address State: "+AddressState+" Address Zip: "+AddressZip+" AddressCountry: "+AddressCountry+" Email: "+Email+" ItemNumber: "+itemNumber+" Invoice: "+invoice+" payment status: "+paymentStatus+" payment Gross: "+paymentGross+" txnid: "+txnId+" payerEmail: "+payerEmail+" subscription start date: "+SubscriptionStartDate+" paypal id: "+PaypalID+" payment type: "+PaymentType+" txniderror: "+txnIdError+" res: "+res+" str:"+str%>" /> </jsp:forward> <% } else { // error, something else besides verified or completed was sent. %> <jsp:forward page="error.jsp" > <jsp:param name="ErrorCode" value="<%=" First Name: "+FirstName+" LastName: "+LastName+" Address: "+Address+" Address Street: "+AddressStreet+" Address City: "+AddressCity+" Address State: "+AddressState+" Address Zip: "+AddressZip+" AddressCountry: "+AddressCountry+" Email: "+Email+" ItemNumber: "+itemNumber+" Invoice: "+invoice+" payment status: "+paymentStatus+" payment Gross: "+paymentGross+" txnid: "+txnId+" payerEmail: "+payerEmail+" subscription start date: "+SubscriptionStartDate+" paypal id: "+PaypalID+" payment type: "+PaymentType+" txniderror: "+txnIdError+" res: "+res+" str: "+str%>" /> </jsp:forward> <% } %> </body> </html> I put a couple of xx's in there to keep system info secure. <hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 12/27/2006 Posts: 13 Location: ,
|
Hi, Can u plz provide me with the sample code for IPN in java/jsp. Act I am done with PDT Script and I am wondering whether do I have to go for IPN also. plz guide me on the same ASAP. And if possible plz do mail me at gourav@logixworld.comRegards Gourav Ajmani
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 12/27/2006 Posts: 13 Location: ,
|
Hi xfacttor, Can u plz provide me the IPN script for payapl in java/jsp,n also guide me on how to update the database with the IPN code, I will be greatfull to u . And if possible plz do mail me at gourav@logixworld.comRegards Gourav
|
|
|
|
Guest
|