如何通过 Ruby 使用 Paypal 的自适应支付 API 来避免身份验证和时间问题?

发布于 2024-08-30 04:58:34 字数 1412 浏览 1 评论 0原文

我在尝试从 Ruby 访问 Paypal 的自适应支付 API 时遇到了多个问题。

我最初遇到的主要问题是 Paypal 要求其 HTTP 标头全部大写,但 Net::HTTP 不保留 HTTP 标头的大小写(它将它们“小写”存储,然后输出“大写”——所以如果您设置标头“X-PAYPAL-SECURITY-USERID”,它存储为“x-paypal-security-userid”并输出为“X-Paypal-Security-Userid”)。

当我尝试将 API 与这些大小写错误的标头一起使用时,出现“500000 Internal Server”错误。

所以我对 Net::HTTP 进行了猴子补丁以保留标头的大小写。但现在我遇到了超时异常:

Timeout::Error (execution expired):
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:60:in `rbuf_fill'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:104:in `read_all'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2220:in `read_body_0'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2173:in `read_body'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2198:in `body'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2137:in `reading_body'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1052:in `request'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start'

那么,回到我最初的问题:是否有人使用 Ruby 成功访问了自适应支付 API?如果是这样,你的秘密是什么?

I'm running into multiple issues trying to access Paypal's Adaptive Payment API from Ruby.

The main issue I ran into initially was that Paypal requires their HTTP headers to be in all caps but Net::HTTP does not preserve the case of HTTP headers (it stores them 'downcased' and then outputs them 'capitalized' -- so if you set the header 'X-PAYPAL-SECURITY-USERID' it is stored as 'x-paypal-security-userid' and output as 'X-Paypal-Security-Userid').

I was getting "500000 Internal Server" errors when I tried to use the API with these mis-cased headers.

So I monkeypatched Net::HTTP to preserve the case of the headers. But now I am getting timeout exceptions:

Timeout::Error (execution expired):
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:60:in `rbuf_fill'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:104:in `read_all'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2220:in `read_body_0'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2173:in `read_body'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2198:in `body'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2137:in `reading_body'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1052:in `request'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start'

So, back to my original question: Is anyone successfully accessing the adaptive payments API using Ruby? If so, what's your secret?

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

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

发布评论

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

评论(4

莫言歌 2024-09-06 04:58:34

我为 ruby​​ 创建了一个 paypal 自适应支付 gem。我在 nextsprocket.com 上成功使用了它,

这是一篇关于它的博客文章: http://tommy.chheng.com/index.php/2009/12/paypal-adaptive-ruby-gem-released/

尝试一下,看看是否对您有帮助。

I created a paypal adaptive payments gem for ruby. I'm using it successfully at nextsprocket.com

Here's a blog post about it: http://tommy.chheng.com/index.php/2009/12/paypal-adaptive-ruby-gem-released/

Give it a shot and see if it will help you.

横笛休吹塞上声 2024-09-06 04:58:34

我建议查看 PayPal 的 Ruby SDK。但 Paypal 的示例 ruby​​ 代码充满了错误。我在下面列出了您需要在示例代码运行之前进行的更改。不确定他们是否已经修复了这些错误。如果还没有,请按照以下步骤操作。

Ruby SDK:https://www.x.com/community/ppx/sdks#ADAPI< /a>

您需要进行的更改:

1) 进入 xxx_controller.rb 文件并将以下行:

@paykey = @response["payKey"]

更改为:

@paykey = @response["payKey"][0 ]

2) 去掉 form_tag 和 ( 之间的所有空格。在他们的代码中,他们将标签写为 <%= form_tag (setpayparallel_path, ....

应该是 <%= form_tag(setpayparallel_path , ....

3) 确保所有表单均以 <%end%> 关闭

到目前为止,我发现 SDK 似乎是自适应支付的一个很好的起点;

I would recommend looking at PayPal's Ruby SDK. Paypal's example ruby code is full of errors though. I've made a list below of changes you'll need to make before their example code wil work. Not sure if they have fixed these errors yet. If the haven't just follow the steps below.

Ruby SDK: https://www.x.com/community/ppx/sdks#ADAPI

Changes you'll need to make:

1) Go into the xxx_controller.rb files and change the following line:

@paykey = @response["payKey"]

to:

@paykey = @response["payKey"][0]

2) Take out all spaces between form_tag and (. In their code, they write the tag as <%= form_tag (setpayparallel_path, ....

this should be <%= form_tag(setpayparallel_path, ....

3) Make sure all the forms are closed with <%end%>

So far I've found that the SDK seems like a great place to start for adaptive payments

只为一人 2024-09-06 04:58:34

我推荐 https://github.com/jpablobr/active_paypal_adaptive_ payment - 我尝试使用 paypal-adaptive gem,但没有成功了,而 APAP 效果很好。 (最终。)

I recommend https://github.com/jpablobr/active_paypal_adaptive_payment - I tried using the paypal-adaptive gem without success, whereas APAP worked great. (Eventually.)

洒一地阳光 2024-09-06 04:58:34

官方 Ruby PayPal 自适应支付 SDK gem https://github.com/paypal/adaptive payments-sdk-ruby< /a>

Offical Ruby PayPal Adaptive Payments SDK gem https://github.com/paypal/adaptivepayments-sdk-ruby

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