spree_robokassa 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ SpreeRobokassa
2
+ ==============
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2011 [name of extension creator], released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../config/application', __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+ require 'rake/packagetask'
7
+ require 'rake/gempackagetask'
8
+
9
+ spec = eval(File.read('spree_robokassa.gemspec'))
10
+
11
+ Rake::GemPackageTask.new(spec) do |p|
12
+ p.gem_spec = spec
13
+ end
14
+
15
+ desc "Release to gemcutter"
16
+ task :release => :package do
17
+ require 'rake/gemcutter'
18
+ Rake::Gemcutter::Tasks.new(spec).define
19
+ Rake::Task['gem:push'].invoke
20
+ end
21
+
22
+ desc "Default Task"
23
+ task :default => [ :spec ]
24
+
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new
27
+
28
+ # require 'cucumber/rake/task'
29
+ # Cucumber::Rake::Task.new do |t|
30
+ # t.cucumber_opts = %w{--format pretty}
31
+ # end
@@ -0,0 +1,17 @@
1
+ CheckoutController.class_eval do
2
+ before_filter :redirect_to_robokassa_form_if_needed, :only => :update
3
+
4
+ private
5
+
6
+ # Redirect to robokassa
7
+ #
8
+ def redirect_to_robokassa_form_if_needed
9
+ return unless params[:state] == "payment"
10
+ payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
11
+ if payment_method.kind_of? Gateway::Robokassa
12
+ redirect_to gateway_robokassa_path(:gateway_id => payment_method.id, :order_id => @order.id)
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,63 @@
1
+ class Gateway::RobokassaController < Spree::BaseController
2
+ skip_before_filter :verify_authenticity_token, :only => [:result, :success, :fail]
3
+ before_filter :load_order, :only => [:result, :success, :fail]
4
+ ssl_required :show
5
+
6
+ def show
7
+ @order = Order.find(params[:order_id])
8
+ @gateway = @order.available_payment_methods.find{|x| x.id == params[:gateway_id].to_i }
9
+
10
+ if @order.blank? || @gateway.blank?
11
+ flash[:error] = I18n.t("invalid_arguments")
12
+ redirect_to :back
13
+ else
14
+ @signature = Digest::MD5.hexdigest([ @gateway.options[:mrch_login],
15
+ @order.total, @order.id, @gateway.options[:password1]
16
+ ].join(':')).upcase
17
+ render :action => :show
18
+ end
19
+ end
20
+
21
+ def result
22
+ if @order && @gateway && valid_signature?(@gateway.options[:password2])
23
+ payment = @order.payments.build(:payment_method => @order.payment_method)
24
+ payment.state = "completed"
25
+ payment.amount = params["OutSum"].to_f
26
+ payment.save
27
+ @order.save!
28
+ @order.next! until @order.state == "complete"
29
+ @order.update!
30
+
31
+ render :text => "OK#{@order.id}"
32
+ else
33
+ render :text => "Invalid Signature"
34
+ end
35
+ end
36
+
37
+ def success
38
+ if @order && @gateway && valid_signature?(@gateway.options[:password1]) && @order.complete?
39
+ session[:order_id] = nil
40
+ redirect_to order_path(@order), :notice => I18n.t("payment_success")
41
+ else
42
+ flash[:error] = t("payment_fail")
43
+ redirect_to root_url
44
+ end
45
+ end
46
+
47
+ def fail
48
+ flash.now[:error] = t("payment_fail")
49
+ redirect_to @order.blank? ? root_url : checkout_state_path("payment")
50
+ end
51
+
52
+ private
53
+
54
+ def load_order
55
+ @order = Order.find_by_id(params["InvId"])
56
+ @gateway = Gateway::Robokassa.current
57
+ end
58
+
59
+ def valid_signature?(key)
60
+ params["SignatureValue"].upcase == Digest::MD5.hexdigest([params["OutSum"], params["InvId"], key ].join(':')).upcase
61
+ end
62
+
63
+ end
@@ -0,0 +1,33 @@
1
+ class Gateway::Robokassa < Gateway
2
+ preference :password1, :string
3
+ preference :password2, :string
4
+ preference :mrch_login, :string
5
+
6
+ def provider_class
7
+ self.class
8
+ end
9
+
10
+ def method_type
11
+ "robokassa"
12
+ end
13
+
14
+ def test?
15
+ options[:test_mode] == true
16
+ end
17
+
18
+ def url
19
+ self.test? ? "http://test.robokassa.ru/Index.aspx" : "https://merchant.roboxchange.com/Index.aspx"
20
+ end
21
+
22
+ def self.current
23
+ self.where(:type => self.to_s, :environment => Rails.env, :active => true).first
24
+ end
25
+
26
+ def desc
27
+ "<p>
28
+ <label> #{I18n.t('robokassa.success_url')}: </label> http://[domain]/gateway/robokassa/success<br />
29
+ <label> #{I18n.t('robokassa.result_url')}: </label> http://[domain]/gateway/robokassa/result<br />
30
+ <label> #{I18n.t('robokassa.fail_url')}: </label> http://[domain]/gateway/robokassa/fail<br />
31
+ </p>"
32
+ end
33
+ end
@@ -0,0 +1,51 @@
1
+ <table>
2
+ <tr>
3
+ <td><label><%=t("name")%></label></td>
4
+ <td><%= text_field :payment_method, :name, {"style" => "width:200px"} %></td>
5
+ </tr>
6
+ <tr>
7
+ <td><label><%=t("description")%></label></td>
8
+ <td><%= text_area :payment_method, :description, {:cols => 60, :rows => 4} %></td>
9
+ </tr>
10
+ <tr>
11
+ <td><label><%=t("environment")%></label></td>
12
+ <td>
13
+ <%= collection_select(:payment_method, :environment, Configuration.configurations.keys, :to_s, :titleize, {}, {:id => "gtwy-env"}) %>
14
+ </td>
15
+ </tr>
16
+ <tr>
17
+ <td><label><%=t("display")%></label></td>
18
+ <td>
19
+ <%= select(:payment_method, :display_on, PaymentMethod::DISPLAY.collect {|display| [t(display), display == :both ? nil : display.to_s]}) %>
20
+ </td>
21
+ </tr>
22
+ <tr>
23
+ <td><label><%= t("active") %></label></td>
24
+ <td>
25
+ <label class="sub">
26
+ <%= radio_button(:payment_method, :active, true ) %>
27
+ <%= t("yes") %>
28
+ </label> &nbsp;
29
+ <label class="sub">
30
+ <%= radio_button(:payment_method, :active, false ) %>
31
+ <%= t("no") %>
32
+ </label>
33
+ </td>
34
+ </tr>
35
+ </table>
36
+
37
+ <h2><%= t('settings') %></h2>
38
+
39
+ <div id="preference-settings">
40
+ <%= f.label(:type, t("provider")) %>
41
+ <%= collection_select(:payment_method, :type, @providers, :to_s, :name, {}, {:id => "gtwy-type"}) %>
42
+
43
+ <% unless @object.new_record? %>
44
+ <%= preference_fields(@object, f) %>
45
+
46
+ <% if @object.respond_to?(:preferences) %>
47
+ <div id="gateway-settings-warning" style="color:#FF0000"><%= t('provider_settings_warning')%></div>
48
+ <% end %>
49
+ <%= raw(@object.desc) if @object.respond_to?(:desc) %>
50
+ <% end %>
51
+ </div>
@@ -0,0 +1,22 @@
1
+ <% content_for :page_title do %>
2
+ <h1 class="font-41 black"><%= t("robokassa.pay")%></h1>
3
+ <% end %>
4
+ <%= form_tag @gateway.url, :method => "POST" do %>
5
+ <%= hidden_field_tag(:"MrchLogin", @gateway.options[:mrch_login]) %>
6
+ <%= hidden_field_tag(:"OutSum", @order.total)%>
7
+ <%= hidden_field_tag(:"InvId", @order.id)%>
8
+ <%= hidden_field_tag(:"Desc", I18n.t("robokassa.details_of_payment", :order_number => @order.number)) %>
9
+ <%= hidden_field_tag(:"SignatureValue", @signature) %>
10
+ <h1 class="font-41 black"><%= "#{t('order')} #{@order.number}" %></h1>
11
+ <%= render :partial => 'shared/order_details', :locals => {:order => @order} %>
12
+ <div class="clear"></div>
13
+ <div class="font-41">&nbsp;</div>
14
+ <button style="margin-left: 350px;" class="button_buy left" href="">
15
+ <span class="left_b"></span>
16
+ <span class="line_b">
17
+ <span class="text_z_1"><%=t("pay") %></span>
18
+ </span>
19
+ <span class="right_b"></span>
20
+ </button>
21
+ <div class="clear"></div>
22
+ <% end %>
@@ -0,0 +1,14 @@
1
+ ---
2
+ en:
3
+ robokassa:
4
+ details_of_payment: 'Payment Order %{order_number}'
5
+ pay: Pay
6
+ success_url: Success URL
7
+ result_url: Result URL
8
+ fail_url: Fail URL
9
+ password1: Password 1
10
+ password2: Password 1
11
+ mrch_login: MerchantLogin login
12
+ invalid_arguments: Invalid Arguments
13
+ payment_fail: PAYMENT FAIL
14
+ payment_success: Payment Success
@@ -0,0 +1,14 @@
1
+ ---
2
+ ru:
3
+ robokassa:
4
+ details_of_payment: 'Оплата заказа %{order_number}'
5
+ pay: Оплата
6
+ success_url: Success URL
7
+ result_url: Result URL
8
+ fail_url: Fail URL
9
+ password1: Пароль 1
10
+ password2: Пароль 2
11
+ mrch_login: MerchantLogin login магазина (обязательный параметр)
12
+ invalid_arguments: Invalid Arguments
13
+ payment_fail: "Не удалось провести оплату"
14
+ payment_success: "Оплата выполнена успешно"
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ Rails.application.routes.draw do
2
+ # Add your extension routes here
3
+ namespace :gateway do
4
+ match '/robokassa/:gateway_id/:order_id' => 'robokassa#show', :as => :robokassa
5
+ match '/robokassa/result' => 'robokassa#result', :as => :robokassa_result
6
+ match '/robokassa/success' => 'robokassa#success', :as => :robokassa_success
7
+ match '/robokassa/fail' => 'robokassa#fail', :as => :robokassa_fail
8
+ end
9
+
10
+ end
@@ -0,0 +1,18 @@
1
+ require 'spree_core'
2
+ require 'spree_robokassa_hooks'
3
+
4
+ module SpreeRobokassa
5
+ class Engine < Rails::Engine
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ def self.activate
10
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
11
+ Rails.env.production? ? require(c) : load(c)
12
+ end
13
+ Gateway::Robokassa.register
14
+ end
15
+
16
+ config.to_prepare &method(:activate).to_proc
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class SpreeRobokassaHooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ end
@@ -0,0 +1,26 @@
1
+ namespace :spree_robokassa do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_robokassa:install:migrations'].invoke
5
+ Rake::Task['spree_robokassa:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
14
+ Spree::FileUtilz.mirror_files(source, destination)
15
+ end
16
+
17
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
18
+ task :assets do
19
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
20
+ destination = File.join(Rails.root, 'public')
21
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
22
+ Spree::FileUtilz.mirror_files(source, destination)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
@@ -0,0 +1,31 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../../../config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+ require 'fabrication'
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ # == Mock Framework
14
+ #
15
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
16
+ #
17
+ # config.mock_with :mocha
18
+ # config.mock_with :flexmock
19
+ # config.mock_with :rr
20
+ config.mock_with :rspec
21
+
22
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
23
+
24
+ #config.include Devise::TestHelpers, :type => :controller
25
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
26
+ # examples within a transaction, comment the following line or assign false
27
+ # instead of true.
28
+ config.use_transactional_fixtures = true
29
+ end
30
+
31
+ @configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'spree_robokassa'
4
+ s.version = '0.50.0'
5
+ s.summary = 'Adds payment method for robokassa.ru'
6
+ #s.description = 'Add (optional) gem description here'
7
+ s.required_ruby_version = '>= 1.8.7'
8
+
9
+ s.authors = ['Roman Smirnov', 'parallel588']
10
+ # s.email = 'david@loudthinking.com'
11
+ s.homepage = 'https://github.com/romul/spree_robokassa'
12
+ # s.rubyforge_project = 'actionmailer'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = [ 'lib' ]
18
+ s.requirements << 'none'
19
+
20
+ s.add_dependency('spree_core', '>= 0.30.1')
21
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_robokassa
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 50
8
+ - 0
9
+ version: 0.50.0
10
+ platform: ruby
11
+ authors:
12
+ - Roman Smirnov
13
+ - parallel588
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-27 00:00:00 +04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spree_core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 30
31
+ - 1
32
+ version: 0.30.1
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email:
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - app/controllers/checkout_controller_decorator.rb
49
+ - app/controllers/gateway/robokassa_controller.rb
50
+ - app/models/gateway/robokassa.rb
51
+ - app/views/admin/payment_methods/_form.html.erb
52
+ - app/views/checkout/payment/_robokassa.html.erb
53
+ - app/views/gateway/robokassa/show.html.erb
54
+ - config/locales/en.yml
55
+ - config/locales/ru.yml
56
+ - config/routes.rb
57
+ - lib/spree_robokassa.rb
58
+ - lib/spree_robokassa_hooks.rb
59
+ - lib/tasks/install.rake
60
+ - lib/tasks/spree_robokassa.rake
61
+ - spec/spec_helper.rb
62
+ - spree_robokassa.gemspec
63
+ has_rdoc: true
64
+ homepage: https://github.com/romul/spree_robokassa
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 1
78
+ - 8
79
+ - 7
80
+ version: 1.8.7
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements:
89
+ - none
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Adds payment method for robokassa.ru
95
+ test_files: []
96
+