adamthedeveloper / wepay-rails

Collect payments from wepay in your rails application.
MIT License
32 stars 24 forks source link

error initializing via WepayRails::Payments::Gateway.new in wiki example #14

Closed nborwankar closed 12 years ago

nborwankar commented 12 years ago

$ rails c Loading development environment (Rails 3.2.3) 1.9.3-p0 :001 > wepay_gateway = WepayRails::Payments::Gateway.new <--- this line is from the wiki example

NoMethodError: undefined method []' for nil:NilClass from /Users/nitin/.rvm/gems/ruby-1.9.3-p0/gems/wepay-rails-2.2.9/lib/wepay-rails.rb:53:ininitialize' from (irb):1:in new' from (irb):1 from /Users/nitin/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands/console.rb:47:instart' from /Users/nitin/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in start' from /Users/nitin/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands.rb:41:in<top (required)>' from script/rails:6:in require' from script/rails:6:in

' 1.9.3-p0 :002 >

line 53 in wepay-rails.rb is expecting an access_token in args but the wiki example doesn't pass in any params to new

SteveAquino commented 12 years ago

That's strange, looks like it's returning nil for @wepay_config, which should be initialized when you call new. Running that command in the console works fine for me, but I'll dig in a little deeper when I get a chance. Try calling wepay_gateway = WepayRails::Payments::Gateway.new(nil) for now, I'll have to look at it tomorrow.

adamthedeveloper commented 12 years ago

Steve, I am curious. Do you not need an initial access_token in wepay.yml when running in multi-account mode? Looks like wepay-rails.rb line 53 sees if an access_token is passed in, if not, it looks in config. If he sets access_token nil in the wepay.yml, I think it blows up there when calling ....Gateway.new

SteveAquino commented 12 years ago

No, I did not change this part of the wepay-rails.rb file at all and calling ...Gateway.new without any arguments works just fine for me, in tests, development, and production. It sounds like the issue is a NoMethodError on calling '[ ]' on nil, which means that @wepay_config is returning nil. That should be set on initialization, but again I didn't change this part of the code so I'm not sure. The changes I've made were pretty trivial, basically I just added an attr_accessor in the Gateway Module so you can get the :account_id for each User dynamically. By leaving the access_token and account_id blank in wepay.yml, @wepay_config[:access_token] should return nil, and in fact for me WepayRails::Payments::Gateway.new returns: #<WepayRails::Payments::Gateway:0x00000005d058e0 @wepay_config={:client_id=>[FILTERED], :client_secret=>[FILTERED], :account_id=>nil, :access_token=>nil, :root_callback_uri=>"http://www.example.com", :after_checkout_redirect_uri=>"http://www.example.com/purchase/finalize", :scope=>["manage_accounts,refund_payments,collect_payments,view_balance,view_user,send_money"], :wepay_api_uri=>"https://stage.wepay.com/v2", :fee_payer=>"Payee", :checkout_type=>"DONATION", :charge_tax=>false, :app_fee=>0, :auto_capture=>true, :require_shipping=>false, :shipping_fee=>0}, @access_token=nil, @base_uri="https://stage.wepay.com/v2">

I'm not sure how @wepay_config is actually set here, but I'll happily look into it in the morning. In the mean time, passing in nil as an argument actually won't solve the problem, but because of ruby short circuiting it should skip the call to @wepay_config if there is at least one argument and avoid the NoMethodError.

adamthedeveloper commented 12 years ago

Ok - cool - thanks for clarifying Steve.

Nitin, did you completely remove the access_token line from wepay.yml or just simply do:

access_token: nil

Try keeping access_token: nil in your wepay.yml or doing as Steve suggested and just pass nil as an arg to ...Gateway.new

It's probably cleaner to have access_token: nil in wepay.yml though.

Thanks,

am

nborwankar commented 12 years ago

Hi all,

My bad - I had the yml file with the value access_token: i.e. blank - which should have been ok. But I had not renamed the file from wepay.yml.example to wepay.yml - looking in the src I saw that's what the code was looking for - renaming the file did the trick - so just keeping the values blank is ok, it appears.

1.9.3-p0 :001 > wepay_gateway = WepayRails::Payments::Gateway.new => #<WepayRails::Payments::Gateway:0x007faa7668c5b8 @wepay_config={:client_id=>114471, :client_secret=>"33fb09f156", :account_id=>nil, :access_token=>nil, :root_callback_uri=>" http://nborwankar.showoff.io/wp", :after_checkout_redirect_uri=>" http://nborwankar.showoff.io/purchase_finalize", :scope=>["refund_payments", "collect_payments", "view_balance", "view_user"], :wepay_api_uri=>"https://stage.wepay.com/v2", :fee_payer=>"Payee", :checkout_type=>"DONATION", :charge_tax=>false, :app_fee=>0, :auto_capture=>true, :require_shipping=>false, :shipping_fee=>0}, @access_token=nil, @base_uri="https://stage.wepay.com/v2 "> 1.9.3-p0 :002 >

Sorry for the noise.

Nitin

Nitin Borwankar nborwankar@gmail.com

On Tue, May 29, 2012 at 12:03 AM, Adam Medeiros < reply@reply.github.com

wrote:

Ok - cool - thanks for clarifying Steve.

Nitin, did you completely remove the access_token line from wepay.yml or just simply do:

access_token: nil

Try keeping access_token: nil in your wepay.yml or doing as Steve suggested and just pass nil as an arg to ...Gateway.new

It's probably cleaner to have access_token: nil in wepay.yml though.

Thanks,

am


Reply to this email directly or view it on GitHub:

https://github.com/adamthedeveloper/wepay-rails/issues/14#issuecomment-5976970

SteveAquino commented 12 years ago

Glad to here you were able to get things working again! Closing this issue...