Paypal 网站支付标准未与 Java 集成

发布于 2024-09-16 02:21:24 字数 3269 浏览 4 评论 0原文

嘿,大家好,我一直在尝试将 java 和 paypal 集成在一起。 我已经在这里发帖了: http://forum.springsource.org/showthread.php?p=316498# post316498

任何帮助将不胜感激,请告知。

更新:

我的困境是,如果我要使用如上所述的贝宝按钮,我什么时候真正将表单信息“保存”到我的本地数据库?换句话说,我需要在付款确认后保存“用户”信息等,之前这样做是没有用的。
我的理解是,只有交易成功时才会触发“返回”URL。如果是这种情况,那么必须有一种方法来识别来自 PayPal 的传入响应,以便将其与“此”用户的表单发布相关联。换句话说,就是“这个”会话。这样就可以保存用户数据。我知道有一个叫IPN的东西?最初是否可以将其合并到相同的表格中,以便我们得到确认?我只是想弄清楚如何处于同一个会话中,以便我可以保留用户信息。如果用户的信用卡被拒绝,它是否仍然会返回到 RETURN URL?需要以某种方式进行区分。

最后,我正在研究 HTTPPOST 代码,基本上我是想在这里模拟浏览器。

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);
}

我想我发现了一些事情,它说:您请求了过时版本的 PayPal。此错误通常是由于使用书签造成的。

在我看来,可以通过java发布到paypal...只是我想我可能会遗漏一些东西。此错误是一个常见错误。
请指教。谢谢。

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.

Update:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖上的星空 2024-09-23 02:21:24

您不能使用 URLConnection 或 apache HttpPost,因为它们将在您的 Web 服务器和 PayPal 之间启动连接,而不是在客户端浏览器和 PayPal 之间启动连接。

由于 paypal 需要 POST,而不是 GET,因此您也不能使用重定向,因此剩下的唯一选择是将 HTML 页面返回给客户端,其中包含所有 paypal 参数作为隐藏 s 的表单,并且一些 javascript 可以立即提交表单。

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 to the client, with a form with all the paypal parameters as hidden <input>s , and a bit of javascript to submit the form immediately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文