ibandit 1.19.0 → 1.21.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47171b99a86687a326f6f674684d5faa489f4aef980e623e2f43d3ffdf841d84
4
- data.tar.gz: 6074f09b34e39a205fdacabbc1a7376dfec8ac38f2821cbfd1d7ae6a8ba683cf
3
+ metadata.gz: 37a15fbc4242dda50e51d295ef5e37e6ee692d5f91d43d32842c2df570213e82
4
+ data.tar.gz: db530699e09d54603f27cbee4c4d6e9f254e89557ce1c41ac0cbfb8e82a58e90
5
5
  SHA512:
6
- metadata.gz: 9f2ff5eb107524c44c68118315f916d86c7550335bae82747165edbfcf4f11d196b29cd3ec6f130babbf7765866925768dca7b5532357510248e8994e9bca0ae
7
- data.tar.gz: 0a66dd61f63feeb8534a6b48de006c64928c6f43bf65463ca8e24ccd412d13aa87fc8b8102a4fb54d5585d70a96df91db50be8117c7c025ac576fb0d033c4909
6
+ metadata.gz: 1a9b288596e9bddae7eab282e12f20a650bdbc74016240f56f4a7a34fa9628885070b276ac079d149a146a4cd0ac68ceb58923001edb40159bd368637b1534d2
7
+ data.tar.gz: '08f3f363786871a019ebe9122d1b9fe96893823811a9578d25a652757a01d8b4e9904ae4ecf32542a2ddb856894486816429a97f65ecd7bc450158c0924de475'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.21.0 - August 6, 2024
2
+
3
+ - Canada, Financial Institution number - allow 3 digits
4
+ - modulus_checker failures will now return validation method specific error message
5
+
6
+ ## 1.20.0 - October 13, 2023
7
+
8
+ - Do not allow all 0 transit numbers in CA
9
+
1
10
  ## 1.19.0 - October 3, 2023
2
11
 
3
12
  - Do not allow all-0 account numbers for CA
@@ -17,3 +17,4 @@ da:
17
17
  bank_code_does_not_exist: "bankkoden findes ikke"
18
18
  has_invalid_clearing_code_length: "længden på clearingskoden er ugyldig"
19
19
  has_invalid_serial_number: "ugyldigt serienummer"
20
+ branch_code_does_not_exist: "filialkode findes ikke"
@@ -17,3 +17,4 @@ de:
17
17
  bank_code_does_not_exist: "Bankleitzahl existiert nicht"
18
18
  has_invalid_clearing_code_length: "Länge des Verrechnungscodes ist ungültig"
19
19
  has_invalid_serial_number: "Seriennummer ist ungültig"
20
+ branch_code_does_not_exist: "Filialcode existiert nicht"
@@ -17,3 +17,4 @@ en:
17
17
  bank_code_does_not_exist: "bank code does not exist"
18
18
  has_invalid_clearing_code_length: "clearing code length is invalid"
19
19
  has_invalid_serial_number: "serial number is invalid"
20
+ branch_code_does_not_exist: "branch code does not exist"
@@ -1,7 +1,7 @@
1
1
  es:
2
2
  ibandit:
3
- invalid_country_code: "\"%{country_code}\" no es un código de país IBAN ISO 3166-1 válido"
4
- invalid_check_digits: "Los dígitos de verificación han generado un error en la comprobación del módulo. Se esperaba \"%{expected_check_digits}\", pero se ha recibido \"%{check_digits}\"."
3
+ invalid_country_code: '"%{country_code}" no es un código de país IBAN ISO 3166-1 válido'
4
+ invalid_check_digits: 'Los dígitos de verificación han generado un error en la comprobación del módulo. Se esperaba "%{expected_check_digits}", pero se ha recibido "%{check_digits}".'
5
5
  invalid_length: "La longitud no coincide con la especificación SWIFT (se esperaban %{expected_length} caracteres, pero se han recibido %{length})"
6
6
  is_required: "es obligatorio"
7
7
  wrong_length: "no tiene la longitud correcta (debe tener %{expected} caracteres)"
@@ -17,3 +17,4 @@ es:
17
17
  bank_code_does_not_exist: "codigo bancario inexistente"
18
18
  has_invalid_clearing_code_length: "codigo de oficina de oficina de compensación invalido"
19
19
  has_invalid_serial_number: "número de serie invalido"
20
+ branch_code_does_not_exist: "código de sucursal no existe"
@@ -17,3 +17,4 @@ fr:
17
17
  bank_code_does_not_exist: "le code de la banque n'existe pas"
18
18
  has_invalid_clearing_code_length: "la longueur du clearing code n'est pas valide"
19
19
  has_invalid_serial_number: "le numéro de série n'est pas valide"
20
+ branch_code_does_not_exist: "le code de la succursale n'existe pas"
@@ -1,6 +1,6 @@
1
1
  it:
2
2
  ibandit:
3
- invalid_country_code: "\"%{country_code}\" non è un codice di paese IBAN 3166-1 valido"
3
+ invalid_country_code: '"%{country_code}" non è un codice di paese IBAN 3166-1 valido'
4
4
  invalid_check_digits: "Controllo del modulo non riuscito per i caratteri. %{expected_check_digits} caratteri previsti, %{check_digits} immessi."
5
5
  invalid_length: "La lunghezza non corrisponde alla specifica SWIFT (%{expected_length} caratteri previsti, %{length} immessi)"
6
6
  is_required: "è obbligatorio"
@@ -17,4 +17,4 @@ it:
17
17
  bank_code_does_not_exist: "codice banca inesistente"
18
18
  has_invalid_clearing_code_length: "lunghezza clearing code non valida"
19
19
  has_invalid_serial_number: "numero di serie non valido"
20
-
20
+ branch_code_does_not_exist: "codice filiale non esiste"
@@ -17,3 +17,4 @@ nb:
17
17
  bank_code_does_not_exist: "bankkoden eksisterer ikke"
18
18
  has_invalid_clearing_code_length: "registreringsnummerets lengde er ugyldig"
19
19
  has_invalid_serial_number: "ugyldig serienummer"
20
+ branch_code_does_not_exist: "filialkode eksisterer ikke"
@@ -17,3 +17,4 @@ nl:
17
17
  bank_code_does_not_exist: "bankcode bestaat niet"
18
18
  has_invalid_clearing_code_length: "lengte clearingcode is ongeldig"
19
19
  has_invalid_serial_number: "serienummer is ongeldig"
20
+ branch_code_does_not_exist: "takcode bestaat niet"
@@ -17,3 +17,4 @@ pt:
17
17
  bank_code_does_not_exist: "o código do banco não existe"
18
18
  has_invalid_clearing_code_length: "o comprimento do código de libertação é inválido"
19
19
  has_invalid_serial_number: "o número de série é inválido"
20
+ branch_code_does_not_exist: "código da filial não existe"
@@ -17,3 +17,4 @@ sl:
17
17
  bank_code_does_not_exist: "koda banke ne obstaja"
18
18
  has_invalid_clearing_code_length: "dolžina klirinške kode ni veljavna"
19
19
  has_invalid_serial_number: "serijska številka ni veljavna"
20
+ branch_code_does_not_exist: "koda podružnice ne obstaja"
@@ -17,3 +17,4 @@ sv:
17
17
  bank_code_does_not_exist: "bankkoden existerar inte"
18
18
  has_invalid_clearing_code_length: "clearingnumrets längd är ogiltigt"
19
19
  has_invalid_serial_number: "ogiltigt serienummer"
20
+ branch_code_does_not_exist: "filialkod finns inte"
@@ -13,14 +13,17 @@ AU:
13
13
  :pseudo_iban_account_number_length: 10
14
14
  :national_id_length: 6
15
15
  CA:
16
- :bank_code_length: 4
16
+ :bank_code_length: !ruby/range
17
+ begin: 3
18
+ end: 4
19
+ excl: false
17
20
  :branch_code_length: 5
18
21
  :account_number_length: !ruby/range
19
22
  begin: 7
20
23
  end: 12
21
24
  excl: false
22
- :bank_code_format: "\\d{4}"
23
- :branch_code_format: "\\d{5}"
25
+ :bank_code_format: "\\d{3,4}"
26
+ :branch_code_format: "0{0,4}[1-9][0-9]{0,4}"
24
27
  :account_number_format: "(?!0+\\z)\\d{7,12}"
25
28
  :national_id_length: 9
26
29
  :pseudo_iban_bank_code_length: 4
data/data/structures.yml CHANGED
@@ -1493,14 +1493,17 @@ AU:
1493
1493
  :pseudo_iban_account_number_length: 10
1494
1494
  :national_id_length: 6
1495
1495
  CA:
1496
- :bank_code_length: 4
1496
+ :bank_code_length: !ruby/range
1497
+ begin: 3
1498
+ end: 4
1499
+ excl: false
1497
1500
  :branch_code_length: 5
1498
1501
  :account_number_length: !ruby/range
1499
1502
  begin: 7
1500
1503
  end: 12
1501
1504
  excl: false
1502
- :bank_code_format: "\\d{4}"
1503
- :branch_code_format: "\\d{5}"
1505
+ :bank_code_format: "\\d{3,4}"
1506
+ :branch_code_format: 0{0,4}[1-9][0-9]{0,4}
1504
1507
  :account_number_format: "(?!0+\\z)\\d{7,12}"
1505
1508
  :national_id_length: 9
1506
1509
  :pseudo_iban_bank_code_length: 4
data/ibandit.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.required_ruby_version = ">= 2.7.0"
30
- spec.add_development_dependency "gc_ruboconfig", "~> 4.3"
30
+ spec.add_development_dependency "gc_ruboconfig", "~> 5.0"
31
31
  spec.add_development_dependency "nokogiri", "~> 1.6"
32
32
  spec.add_development_dependency "pry", "~> 0.13"
33
33
  spec.add_development_dependency "pry-byebug", "~> 3.10"
data/lib/ibandit/iban.rb CHANGED
@@ -158,14 +158,17 @@ module Ibandit
158
158
 
159
159
  def valid_bank_code_length?
160
160
  return unless valid_country_code?
161
- return true if structure[:bank_code_length]&.zero?
161
+ if structure[:bank_code_length].is_a?(Integer) && structure[:bank_code_length].zero?
162
+ return true
163
+ end
162
164
 
163
165
  if swift_bank_code.nil? || swift_bank_code.empty?
164
166
  @errors[:bank_code] = Ibandit.translate(:is_required)
165
167
  return false
166
168
  end
167
169
 
168
- return true if swift_bank_code.length == structure[:bank_code_length]
170
+ return true if valid_input_length?(structure[:bank_code_length],
171
+ swift_bank_code.length)
169
172
 
170
173
  @errors[:bank_code] =
171
174
  Ibandit.translate(:wrong_length, expected: structure[:bank_code_length])
@@ -197,14 +200,8 @@ module Ibandit
197
200
  return false
198
201
  end
199
202
 
200
- case structure[:account_number_length]
201
- when Range
202
- if structure[:account_number_length].include?(swift_account_number.length)
203
- return true
204
- end
205
- else
206
- return true if swift_account_number.length == structure[:account_number_length]
207
- end
203
+ return true if valid_input_length?(structure[:account_number_length],
204
+ swift_account_number.length)
208
205
 
209
206
  @errors[:account_number] =
210
207
  Ibandit.translate(:wrong_length,
@@ -240,7 +237,9 @@ module Ibandit
240
237
 
241
238
  def valid_bank_code_format?
242
239
  return unless valid_bank_code_length?
243
- return true if structure[:bank_code_length]&.zero?
240
+ if structure[:bank_code_length].is_a?(Integer) && structure[:bank_code_length].zero?
241
+ return true
242
+ end
244
243
 
245
244
  if swift_bank_code&.match?(
246
245
  entire_string_regex(structure[:bank_code_format]),
@@ -509,17 +508,26 @@ module Ibandit
509
508
  iban.to_s.gsub(/(.{4})/, '\1 ').strip
510
509
  end
511
510
 
511
+ def valid_input_length?(allowed_length, input_length)
512
+ case allowed_length
513
+ when Range
514
+ allowed_length.include?(input_length)
515
+ else
516
+ allowed_length == input_length
517
+ end
518
+ end
519
+
512
520
  def valid_modulus_check_bank_code?
513
521
  return true if Ibandit.modulus_checker.valid_bank_code?(self)
514
522
 
515
- @errors[:bank_code] = Ibandit.translate(:failed_modulus_check)
523
+ @errors[:bank_code] = Ibandit.translate(:bank_code_does_not_exist)
516
524
  false
517
525
  end
518
526
 
519
527
  def valid_modulus_check_branch_code?
520
528
  return true if Ibandit.modulus_checker.valid_branch_code?(self)
521
529
 
522
- @errors[:branch_code] = Ibandit.translate(:failed_modulus_check)
530
+ @errors[:branch_code] = Ibandit.translate(:branch_code_does_not_exist)
523
531
  false
524
532
  end
525
533
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibandit
4
- VERSION = "1.19.0"
4
+ VERSION = "1.21.0"
5
5
  end
@@ -422,10 +422,55 @@ describe Ibandit::IBAN do
422
422
  {
423
423
  country_code: "CA",
424
424
  bank_code: bank_code,
425
- branch_code: "00063",
425
+ branch_code: branch_code,
426
426
  account_number: account_number,
427
427
  }
428
428
  end
429
+ let(:branch_code) { "00063" }
430
+
431
+ context "and a 5 digit branch code" do
432
+ let(:account_number) { "0123456" }
433
+ let(:bank_code) { "036" }
434
+ let(:branch_code) { "00063" }
435
+
436
+ its(:country_code) { is_expected.to eq("CA") }
437
+ its(:bank_code) { is_expected.to eq("0036") }
438
+ its(:branch_code) { is_expected.to eq("00063") }
439
+ its(:account_number) { is_expected.to eq("0123456") }
440
+ its(:swift_bank_code) { is_expected.to eq("0036") }
441
+ its(:swift_branch_code) { is_expected.to eq("00063") }
442
+ its(:swift_account_number) { is_expected.to eq("0123456") }
443
+ its(:swift_national_id) { is_expected.to eq("003600063") }
444
+ its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") }
445
+
446
+ its(:iban) { is_expected.to be_nil }
447
+ its(:valid?) { is_expected.to eq(true) }
448
+ its(:to_s) { is_expected.to eq("") }
449
+ end
450
+
451
+ context "for an all zero transit number" do
452
+ let(:account_number) { "0123456" }
453
+ let(:bank_code) { "036" }
454
+ let(:branch_code) { "00000" }
455
+
456
+ it "is invalid and has the correct errors" do
457
+ expect(subject.valid?).to eq(false)
458
+ expect(subject.errors).
459
+ to eq(branch_code: "format is invalid")
460
+ end
461
+ end
462
+
463
+ context "and a 4 digit branch code" do
464
+ let(:account_number) { "0123456" }
465
+ let(:bank_code) { "036" }
466
+ let(:branch_code) { "0063" }
467
+
468
+ it "is invalid and has the correct errors" do
469
+ expect(subject.valid?).to eq(false)
470
+ expect(subject.errors).
471
+ to eq(branch_code: "is the wrong length (should be 5 characters)")
472
+ end
473
+ end
429
474
 
430
475
  context "and a 3 digit bank code" do
431
476
  let(:account_number) { "0123456" }
@@ -1296,7 +1341,7 @@ describe Ibandit::IBAN do
1296
1341
  it { is_expected.to be(false) }
1297
1342
 
1298
1343
  it "sets the errors on the IBAN" do
1299
- expect(iban.errors).to include(bank_code: "did not pass modulus check")
1344
+ expect(iban.errors).to include(bank_code: "bank code does not exist")
1300
1345
  end
1301
1346
  end
1302
1347
 
@@ -1323,7 +1368,7 @@ describe Ibandit::IBAN do
1323
1368
  it { is_expected.to be(false) }
1324
1369
 
1325
1370
  it "sets the errors on the IBAN" do
1326
- expect(iban.errors).to include(branch_code: "did not pass modulus check")
1371
+ expect(iban.errors).to include(branch_code: "branch code does not exist")
1327
1372
  end
1328
1373
  end
1329
1374
 
@@ -1536,7 +1581,7 @@ describe Ibandit::IBAN do
1536
1581
  it { is_expected.to be(false) }
1537
1582
 
1538
1583
  it "sets the errors on the IBAN" do
1539
- expect(iban.errors).to include(branch_code: "did not pass modulus check")
1584
+ expect(iban.errors).to include(branch_code: "branch code does not exist")
1540
1585
  end
1541
1586
  end
1542
1587
  end
@@ -1601,7 +1646,7 @@ describe Ibandit::IBAN do
1601
1646
  it { is_expected.to be(false) }
1602
1647
 
1603
1648
  it "sets the errors on the IBAN" do
1604
- expect(iban.errors).to include(branch_code: "did not pass modulus check")
1649
+ expect(iban.errors).to include(branch_code: "branch code does not exist")
1605
1650
  end
1606
1651
  end
1607
1652
  end
@@ -1666,7 +1711,7 @@ describe Ibandit::IBAN do
1666
1711
  it { is_expected.to be(false) }
1667
1712
 
1668
1713
  it "sets the errors on the IBAN" do
1669
- expect(iban.errors).to include(branch_code: "did not pass modulus check")
1714
+ expect(iban.errors).to include(branch_code: "branch code does not exist")
1670
1715
  end
1671
1716
  end
1672
1717
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibandit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.0
4
+ version: 1.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-03 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gc_ruboconfig
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.3'
19
+ version: '5.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.3'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement