smartkiosk-server 0.11.2 → 0.11.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -12,61 +12,32 @@ class PaymentsController < ApplicationController
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def create
|
15
|
-
|
16
|
-
|
17
|
-
if
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
payment.plog :info, :transport, "Created"
|
34
|
-
|
35
|
-
payment.plog :info, :transport, "Checked" do
|
36
|
-
payment.check!
|
37
|
-
end
|
38
|
-
|
39
|
-
render :json => {
|
40
|
-
:id => payment.id,
|
41
|
-
:state => payment.state,
|
42
|
-
:requires_print => provider.requires_print,
|
43
|
-
:limits => Limit.for(payment, false).as_json(
|
44
|
-
:only => [:min, :max], :methods => [:weight]
|
45
|
-
),
|
46
|
-
:commissions => Commission.for(payment, false).as_json(
|
47
|
-
:only => [:min, :max, :percent_fee, :static_fee, :payment_type],
|
48
|
-
:methods => [:weight]
|
49
|
-
),
|
50
|
-
:receipt_template => ProviderReceiptTemplate.for(payment).compile(payment)
|
51
|
-
}
|
52
|
-
else
|
53
|
-
Payment.plog :info, :web, "Payment was not created"
|
54
|
-
render :nothing => true, :status => 406
|
55
|
-
end
|
15
|
+
payment = Payment.build!(@terminal, Provider.find_by_keyword(params[:provider]), params[:payment])
|
16
|
+
|
17
|
+
if payment
|
18
|
+
payment.check!
|
19
|
+
|
20
|
+
render :json => {
|
21
|
+
:id => payment.id,
|
22
|
+
:state => payment.state,
|
23
|
+
:requires_print => provider.requires_print,
|
24
|
+
:limits => Limit.for(payment, false).as_json(
|
25
|
+
:only => [:min, :max], :methods => [:weight]
|
26
|
+
),
|
27
|
+
:commissions => Commission.for(payment, false).as_json(
|
28
|
+
:only => [:min, :max, :percent_fee, :static_fee, :payment_type],
|
29
|
+
:methods => [:weight]
|
30
|
+
),
|
31
|
+
:receipt_template => ProviderReceiptTemplate.for(payment).compile(payment)
|
32
|
+
}
|
56
33
|
else
|
57
|
-
|
58
|
-
render :nothing => true, :status => 406
|
34
|
+
render :text => nil, :status => 406
|
59
35
|
end
|
60
36
|
end
|
61
37
|
|
62
38
|
def pay
|
63
39
|
payment = @terminal.payments.find(params[:id])
|
64
|
-
|
65
|
-
unless payment.queue?
|
66
|
-
payment.plog :info, :transport, "Sent to queue" do
|
67
|
-
payment.enqueue!(params[:payment])
|
68
|
-
end
|
69
|
-
end
|
40
|
+
payment.enqueue!(params[:payment]) unless payment.queue?
|
70
41
|
|
71
42
|
render :text => nil, :status => 200
|
72
43
|
end
|
data/app/models/payment.rb
CHANGED
@@ -74,15 +74,17 @@ class Payment < ActiveRecord::Base
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def enqueue!(attributes={})
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
plog :info, :model, "Sent to queue" do
|
78
|
+
[ :paid_amount, :receipt_number, :card_track1, :card_track2, :meta ].each do |key|
|
79
|
+
if attributes.include? key
|
80
|
+
write_attribute key, attributes[key]
|
81
|
+
end
|
80
82
|
end
|
81
|
-
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
enqueue
|
85
|
+
save!
|
86
|
+
PayWorker.perform_async(id)
|
87
|
+
end
|
86
88
|
end
|
87
89
|
|
88
90
|
#
|
@@ -186,7 +188,7 @@ class Payment < ActiveRecord::Base
|
|
186
188
|
severity,
|
187
189
|
datetime.iso8601(12),
|
188
190
|
data[:progname],
|
189
|
-
data[:payment_id],
|
191
|
+
"##{data[:payment_id]}",
|
190
192
|
data[:payment_state],
|
191
193
|
data[:session_id],
|
192
194
|
data[:terminal_id],
|
@@ -245,17 +247,31 @@ class Payment < ActiveRecord::Base
|
|
245
247
|
|
246
248
|
def self.build!(terminal, provider, attributes)
|
247
249
|
payment = new(attributes)
|
250
|
+
|
251
|
+
if provider.blank?
|
252
|
+
payment.plog :warn, :model, "Provider not found"
|
253
|
+
return false
|
254
|
+
end
|
255
|
+
|
248
256
|
provider_gateway = provider.provider_gateways.enabled.order(:priority).first
|
249
257
|
|
250
|
-
|
258
|
+
if provider_gateway.blank?
|
259
|
+
payment.plog :info, :model, "Provider has no gateways attached"
|
260
|
+
return false
|
261
|
+
end
|
251
262
|
|
252
263
|
payment.terminal = terminal
|
253
264
|
payment.provider_gateway = provider_gateway
|
254
265
|
payment.raw_fields = payment.fields
|
255
266
|
payment.fields = provider_gateway.map(payment.account, payment.fields)
|
256
267
|
|
257
|
-
payment.save
|
258
|
-
|
268
|
+
if payment.save
|
269
|
+
payment.plog :info, :model, "Payment created"
|
270
|
+
payment
|
271
|
+
else
|
272
|
+
payment.plog :warn, :model, "Payment was invalidated: #{payment.errors.full_messages.join(', ')}"
|
273
|
+
false
|
274
|
+
end
|
259
275
|
end
|
260
276
|
|
261
277
|
def provider_gateway=(pg)
|
@@ -282,11 +298,13 @@ class Payment < ActiveRecord::Base
|
|
282
298
|
result = self.gateway.librarize.check(self)
|
283
299
|
|
284
300
|
if result[:success]
|
301
|
+
plog :info, :model, "Checked"
|
285
302
|
self.gateway_error = nil
|
286
303
|
self.gateway_payment_id = result[:gateway_payment_id] unless result[:gateway_payment_id].blank?
|
287
304
|
self.save!
|
288
305
|
return :checked
|
289
306
|
else
|
307
|
+
plog :info, :model, "Declined: #{result[:error]}"
|
290
308
|
self.update_attribute(:gateway_error, result[:error])
|
291
309
|
return :declined
|
292
310
|
end
|
@@ -308,7 +326,7 @@ class Payment < ActiveRecord::Base
|
|
308
326
|
|
309
327
|
self.save!
|
310
328
|
if !transaction.confirm
|
311
|
-
self.plog :error, :
|
329
|
+
self.plog :error, :model, "unable to confirm transaction: #{transaction.error}"
|
312
330
|
|
313
331
|
# TODO: reverse on gateway if possible
|
314
332
|
end
|
@@ -317,7 +335,7 @@ class Payment < ActiveRecord::Base
|
|
317
335
|
else
|
318
336
|
self.update_attribute(:gateway_error, result[:error])
|
319
337
|
if !transaction.reverse
|
320
|
-
self.plog :error, :
|
338
|
+
self.plog :error, :model, "unable to reverse transaction: #{transaction.error}"
|
321
339
|
end
|
322
340
|
|
323
341
|
return :error
|
@@ -48,6 +48,53 @@ describe PaymentsController do
|
|
48
48
|
}
|
49
49
|
end
|
50
50
|
|
51
|
+
it "declines empty provider" do
|
52
|
+
post :create,
|
53
|
+
:terminal => 'test',
|
54
|
+
:payment => {
|
55
|
+
:session_id => 31337,
|
56
|
+
:account => '9261111111',
|
57
|
+
:payment_type => Payment::TYPE_CASH
|
58
|
+
}
|
59
|
+
|
60
|
+
response.code.should == "404"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "declines absent provider" do
|
64
|
+
post :create,
|
65
|
+
:terminal => 'test',
|
66
|
+
:provider => 'idontexist',
|
67
|
+
:payment => {
|
68
|
+
:session_id => 31337,
|
69
|
+
:account => '9261111111',
|
70
|
+
:payment_type => Payment::TYPE_CASH
|
71
|
+
}
|
72
|
+
|
73
|
+
response.code.should == "404"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "declines duplicating session id" do
|
77
|
+
post :create,
|
78
|
+
:terminal => 'test',
|
79
|
+
:provider => 'test',
|
80
|
+
:payment => {
|
81
|
+
:session_id => 31337,
|
82
|
+
:account => '9261111111',
|
83
|
+
:payment_type => Payment::TYPE_CASH
|
84
|
+
}
|
85
|
+
|
86
|
+
post :create,
|
87
|
+
:terminal => 'test',
|
88
|
+
:provider => 'test',
|
89
|
+
:payment => {
|
90
|
+
:session_id => 31337,
|
91
|
+
:account => '9261111111',
|
92
|
+
:payment_type => Payment::TYPE_CASH
|
93
|
+
}
|
94
|
+
|
95
|
+
response.code.should == "406"
|
96
|
+
end
|
97
|
+
|
51
98
|
it "pays" do
|
52
99
|
post :create,
|
53
100
|
:terminal => 'test',
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -332,7 +332,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
332
332
|
version: '0'
|
333
333
|
segments:
|
334
334
|
- 0
|
335
|
-
hash:
|
335
|
+
hash: 2751133508454068460
|
336
336
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
337
337
|
none: false
|
338
338
|
requirements:
|