synergy_mainpay 0.70.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ *.swo
2
+ *.swp
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.
@@ -0,0 +1,4 @@
1
+ SynergyMainpay
2
+ ============
3
+
4
+ Copyright (c) 2011 Sergey Rezvanov, Service & Consulting (http://secoint.ru)
@@ -0,0 +1,26 @@
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('synergy_mainpay.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
@@ -0,0 +1,16 @@
1
+ CheckoutController.class_eval do
2
+ before_filter :redirect_to_mainpay_form_if_needed, :only => :update
3
+
4
+ private
5
+
6
+ def redirect_to_mainpay_form_if_needed
7
+ return unless params[:state] == 'payment'
8
+
9
+ payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
10
+ if payment_method.is_a? Gateway::Mainpay
11
+ redirect_to gateway_mainpay_path(:gateway_id => payment_method.id, :order_id => @order.id)
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,85 @@
1
+ class Gateway::MainpayController < Spree::BaseController
2
+ ssl_required :show
3
+ before_filter :find_order_and_gateway, :only => [ :handler, :success, :fail ]
4
+ skip_before_filter :verify_authenticity_token, :only => [ :handler, :success, :fail ]
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
+ unless @order || @gateway
11
+ flash[:error] = t('.invalid_arguments')
12
+ redirect_to :back
13
+ end
14
+
15
+ end
16
+
17
+ def handler
18
+ if @order && @gateway && response_valid?
19
+ payment = @order.payments.build(:payment_method => @order.payment_method)
20
+ payment.state = 'completed'
21
+ payment.amount = params[:system_income].to_f
22
+ payment.save
23
+
24
+ @order.save!
25
+ @order.next! until @order.state == 'complete'
26
+ @order.update!
27
+
28
+ render :text => "OK#{@order.id}"
29
+
30
+ else
31
+ render :text => 'Bad response'
32
+ end
33
+
34
+ end
35
+
36
+ def success
37
+ if @order && @gateway && response_valid? && @order.complete?
38
+ session[:order_id] = nil
39
+ redirect_to order_path(@order), t('.payment_success')
40
+ else
41
+ flash[:error] = t('.payment_fail')
42
+ redirect_to root_url
43
+ end
44
+ end
45
+
46
+ def fail
47
+ flash[:error] = t('.payment_fail')
48
+ redirect_to @order.blank? ? root_url : checkout_state_path('payment')
49
+ end
50
+
51
+ private
52
+
53
+ def find_order_and_gateway
54
+ @order = Order.find_by_id(params[:order_id])
55
+ @gateway = Gateway::Mainpay.current
56
+ end
57
+
58
+ def response_valid?
59
+ unless params[:system_income].to_f == @order.total
60
+ return false
61
+ end
62
+
63
+ joined_params = [
64
+ params[:tid],
65
+ params[:name],
66
+ params[:comment],
67
+ params[:partner_id],
68
+ params[:service_id],
69
+ params[:order_id],
70
+ params[:type],
71
+ params[:partner_income],
72
+ params[:system_income],
73
+ (params[:test] if @gateway.options[:test_mode]),
74
+ @gateway.options[:secret2]
75
+ ].join
76
+
77
+ unless params[:check].downcase == Digest::MD5.hexdigest(joined_params).downcase
78
+ return false
79
+ end
80
+
81
+ true
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,29 @@
1
+ class Gateway::Mainpay < Gateway
2
+ preference :secret1, :string
3
+ preference :secret2, :string
4
+
5
+ def provider_class
6
+ self.class
7
+ end
8
+
9
+ def method_type
10
+ 'mainpay'
11
+ end
12
+
13
+ def self.current
14
+ self.where(:type => self.to_s, :environment => Rails.env, :active => true).first
15
+ end
16
+
17
+ def input_url
18
+ 'https://partner.mainpay.ru/a1lite/input'
19
+ end
20
+
21
+ def desc
22
+ "<p>
23
+ <label>#{I18n.t('success_url')}:</label> http://[domain]/gateway/mainpay/success<br />
24
+ <label>#{I18n.t('fail_url')}:</label> http://[domain]/gateway/mainpay/fail<br />
25
+ <label>#{I18n.t('handler_url')}:</label> http://[domain]/gateway/mainpay/handler<br />
26
+ </p>"
27
+ end
28
+
29
+ end
@@ -0,0 +1,54 @@
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_on) %></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
+
50
+ <%= raw(@object.desc) if @object.respond_to?(:desc) %>
51
+
52
+ <% end %>
53
+
54
+ </div>
@@ -0,0 +1,30 @@
1
+ <% content_for :page_title do %>
2
+ <h1 class="font-41 black"><%= t('.pay') %></h1>
3
+ <% end %>
4
+
5
+ <%= form_tag @gateway.input_url, :method => :post, :accept_charset => 'UTF8' do %>
6
+ <%= hidden_field_tag(:default_email, @order.email)%>
7
+ <%= hidden_field_tag(:key, @gateway.options[:secret1]) %>
8
+ <%= hidden_field_tag(:order_id, @order.id)%>
9
+ <%= hidden_field_tag(:name, t('.details', :order_number => @order.number)) %>
10
+ <%= hidden_field_tag(:cost, @order.total) %>
11
+ <%= hidden_field_tag(:comment, 'from_synergy') %>
12
+
13
+ <% if @gateway.options[:test_mode] %>
14
+ <%= hidden_field_tag(:test, 1) %>
15
+ <% end %>
16
+
17
+ <h1 class="font-41 black"><%= "#{t('order')} #{@order.number}" %></h1>
18
+
19
+ <%= render :partial => 'shared/order_details', :locals => { :order => @order } %>
20
+
21
+ <div class="clear"></div>
22
+ <div class="font-41">&nbsp;</div>
23
+ <button class="button_buy left">
24
+ <span class="left_b"></span>
25
+ <span class="line_b"><span class="text_z_1"><%= t('.pay') %></span></span>
26
+ <span class="right_b"></span>
27
+ </button>
28
+ <div class="clear"></div>
29
+
30
+ <% end %>
@@ -0,0 +1,15 @@
1
+ ---
2
+ en:
3
+ secret1: 'Payment button key'
4
+ secret2: 'Secret key'
5
+ payment_fail: 'Failed to make payment'
6
+ payment_success: 'Payment is successfull'
7
+ success_url: 'Success URL'
8
+ fail_url: 'Fail URL'
9
+ handler_url: 'Handler URL'
10
+
11
+ gateway:
12
+ mainpay:
13
+ show:
14
+ pay: 'Pay'
15
+ details: 'Payment order %{order_number}'
@@ -0,0 +1,15 @@
1
+ ---
2
+ ru:
3
+ secret1: 'Код кнопки оплаты'
4
+ secret2: 'Секретный ключ'
5
+ payment_fail: 'Не удалось выполнить платеж'
6
+ payment_success: 'Платеж выполнен успешно'
7
+ success_url: 'URL успешной покупки'
8
+ fail_url: 'URL ошибки'
9
+ handler_url: 'URL обработчика'
10
+
11
+ gateway:
12
+ mainpay:
13
+ show:
14
+ pay: 'Оплата'
15
+ details: 'Оплата заказа %{order_number}'
@@ -0,0 +1,11 @@
1
+ Rails.application.routes.draw do
2
+ namespace :gateway do
3
+ match '/mainpay/:gateway_id/:order_id' => 'mainpay#show', :as => :mainpay
4
+
5
+ match '/mainpay/handler' => 'mainpay#handler'
6
+
7
+ match '/mainpay/success' => 'mainpay#success'
8
+ match '/mainpay/fail' => 'mainpay#fail'
9
+
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ require 'spree_core'
2
+ require 'synergy_mainpay/engine'
@@ -0,0 +1,30 @@
1
+ module SynergyMainpay
2
+ class Engine < Rails::Engine
3
+ engine_name 'synergy_mainpay'
4
+
5
+ config.autoload_paths += %W(#{config.root}/lib)
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ def self.activate
13
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
14
+ Rails.application.config.cache_classes ? require(c) : load(c)
15
+ end
16
+
17
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
18
+ Rails.application.config.cache_classes ? require(c) : load(c)
19
+ end
20
+ end
21
+
22
+ config.to_prepare &method(:activate).to_proc
23
+
24
+ initializer "synergy_mainpay.register.payment_methods", :after => 'spree.register.payment_methods' do |app|
25
+ app.config.spree.payment_methods += [
26
+ Gateway::Mainpay
27
+ ]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ namespace :synergy_mainpay do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['synergy_mainpay:install:migrations'].invoke
5
+ Rake::Task['synergy_mainpay: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,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'synergy_mainpay'
4
+ s.version = '0.70.1'
5
+ s.summary = 'Adds payment method for mainpay.ru'
6
+ s.required_ruby_version = '>= 1.8.7'
7
+
8
+ s.authors = 'Sergey Rezvanov (Service & Consulting)'
9
+ s.email = 'service@secoint.ru'
10
+ s.homepage = 'http://github.com/secoint/synergy_mainpay'
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+
15
+ s.require_paths = [ 'lib' ]
16
+ s.requirements << 'none'
17
+
18
+ s.add_dependency('spree_core', '>= 0.70.1')
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: synergy_mainpay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 261
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 70
9
+ - 1
10
+ version: 0.70.1
11
+ platform: ruby
12
+ authors:
13
+ - Sergey Rezvanov (Service & Consulting)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: spree_core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 261
29
+ segments:
30
+ - 0
31
+ - 70
32
+ - 1
33
+ version: 0.70.1
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description:
37
+ email: service@secoint.ru
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - app/controllers/checkout_controller_decorator.rb
50
+ - app/controllers/gateway/mainpay_controller.rb
51
+ - app/models/gateway/mainpay.rb
52
+ - app/views/admin/payment_methods/_form.html.erb
53
+ - app/views/admin/payments/source_forms/_mainpay.html.erb
54
+ - app/views/admin/payments/source_views/_mainpay.html.erb
55
+ - app/views/checkout/payment/_mainpay.html.erb
56
+ - app/views/gateway/mainpay/show.html.erb
57
+ - config/locales/en.yml
58
+ - config/locales/ru.yml
59
+ - config/routes.rb
60
+ - lib/synergy_mainpay.rb
61
+ - lib/synergy_mainpay/engine.rb
62
+ - lib/tasks/install.rake
63
+ - lib/tasks/synergy_mainpay.rake
64
+ - spec/spec_helper.rb
65
+ - synergy_mainpay.gemspec
66
+ homepage: http://github.com/secoint/synergy_mainpay
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 57
80
+ segments:
81
+ - 1
82
+ - 8
83
+ - 7
84
+ version: 1.8.7
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements:
95
+ - none
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.15
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Adds payment method for mainpay.ru
101
+ test_files: []
102
+