issuer_response_codes 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +38 -0
- data/.rubocop.yml +3 -76
- data/.ruby-version +1 -1
- data/CHANGELOG.md +13 -0
- data/Gemfile +9 -1
- data/Gemfile.lock +54 -41
- data/README.md +7 -1
- data/Rakefile +8 -6
- data/bin/console +6 -4
- data/issuer_response_codes.gemspec +14 -20
- data/lib/issuer_response_codes/code.rb +21 -6
- data/lib/issuer_response_codes/context.rb +16 -0
- data/lib/issuer_response_codes/locale_library.rb +52 -27
- data/lib/issuer_response_codes/tds_code.rb +21 -4
- data/lib/issuer_response_codes/version.rb +2 -1
- data/lib/issuer_response_codes.rb +12 -7
- data/lib/locale/es.yml +300 -0
- data/lib/locale/fi.yml +300 -0
- data/lib/locale/fr.yml +300 -0
- data/lib/locale/hr.yml +300 -0
- data/lib/locale/it.yml +157 -157
- data/lib/locale/nl.yml +300 -0
- data/lib/locale/pt.yml +300 -0
- metadata +17 -108
- data/.travis.yml +0 -6
- data/LICENSE +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78eac7a89806d60339f0ef7f789ed08b60a6fb675e651e620cd51e3de49dbcfe
|
4
|
+
data.tar.gz: 6b48a34c1925e916cc67a6c29cc4857104e7e34081588f49035294024b383d8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce421e3c6b41c00929a3bd71756b28d4002707dbc4ff2bc65c284a2055fe548b5b855492d7dbfbffdc9651b2527f7d903d6c654bca7327556ca2792899226db
|
7
|
+
data.tar.gz: 73cc431569db42ccae5f0c899858af55eb04719964525f8b648c759fac085e2e5f23f2475ecce812c421ff1f833dcf20de28fb97412587f23be11533ba5b6593
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: CI Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ 'main' ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ 'main' ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
env:
|
13
|
+
CI: true
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ['3.0', '3.1', '3.2']
|
17
|
+
steps:
|
18
|
+
- name: Checkout code
|
19
|
+
uses: actions/checkout@v3
|
20
|
+
- name: Install Ruby and gems
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
25
|
+
- name: Run unit tests
|
26
|
+
run: bundle exec rake test
|
27
|
+
|
28
|
+
lint:
|
29
|
+
runs-on: ubuntu-latest
|
30
|
+
steps:
|
31
|
+
- name: Checkout code
|
32
|
+
uses: actions/checkout@v3
|
33
|
+
- name: Install Ruby and gems
|
34
|
+
uses: ruby/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
+
- name: Lint
|
38
|
+
run: bundle exec rubocop --parallel --color
|
data/.rubocop.yml
CHANGED
@@ -1,78 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Style/SingleArgumentDig:
|
5
|
-
Enabled: false
|
6
|
-
|
7
|
-
Layout/LineLength:
|
8
|
-
Enabled: false
|
9
|
-
|
10
|
-
Style/Documentation:
|
11
|
-
Enabled: false
|
12
|
-
|
13
|
-
Style/ClassAndModuleChildren:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
Style/MethodCallWithArgsParentheses:
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
Style/ModuleFunction:
|
20
|
-
EnforcedStyle: 'extend_self'
|
21
|
-
|
22
|
-
Style/MissingElse:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Lint/NumberConversion:
|
26
|
-
Enabled: false
|
27
|
-
|
28
|
-
Lint/ConstantResolution:
|
29
|
-
Enabled: false
|
30
|
-
|
31
|
-
Style/RescueStandardError:
|
32
|
-
Enabled: false
|
33
|
-
|
34
|
-
Style/FormatStringToken:
|
35
|
-
Enabled: false
|
36
|
-
|
37
|
-
Style/FormatString:
|
38
|
-
Enabled: false
|
39
|
-
|
40
|
-
Style/DocumentationMethod:
|
41
|
-
Enabled: false
|
42
|
-
|
43
|
-
Style/Copyright:
|
44
|
-
Enabled: false
|
45
|
-
|
46
|
-
Style/StringHashKeys:
|
47
|
-
Enabled: false
|
48
|
-
|
49
|
-
Style/InlineComment:
|
50
|
-
Enabled: false
|
51
|
-
|
52
|
-
Layout/FirstHashElementLineBreak:
|
53
|
-
Enabled: false
|
54
|
-
|
55
|
-
Layout/FirstMethodArgumentLineBreak:
|
56
|
-
Enabled: false
|
57
|
-
|
58
|
-
Style/ConstantVisibility:
|
59
|
-
Enabled: false
|
60
|
-
|
61
|
-
Layout/FirstArrayElementLineBreak:
|
62
|
-
Enabled: false
|
63
|
-
|
64
|
-
Layout/MultilineMethodArgumentLineBreaks:
|
65
|
-
Enabled: false
|
66
|
-
|
67
|
-
Layout/MultilineAssignmentLayout:
|
68
|
-
Enabled: false
|
69
|
-
|
70
|
-
Bundler/GemComment:
|
71
|
-
Enabled: false
|
1
|
+
inherit_gem:
|
2
|
+
rubocop-espago: rubocop.yml
|
72
3
|
|
73
4
|
AllCops:
|
74
|
-
|
75
|
-
Exclude:
|
76
|
-
- 'bin/*'
|
77
|
-
- 'spec/**/*'
|
78
|
-
- 'test/**/*'
|
5
|
+
TargetRubyVersion: 3.0
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.4
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
|
9
|
+
## [0.3.0]
|
10
|
+
|
11
|
+
[Diff](https://github.com/espago/issuer_response_codes/compare/v0.3.0...espago:issuer_response_codes:v0.2.5)
|
12
|
+
|
13
|
+
This release adds support for Ruby 3.1 and 3.2 and full translations for brand new languages: `:es, :fi, :fr, :hr, :it, :nl, :pt`.
|
data/Gemfile
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in issuer_response_codes.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
gem 'bundler', '~> 2.0' # library manager
|
9
|
+
gem 'debug', '~> 1.6.3' # debugger
|
10
|
+
gem 'minitest', '~> 5.0' # test framework
|
11
|
+
gem 'rake', '~> 12.0' # automation
|
12
|
+
gem 'rubocop', '~> 1.54' # linter
|
13
|
+
gem 'rubocop-espago', '~> 1.0' # linter config
|
14
|
+
gem 'solargraph', '~> 0.49' # language server
|
data/Gemfile.lock
CHANGED
@@ -1,84 +1,97 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
issuer_response_codes (0.
|
4
|
+
issuer_response_codes (0.3.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
10
|
backport (1.2.0)
|
11
|
-
benchmark (0.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
diff-lcs (1.4.4)
|
11
|
+
benchmark (0.2.1)
|
12
|
+
debug (1.6.3)
|
13
|
+
irb (>= 1.3.6)
|
14
|
+
reline (>= 0.3.1)
|
15
|
+
diff-lcs (1.5.0)
|
17
16
|
e2mmap (0.1.0)
|
18
|
-
|
19
|
-
|
17
|
+
io-console (0.5.11)
|
18
|
+
irb (1.4.1)
|
19
|
+
reline (>= 0.3.0)
|
20
|
+
jaro_winkler (1.5.6)
|
21
|
+
json (2.6.3)
|
22
|
+
kramdown (2.4.0)
|
20
23
|
rexml
|
21
24
|
kramdown-parser-gfm (1.1.0)
|
22
25
|
kramdown (~> 2.0)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
language_server-protocol (3.17.0.3)
|
27
|
+
mini_portile2 (2.8.4)
|
28
|
+
minitest (5.18.1)
|
29
|
+
nokogiri (1.15.3)
|
30
|
+
mini_portile2 (~> 2.8.2)
|
27
31
|
racc (~> 1.4)
|
28
|
-
parallel (1.
|
29
|
-
parser (3.
|
32
|
+
parallel (1.23.0)
|
33
|
+
parser (3.2.2.3)
|
30
34
|
ast (~> 2.4.1)
|
31
|
-
|
32
|
-
|
35
|
+
racc
|
36
|
+
racc (1.7.1)
|
37
|
+
rainbow (3.1.1)
|
33
38
|
rake (12.3.3)
|
34
|
-
|
35
|
-
|
39
|
+
rbs (2.8.4)
|
40
|
+
regexp_parser (2.8.1)
|
41
|
+
reline (0.3.1)
|
42
|
+
io-console (~> 0.5)
|
43
|
+
reverse_markdown (2.1.1)
|
36
44
|
nokogiri
|
37
45
|
rexml (3.2.5)
|
38
|
-
rubocop (1.
|
46
|
+
rubocop (1.54.2)
|
47
|
+
json (~> 2.3)
|
48
|
+
language_server-protocol (>= 3.17.0)
|
39
49
|
parallel (~> 1.10)
|
40
|
-
parser (>= 3.
|
50
|
+
parser (>= 3.2.2.3)
|
41
51
|
rainbow (>= 2.2.2, < 4.0)
|
42
52
|
regexp_parser (>= 1.8, < 3.0)
|
43
|
-
rexml
|
44
|
-
rubocop-ast (>= 1.
|
53
|
+
rexml (>= 3.2.5, < 4.0)
|
54
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
45
55
|
ruby-progressbar (~> 1.7)
|
46
|
-
unicode-display_width (>=
|
47
|
-
rubocop-ast (1.
|
48
|
-
parser (>= 3.
|
49
|
-
|
50
|
-
|
56
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
57
|
+
rubocop-ast (1.29.0)
|
58
|
+
parser (>= 3.2.1.0)
|
59
|
+
rubocop-espago (1.0.3)
|
60
|
+
rubocop
|
61
|
+
ruby-progressbar (1.13.0)
|
62
|
+
solargraph (0.49.0)
|
51
63
|
backport (~> 1.2)
|
52
64
|
benchmark
|
53
|
-
bundler (
|
65
|
+
bundler (~> 2.0)
|
54
66
|
diff-lcs (~> 1.4)
|
55
67
|
e2mmap
|
56
68
|
jaro_winkler (~> 1.5)
|
57
69
|
kramdown (~> 2.3)
|
58
70
|
kramdown-parser-gfm (~> 1.1)
|
59
71
|
parser (~> 3.0)
|
60
|
-
|
61
|
-
|
72
|
+
rbs (~> 2.0)
|
73
|
+
reverse_markdown (~> 2.0)
|
74
|
+
rubocop (~> 1.38)
|
62
75
|
thor (~> 1.0)
|
63
76
|
tilt (~> 2.0)
|
64
77
|
yard (~> 0.9, >= 0.9.24)
|
65
|
-
thor (1.
|
66
|
-
tilt (2.0
|
67
|
-
unicode-display_width (2.
|
68
|
-
yard (0.9.
|
78
|
+
thor (1.2.2)
|
79
|
+
tilt (2.2.0)
|
80
|
+
unicode-display_width (2.4.2)
|
81
|
+
yard (0.9.34)
|
69
82
|
|
70
83
|
PLATFORMS
|
71
84
|
ruby
|
72
85
|
|
73
86
|
DEPENDENCIES
|
74
|
-
bundler
|
75
|
-
|
76
|
-
byebug
|
87
|
+
bundler (~> 2.0)
|
88
|
+
debug (~> 1.6.3)
|
77
89
|
issuer_response_codes!
|
78
90
|
minitest (~> 5.0)
|
79
91
|
rake (~> 12.0)
|
80
|
-
rubocop
|
81
|
-
|
92
|
+
rubocop (~> 1.54)
|
93
|
+
rubocop-espago (~> 1.0)
|
94
|
+
solargraph (~> 0.49)
|
82
95
|
|
83
96
|
BUNDLED WITH
|
84
|
-
2.
|
97
|
+
2.4.17
|
data/README.md
CHANGED
@@ -4,12 +4,18 @@ This gem provides a quite comprehensive library of Issuer Response Code and 3D-S
|
|
4
4
|
- Complete locales:
|
5
5
|
- en
|
6
6
|
- pl
|
7
|
+
- es
|
8
|
+
- fi
|
9
|
+
- fr
|
10
|
+
- hr
|
11
|
+
- it
|
12
|
+
- nl
|
13
|
+
- pt
|
7
14
|
|
8
15
|
- Incomplete locales:
|
9
16
|
- da
|
10
17
|
- de
|
11
18
|
- ee
|
12
|
-
- it
|
13
19
|
- lt
|
14
20
|
- lv
|
15
21
|
- sv
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.test_files = FileList[
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
10
|
end
|
9
11
|
|
10
|
-
task :
|
12
|
+
task default: :test
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'issuer_response_codes'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,7 @@ require "issuer_response_codes"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
include ::IssuerResponseCodes
|
14
|
+
|
15
|
+
require 'irb'
|
16
|
+
::IRB.start(__FILE__)
|
@@ -3,34 +3,28 @@
|
|
3
3
|
require_relative 'lib/issuer_response_codes/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
6
|
+
spec.name = 'issuer_response_codes'
|
7
7
|
spec.version = IssuerResponseCodes::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
8
|
+
spec.authors = ['Espago', 'Mateusz Drewniak']
|
9
|
+
spec.email = ['m.drewniak@espago.com']
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
|
14
|
-
spec.
|
15
|
-
spec.
|
11
|
+
spec.summary = 'Issuer Response Code descriptions for cardholders and merchants'
|
12
|
+
spec.description =
|
13
|
+
'A simple Ruby gem which provides Issuer Response Code descriptions and suggestions for cardholders and merchants'
|
14
|
+
spec.homepage = 'https://github.com/espago/issuer_response_codes'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.0')
|
16
17
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/espago/issuer_response_codes'
|
19
20
|
|
20
21
|
# Specify which files should be added to the gem when it is released.
|
21
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
23
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
25
|
end
|
25
|
-
spec.bindir =
|
26
|
+
spec.bindir = 'exe'
|
26
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
-
spec.require_paths = [
|
28
|
-
|
29
|
-
spec.add_development_dependency 'bundler'
|
30
|
-
spec.add_development_dependency 'bundler-audit'
|
31
|
-
spec.add_development_dependency 'byebug'
|
32
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
33
|
-
spec.add_development_dependency 'rake', '~> 12.0'
|
34
|
-
spec.add_development_dependency 'rubocop'
|
35
|
-
spec.add_development_dependency 'solargraph'
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
36
30
|
end
|
@@ -1,17 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module IssuerResponseCodes
|
4
|
+
# ISO-8583 Response code.
|
4
5
|
class Code
|
5
6
|
attr_reader :id, :target, :locale, :fraud_notice
|
6
7
|
|
7
8
|
NOT_PROVIDED = ::Object.new
|
8
9
|
|
10
|
+
# @param id [String]
|
11
|
+
# @param target [Symbol]
|
12
|
+
# @param locale [Symbol]
|
13
|
+
# @param fraud_notice [Boolean, Object]
|
9
14
|
def initialize(id:, target: :merchant, locale: :en, fraud_notice: NOT_PROVIDED)
|
10
15
|
@id = id
|
11
16
|
@target = target
|
12
17
|
@locale = locale
|
13
18
|
|
14
|
-
|
19
|
+
@locale = :en unless AVAILABLE_LOCALES.include?(locale)
|
15
20
|
raise IllegalTarget, "No such target: #{target.inspect}" unless AVAILABLE_TARGETS.include?(target)
|
16
21
|
|
17
22
|
if fraud_notice != NOT_PROVIDED
|
@@ -22,25 +27,35 @@ module IssuerResponseCodes
|
|
22
27
|
@fraud_notice = target == :merchant
|
23
28
|
end
|
24
29
|
|
30
|
+
# @return [String]
|
25
31
|
def humanize
|
26
32
|
"#{reason} #{behaviour}"
|
27
33
|
end
|
28
|
-
|
29
34
|
alias description humanize
|
30
35
|
|
36
|
+
# @return [String]
|
31
37
|
def reason
|
32
|
-
LOCALE_LIBRARY
|
38
|
+
LOCALE_LIBRARY[path: id,
|
39
|
+
scope: "issuer_response_codes.targeted.#{target}",
|
40
|
+
locale: locale,
|
41
|
+
default: :unknown]
|
33
42
|
end
|
34
43
|
|
44
|
+
# @return [String]
|
35
45
|
def behaviour
|
36
|
-
behaviour_str = LOCALE_LIBRARY
|
46
|
+
behaviour_str = LOCALE_LIBRARY[path: id,
|
47
|
+
scope: 'issuer_response_codes.behaviour',
|
48
|
+
locale: locale,
|
49
|
+
default: :unknown]
|
37
50
|
return behaviour_str unless fraud_notice && fraudulent_code?
|
38
51
|
|
39
|
-
"#{behaviour_str} #{LOCALE_LIBRARY
|
52
|
+
"#{behaviour_str} #{LOCALE_LIBRARY[path: 'issuer_response_codes.fraud_notice']}"
|
40
53
|
end
|
41
54
|
|
55
|
+
# @return [Boolean]
|
42
56
|
def fraudulent_code?
|
43
|
-
@fraudulent_code ||= LOCALE_LIBRARY
|
57
|
+
@fraudulent_code ||= LOCALE_LIBRARY[path: id, scope: 'issuer_response_codes.fraudulent_codes', locale: locale]
|
44
58
|
end
|
59
|
+
|
45
60
|
end
|
46
61
|
end
|
@@ -1,11 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module IssuerResponseCodes
|
4
|
+
# Context stores default settings for retrieving codes.
|
4
5
|
class Context
|
5
6
|
attr_reader :default_target, :default_locale, :fraud_notice_by_default
|
6
7
|
|
7
8
|
NOT_PROVIDED = ::Object.new
|
8
9
|
|
10
|
+
# @param default_target [Symbol]
|
11
|
+
# @param default_locale [Symbol]
|
12
|
+
# @param fraud_notice_by_default [Boolean, Object]
|
13
|
+
# @raise [IllegalLocale]
|
14
|
+
# @raise [IllegalTarget]
|
9
15
|
def initialize(default_target: :merchant, default_locale: :en, fraud_notice_by_default: NOT_PROVIDED)
|
10
16
|
@default_target = default_target
|
11
17
|
@default_locale = default_locale
|
@@ -21,10 +27,20 @@ module IssuerResponseCodes
|
|
21
27
|
@fraud_notice_by_default = default_target == :merchant
|
22
28
|
end
|
23
29
|
|
30
|
+
# @param id [String, Symbol]
|
31
|
+
# @param target [Symbol]
|
32
|
+
# @param locale [Symbol]
|
33
|
+
# @param fraud_notice [Boolean, Object]
|
34
|
+
# @return [Code]
|
24
35
|
def code(id:, target: default_target, locale: default_locale, fraud_notice: fraud_notice_by_default)
|
25
36
|
Code.new(id: id, target: target, locale: locale, fraud_notice: fraud_notice)
|
26
37
|
end
|
27
38
|
|
39
|
+
# @param id [String, Symbol]
|
40
|
+
# @param target [Symbol]
|
41
|
+
# @param locale [Symbol]
|
42
|
+
# @param fraud_notice [Boolean, Object]
|
43
|
+
# @return [TdsCode]
|
28
44
|
def tds_code(id:, target: default_target, locale: default_locale, fraud_notice: fraud_notice_by_default)
|
29
45
|
TdsCode.new(id: id, target: target, locale: locale, fraud_notice: fraud_notice)
|
30
46
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
5
|
module IssuerResponseCodes
|
6
|
+
# Stores the translations of codes.
|
6
7
|
class LocaleLibrary
|
7
8
|
attr_reader :locale_hash
|
8
9
|
|
@@ -14,21 +15,25 @@ module IssuerResponseCodes
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
# @param path [String]
|
19
|
+
# @param locale [Symbol]
|
20
|
+
# @param scope [String]
|
21
|
+
# @param default [Symbol, String, nil]
|
22
|
+
# @return [String, Hash, nil]
|
23
|
+
def dig(path:, locale: :en, scope: '', default: nil)
|
24
|
+
__dig__(path: path, locale: locale, scope: scope, default: default)
|
23
25
|
end
|
26
|
+
alias [] dig
|
24
27
|
|
28
|
+
# @param locale [Symbol]
|
29
|
+
# @return [Hash{SYmbol => Hash{Symbol => Object}}]
|
25
30
|
def issuer_response_codes(locale: :en)
|
26
31
|
fraudulent_codes = locale_hash.dig(locale, :issuer_response_codes, :fraudulent_codes)
|
27
32
|
behaviours = locale_hash.dig(locale, :issuer_response_codes, :behaviour)
|
28
33
|
cardholder_reasons = locale_hash.dig(locale, :issuer_response_codes, :targeted, :cardholder)
|
29
34
|
merchant_reasons = locale_hash.dig(locale, :issuer_response_codes, :targeted, :merchant)
|
30
35
|
|
31
|
-
merchant_reasons.
|
36
|
+
merchant_reasons.to_h do |code, merchant_reason|
|
32
37
|
[
|
33
38
|
code,
|
34
39
|
{
|
@@ -38,16 +43,18 @@ module IssuerResponseCodes
|
|
38
43
|
fraudulent: fraudulent_codes[code] == true
|
39
44
|
}
|
40
45
|
]
|
41
|
-
end
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
49
|
+
# @param locale [Symbol]
|
50
|
+
# @return [Hash{Symbol => Hash{Symbol => Object}}]
|
44
51
|
def tds_codes(locale: :en)
|
45
52
|
fraudulent_codes = locale_hash.dig(locale, :tds_status_codes, :fraudulent_codes)
|
46
53
|
behaviours = locale_hash.dig(locale, :tds_status_codes, :behaviour)
|
47
54
|
cardholder_reasons = locale_hash.dig(locale, :tds_status_codes, :targeted, :cardholder)
|
48
55
|
merchant_reasons = locale_hash.dig(locale, :tds_status_codes, :targeted, :merchant)
|
49
56
|
|
50
|
-
merchant_reasons.
|
57
|
+
merchant_reasons.to_h do |code, merchant_reason|
|
51
58
|
[
|
52
59
|
code,
|
53
60
|
{
|
@@ -57,25 +64,16 @@ module IssuerResponseCodes
|
|
57
64
|
fraudulent: fraudulent_codes[code] == true
|
58
65
|
}
|
59
66
|
]
|
60
|
-
end.to_h
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.symbolize_keys(hash)
|
64
|
-
h = hash.map do |k, v|
|
65
|
-
v_sym = if v.instance_of? Hash
|
66
|
-
symbolize_keys(v)
|
67
|
-
else
|
68
|
-
v
|
69
|
-
end
|
70
|
-
|
71
|
-
[k.to_sym, v_sym]
|
72
67
|
end
|
73
|
-
|
74
|
-
h.to_h
|
75
68
|
end
|
76
69
|
|
77
70
|
private
|
78
71
|
|
72
|
+
# @param path [String]
|
73
|
+
# @param locale [Symbol]
|
74
|
+
# @param scope [String]
|
75
|
+
# @param default [Symbol, String, nil]
|
76
|
+
# @return [String, Hash, nil]
|
79
77
|
def __dig__(path:, locale: :en, scope: '', default: nil)
|
80
78
|
result = dig_provided_path(path, scope, locale)
|
81
79
|
return result if result || !default
|
@@ -85,6 +83,10 @@ module IssuerResponseCodes
|
|
85
83
|
dig_provided_path(default.to_s, scope, locale)
|
86
84
|
end
|
87
85
|
|
86
|
+
# @param path [String]
|
87
|
+
# @param locale [Symbol]
|
88
|
+
# @param scope [String]
|
89
|
+
# @return [String, Hash, nil]
|
88
90
|
def dig_provided_path(path, scope, locale)
|
89
91
|
return if path.nil? || path.empty?
|
90
92
|
|
@@ -95,12 +97,35 @@ module IssuerResponseCodes
|
|
95
97
|
locale_hash.dig(*full_path_array)
|
96
98
|
end
|
97
99
|
|
100
|
+
# @param name [Symbol, String]
|
101
|
+
# @return [void]
|
98
102
|
def load_locale(name)
|
99
|
-
|
103
|
+
raw_hash = load_yaml(::File.join(::File.dirname(::File.expand_path(__FILE__)), "../locale/#{name}.yml"))
|
104
|
+
name = name.to_sym
|
100
105
|
|
101
|
-
|
102
|
-
single_locale_hash = self.class.symbolize_keys(raw_hash)
|
103
|
-
@locale_hash[name] = single_locale_hash
|
106
|
+
@locale_hash[name] = raw_hash[name]
|
104
107
|
end
|
108
|
+
|
109
|
+
if ::Psych::VERSION > '4'
|
110
|
+
# @param file_path [String]
|
111
|
+
# @return [Hash{Symbol => Object}]
|
112
|
+
def load_yaml(file_path)
|
113
|
+
::YAML.load_file(
|
114
|
+
file_path,
|
115
|
+
symbolize_names: true,
|
116
|
+
aliases: true
|
117
|
+
)
|
118
|
+
end
|
119
|
+
else
|
120
|
+
# @param file_path [String]
|
121
|
+
# @return [Hash{Symbol => Object}]
|
122
|
+
def load_yaml(file_path)
|
123
|
+
::YAML.load_file(
|
124
|
+
file_path,
|
125
|
+
symbolize_names: true
|
126
|
+
)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
105
130
|
end
|
106
131
|
end
|