Forum: Ruby on Rails Paypal payments and IPN

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
90bd17e8484a3ad7db3bf0fbd276baad?d=identicon&s=25 Matt Richards (Guest)
on 2006-04-21 10:33
I have followed the instructions over at
http://dist.leetsoft.com/api/paypal/

In order I:

1. installed the money library with gem install --source
http://dist.leetsoft.com/api/paypal/ money

2. installed the paypal library with gem install --source
http://dist.leetsoft.com/api/paypal/ paypal

3. created a new app with rails NewApp

4. added the PaymentHelper module to the app/controllers/application.rb

5. generated controller(and view) Test with ./script/generate controller
Test index

6. launched the server

7. connected to server with http://<mydomain>/Test/index

I get the following:

NameError in <controller not set>#<action not set>

uninitialized constant Paypal

RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:112:in
`const_missing'
#{RAILS_ROOT}/app/controllers/application.rb:5

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:112:in
`const_missing'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:129:in
`load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:56:in
`require_or_load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:30:in
`depend_on'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:74:in
`require_dependency'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:69:in
`prepare_application'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:37:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:115:in
`handle_dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:81:in
`service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:67:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require'
./script/server:3

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:112:in
`const_missing'
#{RAILS_ROOT}/app/controllers/application.rb:5
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:129:in
`load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:56:in
`require_or_load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:30:in
`depend_on'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:74:in
`require_dependency'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:69:in
`prepare_application'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:37:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:115:in
`handle_dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:81:in
`service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:67:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require'
./script/server:3

This error occured while loading the following files:
application.rb
application_controller/payment_helper/paypal.rb

Could someone please point me in the right direction!!!!


Thanks in advance.

mjr
188a96403bfb1b3781ab95fc1bc92241?d=identicon&s=25 Jordan Elver (jordelver)
on 2006-04-21 11:54
(Received via mailing list)
> 4. added the PaymentHelper module to the app/controllers/application.rb

I needed to require the paypal module as well:

require 'paypal'
module ApplicationHelper
	include Paypal::Helpers
end

HTH,
Jord
90bd17e8484a3ad7db3bf0fbd276baad?d=identicon&s=25 Matt Richards (Guest)
on 2006-04-21 14:16
Jordan Elver wrote:
>> 4. added the PaymentHelper module to the app/controllers/application.rb
>
> I needed to require the paypal module as well:
>
> require 'paypal'
> module ApplicationHelper
> 	include Paypal::Helpers
> end
>
> HTH,
> Jord

That got a me a step further, but now, if I put:

 <%= paypal_form_tag %>
     <%= paypal_setup "Item 500", Money.us_dollar(50000),
"bob@bigbusiness.com", :notify_url => url_for(:path_only => false,
:action => 'paypal_ipn') %>

     Please press here to pay $500US using paypal. <br/>
     <%= submit_tag "Go to paypal >>" %>

   <% end_form_tag %>

into /app/views/test/index.rhtml  I get:

NameError in Test#index

Showing app/views/test/index.rhtml where line #3 raised:

undefined local variable or method `paypal_form_tag' for
#<#<Class:0xb796b5bc>:0xb796b544>

Extracted source (around line #3):

1: <h1>Test#index</h1>
2: <p>Find me in app/views/test/index.rhtml</p>
3:  <%= paypal_form_tag %>
4:      <%= paypal_setup "Item 500", Money.us_dollar(50000),
"bob@bigbusiness.com", :notify_url => url_for(:path_only => false,
:action => 'paypal_ipn') %>
5:
6:      Please press here to pay $500US using paypal. <br/>

RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/views/test/index.rhtml:3:in `_run_rhtml_test_index'

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:309:in
`compile_and_render_template'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:285:in
`render_template'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:244:in
`render_file'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:697:in
`render_file'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:619:in
`render_with_no_layout'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/layout.rb:251:in
`render_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`render'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`render'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:909:in
`perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/filters.rb:355:in
`perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/rescue.rb:82:in
`perform_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:379:in
`process_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/filters.rb:364:in
`process_without_session_management_support'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/session_management.rb:117:in
`process'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:38:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:115:in
`handle_dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:81:in
`service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:67:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require'
./script/server:3

#{RAILS_ROOT}/app/views/test/index.rhtml:3:in `_run_rhtml_test_index'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:309:in
`compile_and_render_template'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:285:in
`render_template'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_view/base.rb:244:in
`render_file'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:697:in
`render_file'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:619:in
`render_with_no_layout'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/layout.rb:251:in
`render_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`render'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:53:in
`render'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:909:in
`perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/filters.rb:355:in
`perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/rescue.rb:82:in
`perform_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:379:in
`process_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/filters.rb:364:in
`process_without_session_management_support'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/session_management.rb:117:in
`process'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:38:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:115:in
`handle_dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:81:in
`service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:67:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in
`require'
./script/server:3

Request

Parameters: None

Show session dump

---
flash: !map:ActionController::Flash::FlashHash {}


Response
Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"}
Fb23bc8cd4030c526b0689276b34c8bd?d=identicon&s=25 Bryan Duxbury (bryanduxbury)
on 2006-04-21 16:14
I believe the way my project team got it working a while ago was by
requiring the paypal library in environment.rb. It was as big a
disappointment to me that it didn't work out of the box as it is to you,
I'm sure.
90bd17e8484a3ad7db3bf0fbd276baad?d=identicon&s=25 Matt Richards (Guest)
on 2006-04-21 16:46
Bryan Duxbury wrote:
> I believe the way my project team got it working a while ago was by
> requiring the paypal library in environment.rb. It was as big a
> disappointment to me that it didn't work out of the box as it is to you,
> I'm sure.

Thanks for the suggestion Bryan, but still no luck.

This whole experience has been very frustrating.  I have wasted so much
time, I've been on forum after forum, even resorted to IRC, still no
luck, I've just as a last resort emailed the developer to see if they
can help, but tbh don't expect to hear back.

Looks like Im going to have to break the principles of DRY and write
another paypal library that works for me.

:(

TFI Friday!
Fb23bc8cd4030c526b0689276b34c8bd?d=identicon&s=25 Bryan Duxbury (bryanduxbury)
on 2006-04-21 16:50
Actually, I was thinking of doing the same thing. A reliable PayPal
library would be very useful. If you'd like to collaborate on the
project, let me know.
A48a41549caf4deaf7a7d0fc532378b7?d=identicon&s=25 Matt Richards (mattr)
on 2006-04-21 16:55
Bryan Duxbury wrote:
> Actually, I was thinking of doing the same thing. A reliable PayPal
> library would be very useful. If you'd like to collaborate on the
> project, let me know.


Just noticed I've not been logged in.

Yes, this could be a real possibility.   What type of timescale did you
have in mind?  Tbh, at this stage I only require a very rudimentary
script to submit payment and handle IPN, but I agree, it would be worth
writing a comprehensive library.

I've had no luck using he PayPal API Plugin either.
D0672139df03b606bda25eb6a31b1416?d=identicon&s=25 Paul Hart (paulhart)
on 2006-04-21 17:19
Matt Richards wrote:
>
> I've had no luck using he PayPal API Plugin either.
>

I'm using (and extending) it successfully, but I don't use the
paypal_form_tag helper. I *do* use paypal_setup, which is the
'important' part of the library from the form perspective, and the IPN
stuff seems to work fine too.

If you want encrypted button support, have a look at my changes:

http://redchocolate.ca/articles/2006/02/03/encrypt...

http://redchocolate.ca/articles/2006/03/01/code-re...

I've posted this to the mailing list too, but I have no idea if
ruby-forum reads what gets mailed there (and I'm on digest mode, so
that'll affect it in any event).
28668141f2faf4eb9f90fbaab79d220c?d=identicon&s=25 Dave (Guest)
on 2006-04-21 22:38
Matt Richards wrote:
> Jordan Elver wrote:
>>> 4. added the PaymentHelper module to the app/controllers/application.rb
>>
>> I needed to require the paypal module as well:
>>
>> require 'paypal'
>> module ApplicationHelper
>> 	include Paypal::Helpers
>> end
>>
>> HTH,
>> Jord
>
> That got a me a step further, but now, if I put:
>
>  <%= paypal_form_tag %>
>      <%= paypal_setup "Item 500", Money.us_dollar(50000),
> "bob@bigbusiness.com", :notify_url => url_for(:path_only => false,
> :action => 'paypal_ipn') %>
>
>      Please press here to pay $500US using paypal. <br/>
>      <%= submit_tag "Go to paypal >>" %>
>
>    <% end_form_tag %>
>
> into /app/views/test/index.rhtml  I get:
>
> NameError in Test#index
>
> Showing app/views/test/index.rhtml where line #3 raised:
>
> undefined local variable or method `paypal_form_tag' for
> #<#<Class:0xb796b5bc>:0xb796b544>
>

Hi -

I've been using the library with good success for a while.  Here's how I
set everything:

1 - put paypal.rb in the \lib folder
2 - include the paypal helper in the \helpers\application_helper.rb,
like this: include Paypal::Helpers

Then in my controller that I use for payments, I setup the paypal stuff
like this:

if RAILS_ENV == 'development'
    Paypal::Notification.ipn_url =
"http://www.sandbox.paypal.com/cgi-bin/webscr"
  else
    Paypal::Notification.ipn_url =
"https://www.paypal.com/cgi-bin/webscr"
  end

and then in the IPN receive, I do something like this:

 def paypal_ipn

   notify = Paypal::Notification.new(request.raw_post)


Good luck... The library itself is fine - I think you'll have some
headaches with Paypal itself, but overall, its been OK.

Dave
E8a6f0957fb0b5c63994fd423ae30235?d=identicon&s=25 Matt Richards (Guest)
on 2006-04-24 23:23
Dave wrote:
> 2 - include the paypal helper in the \helpers\application_helper.rb,
> like this: include Paypal::Helpers


That did it.


Nice one.
This topic is locked and can not be replied to.