Skip to content

Commit

Permalink
Merge pull request #245 from gocardless/ca_improvements
Browse files Browse the repository at this point in the history
Do not allow all-0 account numbers for CA; refactor all-0 check for AU
  • Loading branch information
rrundzansgc authored Oct 3, 2023
2 parents f0d8f87 + cbcef0d commit 6496977
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions data/raw/pseudo_ibans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AU:
end: 10
excl: false
:branch_code_format: "\\d{6}"
:account_number_format: "[A-Z0-9]{5,10}"
:account_number_format: "(?!0+\\z)[A-Z0-9]{5,10}"
:pseudo_iban_bank_code_length: 0
:pseudo_iban_branch_code_length: 6
:pseudo_iban_account_number_length: 10
Expand All @@ -21,7 +21,7 @@ CA:
excl: false
:bank_code_format: "\\d{4}"
:branch_code_format: "\\d{5}"
:account_number_format: "\\d{7,12}"
:account_number_format: "(?!0+\\z)\\d{7,12}"
:national_id_length: 9
:pseudo_iban_bank_code_length: 4
:pseudo_iban_branch_code_length: 5
Expand Down
4 changes: 2 additions & 2 deletions data/structures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ AU:
end: 10
excl: false
:branch_code_format: "\\d{6}"
:account_number_format: "[A-Z0-9]{5,10}"
:account_number_format: "(?!0+\\z)[A-Z0-9]{5,10}"
:pseudo_iban_bank_code_length: 0
:pseudo_iban_branch_code_length: 6
:pseudo_iban_account_number_length: 10
Expand All @@ -1501,7 +1501,7 @@ CA:
excl: false
:bank_code_format: "\\d{4}"
:branch_code_format: "\\d{5}"
:account_number_format: "\\d{7,12}"
:account_number_format: "(?!0+\\z)\\d{7,12}"
:national_id_length: 9
:pseudo_iban_bank_code_length: 4
:pseudo_iban_branch_code_length: 5
Expand Down
13 changes: 0 additions & 13 deletions lib/ibandit/iban.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,6 @@ def valid_ca_details?

def valid_australian_details?
return true unless country_code == "AU"

bsb_check? && account_number_not_all_zeros?
end

def bsb_check?
return true unless country_code == "AU"
return true unless Ibandit.modulus_checker

valid_modulus_check_branch_code?
Expand Down Expand Up @@ -550,12 +544,5 @@ def pseudo_iban?(input)

input.slice(2, 2) == Constants::PSEUDO_IBAN_CHECK_DIGITS
end

def account_number_not_all_zeros?
return true if @swift_account_number.to_s.chars.uniq != ["0"]

@errors[:account_number] = Ibandit.translate(:is_invalid)
false
end
end
end
11 changes: 11 additions & 0 deletions spec/ibandit/iban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,17 @@
its(:valid?) { is_expected.to be false }
end

context "and account number has only zeroes in it" do
let(:account_number) { "0000000" }
let(:bank_code) { "0036" }

it "is invalid and has the correct errors" do
expect(subject.valid?).to eq(false)
expect(subject.errors).
to eq(account_number: "format is invalid")
end
end

context "and a 12 digit account number" do
let(:account_number) { "012345678900" }
let(:bank_code) { "0036" }
Expand Down

0 comments on commit 6496977

Please sign in to comment.