smartkiosk-server 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -68,4 +68,4 @@ group :development do
68
68
  gem 'i18n_yaml_sorter'
69
69
  end
70
70
 
71
- gem 'iso8583-mkb', '0.0.1'
71
+ gem 'iso8583-mkb', '0.0.2'
data/Gemfile.lock CHANGED
@@ -169,7 +169,7 @@ GEM
169
169
  has_scope (~> 0.5.0)
170
170
  responders (~> 0.6)
171
171
  iso8583 (0.1.4)
172
- iso8583-mkb (0.0.1)
172
+ iso8583-mkb (0.0.2)
173
173
  eventmachine
174
174
  iso8583
175
175
  jdbc-postgres (9.2.1002)
@@ -397,7 +397,7 @@ DEPENDENCIES
397
397
  guard-spork!
398
398
  haml
399
399
  i18n_yaml_sorter
400
- iso8583-mkb (= 0.0.1)
400
+ iso8583-mkb (= 0.0.2)
401
401
  jquery-rails
402
402
  jruby-openssl
403
403
  liquid
@@ -19,29 +19,81 @@ class CardsMkbAcquirer
19
19
  end
20
20
  end
21
21
 
22
- class Authorization
23
- def initialize(auth)
24
- @auth = auth
22
+ class Transaction
23
+ attr_reader :error
24
+
25
+ def initialize(payment, config)
26
+ @payment = payment
27
+ @auth = nil
28
+ @config = config
29
+ @transaction = nil
30
+ @error = nil
31
+ @auth = nil
25
32
  end
26
33
 
27
- def success?
28
- @auth.success?
34
+ def id
35
+ @transaction.id
29
36
  end
30
37
 
31
- def error
32
- @auth.status_description
38
+ def transact(&block)
39
+ CardsMkbAcquirer.gateway.transaction do |transaction|
40
+ @transaction = transaction
41
+ begin
42
+ yield self
43
+ ensure
44
+ @transaction = nil
45
+ end
46
+ end
33
47
  end
34
48
 
35
- def confirm
49
+ def authorize
50
+ auth = ISO8583::MKB::Authorization.new(@transaction)
51
+ auth.processing_code = @config[:processing_code]
52
+ auth.merchant_type = @config[:merchant_type]
53
+ auth.acquirer_country = @config[:acquirer_country]
54
+ auth.entry_mode = @config[:entry_mode]
55
+ auth.condition_code = @config[:condition_code]
56
+ auth.acquirer = @config[:acquirer]
57
+ auth.terminal_id = @config[:terminal_id]
58
+ auth.acceptor_id = @config[:acceptor_id]
59
+
60
+ auth.track2 = @payment.card_track2
61
+
62
+ delimiter = auth.track2.index '='
63
+ auth.pan = auth.track2.slice(0, delimiter)
64
+ auth.expiry = auth.track2.slice(delimiter + 1, 4)
65
+
66
+ terminal = "OOOMKB TERM#{@payment.terminal.keyword}"
67
+ city = "Moscow"
68
+ country = "RU"
36
69
 
70
+ auth.acceptor_name = sprintf("%-25s%-13s%-2s", terminal, city, country)
71
+
72
+ # TODO: implement currency handling
73
+ auth.amount = (@payment.paid_amount * 100).to_i
74
+ auth.currency = 643
75
+
76
+ # TODO: build additional data
77
+ auth.additional = "USRDT, <cm>#{@payment.commission_amount}</cm>, <ses>#{@payment.session_id}</ses>backend data"
78
+
79
+ CardsMkbAcquirer.gateway.execute auth
80
+
81
+ @auth = auth
82
+ @error = auth.status_description
83
+
84
+ auth.success?
37
85
  end
38
86
 
39
87
  def reverse
40
88
  reversal = @auth.reverse
41
- # TODO: set reason code
42
-
43
89
  CardsMkbAcquirer.gateway.execute reversal
44
- # TODO: possibly report failure
90
+
91
+ @error = reversal.status_description
92
+ reversal.success?
93
+ end
94
+
95
+ def confirm
96
+ true
45
97
  end
46
98
  end
47
99
 
@@ -50,38 +102,9 @@ class CardsMkbAcquirer
50
102
  CardsMkbAcquirer.ensure_running @config
51
103
  end
52
104
 
53
- def authorize(payment)
54
- auth = ISO8583::MKB::Authorization.new
55
- auth.processing_code = @config[:processing_code]
56
- auth.merchant_type = @config[:merchant_type]
57
- auth.acquirer_country = @config[:acquirer_country]
58
- auth.entry_mode = @config[:entry_mode]
59
- auth.condition_code = @config[:condition_code]
60
- auth.acquirer = @config[:acquirer]
61
- auth.terminal_id = @config[:terminal_id]
62
- auth.acceptor_id = @config[:acceptor_id]
63
-
64
- auth.track2 = payment.card_track2
65
-
66
- delimiter = auth.track2.index '='
67
- auth.pan = auth.track2.slice(0, delimiter)
68
- auth.expiry = auth.track2.slice(delimiter + 1, 4)
69
-
70
- terminal = "OOOMKB TERM#{payment.terminal.keyword}"
71
- city = "Moscow"
72
- country = "RU"
73
-
74
- auth.acceptor_name = sprintf("%-25s%-13s%-2s", terminal, city, country)
75
-
76
- # TODO: implement currency handling
77
- auth.amount = (payment.paid_amount * 100).to_i
78
- auth.currency = 643
79
-
80
- # TODO: build additional data
81
- auth.additional = "USRDT, <cm>#{payment.commission_amount}</cm>, <ses>#{payment.session_id}</ses>backend data"
82
-
83
- CardsMkbAcquirer.gateway.execute auth
84
-
85
- Authorization.new auth
105
+ def transaction(payment, &block)
106
+ transaction = Transaction.new(payment, @config)
107
+ transaction.transact(&block)
86
108
  end
87
109
  end
110
+
@@ -1,22 +1,34 @@
1
1
  class CashAcquirer
2
2
  def initialize(*args)
3
3
  end
4
-
5
- class Authorization
6
- def success?
7
- true
4
+
5
+ class Transaction
6
+ def initialize(payment)
7
+ @payment = payment
8
8
  end
9
9
 
10
- def confirm
10
+ def id
11
+ "0"
12
+ end
11
13
 
14
+ def authorize
15
+ true
12
16
  end
13
17
 
14
18
  def reverse
19
+ true
20
+ end
21
+
22
+ def confirm
23
+ true
24
+ end
15
25
 
26
+ def error
27
+ nil
16
28
  end
17
29
  end
18
30
 
19
- def authorize(payment)
20
- Authorization.new
31
+ def transaction(payment, &block)
32
+ yield Transaction.new(payment)
21
33
  end
22
34
  end
@@ -291,28 +291,38 @@ class Payment < ActiveRecord::Base
291
291
 
292
292
  def pay?
293
293
  acquirer = Payment.acquirer(self.payment_type)
294
- authorization = acquirer.authorize(self)
294
+ acquirer.transaction(self) do |transaction|
295
+ self.update_attribute(:acquirer_transaction, transaction.id)
295
296
 
296
- if authorization.success?
297
- result = self.gateway.librarize.pay(self)
297
+ if transaction.authorize
298
+ result = self.gateway.librarize.pay(self)
298
299
 
299
- if result[:success]
300
- self.gateway_error = nil
301
- self.gateway_payment_id = result[:gateway_payment_id] unless result[:gateway_payment_id].blank?
302
- self.paid_at = DateTime.now
303
- self.meta[:gateway] = self.gateway.serialize_options
300
+ if result[:success]
301
+ self.gateway_error = nil
302
+ self.gateway_payment_id = result[:gateway_payment_id] unless result[:gateway_payment_id].blank?
303
+ self.paid_at = DateTime.now
304
+ self.meta[:gateway] = self.gateway.serialize_options
304
305
 
305
- self.save!
306
- authorization.confirm
307
- return :paid
306
+ self.save!
307
+ if !transaction.confirm
308
+ self.plog :error, :acquirer, "unable to confirm transaction: #{transaction.error}"
309
+
310
+ # TODO: reverse on gateway if possible
311
+ end
312
+
313
+ return :paid
314
+ else
315
+ self.update_attribute(:gateway_error, result[:error])
316
+ if !transaction.reverse
317
+ self.plog :error, :acquirer, "unable to reverse transaction: #{transaction.error}"
318
+ end
319
+
320
+ return :error
321
+ end
308
322
  else
309
- self.update_attribute(:gateway_error, result[:error])
310
- authorization.reverse
323
+ self.update_attribute(:acquirer_error, transaction.error)
311
324
  return :error
312
325
  end
313
- else
314
- self.update_attribute(:acquirer_error, authorization.error)
315
- return :error
316
326
  end
317
327
  end
318
328
 
@@ -25,6 +25,7 @@ class CreatePayments < ActiveRecord::Migration
25
25
  t.string :state, :null => false, :default => 'new'
26
26
  t.string :acquirer_error
27
27
  t.integer :gateway_error
28
+ t.string :acquirer_transaction
28
29
  t.string :gateway_provider_id
29
30
  t.string :gateway_payment_id
30
31
  t.datetime :hour
data/db/schema.rb CHANGED
@@ -177,7 +177,9 @@ ActiveRecord::Schema.define(:version => 20130108091644) do
177
177
  t.decimal "enrolled_amount", :precision => 38, :scale => 2
178
178
  t.decimal "rebate_amount", :precision => 38, :scale => 2
179
179
  t.string "state", :default => "new", :null => false
180
+ t.string "acquirer_error"
180
181
  t.integer "gateway_error"
182
+ t.string "acquirer_transaction"
181
183
  t.string "gateway_provider_id"
182
184
  t.string "gateway_payment_id"
183
185
  t.datetime "hour"
@@ -1,5 +1,5 @@
1
1
  module Smartkiosk
2
2
  module Server
3
- VERSION = '0.10.3'
3
+ VERSION = '0.10.4'
4
4
  end
5
5
  end
@@ -5,8 +5,8 @@ require 'smartkiosk/server/version'
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'smartkiosk-server'
7
7
  gem.version = Smartkiosk::Server::VERSION
8
- gem.authors = ['Boris Staal']
9
- gem.email = ['boris@roundlake.ru']
8
+ gem.authors = ['Boris Staal', 'Sergey Gridasov']
9
+ gem.email = ['boris@roundlake.ru', 'grindars@gmail.com']
10
10
  gem.description = %q{Smartkiosk server application}
11
11
  gem.summary = gem.description
12
12
  gem.homepage = 'https://github.com/smartkiosk/smartkiosk-server'
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartkiosk-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.10.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Boris Staal
9
+ - Sergey Gridasov
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
@@ -13,18 +14,23 @@ date: 2013-02-06 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rails
16
- requirement: &70215271531040 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
- - - =
20
+ - - '='
20
21
  - !ruby/object:Gem::Version
21
22
  version: 3.2.11
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70215271531040
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '='
29
+ - !ruby/object:Gem::Version
30
+ version: 3.2.11
25
31
  - !ruby/object:Gem::Dependency
26
32
  name: matrioshka
27
- requirement: &70215271565160 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
28
34
  none: false
29
35
  requirements:
30
36
  - - ! '>='
@@ -32,10 +38,16 @@ dependencies:
32
38
  version: 0.1.1
33
39
  type: :runtime
34
40
  prerelease: false
35
- version_requirements: *70215271565160
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.1.1
36
47
  description: Smartkiosk server application
37
48
  email:
38
49
  - boris@roundlake.ru
50
+ - grindars@gmail.com
39
51
  executables: []
40
52
  extensions: []
41
53
  extra_rdoc_files: []
@@ -111,6 +123,8 @@ files:
111
123
  - app/helpers/application_helper.rb
112
124
  - app/mailers/.gitkeep
113
125
  - app/models/.gitkeep
126
+ - app/models/.terminal_ping.rb.kate-swp
127
+ - app/models/.terminal_profile.rb.kate-swp
114
128
  - app/models/ability.rb
115
129
  - app/models/agent.rb
116
130
  - app/models/collection.rb
@@ -307,7 +321,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
307
321
  version: '0'
308
322
  segments:
309
323
  - 0
310
- hash: 852346977884785449
324
+ hash: 1639411805563885975
311
325
  required_rubygems_version: !ruby/object:Gem::Requirement
312
326
  none: false
313
327
  requirements:
@@ -316,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
330
  version: '0'
317
331
  requirements: []
318
332
  rubyforge_project:
319
- rubygems_version: 1.8.15
333
+ rubygems_version: 1.8.24
320
334
  signing_key:
321
335
  specification_version: 3
322
336
  summary: Smartkiosk server application