eml 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -85,8 +85,11 @@ module EML
85
85
  end
86
86
 
87
87
  sig do
88
- params(param_name: Symbol, param_value: String, allowed_values: T::Array[String]).
89
- void
88
+ params(
89
+ param_name: Symbol,
90
+ param_value: String,
91
+ allowed_values: T::Array[String]
92
+ ).void
90
93
  end
91
94
  def validate_enum(param_name, param_value, allowed_values)
92
95
  return if allowed_values.include?(param_value)
data/lib/eml/uk.rb CHANGED
@@ -12,7 +12,9 @@ require "eml/uk/config"
12
12
  require "eml/uk/lib/endpoint_class"
13
13
  require "eml/uk/lib/parse_date"
14
14
 
15
- require "eml/uk/model/transaction"
15
+ require "eml/uk/models/tns_card"
16
+ require "eml/uk/models/tns_transaction"
17
+ require "eml/uk/models/transaction"
16
18
 
17
19
  require "eml/uk/parameters"
18
20
  require "eml/uk/parameters/agreement/show"
@@ -28,9 +30,7 @@ require "eml/uk/parameters/card/unlock"
28
30
  require "eml/uk/payload"
29
31
  require "eml/uk/payload/agreement/show"
30
32
  require "eml/uk/payload/iso"
31
- require "eml/uk/payload/contactentity"
32
33
  require "eml/uk/payload/location"
33
- require "eml/uk/payload/nil"
34
34
  require "eml/uk/payload/card/activation"
35
35
  require "eml/uk/payload/card/show"
36
36
  require "eml/uk/payload/card/lock"
@@ -49,3 +49,6 @@ require "eml/uk/responses/agreement/show"
49
49
  require "eml/uk/responses/card/reload"
50
50
  require "eml/uk/responses/card/show"
51
51
  require "eml/uk/responses/card/transaction"
52
+
53
+ require "eml/uk/tns/process_request"
54
+ require "eml/uk/tns/response"
@@ -52,11 +52,13 @@ module EML
52
52
 
53
53
  sig { returns(T::Hash[Symbol, T.nilable(String)]) }
54
54
  def credentials
55
- config = EML::UK.config
56
- {
57
- username: config.username,
58
- password: config.password,
59
- }
55
+ @credentials ||= begin
56
+ config = EML::UK.config
57
+ {
58
+ username: config.rest_username,
59
+ password: config.rest_password,
60
+ }
61
+ end
60
62
  end
61
63
 
62
64
  sig { returns(String) }
@@ -70,14 +72,13 @@ module EML
70
72
 
71
73
  sig { returns(T::Hash[String, String]) }
72
74
  def headers
73
- @headers ||= { "Authorization" => "Basic #{base64_credentials}" }
74
- end
75
-
76
- sig { returns(String) }
77
- def base64_credentials
78
- username = credentials[:username]
79
- password = credentials[:password]
80
- Base64.encode64("#{username}:#{password}").tr("\n", "")
75
+ @headers ||= {
76
+ "Authorization" => ::EML::BasicAuth::Generate.(
77
+ credentials[:username],
78
+ credentials[:password],
79
+ prefix: "Basic "
80
+ ),
81
+ }
81
82
  end
82
83
 
83
84
  sig { params(endpoint: String).returns(T.class_of(EML::Response)) }
data/lib/eml/uk/config.rb CHANGED
@@ -21,20 +21,26 @@ module EML
21
21
  extend T::Sig
22
22
 
23
23
  sig { returns(String) }
24
- attr_accessor :username
24
+ attr_accessor :merchant_group
25
25
 
26
26
  sig { returns(String) }
27
- attr_accessor :password
27
+ attr_accessor :program
28
28
 
29
29
  sig { returns(String) }
30
- attr_accessor :merchant_group
30
+ attr_accessor :rest_username
31
31
 
32
32
  sig { returns(String) }
33
- attr_accessor :program
33
+ attr_accessor :rest_password
34
34
 
35
35
  sig { returns(String) }
36
36
  attr_accessor :search_parameter
37
37
 
38
+ sig { returns(String) }
39
+ attr_accessor :tns_username
40
+
41
+ sig { returns(String) }
42
+ attr_accessor :tns_password
43
+
38
44
  private
39
45
 
40
46
  sig { params(param: Symbol).void }
@@ -0,0 +1,20 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module EML
5
+ module UK
6
+ module Models
7
+ class TNSCard < ::EML::Model
8
+ fields(
9
+ "AvailableBalance" => :availableBalance,
10
+ "CarrierNumber" => :carrierNumber,
11
+ "ClientTrackingId" => :clientTrackingId,
12
+ "Currency" => :currency,
13
+ "ExternalId" => :externalId,
14
+ "Program" => :program,
15
+ "MerchantGroup" => :merchantGroup,
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module EML
5
+ module UK
6
+ module Models
7
+ class TNSTransaction < ::EML::Model
8
+ extend T::Sig
9
+
10
+ fields(
11
+ "AuthorizationRequestId" => :authorizationRequestId,
12
+ "Card" => :card,
13
+ "Cards" => :cards,
14
+ "EmlId" => :emlId,
15
+ "MerchantCategoryCode" => :merchantCategoryCode,
16
+ "MerchantCountry" => :merchantCountry,
17
+ "Note" => :note,
18
+ "OriginalTransactionDate" => :originalDate,
19
+ "PosTransactionTime" => :posTime,
20
+ "Reason" => :reason,
21
+ "Result" => :result,
22
+ "RetrievalReferenceNumber" => :retrievalReferenceNumber,
23
+ "TransactionAmount" => :amount,
24
+ "TransactionCurrency" => :currency,
25
+ "TransactionDescription" => :description,
26
+ "TransactionId" => :transactionId,
27
+ "TransactionLocation" => :location,
28
+ "TransactionTime" => :time
29
+ )
30
+
31
+ sig { params(raw_values: T::Hash[String, T.untyped]).void }
32
+ def initialize(raw_values)
33
+ super
34
+ initialize_cards
35
+ end
36
+
37
+ private
38
+
39
+ sig { void }
40
+ def initialize_cards
41
+ @card = TNSCard.new(@card) unless @card.nil?
42
+ @cards = (@cards || []).each_with_object([]) do |card, cards|
43
+ cards << TNSCard.new(card)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -3,9 +3,11 @@
3
3
 
4
4
  module EML
5
5
  module UK
6
- class Model
7
- class Transaction
8
- FIELDS = %w[
6
+ module Models
7
+ class Transaction < ::EML::Model
8
+ extend T::Sig
9
+
10
+ fields(%w[
9
11
  acceptor_code
10
12
  acceptor_location
11
13
  activity
@@ -29,22 +31,13 @@ module EML
29
31
  transaction_amount
30
32
  transaction_currency
31
33
  user
32
- ].freeze
33
- private_constant :FIELDS
34
-
35
- FIELDS.each { |field| __send__(:attr_reader, :"#{field}") }
36
-
37
- def initialize(response)
38
- FIELDS.each do |field|
39
- value = field_value(field, response[field])
40
- instance_variable_set(:"@#{field}", value)
41
- end
42
- end
34
+ ])
43
35
 
44
- private
36
+ protected
45
37
 
38
+ sig { params(field: String, raw_value: T.untyped).returns(T.untyped) }
46
39
  def field_value(field, raw_value)
47
- if field.include?("time")
40
+ if field.match?(/date|time/)
48
41
  EML::UK::ParseDate.(raw_value)
49
42
  else
50
43
  raw_value
@@ -40,17 +40,6 @@ module EML
40
40
 
41
41
  protected
42
42
 
43
- BOOLEAN_OPTIONS = %w[true false].freeze
44
-
45
- sig { params(param_name: String, param_value: String).void }
46
- def validate_boolean(param_name, param_value)
47
- return if BOOLEAN_OPTIONS.include?(param_value)
48
-
49
- message = "#{param_name} should be the string 'true' or 'false' but " \
50
- "received #{param_value.inspect}"
51
- raise ArgumentError, message
52
- end
53
-
54
43
  SEARCH_PARAMETER_OPTIONS = %w[
55
44
  ActualCardNumber CarrierNumber ClientTrackingId ExternalId
56
45
  PaymentTrackingID PrintText
@@ -72,16 +72,14 @@ module EML
72
72
  @fields = fields.join(",")
73
73
  end
74
74
 
75
- sig { params(log_balance_inquiry: String).returns(String) }
75
+ sig { params(log_balance_inquiry: T::Boolean).returns(String) }
76
76
  def log_balance_inquiry=(log_balance_inquiry)
77
- validate_boolean("log_balance_inquiry", log_balance_inquiry)
78
- @log_balance_inquiry = log_balance_inquiry
77
+ @log_balance_inquiry = log_balance_inquiry.inspect
79
78
  end
80
79
 
81
- sig { params(only_valid_status: String).returns(String) }
80
+ sig { params(only_valid_status: T::Boolean).returns(String) }
82
81
  def only_valid_status=(only_valid_status)
83
- validate_boolean("only_valid_status", only_valid_status)
84
- @only_valid_status = only_valid_status
82
+ @only_valid_status = only_valid_status.inspect
85
83
  end
86
84
 
87
85
  sig { params(program: String).returns(String) }
@@ -40,17 +40,6 @@ module EML
40
40
 
41
41
  protected
42
42
 
43
- BOOLEAN_OPTIONS = %w[true false].freeze
44
-
45
- sig { params(param_name: String, param_value: String).void }
46
- def validate_boolean(param_name, param_value)
47
- return if BOOLEAN_OPTIONS.include?(param_value)
48
-
49
- message = "#{param_name} should be the string 'true' or 'false' but " \
50
- "received #{param_value.inspect}"
51
- raise ArgumentError, message
52
- end
53
-
54
43
  sig { params(dob: String).void }
55
44
  def validate_dob(dob)
56
45
  validate_max_length(:dob, dob, 8)
@@ -19,17 +19,17 @@ module EML
19
19
  sig { params(developer: String).returns(String) }
20
20
  attr_accessor :developer
21
21
 
22
- sig { params(is_account_expiry: String).returns(String) }
22
+ # rubocop:disable Naming/VariableName
23
+ sig { params(is_account_expiry: T::Boolean).returns(String) }
23
24
  def is_account_expiry=(is_account_expiry)
24
- validate_boolean("is_account_expiry", is_account_expiry)
25
- @Is_account_expiry = is_account_expiry
25
+ @Is_account_expiry = is_account_expiry.inspect
26
26
  end
27
27
 
28
- sig { params(is_fee_free: String).returns(String) }
28
+ sig { params(is_fee_free: T::Boolean).returns(String) }
29
29
  def is_fee_free=(is_fee_free)
30
- validate_boolean("is_fee_free", is_fee_free)
31
- @Is_fee_free = is_fee_free
30
+ @Is_fee_free = is_fee_free.inspect
32
31
  end
32
+ # rubocop:enable Naming/VariableName
33
33
 
34
34
  sig { params(merchant_group: String).returns(String) }
35
35
  attr_accessor :merchant_group
@@ -10,11 +10,11 @@ module EML
10
10
 
11
11
  field :count
12
12
 
13
- sig { returns(T::Array[::EML::UK::Model::Transaction]) }
13
+ sig { returns(T::Array[::EML::UK::Models::Transaction]) }
14
14
  def transactions
15
15
  @transactions ||= body["transactions"].
16
16
  each_with_object([]) do |transaction, array|
17
- array << ::EML::UK::Model::Transaction.new(transaction)
17
+ array << ::EML::UK::Models::Transaction.new(transaction)
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,64 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module EML
5
+ module UK
6
+ module TNS
7
+ class ProcessRequest
8
+ extend T::Sig
9
+
10
+ sig do
11
+ params(
12
+ auth_token: String,
13
+ parameters: T::Hash[Symbol, T.untyped]
14
+ ).returns(EML::UK::TNS::Response)
15
+ end
16
+ def self.call(auth_token, parameters)
17
+ new(auth_token, parameters).call
18
+ end
19
+
20
+ sig do
21
+ params(
22
+ auth_token: String,
23
+ parameters: T::Hash[Symbol, T.untyped]
24
+ ).void
25
+ end
26
+ def initialize(auth_token, parameters)
27
+ @auth_token = auth_token
28
+ @parameters = parameters
29
+ end
30
+
31
+ sig { returns(EML::UK::TNS::Response) }
32
+ def call
33
+ verify_auth_token
34
+ EML::UK::TNS::Response.new(@parameters)
35
+ end
36
+
37
+ private
38
+
39
+ sig { void }
40
+ def verify_auth_token
41
+ valid = ::EML::BasicAuth::Verify.(
42
+ @auth_token,
43
+ credentials[:username],
44
+ credentials[:password]
45
+ )
46
+ return if valid == true
47
+
48
+ raise ::EML::TNS::AuthenticationError
49
+ end
50
+
51
+ sig { returns(T::Hash[Symbol, T.untyped]) }
52
+ def credentials
53
+ @credentials ||= begin
54
+ config = EML::UK.config
55
+ {
56
+ username: config.tns_username,
57
+ password: config.tns_password,
58
+ }
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module EML
5
+ module UK
6
+ module TNS
7
+ class Response
8
+ extend T::Sig
9
+
10
+ attr_reader :transactions
11
+
12
+ sig { params(response: T::Hash[Symbol, T.untyped]).void }
13
+ def initialize(response)
14
+ @transactions = response[:Transactions].
15
+ each_with_object([]) do |raw_transaction, transactions|
16
+ transactions << EML::UK::Models::TNSTransaction.
17
+ new(raw_transaction)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/eml/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module EML
5
- VERSION = "1.0.0"
5
+ VERSION = "2.0.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morning Coffee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-14 00:00:00.000000000 Z
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: dotenv
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rspec
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -203,9 +231,13 @@ files:
203
231
  - ".gitignore"
204
232
  - ".rspec"
205
233
  - ".rubocop.yml"
234
+ - CODE_OF_CONDUCT.md
206
235
  - Gemfile
207
236
  - LICENSE
208
237
  - README.md
238
+ - Rakefile
239
+ - bin/console
240
+ - bin/setup
209
241
  - eml.gemspec
210
242
  - lib/eml.rb
211
243
  - lib/eml/config.rb
@@ -222,7 +254,13 @@ files:
222
254
  - lib/eml/error/rest/internal_server.rb
223
255
  - lib/eml/error/rest/not_found.rb
224
256
  - lib/eml/error/rest/unprocessable_entity.rb
257
+ - lib/eml/error/tns.rb
258
+ - lib/eml/error/tns/authentication.rb
259
+ - lib/eml/lib/basic_auth/generate.rb
260
+ - lib/eml/lib/basic_auth/verify.rb
261
+ - lib/eml/lib/constant_time_compare.rb
225
262
  - lib/eml/lib/endpoint_class.rb
263
+ - lib/eml/model.rb
226
264
  - lib/eml/parameters.rb
227
265
  - lib/eml/payload.rb
228
266
  - lib/eml/response.rb
@@ -231,7 +269,9 @@ files:
231
269
  - lib/eml/uk/config.rb
232
270
  - lib/eml/uk/lib/endpoint_class.rb
233
271
  - lib/eml/uk/lib/parse_date.rb
234
- - lib/eml/uk/model/transaction.rb
272
+ - lib/eml/uk/models/tns_card.rb
273
+ - lib/eml/uk/models/tns_transaction.rb
274
+ - lib/eml/uk/models/transaction.rb
235
275
  - lib/eml/uk/parameters.rb
236
276
  - lib/eml/uk/parameters/agreement/show.rb
237
277
  - lib/eml/uk/parameters/card/activation.rb
@@ -254,7 +294,6 @@ files:
254
294
  - lib/eml/uk/payload/card/unload.rb
255
295
  - lib/eml/uk/payload/card/unlock.rb
256
296
  - lib/eml/uk/payload/card/void.rb
257
- - lib/eml/uk/payload/contactentity.rb
258
297
  - lib/eml/uk/payload/iso.rb
259
298
  - lib/eml/uk/payload/location.rb
260
299
  - lib/eml/uk/resources/agreement.rb
@@ -264,6 +303,8 @@ files:
264
303
  - lib/eml/uk/responses/card/reload.rb
265
304
  - lib/eml/uk/responses/card/show.rb
266
305
  - lib/eml/uk/responses/card/transaction.rb
306
+ - lib/eml/uk/tns/process_request.rb
307
+ - lib/eml/uk/tns/response.rb
267
308
  - lib/eml/version.rb
268
309
  - sorbet/config
269
310
  - sorbet/rbi/gems/addressable.rbi
@@ -305,14 +346,6 @@ files:
305
346
  - sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi
306
347
  - sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi
307
348
  - sorbet/rbi/todo.rbi
308
- - spec/config_spec.rb
309
- - spec/helpers/config_helper.rb
310
- - spec/helpers/vcr_helper.rb
311
- - spec/spec_helper.rb
312
- - spec/uk/api_resource_spec.rb
313
- - spec/uk/resources/agreement_spec.rb
314
- - spec/uk/resources/card_spec.rb
315
- - spec/vcr_cassettes/.keep
316
349
  homepage: https://github.com/MorningCoffeeDev/eml_ruby
317
350
  licenses:
318
351
  - MIT