简体   繁体   中英

How can I avoid auth and time issues using Paypal's Adaptive Payments API with Ruby?

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?

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.

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

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

官方Ruby PayPal自适应支付SDK gem https://github.com/paypal/adaptivepayments-sdk-ruby

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM