spree_omnikassa 0.4.2
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 +11 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +224 -0
- data/LICENSE +26 -0
- data/README.md +36 -0
- data/Rakefile +29 -0
- data/Versionfile +9 -0
- data/app/assets/javascripts/admin/spree_omnikassa.js +1 -0
- data/app/assets/javascripts/store/spree_omnikassa.js +1 -0
- data/app/assets/stylesheets/admin/spree_omnikassa.css +3 -0
- data/app/assets/stylesheets/store/spree_omnikassa.css +3 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +10 -0
- data/app/controllers/spree/omnikassa_payments_controller.rb +97 -0
- data/app/models/spree/omnikassa_payment_request.rb +89 -0
- data/app/models/spree/omnikassa_payment_response.rb +129 -0
- data/app/models/spree/order_decorator.rb +33 -0
- data/app/models/spree/payment_method/omnikassa.rb +39 -0
- data/app/views/spree/checkout/omnikassa_edit.html.erb +36 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +5 -0
- data/lib/generators/spree_omnikassa/install/install_generator.rb +29 -0
- data/lib/spree_omnikassa.rb +26 -0
- data/script/rails +5 -0
- data/spec/controllers/spree/checkout_controller_spec.rb +28 -0
- data/spec/controllers/spree/omnikassa_payments_controller_spec.rb +198 -0
- data/spec/functional/spree_omnikassa_checkout_decorator_spec.rb +10 -0
- data/spec/integration/spree_omnikassa_checkout_spec.rb +10 -0
- data/spec/models/spree_omnikassa_payment_request_spec.rb +93 -0
- data/spec/models/spree_omnikassa_payment_response_spec.rb +144 -0
- data/spec/models/spree_payment_method_omnikassa_spec.rb +72 -0
- data/spec/spec_helper.rb +79 -0
- data/spree_omnikassa.gemspec +19 -0
- metadata +114 -0
data/.gitignore
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
source :rubygems
|
|
2
|
+
|
|
3
|
+
group :test do
|
|
4
|
+
gem 'rspec-rails', '~> 2.12.2'
|
|
5
|
+
gem 'spork'
|
|
6
|
+
gem 'factory_girl', '~> 2'
|
|
7
|
+
gem 'ffaker'
|
|
8
|
+
gem 'sqlite3'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
if RUBY_VERSION < "1.9"
|
|
12
|
+
gem "ruby-debug"
|
|
13
|
+
else
|
|
14
|
+
gem "ruby-debug19"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
gemspec
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
spree_omnikassa (0.4.2)
|
|
5
|
+
spree (~> 1.0.6)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: http://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
actionmailer (3.1.10)
|
|
11
|
+
actionpack (= 3.1.10)
|
|
12
|
+
mail (~> 2.3.3)
|
|
13
|
+
actionpack (3.1.10)
|
|
14
|
+
activemodel (= 3.1.10)
|
|
15
|
+
activesupport (= 3.1.10)
|
|
16
|
+
builder (~> 3.0.0)
|
|
17
|
+
erubis (~> 2.7.0)
|
|
18
|
+
i18n (~> 0.6)
|
|
19
|
+
rack (~> 1.3.6)
|
|
20
|
+
rack-cache (~> 1.2)
|
|
21
|
+
rack-mount (~> 0.8.2)
|
|
22
|
+
rack-test (~> 0.6.1)
|
|
23
|
+
sprockets (~> 2.0.4)
|
|
24
|
+
active_utils (1.0.5)
|
|
25
|
+
activesupport (>= 2.3.11)
|
|
26
|
+
i18n
|
|
27
|
+
activemerchant (1.20.1)
|
|
28
|
+
active_utils (>= 1.0.1)
|
|
29
|
+
activesupport (>= 2.3.11)
|
|
30
|
+
braintree (>= 2.0.0)
|
|
31
|
+
builder (>= 2.0.0)
|
|
32
|
+
i18n
|
|
33
|
+
json (>= 1.5.1)
|
|
34
|
+
money (<= 3.7.1)
|
|
35
|
+
activemodel (3.1.10)
|
|
36
|
+
activesupport (= 3.1.10)
|
|
37
|
+
builder (~> 3.0.0)
|
|
38
|
+
i18n (~> 0.6)
|
|
39
|
+
activerecord (3.1.10)
|
|
40
|
+
activemodel (= 3.1.10)
|
|
41
|
+
activesupport (= 3.1.10)
|
|
42
|
+
arel (~> 2.2.3)
|
|
43
|
+
tzinfo (~> 0.3.29)
|
|
44
|
+
activeresource (3.1.10)
|
|
45
|
+
activemodel (= 3.1.10)
|
|
46
|
+
activesupport (= 3.1.10)
|
|
47
|
+
activesupport (3.1.10)
|
|
48
|
+
multi_json (>= 1.0, < 1.3)
|
|
49
|
+
acts_as_list (0.1.4)
|
|
50
|
+
arel (2.2.3)
|
|
51
|
+
bcrypt-ruby (3.0.1)
|
|
52
|
+
braintree (2.22.0)
|
|
53
|
+
builder (>= 2.0.0)
|
|
54
|
+
builder (3.0.4)
|
|
55
|
+
cancan (1.6.7)
|
|
56
|
+
climate_control (0.0.3)
|
|
57
|
+
activesupport (>= 3.0)
|
|
58
|
+
cocaine (0.5.1)
|
|
59
|
+
climate_control (>= 0.0.3, < 1.0)
|
|
60
|
+
columnize (0.3.6)
|
|
61
|
+
deface (0.9.1)
|
|
62
|
+
nokogiri (~> 1.5.0)
|
|
63
|
+
rails (~> 3.1)
|
|
64
|
+
devise (1.4.8)
|
|
65
|
+
bcrypt-ruby (~> 3.0)
|
|
66
|
+
orm_adapter (~> 0.0.3)
|
|
67
|
+
warden (~> 1.0.3)
|
|
68
|
+
diff-lcs (1.1.3)
|
|
69
|
+
erubis (2.7.0)
|
|
70
|
+
factory_girl (2.6.4)
|
|
71
|
+
activesupport (>= 2.3.9)
|
|
72
|
+
ffaker (1.12.1)
|
|
73
|
+
highline (1.6.8)
|
|
74
|
+
hike (1.2.1)
|
|
75
|
+
httparty (0.8.3)
|
|
76
|
+
multi_json (~> 1.0)
|
|
77
|
+
multi_xml
|
|
78
|
+
i18n (0.6.1)
|
|
79
|
+
jquery-rails (1.0.19)
|
|
80
|
+
railties (~> 3.0)
|
|
81
|
+
thor (~> 0.14)
|
|
82
|
+
json (1.7.6)
|
|
83
|
+
kaminari (0.14.1)
|
|
84
|
+
actionpack (>= 3.0.0)
|
|
85
|
+
activesupport (>= 3.0.0)
|
|
86
|
+
linecache (0.46)
|
|
87
|
+
rbx-require-relative (> 0.0.4)
|
|
88
|
+
mail (2.3.3)
|
|
89
|
+
i18n (>= 0.4.0)
|
|
90
|
+
mime-types (~> 1.16)
|
|
91
|
+
treetop (~> 1.4.8)
|
|
92
|
+
meta_search (1.1.1)
|
|
93
|
+
actionpack (~> 3.1.0)
|
|
94
|
+
activerecord (~> 3.1.0)
|
|
95
|
+
activesupport (~> 3.1.0)
|
|
96
|
+
polyamorous (~> 0.5.0)
|
|
97
|
+
mime-types (1.19)
|
|
98
|
+
money (3.7.1)
|
|
99
|
+
i18n (~> 0.4)
|
|
100
|
+
multi_json (1.2.0)
|
|
101
|
+
multi_xml (0.5.2)
|
|
102
|
+
nested_set (1.6.8)
|
|
103
|
+
activerecord (>= 3.0.0)
|
|
104
|
+
railties (>= 3.0.0)
|
|
105
|
+
nokogiri (1.5.6)
|
|
106
|
+
orm_adapter (0.0.7)
|
|
107
|
+
paperclip (2.7.0)
|
|
108
|
+
activerecord (>= 2.3.0)
|
|
109
|
+
activesupport (>= 2.3.2)
|
|
110
|
+
cocaine (>= 0.0.2)
|
|
111
|
+
mime-types
|
|
112
|
+
polyamorous (0.5.0)
|
|
113
|
+
activerecord (~> 3.0)
|
|
114
|
+
polyglot (0.3.3)
|
|
115
|
+
rack (1.3.9)
|
|
116
|
+
rack-cache (1.2)
|
|
117
|
+
rack (>= 0.4)
|
|
118
|
+
rack-mount (0.8.3)
|
|
119
|
+
rack (>= 1.0.0)
|
|
120
|
+
rack-ssl (1.3.2)
|
|
121
|
+
rack
|
|
122
|
+
rack-test (0.6.2)
|
|
123
|
+
rack (>= 1.0)
|
|
124
|
+
rails (3.1.10)
|
|
125
|
+
actionmailer (= 3.1.10)
|
|
126
|
+
actionpack (= 3.1.10)
|
|
127
|
+
activerecord (= 3.1.10)
|
|
128
|
+
activeresource (= 3.1.10)
|
|
129
|
+
activesupport (= 3.1.10)
|
|
130
|
+
bundler (~> 1.0)
|
|
131
|
+
railties (= 3.1.10)
|
|
132
|
+
railties (3.1.10)
|
|
133
|
+
actionpack (= 3.1.10)
|
|
134
|
+
activesupport (= 3.1.10)
|
|
135
|
+
rack-ssl (~> 1.3.2)
|
|
136
|
+
rake (>= 0.8.7)
|
|
137
|
+
rdoc (~> 3.4)
|
|
138
|
+
thor (~> 0.14.6)
|
|
139
|
+
rake (10.0.3)
|
|
140
|
+
rbx-require-relative (0.0.5)
|
|
141
|
+
rdoc (3.12)
|
|
142
|
+
json (~> 1.4)
|
|
143
|
+
rspec-core (2.12.2)
|
|
144
|
+
rspec-expectations (2.12.1)
|
|
145
|
+
diff-lcs (~> 1.1.3)
|
|
146
|
+
rspec-mocks (2.12.1)
|
|
147
|
+
rspec-rails (2.12.2)
|
|
148
|
+
actionpack (>= 3.0)
|
|
149
|
+
activesupport (>= 3.0)
|
|
150
|
+
railties (>= 3.0)
|
|
151
|
+
rspec-core (~> 2.12.0)
|
|
152
|
+
rspec-expectations (~> 2.12.0)
|
|
153
|
+
rspec-mocks (~> 2.12.0)
|
|
154
|
+
ruby-debug (0.10.4)
|
|
155
|
+
columnize (>= 0.1)
|
|
156
|
+
ruby-debug-base (~> 0.10.4.0)
|
|
157
|
+
ruby-debug-base (0.10.4)
|
|
158
|
+
linecache (>= 0.3)
|
|
159
|
+
spork (0.9.2)
|
|
160
|
+
spree (1.0.6)
|
|
161
|
+
spree_api (= 1.0.6)
|
|
162
|
+
spree_auth (= 1.0.6)
|
|
163
|
+
spree_cmd (= 1.0.6)
|
|
164
|
+
spree_core (= 1.0.6)
|
|
165
|
+
spree_dash (= 1.0.6)
|
|
166
|
+
spree_promo (= 1.0.6)
|
|
167
|
+
spree_sample (= 1.0.6)
|
|
168
|
+
spree_api (1.0.6)
|
|
169
|
+
spree_auth (= 1.0.6)
|
|
170
|
+
spree_core (= 1.0.6)
|
|
171
|
+
spree_auth (1.0.6)
|
|
172
|
+
cancan (= 1.6.7)
|
|
173
|
+
devise (= 1.4.8)
|
|
174
|
+
spree_core (= 1.0.6)
|
|
175
|
+
spree_cmd (1.0.6)
|
|
176
|
+
spree_core (1.0.6)
|
|
177
|
+
activemerchant (= 1.20.1)
|
|
178
|
+
acts_as_list (= 0.1.4)
|
|
179
|
+
deface (>= 0.9.0)
|
|
180
|
+
ffaker (~> 1.12.0)
|
|
181
|
+
highline (= 1.6.8)
|
|
182
|
+
jquery-rails (>= 1.0.18, <= 1.0.19)
|
|
183
|
+
kaminari (>= 0.13.0)
|
|
184
|
+
meta_search (= 1.1.1)
|
|
185
|
+
nested_set (= 1.6.8)
|
|
186
|
+
paperclip (= 2.7.0)
|
|
187
|
+
rails (~> 3.1.6)
|
|
188
|
+
state_machine (= 1.1.1)
|
|
189
|
+
stringex (~> 1.3.2)
|
|
190
|
+
spree_dash (1.0.6)
|
|
191
|
+
httparty (~> 0.8.1)
|
|
192
|
+
spree_core (= 1.0.6)
|
|
193
|
+
spree_promo (1.0.6)
|
|
194
|
+
spree_auth (= 1.0.6)
|
|
195
|
+
spree_core (= 1.0.6)
|
|
196
|
+
spree_sample (1.0.6)
|
|
197
|
+
spree_core (= 1.0.6)
|
|
198
|
+
sprockets (2.0.4)
|
|
199
|
+
hike (~> 1.2)
|
|
200
|
+
rack (~> 1.0)
|
|
201
|
+
tilt (~> 1.1, != 1.3.0)
|
|
202
|
+
sqlite3 (1.3.5)
|
|
203
|
+
state_machine (1.1.1)
|
|
204
|
+
stringex (1.3.3)
|
|
205
|
+
thor (0.14.6)
|
|
206
|
+
tilt (1.3.3)
|
|
207
|
+
treetop (1.4.12)
|
|
208
|
+
polyglot
|
|
209
|
+
polyglot (>= 0.3.1)
|
|
210
|
+
tzinfo (0.3.35)
|
|
211
|
+
warden (1.0.6)
|
|
212
|
+
rack (>= 1.0)
|
|
213
|
+
|
|
214
|
+
PLATFORMS
|
|
215
|
+
ruby
|
|
216
|
+
|
|
217
|
+
DEPENDENCIES
|
|
218
|
+
factory_girl (~> 2)
|
|
219
|
+
ffaker
|
|
220
|
+
rspec-rails (~> 2.12.2)
|
|
221
|
+
ruby-debug
|
|
222
|
+
spork
|
|
223
|
+
spree_omnikassa!
|
|
224
|
+
sqlite3
|
data/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (c) 2012 [name of plugin creator]
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
|
13
|
+
endorse or promote products derived from this software without specific
|
|
14
|
+
prior written permission.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
SpreeOmnikassa
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
A [Spree payment method](http://guides.spreecommerce.com/payment_gateways.html) for the [Dutch Rabobank Omnikassa](http://www.rabobank.nl/bedrijven/producten/betalen_en_ontvangen/geld_ontvangen/rabo_omnikassa/).
|
|
5
|
+
|
|
6
|
+
It was developed for [Anna Treurniet](http://annatreurniet.nl) and
|
|
7
|
+
mentioned in the [whitepaper on my blog](http://berk.es/2012/10/22/spree-on-budgethoster-site5/).
|
|
8
|
+
|
|
9
|
+
It was developed to "just work" and not more. It is unmaintained and
|
|
10
|
+
might not work.
|
|
11
|
+
|
|
12
|
+
The reason for that is Spree's lack of any kind of support for offsite
|
|
13
|
+
payments. Omnikassa is offsite. And as such it needs to be hacked into
|
|
14
|
+
Spree; with many ugly overrides.
|
|
15
|
+
On said site, it _works_, but this plugin breaks many things, due to the
|
|
16
|
+
hackish way it needs to override the checkout workflow.
|
|
17
|
+
|
|
18
|
+
* Coupons break; you cannot have coupons.
|
|
19
|
+
* You cannot run it togeter with other payment methods.
|
|
20
|
+
* Somehow the user-registration breaks, you can only run with anon users
|
|
21
|
+
and even then in the backend some sub-sub-menu throws a 500-error.
|
|
22
|
+
* It is tightly coupled to Spree 1.0. And upgrading requires quit
|
|
23
|
+
extensive hacks or re-doing parts of the decorators.
|
|
24
|
+
|
|
25
|
+
I am severely dissapointed in the stubborn nature of Spree in this. As
|
|
26
|
+
such, I have no plans to upgrade this to a recent version. I have no
|
|
27
|
+
plans to maintain it, untill maybe Spree becomes more of a DSL for
|
|
28
|
+
e-commerce rather then a complete, turnkey solution with all sorts of
|
|
29
|
+
assumptions. Assumptions such as "payments are always done through gateways".
|
|
30
|
+
|
|
31
|
+
Testing
|
|
32
|
+
-------
|
|
33
|
+
|
|
34
|
+
I had plans to maintain and continue this extension; Hence I started off the extension with Rspec-coverage. Feel free to fork and continue this extension and when doing so, consider updating or removing the RSpec specs.
|
|
35
|
+
|
|
36
|
+
Copyright (c) 2012 Bèr Kessels, released under the New BSD License
|
data/Rakefile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
require 'rake/packagetask'
|
|
4
|
+
require 'rubygems/package_task'
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
|
+
require 'spree/core/testing_support/common_rake'
|
|
7
|
+
|
|
8
|
+
RSpec::Core::RakeTask.new
|
|
9
|
+
|
|
10
|
+
task :default => [:spec]
|
|
11
|
+
|
|
12
|
+
spec = eval(File.read('spree_omnikassa.gemspec'))
|
|
13
|
+
|
|
14
|
+
Gem::PackageTask.new(spec) do |p|
|
|
15
|
+
p.gem_spec = spec
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
desc "Release to gemcutter"
|
|
19
|
+
task :release => :package do
|
|
20
|
+
require 'rake/gemcutter'
|
|
21
|
+
Rake::Gemcutter::Tasks.new(spec).define
|
|
22
|
+
Rake::Task['gem:push'].invoke
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc "Generates a dummy app for testing"
|
|
26
|
+
task :test_app do
|
|
27
|
+
ENV['LIB_NAME'] = 'spree_omnikassa'
|
|
28
|
+
Rake::Task['common:test_app'].invoke
|
|
29
|
+
end
|
data/Versionfile
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# This file is used to designate compatibilty with different versions of Spree
|
|
2
|
+
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
|
|
3
|
+
|
|
4
|
+
# Examples
|
|
5
|
+
#
|
|
6
|
+
# "0.70.x" => { :branch => "master"}
|
|
7
|
+
# "0.60.x" => { :branch => "0-60-stable" }
|
|
8
|
+
# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
|
|
9
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//= require admin/spree_core
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//= require store/spree_core
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Spree::CheckoutController.class_eval do
|
|
2
|
+
def edit
|
|
3
|
+
if ((@order.state == "payment") && @order.valid?)
|
|
4
|
+
transaction_reference = Spree::OmnikassaPaymentRequest.build_transaction_reference(@order.id)
|
|
5
|
+
@payment_request = Spree::OmnikassaPaymentRequest.new(@order.total, transaction_reference)
|
|
6
|
+
|
|
7
|
+
render "omnikassa_edit"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class OmnikassaPaymentsController < ApplicationController
|
|
3
|
+
skip_before_filter :verify_authenticity_token
|
|
4
|
+
|
|
5
|
+
def homecoming
|
|
6
|
+
@payment_response = payment_response_from_params(params)
|
|
7
|
+
@order = @payment_response.order
|
|
8
|
+
|
|
9
|
+
if not @payment_response.valid?
|
|
10
|
+
flash[:error] = "Invalid request"
|
|
11
|
+
redirect_to(root_url) and return
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
case @payment_response.response_level
|
|
15
|
+
when :success
|
|
16
|
+
flash[:info] = "Success!"
|
|
17
|
+
when :pending
|
|
18
|
+
flash[:info] = "Still pending. You will recieve a message"
|
|
19
|
+
when :cancelled
|
|
20
|
+
flash[:error] = "Order cancelled"
|
|
21
|
+
when :failed
|
|
22
|
+
flash[:error] = "Error occurred"
|
|
23
|
+
else
|
|
24
|
+
flash[:error] = "Unknown Error occurred"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
session[:order_id] = nil
|
|
28
|
+
|
|
29
|
+
redirect_to(root_url) and return
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def reply
|
|
33
|
+
@payment_response = payment_response_from_params(params)
|
|
34
|
+
@order = @payment_response.order
|
|
35
|
+
add_payment_if_not_exists
|
|
36
|
+
message = "OmnikassaPaymentResponse posted: payment: # @payment_response.payment.id}; params: #{params.inspect}"
|
|
37
|
+
|
|
38
|
+
if @payment_response.valid?
|
|
39
|
+
case @payment_response.response_level
|
|
40
|
+
when :success
|
|
41
|
+
Rails.logger.info message
|
|
42
|
+
@payment_response.payment.complete!
|
|
43
|
+
advance_order_status :complete
|
|
44
|
+
when :pending
|
|
45
|
+
Rails.logger.info message
|
|
46
|
+
@payment_response.payment.pend!
|
|
47
|
+
advance_order_status :payment
|
|
48
|
+
when :cancelled
|
|
49
|
+
Rails.logger.info message
|
|
50
|
+
@payment_response.payment.failure!
|
|
51
|
+
@payment_response.order.cancel
|
|
52
|
+
when :failed
|
|
53
|
+
Rails.logger.error message
|
|
54
|
+
@payment_response.payment.failure!
|
|
55
|
+
@payment_response.order.cancel
|
|
56
|
+
else
|
|
57
|
+
Rails.logger.error message
|
|
58
|
+
@payment_response.payment.pend!
|
|
59
|
+
@payment_response.order.cancel
|
|
60
|
+
end
|
|
61
|
+
else
|
|
62
|
+
Rails.logger.error message
|
|
63
|
+
@payment_response.payment.pend!
|
|
64
|
+
end
|
|
65
|
+
render :text => @payment_response.response_level.to_s
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
def advance_order_status upto_state
|
|
70
|
+
@order.update_attribute(:state, upto_state.to_s)
|
|
71
|
+
session[:order_id] = nil # Usually checkout_controllers after_complete is called, setting session[:order_id] to nil
|
|
72
|
+
@order.finalize!
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Adds a payment to order if order has no payments yet.
|
|
76
|
+
# Allows both homecoming and reply to create a payment, but avoids having two payments.
|
|
77
|
+
def add_payment_if_not_exists
|
|
78
|
+
if @order.payments.empty?
|
|
79
|
+
p = Spree::Payment.new(
|
|
80
|
+
:payment_method => Spree::PaymentMethod::Omnikassa.fetch_payment_method,
|
|
81
|
+
:amount => @order.total)
|
|
82
|
+
|
|
83
|
+
p.response_code = @payment_response.attributes[:response_code]
|
|
84
|
+
p.source = @payment_response.payment_method
|
|
85
|
+
p.order_id = @order.id
|
|
86
|
+
p.save!
|
|
87
|
+
p.started_processing!
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def payment_response_from_params params
|
|
92
|
+
Spree::OmnikassaPaymentResponse.new(params["Seal"], params["Data"])
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
|