hey people, I am stuck trying to integrate java and paypal together. I have posted here: http://forum.springsource.org/showthread.php?p=316498#post316498
any help would be greatly appreciated, please advise.
hey people, I am stuck trying to integrate java and paypal together. I have posted here: http://forum.springsource.org/showthread.php?p=316498#post316498
any help would be greatly appreciated, please advise.
You cannot use an URLConnection nor an apache HttpPost because these will initiate a connection between your web server and paypal, not between the client's browser and paypal.
Since paypal requires a POST, not a GET, you cannot use a redirect either, so the only option that's left, is returning an HTML page the the client, with a form with all the paypal parameters as hidden <input>s , and a bit of javascript to submit the form immediately.
well my dilemma is that if I was to use a paypal button as mentioned, when do I actually "save" the form information to my local database? In other words I need to save the "user" information etc. only AFTER payment confirmation, it would be useless to do it before.
My understanding is that the "return" URL only will be triggered if there is a successful transaction. If that is the case, then there must be a way to identify this incoming response from paypal so that it was associated with the form post for "this" user. In other words for "this" session. In that way, the user data can then be saved. I know there is something called IPN? Could that be incorpated in the same form initially so we get back a confirmation? I am just trying to figure out how to be in the same session so I can persist the user information. AND if the user's credit card is rejected, does it still go back to the RETURN URL regardless? Need to distinguish somehow.
Lastly, I was playing around with the HTTPPOST code, basically I am tring to simulate a browser here.
public void testPost15() throws ClientProtocolException, IOException {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://www.paypal.com/cgi-bin/webscr");
post.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3");
//conn.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0");
//httpPost.setHeader( "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
//post.setHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
//httpPost.setHeader( "Accept-Language", "en-us,en;q=0.5");
//post.setHeader("Accept-Language","en-gb,en;q=0.5");
List<NameValuePair> params = new ArrayList<NameValuePair>();
//params.add(new BasicNameValuePair("cmd", "_s-xclick"));
params.add(new BasicNameValuePair("cmd", "_xclick"));
//params.add(new BasicNameValuePair("cmd", "_ext-enter"));
//params.add(new BasicNameValuePair("redirect_cmd", "_xclick-subscriptions"));
params.add(new BasicNameValuePair("business", "[email protected]"));
params.add(new BasicNameValuePair("currency_code", "USD"));
params.add(new BasicNameValuePair("amount", "4"));
params.add(new BasicNameValuePair("item_name", "PiT words"));
params.add(new BasicNameValuePair("no_note", "1"));
params.add(new BasicNameValuePair("return", "http://localhost:8080/pit-web-0.0.1-SNAPSHOT/welcome"));
post.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = client.execute(post);
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
str.append(line + "\n");
}
is.close();
String responseText = str.toString();
System.out.println("response: "+responseText);
}
and I think I am onto something, it says: You have requested an outdated version of PayPal. This error often results from the use of bookmarks.
It seems to me it is possible to post to paypal via java...its just that I think I might be missing something. This error is a common error.
Please advise. Thank you.