Paypal payments and IPN

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:///Test/index

I get the following:

NameError in #

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

  1. 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

Jordan E. wrote:

  1. 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),
[email protected]”, :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:

Test#index


2:

Find me in app/views/test/index.rhtml


3: <%= paypal_form_tag %>
4: <%= paypal_setup “Item 500”, Money.us_dollar(50000),
[email protected]”, :notify_url => url_for(:path_only => false,
:action => ‘paypal_ipn’) %>
5:
6: Please press here to pay $500US using paypal.

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:inrender_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:inrender_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:inrender_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:inmeasure’
/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:inperform_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:inperform_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:inperform_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:inprocess_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:inprocess’
/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:inhandle_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:inservice’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:instart’
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:instart’
/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:indispatch’
/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:inrequire’
/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:inrequire’
./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:incompile_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:inrender_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:inrender_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:inrender’
/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:inrender’
/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:inperform_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:inmeasure’
/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:inperform_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:inprocess_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:indispatch’
/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:inservice’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:instart’
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:instart’
/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:inrequire’
/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:inrequire’
/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”}

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.

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.

Bryan D. 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.

:frowning:

TFI Friday!

Bryan D. 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.

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/encrypted-paypal-buttons-with-ruby

http://redchocolate.ca/articles/2006/03/01/code-release-for-paypal-gem

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).

Dave wrote:

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

That did it.

Nice one.

Matt Richards wrote:

Jordan E. wrote:

  1. 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),
[email protected]”, :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