spree_webmoney 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +23 -0
- data/README.md +13 -0
- data/app/controllers/gateway/webmoney_controller.rb +97 -0
- data/app/models/gateway/webmoney.rb +23 -0
- data/app/views/admin/payment_methods/_form.html.erb +51 -0
- data/app/views/checkout/payment/_webmoney.html.erb +1 -0
- data/app/views/gateway/webmoney/show.html.erb +24 -0
- data/lib/overload/controller/checkouts_module.rb +32 -0
- data/lib/spree_webmoney.rb +19 -0
- data/lib/spree_webmoney_hooks.rb +3 -0
- data/lib/tasks/install.rake +26 -0
- data/lib/tasks/spree_webmoney.rake +1 -0
- metadata +95 -0
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,97 @@
|
|
1
|
+
class Gateway::WebmoneyController < Spree::BaseController
|
2
|
+
skip_before_filter :verify_authenticity_token, :only => [:result, :success, :fail]
|
3
|
+
before_filter :parse_payment_params, :only => [:result, :success, :fail]
|
4
|
+
before_filter :valid_payment, :only => [:result]
|
5
|
+
|
6
|
+
def show
|
7
|
+
@order = Order.unscoped{ Order.find(params[:order_id]) }
|
8
|
+
@gateway = @order.available_payment_methods.find{|x| x.id == params[:gateway_id].to_i }
|
9
|
+
@order.payments.destroy_all
|
10
|
+
payment = @order.payments.create!(:amount => 0, :payment_method_id => @gateway.id)
|
11
|
+
|
12
|
+
if @order.blank? || @gateway.blank?
|
13
|
+
flash[:error] = I18n.t("Invalid arguments")
|
14
|
+
redirect_to :back
|
15
|
+
else
|
16
|
+
render :action => :show
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def result
|
21
|
+
raise GatewayError, "Not found order" unless @order
|
22
|
+
payment = @order.payments.first
|
23
|
+
payment.state = "completed"
|
24
|
+
payment.amount = @payment_params[:payment_amount].to_f
|
25
|
+
payment.save
|
26
|
+
@order.save!
|
27
|
+
@order.next! until @order.state == "complete"
|
28
|
+
|
29
|
+
render :text => "YES"
|
30
|
+
end
|
31
|
+
|
32
|
+
def success
|
33
|
+
@order = Order.unscoped{ Order.find_by_id(@payment_params[:payment_no]) }
|
34
|
+
if @order && @order.complete?
|
35
|
+
session[:order_id] = nil
|
36
|
+
redirect_to order_path(@order)
|
37
|
+
else
|
38
|
+
flash[:error] = t("payment_fail")
|
39
|
+
redirect_to root_url
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def fail
|
44
|
+
@order = Order.unscoped{ Order.find_by_id(@payment_params[:payment_no]) }
|
45
|
+
flash.now[:error] = t("payment_fail")
|
46
|
+
redirect_to @order.blank? ? root_url : edit_order_checkout_url(@order, :step => "payment")
|
47
|
+
return
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# parse params
|
53
|
+
def parse_payment_params
|
54
|
+
@payment_params = HashWithIndifferentAccess.new
|
55
|
+
params.each do |key, value|
|
56
|
+
if key.starts_with?('LMI_')
|
57
|
+
@payment_params[key.gsub(/^LMI_/, "").downcase] = value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def valid_payment
|
64
|
+
@order = Order.unscoped{ Order.find_by_id(@payment_params[:payment_no]) }
|
65
|
+
@gateway = @order.payments.first.payment_method
|
66
|
+
|
67
|
+
raise "invalid gateway" unless @gateway
|
68
|
+
@secret = @gateway.options[:secret]
|
69
|
+
|
70
|
+
if @payment_params[:prerequest] == "1"
|
71
|
+
render :text => "YES"
|
72
|
+
elsif @secret.blank? # если не указан секретный ключ
|
73
|
+
raise ArgumentError.new("WebMoney secret key is not provided")
|
74
|
+
elsif !valid_hash?(@payment_params, @secret)
|
75
|
+
raise "not valid payment"
|
76
|
+
end
|
77
|
+
rescue => ex
|
78
|
+
Rails.logger.error "not valid payment #{ex.message}"
|
79
|
+
render :text => "not valid payment"
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
def valid_hash?(payment_params, secret)
|
85
|
+
payment_params[:hash] ==
|
86
|
+
Digest::MD5.hexdigest([
|
87
|
+
payment_params[:payee_purse], payment_params[:payment_amount],
|
88
|
+
payment_params[:payment_no], payment_params[:mode],
|
89
|
+
payment_params[:sys_invs_no], payment_params[:sys_trans_no],
|
90
|
+
payment_params[:sys_trans_date], secret,
|
91
|
+
payment_params[:payer_purse], payment_params[:payer_wm]
|
92
|
+
].join("")).upcase
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Gateway::Webmoney < Gateway
|
2
|
+
preference :secret, :string
|
3
|
+
preference :wallet, :string
|
4
|
+
|
5
|
+
def provider_class
|
6
|
+
self.class
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_type
|
10
|
+
"webmoney"
|
11
|
+
end
|
12
|
+
def test?
|
13
|
+
options[:test_mode] == true
|
14
|
+
end
|
15
|
+
|
16
|
+
def desc
|
17
|
+
"<p>
|
18
|
+
<label> #{I18n.t('webmoney.success_url')}: </label> htpp://[domain]/gateway/webmoney/success<br />
|
19
|
+
<label> #{I18n.t('webmoney.result_url')}: </label> http://[domain]/gateway/webmoney/result<br />
|
20
|
+
<label> #{I18n.t('webmoney.fail_url')}: </label> http://[domain]/gateway/webmoney/fails<br />
|
21
|
+
</p>"
|
22
|
+
end
|
23
|
+
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>
|
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 @@
|
|
1
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<% content_for :page_title do %>
|
2
|
+
<h1 class="font-41 black"><%= t("webmoney.pay")%></h1>
|
3
|
+
<% end %>
|
4
|
+
<%= form_tag "https://merchant.webmoney.ru/lmi/payment.asp", :method => "POST" do %>
|
5
|
+
<%= hidden_field_tag(:LMI_PAYEE_PURSE, @gateway.options[:wallet]) %>
|
6
|
+
<%= hidden_field_tag(:LMI_PAYMENT_AMOUNT, @order.total)%>
|
7
|
+
<%= hidden_field_tag(:LMI_SIM_MODE, 0) if @gateway.test? %>
|
8
|
+
<%= hidden_field_tag(:LMI_PAYMENT_NO, @order.id)%>
|
9
|
+
<%= hidden_field_tag(:LMI_PAYMENT_DESC_BASE64, [I18n.t("webmoney.details_of_payment", :order_number => @order.number)].pack("m")) %>
|
10
|
+
<h1 class="font-41 black"><%= "#{t('order')} #{@order.number}" %></h1>
|
11
|
+
<%= render :partial => 'shared/order_details', :locals => {:order => @order} %>
|
12
|
+
|
13
|
+
<div class="clear"></div>
|
14
|
+
<div class="font-41"> </div>
|
15
|
+
<button style="margin-left: 350px;" class="button_buy left" href="">
|
16
|
+
<span class="left_b"></span>
|
17
|
+
<span class="line_b">
|
18
|
+
<span class="text_z_1"><%=t("pay") %></span>
|
19
|
+
<span class="text_z_2"><%=t("pay") %></span>
|
20
|
+
</span>
|
21
|
+
<span class="right_b"></span>
|
22
|
+
</button>
|
23
|
+
<div class="clear"></div>
|
24
|
+
<% end %>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Overload
|
2
|
+
module Controller
|
3
|
+
module CheckoutsModule
|
4
|
+
|
5
|
+
def self.included recipient
|
6
|
+
recipient.class_eval do
|
7
|
+
before_filter :redirect_to_webmonay_form_if_needed, :only => [:update]
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def redirect_to_webmonay_form_if_needed
|
12
|
+
return unless params[:state] == "payment"
|
13
|
+
payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
|
14
|
+
if payment_method.kind_of? Gateway::Webmoney
|
15
|
+
if !request.ssl? && Rails.env =~ /production/
|
16
|
+
redirect_to gateway_webmoney_path(:gateway_id => payment_method.id, :order_id => @order.id,
|
17
|
+
:protocol => "https", :host => Rails.configuration.main_domain)
|
18
|
+
else
|
19
|
+
redirect_to gateway_webmoney_path(:gateway_id => payment_method.id, :order_id => @order.id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'spree_webmoney_hooks'
|
3
|
+
|
4
|
+
module SpreeWebmoney
|
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::Webmoney.register
|
14
|
+
CheckoutController.send :include, Overload::Controller::CheckoutsModule
|
15
|
+
end
|
16
|
+
|
17
|
+
config.to_prepare &method(:activate).to_proc
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :spree_webmoney 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_webmoney:install:migrations'].invoke
|
5
|
+
Rake::Task['spree_webmoney: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
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_webmoney
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- tradefast.ru
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-16 00:00:00 +03: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
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 101
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 30
|
33
|
+
- 1
|
34
|
+
version: 0.30.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Add webmoney support for spree
|
38
|
+
email: pronix.service@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- README.md
|
47
|
+
- LICENSE
|
48
|
+
- lib/tasks/install.rake
|
49
|
+
- lib/tasks/spree_webmoney.rake
|
50
|
+
- lib/spree_webmoney.rb
|
51
|
+
- lib/spree_webmoney_hooks.rb
|
52
|
+
- lib/overload/controller/checkouts_module.rb
|
53
|
+
- app/models/gateway/webmoney.rb
|
54
|
+
- app/views/checkout/payment/_webmoney.html.erb
|
55
|
+
- app/views/gateway/webmoney/show.html.erb
|
56
|
+
- app/views/admin/payment_methods/_form.html.erb
|
57
|
+
- app/controllers/gateway/webmoney_controller.rb
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://tradefast.ru
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 57
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 8
|
76
|
+
- 7
|
77
|
+
version: 1.8.7
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
requirements:
|
88
|
+
- none
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.3.7
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Add gem summary here
|
94
|
+
test_files: []
|
95
|
+
|