Let's see, you could google this search query: +java +code +post +paypal
You'll find this page which explains it all very nicely on how to post to
PayPal:
http://www.paypaldev.org/topic.asp?TOPIC_ID=228
My personal code is very similar to it. I'm not the best coder so don't be
too critical of my code. Below is a snippet of my method that does a POST
(HTTPS) to Verisign's PayFlowLink. It shouldn't take much for you to do the
same to adapt it to HTTP(S?) Post to PayPal.
// BEGIN RELEVANT CODE SNIPPETS
// The basics are to put these things in your method:
// Add a security provider to allow SSL POSTs:
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// Set a handler for SSL (not sure how this is different from the above
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
try {
// Setup the URL:
URL url = new URL("https://payflowlink.verisign.com/RunTrans.cfm");
// Setup the connection object:
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// Setup the query string --- WARNING this below is for
// Verisign PayFlowLink, NOT PAYPAL!
String separators = new String("&");
StringBuffer parms = new StringBuffer("SOMETHING=SOMEVALUE" + separator);
parms.append("PARAMTWO=VALUETWO" + separator);
parms.append("PARAMTHREE=VALUETHREE" + separator);
// An echo print for your testing mode (remove in production!!!!)
System.out.println("Verisign POST is: " + parms.toString());
// Use a byte array for the String in the connection and set various
// properties for the connection
byte[] bytes = parms.toString().getBytes();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
conn.setRequestProperty("Content-length",
String.valueOf(bytes.length));
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream out = null;
// Perform the HTTPS POST
try {
out = conn.getOutputStream();
out.write(bytes);
out.flush();
out.close();
} catch (Exception e) {
System.out.println(
"Error opening OutputStream from Verisign Payment Post is:"
+ e.getMessage());
return (false);
}
// Read the returned information
BufferedReader reader =
new BufferedReader(
new InputStreamReader(conn.getInputStream()));
// Figure out how to read it. I use Perl5Utils to scan through
// my Verisign result for specific error codes
response = reader.readLine();
} catch (MalformedURLException mue) {
System.out.println("Verisign Purchase: Bad URL, aborting.");
return (false);
} catch (IOException ioe) {
System.out.println(
"Verisign Purchase: Failed Internet Connection Attempt.");
return (false);
}
// END RELEVANT CODE SNIPPETS
Regards,
David
-----Original Message-----
From: Wendy Smoak [mailto:[EMAIL PROTECTED]
Sent: Friday, September 10, 2004 7:16 PM
To: Struts Users Mailing List
Subject: Re: Create and submit POST form from Action
From: "mail" <[EMAIL PROTECTED]>
> I populate my cart, and paypal expects a POST form submission to present
> the user with the payment forms (register/login/submit payment),
> and after the user submits or cancels the payment, paypal would submit a
> reply form to my site ... at least this is the flow I understand from the
> paypal developer docs.
AFAIK they do their thing and either post to your 'success' page or your
'failure' page. So if you make your 'success' page a URL that maps to an
Action... wouldn't that do it?
You may also want to go talk with these guys:
http://www.paypaldev.org/topic.asp?TOPIC_ID=3239
--
Wendy Smoak
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]