YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Problem with JSP and subscriptions Options
xfactor973
#1 Posted : Monday, February 03, 2003 3:14:23 PM
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.
Sponsor  
 
paypal_pb
#2 Posted : Monday, February 03, 2003 3:57:10 PM
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
xfactor973
#3 Posted : Tuesday, February 04, 2003 3:27:02 PM
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.
paypal_pb
#4 Posted : Tuesday, February 04, 2003 5:31:34 PM
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.

&lt;form method="post" action="http://www.mysite.com/ipn.cfm"&gt;
&lt;input type="submit" name="" value="Test IPN"&gt;
&lt;input type="hidden" name="payment_date" value="17:53:45 Nov 5, 2002 PST"&gt;
&lt;input type="hidden" name="txn_type" value="web_accept"&gt;
&lt;input type="hidden" name="last_name" value="Breitenbach"&gt;
&lt;input type="hidden" name="item_name" value=""&gt;
&lt;input type="hidden" name="payment_gross" value="0.01"&gt;
&lt;input type="hidden" name="mc_currency" value="USD"&gt;
&lt;input type="hidden" name="payment_type" value="instant"&gt;
&lt;input type="hidden" name="verify_sign" value="AlWncXKLadIepzMosHhM.VWxC0Z6AZYI0ynXRnEUma0d3RMC.TXWaJro"&gt;
&lt;input type="hidden" name="payer_status" value="unverified"&gt;
&lt;input type="hidden" name="payer_email" value="pb-test@paypal.com"&gt;
&lt;input type="hidden" name="txn_id" value="01G32341KC3727119"&gt;
&lt;input type="hidden" name="first_name" value="Patrick"&gt;
&lt;input type="hidden" name="quantity" value="1"&gt;
&lt;input type="hidden" name="receiver_email" value="pb-sell@paypal.com"&gt;
&lt;input type="hidden" name="payer_id" value="QGVDAFGZ9XHLJ"&gt;
&lt;input type="hidden" name="payment_method" value="non_cc"&gt;
&lt;input type="hidden" name="item_number" value=""&gt;
&lt;input type="hidden" name="payment_status" value="Completed"&gt;
&lt;input type="hidden" name="mc_gross" value="0.01"&gt;
&lt;input type="hidden" name="custom" value=""&gt;
&lt;input type="hidden" name="notify_version" value="1.4"&gt;
&lt;/form&gt;

Patrick Breitenbach
PayPal, Inc.
Dev Net: https://www.paypal.com/pdn
xfactor973
#5 Posted : Friday, February 07, 2003 10:40:01 AM
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.
xfactor973
#6 Posted : Friday, February 07, 2003 12:36:59 PM
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.
paypal_pb
#7 Posted : Friday, February 07, 2003 5:10:27 PM
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:

&lt;form method="post" action="http://www.mysite.com/ipn.cfm"&gt;

Patrick Breitenbach
PayPal, Inc.
Dev Net: https://www.paypal.com/pdn
xfactor973
#8 Posted : Sunday, February 09, 2003 2:48:58 AM
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?
paypal_pb
#9 Posted : Monday, February 10, 2003 6:09:14 PM
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
xfactor973
#10 Posted : Tuesday, February 11, 2003 4:48:11 PM
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.
xfactor973
#11 Posted : Tuesday, February 11, 2003 6:54:56 PM
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.
xfactor973
#12 Posted : Tuesday, February 11, 2003 7:09:28 PM
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.
midntrdr
#13 Posted : Monday, March 24, 2003 6:32:19 PM
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?
munot
#14 Posted : Sunday, October 26, 2003 12:52:22 PM
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?
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;
ProcessPayment
&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;%@ page import="java.util.*,java.net.*,java.io.*,java.sql.*,javax.mail.*,javax.mail.internet.*" %&gt;
&lt;%@ page session="false" %&gt;
&lt;%
// 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);
%&gt;
&lt;jsp:forward page="registrationservlet" &gt;
&lt;jsp:param name="payerEmail" value="&lt;%=payerEmail%&gt;" /&gt;
&lt;/jsp:forward&gt;
&lt;%
}
}
}catch(SQLException e){%&gt;
&lt;jsp:forward page="error.jsp" &gt;
&lt;jsp:param name="ErrorCode" value="&lt;%=e.toString()%&gt;" /&gt;
&lt;/jsp:forward&gt;
&lt;%
}
catch(Exception e){%&gt;
&lt;jsp:forward page="error.jsp" &gt;
&lt;jsp:param name="ErrorCode" value="&lt;%=e.toString()%&gt;" /&gt;
&lt;/jsp:forward&gt;
&lt;%
}
if(txnIdError){
%&gt;
&lt;jsp:forward page="error.jsp" &gt;
&lt;jsp:param name="ErrorCode" value="&lt;%=" 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%&gt;" /&gt; &lt;/jsp:forward&gt;
&lt;%
}
}
}
else if(res.equals("INVALID")) {
// log for investigation, create some log to handle all of the errors for further reviewing
%&gt;
&lt;jsp:forward page="error.jsp" &gt;
&lt;jsp:param name="ErrorCode" value="&lt;%=" 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%&gt;" /&gt; &lt;/jsp:forward&gt;
&lt;%
}
else {
// error, something else besides verified or completed was sent.
%&gt;
&lt;jsp:forward page="error.jsp" &gt;
&lt;jsp:param name="ErrorCode" value="&lt;%=" 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%&gt;" /&gt; &lt;/jsp:forward&gt;
&lt;%
}
%&gt;
&lt;/body&gt;
&lt;/html&gt;
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">
gourav_ajmani
#15 Posted : Wednesday, January 31, 2007 7:07:52 AM
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.com

Regards
Gourav Ajmani
gourav_ajmani
#16 Posted : Thursday, February 08, 2007 6:40:58 AM
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.com

Regards
Gourav
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFVision Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 1.123 seconds.