pronix / spree_robokassa

BSD 3-Clause "New" or "Revised" License
11 stars 18 forks source link

StateMachine::InvalidTransition (Cannot transition state via :next from :payment (Reason(s): Нет незавершённых платежей) #1

Open BRZInc opened 10 years ago

BRZInc commented 10 years ago

Hello,

Thanks for development of spree_robokassa gem. It looks excellent. Though I have a small issue with it.

Yesterday I've installed it to my site and still can't make it work for me in the test mode. Whenever I try to proceed with payment I get the following exception: StateMachine::InvalidTransition (Cannot transition state via :next from :payment (Reason(s): Нет незавершённых платежей) (in english exception message says 'No payment found').

This exception occurs when I get to the "http://test.robokassa.ru/ReturnResults.aspx?Culture=ru" page and click on "Перейти" button.

I use spree 2.1.4. I've made a fork of this gem and added a few small changes into it: https://github.com/BRZInc/spree_robokassa.git

Here is my log: I, [2014-01-29T16:45:05.960022 #1095] INFO -- : Completed 200 OK in 1065ms (Views: 775.6ms | ActiveRecord: 43.6ms) I, [2014-01-29T16:45:15.142067 #1090] INFO -- : Started GET "/gateway/robokassa/result?OutSum=2690.0&InvId=724416111&SignatureValue=A08D9FEE8B0972A64D34802D92546F48" $ I, [2014-01-29T16:45:15.151368 #1090] INFO -- : Processing by Spree::Gateway::RobokassaController#result as HTML I, [2014-01-29T16:45:15.151471 #1090] INFO -- : Parameters: {"OutSum"=>"2690.0", "InvId"=>"724416111", "SignatureValue"=>"A08D9FEE8B0972A64D34802D92546F48"} I, [2014-01-29T16:45:15.304705 #1090] INFO -- : Completed 500 Internal Server Error in 153ms F, [2014-01-29T16:45:15.308554 #1090] FATAL -- : StateMachine::InvalidTransition (Cannot transition state via :next from :payment (Reason(s): Нет незавершённых платежей)): state_machine (1.2.0) lib/state_machine/event.rb:252:in block in add_actions' state_machine (1.2.0) lib/state_machine/machine.rb:765:incall' state_machine (1.2.0) lib/state_machine/machine.rb:765:in block (2 levels) in define_helper' /home/spree/jersey_shop/shared/bundle/ruby/1.9.1/bundler/gems/spree_robokassa-1257d39b8ac2/app/controllers/spree/gateway/robokassa_controller.rb:34:inresult' actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in send_action' actionpack (4.0.0) lib/abstract_controller/base.rb:189:inprocess_action' actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in process_action' actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:inblock in process_action' activesupport (4.0.0) lib/active_support/callbacks.rb:463:in _run__187398052__process_action__callbacks' activesupport (4.0.0) lib/active_support/callbacks.rb:80:inrun_callbacks' actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in process_action' actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:inprocess_action' actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in block in process_action' activesupport (4.0.0) lib/active_support/notifications.rb:159:inblock in instrument' activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.0.0) lib/active_support/notifications.rb:159:ininstrument' actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:inprocess_action' activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in process_action' actionpack (4.0.0) lib/abstract_controller/base.rb:136:inprocess' actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in process' actionpack (4.0.0) lib/action_controller/metal.rb:195:indispatch' actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.0.0) lib/action_controller/metal.rb:231:inblock in action' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'

From the log I see that Robokassa tries to call back my site by the Return URL, but an exception occurs on my side, when I try to call @order.next!. I've checked by InvId - I have such an order in my list in the Payment state.

Please help! This thing blows my mind for 2 days already. Can't figure out what else to try

BRZInc commented 10 years ago

Below is my Gemfile:

source 'http://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

gem 'nokogiri', '~> 1.6.0'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :development, :test do
  gem 'sqlite3' # Use sqlite3 as the database for Active Record
end

group :production do
 gem 'therubyracer', :platforms => :ruby
 gem 'unicorn' # Use unicorn as the app server
 gem 'pg'
end

# Use Capistrano for deployment
group :development do
  gem 'capistrano'
  gem 'capistrano-rails'
  gem 'capistrano-bundler'
  gem 'capistrano-rvm'
end

# Use debugger
# gem 'debugger', group: [:development, :test]

#gem 'bcrypt-ruby', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt' #needed for prod

#gem 'money', '~>5.1' # fix for Bundler could not find compatible versions for gem "money"
#gem 'money', :github => "RubyMoney/money"
gem 'spree', :git => 'https://github.com/spree/spree.git', :branch => '2-1-stable'
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-1-stable'
gem 'spree_auth_devise', :git => 'https://github.com/spree/spree_auth_devise.git', :branch => '2-1-stable'
gem 'devise-i18n', :git => 'https://github.com/tigrish/devise-i18n.git' #Contains proper russian translations for auth functionality

# Use this gem for zooming product images
gem "spree_product_zoom", :git => "https://github.com/BRZInc/spree_product_zoom.git" 

# Use this gem to add customizable fields to product page
# Use fork & need to fix mini_magick reference
gem 'mini_magick', :git => 'git://github.com/minimagick/minimagick.git', :ref => '6d0f8f953112cce6324a524d76c7e126ee14f392'
#gem 'spree_flexi_variants', :git => 'https://github.com/charredUtensil/spree_flexi_variants.git'

# Use this gem to have static pages in Spree,e.g. About page
gem 'spree_static_content', :git => 'https://github.com/DasWasser/spree_static_content.git', :branch => '2-1-stable'

# Turns on spree localization
gem 'russian'
gem 'rails-i18n'
gem 'spree_i18n', :git => 'https://github.com/spree/spree_i18n.git', :branch => '2-1-stable'
gem 'globalize', github: 'globalize/globalize'

# Allow paypal payments
gem 'spree_paypal_express', :github => "radar/better_spree_paypal_express", :branch => "2-1-stable"

# Allow bank transfer payments
gem 'spree_bank_transfer', :git => 'https://github.com/GarPit/spree_bank_transfer'

# Replaces standard frontend with bootstrap one
gem 'spree_bootstrap_frontend', github: '200Creative/spree_bootstrap_frontend', branch: '2-1-stable'

# Optimizes work with options
gem 'spree_variant_options', :git => 'https://github.com/joshblour/spree_variant_options.git', :branch => "2-1-stable"

# Turns on robokassa payments
gem 'spree_robokassa', :git => 'https://github.com/BRZInc/spree_robokassa.git'
pronix commented 10 years ago

it is not ready for current stable spree version. you can try to fix it , and i will merge you pull request.

BRZInc commented 10 years ago

The problem is that I can't figure out myself what goes wrong:(

For some reason @order.next! throws me an error.

Can you please help?

pronix commented 10 years ago

order haven't payments.

BRZInc commented 10 years ago

I've meant that exception occurs on the following line: @order.next! until @order.state == "complete"

BRZInc commented 10 years ago

@artemaminov, sorry for disturbing you, but probably you have some bright ideas about this?

pronix commented 10 years ago

order should have payments for call 'next!' on 'payment' state

(Cannot transition state via :next from :payment (Reason(s): Нет незавершённых платежей) (in english exception message says 'No payment found').
artemaminov commented 10 years ago

@BRZInc, @pronix is absolutely right

BRZInc commented 10 years ago

@pronix, @artemaminov Gentlemen, but what should I do in this case? I've took @artemaminov 's fork, made some minor changes into it. Now can't figure out why it's not working.

Though I haven't tried production mode, but testing mode is not working for me.

pronix commented 10 years ago

@BRZInc try to understand how to working aasm in spree.

artemaminov commented 10 years ago

@BRZInc, excuse me, but my fork is not ready yet

BRZInc commented 10 years ago

@pronix @artemaminov gentlemen, thanks a lot for your comments! Fincally I've used forked fork of @antonfefilov. It looks a bot more stable for me.

Overall thing seems to be working. Though with test robokassa account I get Invalid Signature error. After the code review I've figured out onew thing in robokassa_controller, which I don't understand. It exists in all versions.

In result and success methods valid_signature is checked against different passwords: In def result:

if @order && @gateway && valid_signature?(@gateway.options[:password2])

In def result:

if @order && @gateway && valid_signature?(@gateway.options[:password1]) && @order.complete?
def valid_signature?(key)
    params["SignatureValue"].upcase == Digest::MD5.hexdigest([params["OutSum"], params["InvId"], key ].join(':')).upcase
  end

How could it come?