ibandit 0.11.13 → 0.11.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4949f38e6085a415b67480155a88e459266b0af0
4
- data.tar.gz: 00fe2984c26437234b467fa3afb49b9c07aa7559
3
+ metadata.gz: 3060e96d5d67d57e9759c68bfd68b4174b65291c
4
+ data.tar.gz: 259f05d4b483b3fc7d96fa22c9904301063ad8fc
5
5
  SHA512:
6
- metadata.gz: 7f8ea0e2d0d7bb0b20bd56a43ea1cd5f7dafe4d5f3279723d2aa41835ec2be2a96c31c6b22a778c21b194aa334749d1c2a6d75142b14bdc983d0e35fc479dd46
7
- data.tar.gz: 1166de4ea4b36c0e7f93811cb492ea417edb480684cc5c27eb90359ed27f3e81fab6526cec1f69c756ca17f166faa3fc40d04160947e99488e41b3555ef02f6d
6
+ metadata.gz: b9c623c432caaefd6aa60fbbf63f3c75380e7723f71164b21d3d6279b71a7416b96b7812932673b24cf09d849d3dfc2106792527e12f47836f4c14f294fbc305
7
+ data.tar.gz: 6244f013565d3f83c28f8d4d244a80b1fc89d8cd533607f02ac919331e1bba02ea79e5f3576274fc990bc34ee078d2cfcca53a3d973f0158ab76ae04ebc7f776
@@ -1,3 +1,7 @@
1
+ ## 0.11.14 - July 26, 2018
2
+
3
+ - Add support for NZ pseudo-IBANs
4
+
1
5
  ## 0.11.13 - May 30, 2018
2
6
 
3
7
  - Allow 5-digits Australian account numbers
data/README.md CHANGED
@@ -46,6 +46,7 @@ For example:
46
46
  | Malta | :white_check_mark: | :white_check_mark: | |
47
47
  | Netherlands | :white_check_mark: | :white_check_mark: | |
48
48
  | Norway | :white_check_mark: | :white_check_mark: | |
49
+ | New Zealand | | | :white_check_mark: |
49
50
  | Poland | :white_check_mark: | :white_check_mark: | |
50
51
  | Portugal | :white_check_mark: | :white_check_mark: | |
51
52
  | Romania | :white_check_mark: | :white_check_mark: | |
@@ -516,6 +517,31 @@ iban.country_code # => "AU"
516
517
  iban.branch_code # => "123456"
517
518
  iban.account_number # => "123456789"
518
519
  iban.iban # => nil
520
+
521
+ # New Zealand
522
+ iban = Ibandit::IBAN.new(
523
+ country_code: 'NZ',
524
+ bank_code: '01',
525
+ branch_code: '5659',
526
+ account_number: '3333333-44' # 7 digit account number and 2/3-digit account suffix
527
+ )
528
+ iban.pseudo_iban # => "NZZZ0156593333333044"
529
+ iban.iban # => nil
530
+
531
+ iban = Ibandit::IBAN.new(
532
+ country_code: 'NZ',
533
+ account_number: '01-5659-3333333-44'
534
+ )
535
+ iban.pseudo_iban # => "NZZZ0156593333333044"
536
+ iban.bank_code # => "01"
537
+ iban.branch_code # => "5659"
538
+ iban.account_number # => "3333333044"
539
+
540
+ iban = Ibandit::IBAN.new('NZZZ0156593333333044')
541
+ iban.country_code # => "NZ"
542
+ iban.bank_code # => "01"
543
+ iban.branch_code # => "5659"
544
+ iban.account_number # => "3333333044"
519
545
  ```
520
546
 
521
547
  ## Other libraries
@@ -528,4 +554,4 @@ details.
528
554
 
529
555
  ---
530
556
 
531
- GoCardless ♥ open source. If you do too, come [join us](https://gocardless.com/about/jobs/software-engineer).
557
+ GoCardless ♥ open source. If you do too, come [join us](https://gocardless.com/about/jobs/software-engineer).
@@ -647,6 +647,17 @@ NL:
647
647
  :account_number_format: "\\d{6}\\d{1}"
648
648
  :local_check_digit_position: 15
649
649
  :local_check_digit_length: 1
650
+ NZ:
651
+ :bank_code_length: 2
652
+ :branch_code_length: 4
653
+ :account_number_length: 10
654
+ :bank_code_format: "\\d{2}"
655
+ :branch_code_format: "\\d{4}"
656
+ :account_number_format: "\\d{7}\\d{3}"
657
+ :pseudo_iban_bank_code_length: 2
658
+ :pseudo_iban_branch_code_length: 4
659
+ :pseudo_iban_account_number_length: 10
660
+ :national_id_length: 6
650
661
  PK:
651
662
  :bank_code_position: 5
652
663
  :bank_code_length: 4
@@ -4,7 +4,7 @@ module Ibandit
4
4
  HR HU IE IS IT LT LU LV MC MT NL NO PL
5
5
  PT RO SE SI SK SM].freeze
6
6
 
7
- PSEUDO_IBAN_COUNTRY_CODES = %w[AU SE].freeze
7
+ PSEUDO_IBAN_COUNTRY_CODES = %w[AU SE NZ].freeze
8
8
  DECONSTRUCTABLE_IBAN_COUNTRY_CODES =
9
9
  CONSTRUCTABLE_IBAN_COUNTRY_CODES - PSEUDO_IBAN_COUNTRY_CODES
10
10
 
@@ -13,6 +13,7 @@ module Ibandit
13
13
  PSEUDO_IBAN_PADDING_CHARACTER_FOR = {
14
14
  "SE" => "X", # Using X for backwards compatibility
15
15
  "AU" => "_", # Using _ because AU account numbers are alphanumeric
16
+ "NZ" => "_",
16
17
  }.freeze
17
18
 
18
19
  SUPPORTED_COUNTRY_CODES = (
@@ -3,8 +3,8 @@ require "yaml"
3
3
  module Ibandit
4
4
  class IBAN
5
5
  attr_reader :errors, :iban, :country_code, :check_digits, :bank_code,
6
- :branch_code, :account_number, :swift_bank_code,
7
- :swift_branch_code, :swift_account_number, :source
6
+ :branch_code, :swift_bank_code, :swift_branch_code,
7
+ :swift_account_number, :source
8
8
 
9
9
  def initialize(argument)
10
10
  if argument.is_a?(String)
@@ -52,6 +52,18 @@ module Ibandit
52
52
  national_id.slice(0, structure[:national_id_length])
53
53
  end
54
54
 
55
+ def account_number
56
+ return @account_number unless country_code == "NZ"
57
+
58
+ @account_number[0..6]
59
+ end
60
+
61
+ def account_number_suffix
62
+ return nil unless country_code == "NZ"
63
+
64
+ @account_number[7..-1]
65
+ end
66
+
55
67
  def local_check_digits
56
68
  return unless decomposable? && structure[:local_check_digit_position]
57
69
 
@@ -70,7 +82,7 @@ module Ibandit
70
82
  country_code: country_code,
71
83
  bank_code: bank_code,
72
84
  branch_code: branch_code,
73
- account_number: account_number,
85
+ account_number: @account_number,
74
86
  ).assemble
75
87
  end
76
88
 
@@ -34,7 +34,8 @@ module Ibandit
34
34
  case country_code
35
35
  when "AT", "CY", "DE", "FI", "LT", "LU", "LV", "NL", "RO", "SI", "SK"
36
36
  %i[bank_code account_number]
37
- when "BE", "CZ", "DK", "EE", "ES", "HR", "HU", "IS", "NO", "PL", "SE"
37
+ when "BE", "CZ", "DK", "EE", "ES", "HR",
38
+ "HU", "IS", "NO", "PL", "SE", "NZ"
38
39
  %i[account_number]
39
40
  when "GB", "IE", "MT"
40
41
  if Ibandit.bic_finder.nil? then %i[bank_code branch_code account_number]
@@ -434,6 +435,45 @@ module Ibandit
434
435
  }
435
436
  end
436
437
 
438
+ def self.clean_nz_details(local_details)
439
+ # This method supports being passed the component parts of the NZ account
440
+ # number, or a single 15/16 digit string (BBbbbb-AAAAAAA-0SS) in the
441
+ # account number field.
442
+ #
443
+ # When given a 15/16 digit string, the component parts (i.e bank_code,
444
+ # branch_code and account_number) are extracted, with the 7-digit account
445
+ # number body and 2/3-digit account number suffix making up the actual
446
+ # account_number field.
447
+ if local_details[:bank_code] && local_details[:branch_code]
448
+ bank_code = local_details[:bank_code]
449
+ branch_code = local_details[:branch_code]
450
+ account_number = local_details[:account_number].tr("-", "")
451
+ else
452
+ cleaned_account_number = local_details[:account_number].tr("-", "")
453
+ bank_code = cleaned_account_number.slice(0, 2)
454
+ branch_code = cleaned_account_number.slice(2, 4)
455
+ account_number = cleaned_account_number[6..-1]
456
+ end
457
+
458
+ if account_number.length == 9
459
+ # > Some banks (such as BNZ) include three digits of the suffix in their
460
+ # > presentation of the account number to the end customer. Other banks
461
+ # > only show the last two digits of the suffix to the end customer.
462
+ # > Technically, all banks have three digit suffixes, it's just that the
463
+ # > first digit of the suffix is always 0 so it's usually ignored.
464
+ # > [https://en.wikipedia.org/wiki/New_Zealand_bank_account_number]
465
+ #
466
+ # Here, we insert the zero in cases where it is ignored.
467
+ account_number = account_number[0..6] + "0" + account_number[7..8]
468
+ end
469
+
470
+ {
471
+ bank_code: bank_code,
472
+ branch_code: branch_code,
473
+ account_number: account_number,
474
+ }
475
+ end
476
+
437
477
  def self.clean_pl_details(local_details)
438
478
  # This method supports being passed the component IBAN parts, as defined
439
479
  # by SWIFT, or a single 26 digit string.
@@ -31,8 +31,7 @@ module Ibandit
31
31
 
32
32
  def branch_code
33
33
  return unless country_code_valid?
34
- pseudo_iban_part(branch_code_start_index,
35
- :pseudo_iban_branch_code_length)
34
+ pseudo_iban_part(branch_code_start_index, :pseudo_iban_branch_code_length)
36
35
  end
37
36
 
38
37
  def account_number
@@ -1,3 +1,3 @@
1
1
  module Ibandit
2
- VERSION = "0.11.13".freeze
2
+ VERSION = "0.11.14".freeze
3
3
  end
@@ -54,6 +54,7 @@ describe Ibandit::IBAN do
54
54
  its(:bank_code) { is_expected.to eq("WEST") }
55
55
  its(:branch_code) { is_expected.to eq("123456") }
56
56
  its(:account_number) { is_expected.to eq("98765432") }
57
+ its(:account_number_suffix) { is_expected.to eq(nil) }
57
58
  its(:swift_bank_code) { is_expected.to eq("WEST") }
58
59
  its(:swift_branch_code) { is_expected.to eq("123456") }
59
60
  its(:swift_account_number) { is_expected.to eq("98765432") }
@@ -68,6 +69,7 @@ describe Ibandit::IBAN do
68
69
  its(:bank_code) { is_expected.to be_nil }
69
70
  its(:branch_code) { is_expected.to be_nil }
70
71
  its(:account_number) { is_expected.to be_nil }
72
+ its(:account_number_suffix) { is_expected.to be_nil }
71
73
  its(:swift_national_id) { is_expected.to be_nil }
72
74
  its(:bban) { is_expected.to be_nil }
73
75
  its(:local_check_digits) { is_expected.to be_nil }
@@ -81,6 +83,7 @@ describe Ibandit::IBAN do
81
83
  its(:bank_code) { is_expected.to be_nil }
82
84
  its(:branch_code) { is_expected.to be_nil }
83
85
  its(:account_number) { is_expected.to be_nil }
86
+ its(:account_number_suffix) { is_expected.to be_nil }
84
87
  its(:swift_bank_code) { is_expected.to eq("800") }
85
88
  its(:swift_branch_code) { is_expected.to be_nil }
86
89
  its(:swift_account_number) { is_expected.to eq("00000075071211203") }
@@ -94,6 +97,7 @@ describe Ibandit::IBAN do
94
97
  its(:bank_code) { is_expected.to eq("19100") }
95
98
  its(:branch_code) { is_expected.to be_nil }
96
99
  its(:account_number) { is_expected.to eq("0000123438") }
100
+ its(:account_number_suffix) { is_expected.to be_nil }
97
101
  its(:swift_bank_code) { is_expected.to eq("19100") }
98
102
  its(:swift_branch_code) { is_expected.to be_nil }
99
103
  its(:swift_account_number) { is_expected.to eq("0000123438") }
@@ -353,6 +357,119 @@ describe Ibandit::IBAN do
353
357
  branch_code: "is invalid")
354
358
  end
355
359
  end
360
+
361
+ context "when the IBAN was created with local details for New Zealand" do
362
+ let(:arg) do
363
+ {
364
+ country_code: "NZ",
365
+ bank_code: "11",
366
+ branch_code: "2222",
367
+ account_number: account_number,
368
+ }
369
+ end
370
+ context "with a 3 digit account number suffix" do
371
+ let(:account_number) { "3333333-944" }
372
+
373
+ its(:country_code) { is_expected.to eq("NZ") }
374
+ its(:bank_code) { is_expected.to eq("11") }
375
+ its(:branch_code) { is_expected.to eq("2222") }
376
+ its(:account_number) { is_expected.to eq("3333333") }
377
+ its(:account_number_suffix) { is_expected.to eq("944") }
378
+ its(:swift_bank_code) { is_expected.to eq("11") }
379
+ its(:swift_branch_code) { is_expected.to eq("2222") }
380
+ its(:swift_account_number) { is_expected.to eq("3333333944") }
381
+ its(:swift_national_id) { is_expected.to eq("112222") }
382
+ its(:iban) { is_expected.to be_nil }
383
+ its(:pseudo_iban) { is_expected.to eq("NZZZ1122223333333944") }
384
+ its(:valid?) { is_expected.to eq(true) }
385
+ its(:to_s) { is_expected.to eq("") }
386
+ end
387
+ context "with a 2 digit account number suffix" do
388
+ let(:account_number) { "3333333-44" }
389
+
390
+ its(:country_code) { is_expected.to eq("NZ") }
391
+ its(:bank_code) { is_expected.to eq("11") }
392
+ its(:branch_code) { is_expected.to eq("2222") }
393
+ its(:account_number) { is_expected.to eq("3333333") }
394
+ its(:account_number_suffix) { is_expected.to eq("044") }
395
+ its(:swift_bank_code) { is_expected.to eq("11") }
396
+ its(:swift_branch_code) { is_expected.to eq("2222") }
397
+ its(:swift_account_number) { is_expected.to eq("3333333044") }
398
+ its(:swift_national_id) { is_expected.to eq("112222") }
399
+ its(:iban) { is_expected.to be_nil }
400
+ its(:pseudo_iban) { is_expected.to eq("NZZZ1122223333333044") }
401
+ its(:valid?) { is_expected.to eq(true) }
402
+ its(:to_s) { is_expected.to eq("") }
403
+ end
404
+ context "with bank and branch code embedded in account_number field" do
405
+ let(:arg) do
406
+ {
407
+ country_code: "NZ",
408
+ account_number: "11-2222-3333333-44",
409
+ }
410
+ end
411
+
412
+ its(:country_code) { is_expected.to eq("NZ") }
413
+ its(:bank_code) { is_expected.to eq("11") }
414
+ its(:branch_code) { is_expected.to eq("2222") }
415
+ its(:account_number) { is_expected.to eq("3333333") }
416
+ its(:account_number_suffix) { is_expected.to eq("044") }
417
+ its(:swift_bank_code) { is_expected.to eq("11") }
418
+ its(:swift_branch_code) { is_expected.to eq("2222") }
419
+ its(:swift_account_number) { is_expected.to eq("3333333044") }
420
+ its(:swift_national_id) { is_expected.to eq("112222") }
421
+ its(:iban) { is_expected.to be_nil }
422
+ its(:pseudo_iban) { is_expected.to eq("NZZZ1122223333333044") }
423
+ its(:valid?) { is_expected.to eq(true) }
424
+ its(:to_s) { is_expected.to eq("") }
425
+ end
426
+ context "with a bank code embedded in account_number field" do
427
+ let(:arg) do
428
+ {
429
+ country_code: "NZ",
430
+ account_number: "11-3333333-44",
431
+ branch_code: "2222",
432
+ }
433
+ end
434
+
435
+ it "is invalid and has the correct errors" do
436
+ expect(subject.valid?).to eq(false)
437
+ expect(subject.errors).to eq(
438
+ account_number: "is the wrong length (should be 10 characters)",
439
+ )
440
+ end
441
+ end
442
+ end
443
+
444
+ context "when the IBAN was created from a New Zealand pseudo-IBAN" do
445
+ let(:arg) { "NZZZ1122223333333044" }
446
+
447
+ its(:country_code) { is_expected.to eq("NZ") }
448
+ its(:bank_code) { is_expected.to eq("11") }
449
+ its(:branch_code) { is_expected.to eq("2222") }
450
+ its(:account_number) { is_expected.to eq("3333333") }
451
+ its(:account_number_suffix) { is_expected.to eq("044") }
452
+ its(:swift_bank_code) { is_expected.to eq("11") }
453
+ its(:swift_branch_code) { is_expected.to eq("2222") }
454
+ its(:swift_account_number) { is_expected.to eq("3333333044") }
455
+ its(:swift_national_id) { is_expected.to eq("112222") }
456
+ its(:iban) { is_expected.to be_nil }
457
+ its(:pseudo_iban) { is_expected.to eq("NZZZ1122223333333044") }
458
+ its(:valid?) { is_expected.to eq(true) }
459
+ its(:to_s) { is_expected.to eq("") }
460
+ end
461
+
462
+ context "when the input is an invalid New Zealand pseudo-IBAN" do
463
+ let(:arg) { "NZZZ11222233333330444" }
464
+
465
+ its(:iban) { is_expected.to be_nil }
466
+ its(:pseudo_iban) { is_expected.to eq(arg) }
467
+ it "is invalid and has the correct errors" do
468
+ expect(subject.valid?).to eq(false)
469
+ expect(subject.errors).
470
+ to eq(account_number: "is the wrong length (should be 10 characters)")
471
+ end
472
+ end
356
473
  end
357
474
 
358
475
  describe "#to_s" do
@@ -2277,6 +2394,16 @@ describe Ibandit::IBAN do
2277
2394
  it { is_expected.to_not be_valid }
2278
2395
  end
2279
2396
 
2397
+ context "for a valid New Zealand pseudo-IBAN" do
2398
+ let(:iban_code) { "NZZZ5566667777777088" }
2399
+ it { is_expected.to be_valid }
2400
+ end
2401
+
2402
+ context "for an invalid New Zealand pseudo-IBAN" do
2403
+ let(:iban_code) { "NZZZ55666677777770888" }
2404
+ it { is_expected.to_not be_valid }
2405
+ end
2406
+
2280
2407
  context "for a valid Pakistani IBAN" do
2281
2408
  let(:iban_code) { "PK36 SCBL 0000 0011 2345 6702" }
2282
2409
  it { is_expected.to be_valid }
@@ -932,6 +932,38 @@ describe Ibandit::LocalDetailsCleaner do
932
932
  end
933
933
  end
934
934
 
935
+ context "New Zealand" do
936
+ let(:country_code) { "NZ" }
937
+ let(:bank_code) { "11" }
938
+ let(:branch_code) { "2222" }
939
+ let(:account_number) { "3333333044" }
940
+
941
+ it { is_expected.to eq(local_details_with_swift) }
942
+
943
+ context "with bank and branch codes in the account number" do
944
+ let(:bank_code) { nil }
945
+ let(:branch_code) { nil }
946
+ let(:account_number) { "11-2222-3333333-044" }
947
+
948
+ its([:bank_code]) { is_expected.to eq("11") }
949
+ its([:branch_code]) { is_expected.to eq("2222") }
950
+ its([:account_number]) { is_expected.to eq("3333333044") }
951
+
952
+ context "with a 2-digit account number suffix" do
953
+ let(:account_number) { "11-2222-3333333-44" }
954
+
955
+ its([:bank_code]) { is_expected.to eq("11") }
956
+ its([:branch_code]) { is_expected.to eq("2222") }
957
+ its([:account_number]) { is_expected.to eq("3333333044") }
958
+ end
959
+ end
960
+
961
+ context "without an account number" do
962
+ let(:account_number) { nil }
963
+ it { is_expected.to eq(local_details_with_swift) }
964
+ end
965
+ end
966
+
935
967
  context "Poland" do
936
968
  let(:country_code) { "PL" }
937
969
  let(:bank_code) { "10201026" }
@@ -87,6 +87,57 @@ describe Ibandit::PseudoIBANAssembler do
87
87
  end
88
88
  end
89
89
 
90
+ context "for New Zealand" do
91
+ context "with valid parameters" do
92
+ let(:local_details) do
93
+ {
94
+ country_code: "NZ",
95
+ bank_code: "11",
96
+ branch_code: "2222",
97
+ account_number: "3333333044",
98
+ }
99
+ end
100
+
101
+ it { is_expected.to eq("NZZZ1122223333333044") }
102
+ end
103
+
104
+ context "without a bank_code" do
105
+ let(:local_details) do
106
+ {
107
+ country_code: "NZ",
108
+ branch_code: "5569",
109
+ account_number: "1234567",
110
+ }
111
+ end
112
+
113
+ it { is_expected.to be_nil }
114
+ end
115
+
116
+ context "without a branch code" do
117
+ let(:local_details) do
118
+ {
119
+ country_code: "NZ",
120
+ bank_code: "01",
121
+ account_number: "1234567",
122
+ }
123
+ end
124
+
125
+ it { is_expected.to be_nil }
126
+ end
127
+
128
+ context "without an account number" do
129
+ let(:local_details) do
130
+ {
131
+ country_code: "NZ",
132
+ bank_code: "01",
133
+ branch_code: "5569",
134
+ }
135
+ end
136
+
137
+ it { is_expected.to be_nil }
138
+ end
139
+ end
140
+
90
141
  context "for a country that does not have pseudo-IBANs" do
91
142
  let(:local_details) do
92
143
  {
@@ -15,6 +15,15 @@ describe Ibandit::PseudoIBANSplitter do
15
15
  its([:account_number]) { is_expected.to eq("0105723") }
16
16
  end
17
17
 
18
+ context "for a New Zealand pseudo-IBAN" do
19
+ let(:pseudo_iban) { "NZZZ0156997777777030" }
20
+
21
+ its([:country_code]) { is_expected.to eq("NZ") }
22
+ its([:bank_code]) { is_expected.to eq("01") }
23
+ its([:branch_code]) { is_expected.to eq("5699") }
24
+ its([:account_number]) { is_expected.to eq("7777777030") }
25
+ end
26
+
18
27
  context "for an australian pseudo-IBAN" do
19
28
  let(:pseudo_iban) { "AUZZ123456123456789" }
20
29
 
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: 0.11.13
4
+ version: 0.11.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  requirements: []
208
208
  rubyforge_project:
209
- rubygems_version: 2.6.14
209
+ rubygems_version: 2.6.13
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Convert national banking details into IBANs, and vice-versa.