smartkiosk-server 0.11.4 → 0.11.5
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/app/acquirers/cash_acquirer.rb +2 -34
- data/app/acquirers/empty_acquirer.rb +34 -0
- data/app/models/payment.rb +20 -12
- data/db/migrate/20130325154559_add_externally_paid_to_payments.rb +5 -0
- data/db/schema.rb +2 -1
- data/lib/smartkiosk/server/version.rb +1 -1
- data/spec/controllers/payments_controller_spec.rb +2 -0
- metadata +4 -2
@@ -1,34 +1,2 @@
|
|
1
|
-
class CashAcquirer
|
2
|
-
|
3
|
-
end
|
4
|
-
|
5
|
-
class Transaction
|
6
|
-
def initialize(payment)
|
7
|
-
@payment = payment
|
8
|
-
end
|
9
|
-
|
10
|
-
def id
|
11
|
-
"0"
|
12
|
-
end
|
13
|
-
|
14
|
-
def authorize
|
15
|
-
true
|
16
|
-
end
|
17
|
-
|
18
|
-
def reverse
|
19
|
-
true
|
20
|
-
end
|
21
|
-
|
22
|
-
def confirm
|
23
|
-
true
|
24
|
-
end
|
25
|
-
|
26
|
-
def error
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def transaction(payment, &block)
|
32
|
-
yield Transaction.new(payment)
|
33
|
-
end
|
34
|
-
end
|
1
|
+
class CashAcquirer < EmptyAcquirer
|
2
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class EmptyAcquirer
|
2
|
+
def initialize(*args)
|
3
|
+
end
|
4
|
+
|
5
|
+
class Transaction
|
6
|
+
def initialize(payment)
|
7
|
+
@payment = payment
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
"0"
|
12
|
+
end
|
13
|
+
|
14
|
+
def authorize
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def reverse
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def confirm
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def error
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def transaction(payment, &block)
|
32
|
+
yield Transaction.new(payment)
|
33
|
+
end
|
34
|
+
end
|
data/app/models/payment.rb
CHANGED
@@ -121,6 +121,10 @@ class Payment < ActiveRecord::Base
|
|
121
121
|
before_validation do
|
122
122
|
self.meta = {} unless self.meta.is_a?(Hash)
|
123
123
|
self.agent = self.terminal.agent unless self.terminal.blank?
|
124
|
+
|
125
|
+
if [ TYPE_CASH, TYPE_IBANK, TYPE_MBANK, TYPE_PURSE, TYPE_ACCOUNT ].include?(self.payment_type)
|
126
|
+
self.externally_paid = true
|
127
|
+
end
|
124
128
|
end
|
125
129
|
|
126
130
|
before_save do
|
@@ -157,21 +161,25 @@ class Payment < ActiveRecord::Base
|
|
157
161
|
#
|
158
162
|
# METHODS
|
159
163
|
#
|
160
|
-
def self.acquirer(
|
161
|
-
unless
|
162
|
-
@acquiring_settings
|
163
|
-
|
164
|
-
|
165
|
-
|
164
|
+
def self.acquirer(payment)
|
165
|
+
unless payment.externally_paid
|
166
|
+
unless @acquiring_settings
|
167
|
+
@acquiring_settings = YAML::load File.read(Rails.root.join 'config/acquiring.yml')
|
168
|
+
@acquiring_settings.each do |x|
|
169
|
+
x['type'] = x['type'].split(',').map do |t|
|
170
|
+
Payment.const_get "TYPE_#{t.strip.upcase}"
|
171
|
+
end
|
172
|
+
x['class'] = x['class'].constantize
|
166
173
|
end
|
167
|
-
x['class'] = x['class'].constantize
|
168
174
|
end
|
169
|
-
end
|
170
175
|
|
171
|
-
|
172
|
-
|
176
|
+
acquirer = @acquiring_settings.find{|x| x['type'].include?(payment.payment_type)}
|
177
|
+
raise "unsupported payment type: #{payment.payment_type}" unless acquirer
|
173
178
|
|
174
|
-
|
179
|
+
acquirer['class'].new(acquirer)
|
180
|
+
else
|
181
|
+
EmptyAcquirer.new
|
182
|
+
end
|
175
183
|
end
|
176
184
|
|
177
185
|
def self.plogger
|
@@ -311,7 +319,7 @@ class Payment < ActiveRecord::Base
|
|
311
319
|
end
|
312
320
|
|
313
321
|
def pay?
|
314
|
-
acquirer
|
322
|
+
acquirer = Payment.acquirer(self)
|
315
323
|
acquirer.transaction(self) do |transaction|
|
316
324
|
self.update_attribute(:acquirer_transaction, transaction.id)
|
317
325
|
|
data/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20130325154559) do
|
15
15
|
|
16
16
|
create_table "active_admin_comments", :force => true do |t|
|
17
17
|
t.string "resource_id", :null => false
|
@@ -194,6 +194,7 @@ ActiveRecord::Schema.define(:version => 20130217113740) do
|
|
194
194
|
t.string "card_track2"
|
195
195
|
t.datetime "created_at", :null => false
|
196
196
|
t.datetime "updated_at", :null => false
|
197
|
+
t.boolean "externally_paid", :default => false, :null => false
|
197
198
|
end
|
198
199
|
|
199
200
|
add_index "payments", ["agent_id"], :name => "index_payments_on_agent_id"
|
@@ -126,6 +126,7 @@ describe PaymentsController do
|
|
126
126
|
PayWorker.new.perform 1
|
127
127
|
payment = Payment.find 1
|
128
128
|
payment.state.should == "paid"
|
129
|
+
payment.externally_paid.should == true
|
129
130
|
end
|
130
131
|
|
131
132
|
xit "pays with card" do
|
@@ -163,6 +164,7 @@ describe PaymentsController do
|
|
163
164
|
payment = Payment.find 1
|
164
165
|
|
165
166
|
payment.state.should == "paid"
|
167
|
+
payment.externally_paid.should == false
|
166
168
|
ensure
|
167
169
|
CardsMkbAcquirer.stop
|
168
170
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartkiosk-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- Rakefile
|
66
66
|
- app/acquirers/cards_mkb_acquirer.rb
|
67
67
|
- app/acquirers/cash_acquirer.rb
|
68
|
+
- app/acquirers/empty_acquirer.rb
|
68
69
|
- app/admin/agents.rb
|
69
70
|
- app/admin/collections.rb
|
70
71
|
- app/admin/commissions.rb
|
@@ -260,6 +261,7 @@ files:
|
|
260
261
|
- db/migrate/20130216173828_add_watchdog_and_card_reader_errors_to_terminals.rb
|
261
262
|
- db/migrate/20130217113617_add_last_session_started_at_to_terminals.rb
|
262
263
|
- db/migrate/20130217113740_create_session_records.rb
|
264
|
+
- db/migrate/20130325154559_add_externally_paid_to_payments.rb
|
263
265
|
- db/schema.rb
|
264
266
|
- db/seeds.rb
|
265
267
|
- db/seeds/receipt_templates/payment.txt
|
@@ -332,7 +334,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
332
334
|
version: '0'
|
333
335
|
segments:
|
334
336
|
- 0
|
335
|
-
hash: -
|
337
|
+
hash: -2336776553200624072
|
336
338
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
337
339
|
none: false
|
338
340
|
requirements:
|