smartkiosk-server 0.11.11 → 0.12
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/admin/terminals.rb +4 -2
- data/app/controllers/payments_controller.rb +21 -0
- data/app/models/payment.rb +17 -6
- data/config/locales/activerecord.ru.yml +1 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20130410142059_add_address_details_to_terminals.rb +5 -0
- data/db/schema.rb +2 -1
- data/lib/smartkiosk/server/version.rb +1 -1
- data/spec/controllers/payments_controller_spec.rb +52 -2
- metadata +3 -2
data/app/admin/terminals.rb
CHANGED
@@ -305,8 +305,9 @@ ActiveAdmin.register Terminal do
|
|
305
305
|
row :rent_finish_date
|
306
306
|
row :collection_zone
|
307
307
|
row :check_phone_number
|
308
|
-
row :address
|
309
|
-
|
308
|
+
row :address
|
309
|
+
row :address_details do |t|
|
310
|
+
div t.address_details
|
310
311
|
unless t.address.blank?
|
311
312
|
div(:class => 'terminal_map', :id => 'map')
|
312
313
|
script(:type => 'text/javascript') do
|
@@ -420,6 +421,7 @@ ActiveAdmin.register Terminal do
|
|
420
421
|
f.input :collection_zone
|
421
422
|
f.input :check_phone_number
|
422
423
|
f.input :address
|
424
|
+
f.input :address_details
|
423
425
|
end
|
424
426
|
f.actions
|
425
427
|
end
|
@@ -34,11 +34,32 @@ class PaymentsController < ApplicationController
|
|
34
34
|
render :text => nil, :status => 406
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
def offline
|
39
|
+
payment = Payment.build!(@terminal, Provider.find_by_keyword(params[:provider]), params[:payment])
|
40
|
+
payment.check!
|
41
|
+
payment.enqueue! if payment.checked?
|
42
|
+
|
43
|
+
render :json => payment.as_json
|
44
|
+
end
|
37
45
|
|
38
46
|
def pay
|
47
|
+
payment = @terminal.payments.find(params[:id])
|
48
|
+
payment.pay!(params[:payment])
|
49
|
+
|
50
|
+
render :json => payment.as_json
|
51
|
+
end
|
52
|
+
|
53
|
+
def enqueue
|
39
54
|
payment = @terminal.payments.find(params[:id])
|
40
55
|
payment.enqueue!(params[:payment]) unless payment.queue?
|
41
56
|
|
42
57
|
render :text => nil, :status => 200
|
43
58
|
end
|
59
|
+
|
60
|
+
def show
|
61
|
+
payment = @terminal.payments.find(params[:id])
|
62
|
+
|
63
|
+
render :json => payment.as_json
|
64
|
+
end
|
44
65
|
end
|
data/app/models/payment.rb
CHANGED
@@ -73,20 +73,31 @@ class Payment < ActiveRecord::Base
|
|
73
73
|
)
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
write_attribute key, attributes[key]
|
81
|
-
end
|
76
|
+
def assign_payment_attributes(attributes)
|
77
|
+
[ :paid_amount, :receipt_number, :card_track1, :card_track2, :meta ].each do |key|
|
78
|
+
if attributes.include? key
|
79
|
+
write_attribute key, attributes[key]
|
82
80
|
end
|
81
|
+
end
|
82
|
+
end
|
83
83
|
|
84
|
+
def enqueue!(attributes={})
|
85
|
+
plog :info, :model, "Sent to queue" do
|
86
|
+
assign_payment_attributes attributes
|
84
87
|
enqueue
|
85
88
|
save!
|
86
89
|
PayWorker.perform_async(id)
|
87
90
|
end
|
88
91
|
end
|
89
92
|
|
93
|
+
def pay!(attributes={})
|
94
|
+
plog :info, :model, "Paid" do
|
95
|
+
assign_payment_attributes attributes
|
96
|
+
pay
|
97
|
+
save!
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
90
101
|
#
|
91
102
|
# RELATIONS
|
92
103
|
#
|
data/config/routes.rb
CHANGED
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 => 20130410142059) do
|
15
15
|
|
16
16
|
create_table "active_admin_comments", :force => true do |t|
|
17
17
|
t.string "resource_id", :null => false
|
@@ -463,6 +463,7 @@ ActiveRecord::Schema.define(:version => 20130410085714) do
|
|
463
463
|
t.integer "card_reader_error"
|
464
464
|
t.integer "watchdog_error"
|
465
465
|
t.integer "last_session_started_at", :default => 0, :null => false
|
466
|
+
t.text "address_details"
|
466
467
|
end
|
467
468
|
|
468
469
|
add_index "terminals", ["agent_id"], :name => "index_terminals_on_agent_id"
|
@@ -95,6 +95,40 @@ describe PaymentsController do
|
|
95
95
|
response.code.should == "406"
|
96
96
|
end
|
97
97
|
|
98
|
+
it "enqueues" do
|
99
|
+
post :create,
|
100
|
+
:terminal => 'test',
|
101
|
+
:provider => 'test',
|
102
|
+
:payment => {
|
103
|
+
:session_id => 31337,
|
104
|
+
:account => '9261111111',
|
105
|
+
:payment_type => Payment::TYPE_CASH
|
106
|
+
}
|
107
|
+
|
108
|
+
result = ActiveSupport::JSON.decode(response.body)
|
109
|
+
result.should == {
|
110
|
+
"id" => 1,
|
111
|
+
"state" => "checked",
|
112
|
+
"requires_print" => true,
|
113
|
+
"limits" => [{"max"=>"9999.0", "min"=>"0.0", "weight"=>1}],
|
114
|
+
"commissions" => [{"max"=>"9999.0", "min"=>"0.0", "payment_type"=>nil, "percent_fee"=>"0.0", "static_fee"=>"0.0", "weight"=>1}],
|
115
|
+
"receipt_template" => "{{ payment_enrolled_amount }}"
|
116
|
+
}
|
117
|
+
|
118
|
+
post :enqueue,
|
119
|
+
:terminal => 'test',
|
120
|
+
:id => 1,
|
121
|
+
:payment => {
|
122
|
+
:paid_amount => 100
|
123
|
+
}
|
124
|
+
response.status.should == 200
|
125
|
+
|
126
|
+
PayWorker.new.perform 1
|
127
|
+
payment = Payment.find 1
|
128
|
+
payment.state.should == "paid"
|
129
|
+
payment.externally_paid.should == true
|
130
|
+
end
|
131
|
+
|
98
132
|
it "pays" do
|
99
133
|
post :create,
|
100
134
|
:terminal => 'test',
|
@@ -123,12 +157,28 @@ describe PaymentsController do
|
|
123
157
|
}
|
124
158
|
response.status.should == 200
|
125
159
|
|
126
|
-
PayWorker.new.perform 1
|
127
160
|
payment = Payment.find 1
|
128
161
|
payment.state.should == "paid"
|
129
162
|
payment.externally_paid.should == true
|
130
163
|
end
|
131
164
|
|
165
|
+
it "pays offline" do
|
166
|
+
post :offline,
|
167
|
+
:terminal => 'test',
|
168
|
+
:provider => 'test',
|
169
|
+
:payment => {
|
170
|
+
:session_id => 31337,
|
171
|
+
:account => '9261111111',
|
172
|
+
:payment_type => Payment::TYPE_CASH,
|
173
|
+
:paid_amount => 100
|
174
|
+
}
|
175
|
+
|
176
|
+
response.status.should == 200
|
177
|
+
result = ActiveSupport::JSON.decode(response.body)
|
178
|
+
result['id'].should == 1
|
179
|
+
result['state'].should == 'queue'
|
180
|
+
end
|
181
|
+
|
132
182
|
xit "pays with card" do
|
133
183
|
post :create,
|
134
184
|
:terminal => 'test',
|
@@ -148,7 +198,7 @@ describe PaymentsController do
|
|
148
198
|
"commissions" => [{"max"=>"9999.0", "min"=>"0.0", "payment_type"=>nil, "percent_fee"=>"0.0", "static_fee"=>"0.0", "weight"=>1}],
|
149
199
|
"receipt_template" => "{{ payment_enrolled_amount }}"
|
150
200
|
}
|
151
|
-
post :
|
201
|
+
post :enqueue,
|
152
202
|
:terminal => 'test',
|
153
203
|
:id => 1,
|
154
204
|
:payment => {
|
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.
|
4
|
+
version: '0.12'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -262,6 +262,7 @@ files:
|
|
262
262
|
- db/migrate/20130217113740_create_session_records.rb
|
263
263
|
- db/migrate/20130325154559_add_externally_paid_to_payments.rb
|
264
264
|
- db/migrate/20130410085714_add_groupping_to_provider_fields.rb
|
265
|
+
- db/migrate/20130410142059_add_address_details_to_terminals.rb
|
265
266
|
- db/schema.rb
|
266
267
|
- db/seeds.rb
|
267
268
|
- db/seeds/receipt_templates/payment.txt
|
@@ -334,7 +335,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
334
335
|
version: '0'
|
335
336
|
segments:
|
336
337
|
- 0
|
337
|
-
hash:
|
338
|
+
hash: 4599455729740215178
|
338
339
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
339
340
|
none: false
|
340
341
|
requirements:
|