3

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?

tommy chheng
  • 9,108
  • 9
  • 55
  • 72
emh
  • 1,279
  • 3
  • 15
  • 26
  • "No, I'm not using Paypal's Adaptive Payments API with Ruby." would be a valid answer to your question's title. You may wish to rephrase it. – Andrew Grimm Jan 26 '12 at 23:07

4 Answers4

6

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.

tommy chheng
  • 9,108
  • 9
  • 55
  • 72
2

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

Oakland510
  • 1,073
  • 2
  • 12
  • 20
  • 3
    +1 Thank you for putting this here. I'm convinced that Paypal's development services are simply set up for the sole purpose of trolling web developers. – varatis Jan 06 '12 at 07:45
0

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

Sai
  • 6,919
  • 6
  • 42
  • 54
0

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

paxer
  • 961
  • 10
  • 17