Skip to content

Commit

Permalink
Merge pull request #187 from gocardless/better-ibandit-errors
Browse files Browse the repository at this point in the history
Improve IBAN validation errors
  • Loading branch information
thekeshavgoel authored Mar 29, 2023
2 parents c278a4c + 9cb123d commit 8b0904f
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.15.0 - March 28, 2023

- Improve the error messages that are generated

## 1.14.0 - March 28, 2023

- Update IBAN registry #233
Expand Down
7 changes: 7 additions & 0 deletions config/locales/da.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ da:
invalid_format: "Uventet format for en IBAN fra %{country_code}."
is_invalid: "er ugyldig"
does_not_support_payments: "understøtter ikke betalinger"
has_invalid_format: "ugyldigt format"
failed_checksum_test: "bestod ikke kontrolsumtesten"
failed_modulus_check: "bestod ikke moduluskontrollen"
has_invalid_length: "ugyldig længde"
bank_code_does_not_exist: "bankkoden findes ikke"
has_invalid_clearing_code_length: "længden på clearingskoden er ugyldig"
has_invalid_serial_number: "ugyldigt serienummer"
7 changes: 7 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ de:
invalid_format: "Unerwartetes Format für eine %{country_code}-IBAN."
is_invalid: "ist ungültig"
does_not_support_payments: "unterstützt keine Zahlungen"
has_invalid_format: "Format ist ungültig"
failed_checksum_test: "Prüfsummentest nicht bestanden"
failed_modulus_check: "Modulprüfung nicht bestanden"
has_invalid_length: "Länge ist ungültig"
bank_code_does_not_exist: "Bankleitzahl existiert nicht"
has_invalid_clearing_code_length: "Länge des Verrechnungscodes ist ungültig"
has_invalid_serial_number: "Seriennummer ist ungültig"
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ en:
invalid_format: "Unexpected format for a %{country_code} IBAN."
is_invalid: "is invalid"
does_not_support_payments: "does not support payments"
has_invalid_format: "format is invalid"
failed_checksum_test: "did not pass checksum test"
failed_modulus_check: "did not pass modulus check"
has_invalid_length: "length is invalid"
bank_code_does_not_exist: "bank code does not exist"
has_invalid_clearing_code_length: "clearing code length is invalid"
has_invalid_serial_number: "serial number is invalid"
7 changes: 7 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ es:
invalid_format: "Formato inesperado para un IBAN de %{country_code}."
is_invalid: "no es válido"
does_not_support_payments: "no admite pagos"
has_invalid_format: "formato invalido"
failed_checksum_test: "fallo en suma de control"
failed_modulus_check: "fallo en control de modulo"
has_invalid_length: "tamaño invalido"
bank_code_does_not_exist: "codigo bancario inexistente"
has_invalid_clearing_code_length: "codigo de oficina de oficina de compensación invalido"
has_invalid_serial_number: "número de serie invalido"
7 changes: 7 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ fr:
invalid_format: "Format non attendu pour un IBAN %{country_code}."
is_invalid: "n'est pas valide"
does_not_support_payments: "ne prend pas en charge les paiements"
has_invalid_format: "le format n'est pas valide"
failed_checksum_test: "échec du test de la somme de contrôle"
failed_modulus_check: "échec du test de module"
has_invalid_length: "la longueur n'est pas valide"
bank_code_does_not_exist: "le code de la banque n'existe pas"
has_invalid_clearing_code_length: "la longueur du clearing code n'est pas valide"
has_invalid_serial_number: "le numéro de série n'est pas valide"
10 changes: 9 additions & 1 deletion config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ it:
non_alphanumeric_characters: "Caratteri non alfanumerici trovati: %{characters}"
invalid_format: "Formato imprevisto per un IBAN %{country_code}."
is_invalid: "non è valido"
does_not_support_payments: "non supporta i pagamenti"
does_not_support_payments: "non supporta i pagamenti"
has_invalid_format: "formato non valido"
failed_checksum_test: "test del checksum non superato"
failed_modulus_check: "test del modulo non superato"
has_invalid_length: "lunghezza non valida"
bank_code_does_not_exist: "codice banca inesistente"
has_invalid_clearing_code_length: "lunghezza clearing code non valida"
has_invalid_serial_number: "numero di serie non valido"

7 changes: 7 additions & 0 deletions config/locales/nb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ nb:
invalid_format: "Uventet format for IBAN for %{country_code}."
is_invalid: "er ikke gyldig"
does_not_support_payments: "støtter ikke betalinger"
has_invalid_format: "formatet er ugyldig"
failed_checksum_test: "besto ikke kontrollsumtesten"
failed_modulus_check: "besto ikke tallverdikontrollen"
has_invalid_length: "ugyldig lengde"
bank_code_does_not_exist: "bankkoden eksisterer ikke"
has_invalid_clearing_code_length: "registreringsnummerets lengde er ugyldig"
has_invalid_serial_number: "ugyldig serienummer"
7 changes: 7 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ nl:
invalid_format: "Onverwachte formaat voor een %{country_code} IBAN."
is_invalid: "is ongeldig"
does_not_support_payments: "ondersteunt geen betalingen"
has_invalid_format: "indeling is ongeldig"
failed_checksum_test: "checksumtest is mislukt"
failed_modulus_check: "moduluscontrole is mislukt"
has_invalid_length: "lengte is ongeldig"
bank_code_does_not_exist: "bankcode bestaat niet"
has_invalid_clearing_code_length: "lengte clearingcode is ongeldig"
has_invalid_serial_number: "serienummer is ongeldig"
7 changes: 7 additions & 0 deletions config/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ pt:
invalid_format: "Formato inesperado para um IBAN %{country_code}."
is_invalid: "é inválido"
does_not_support_payments: "não suporta pagamentos"
has_invalid_format: "o formato é inválido"
failed_checksum_test: "não passou no teste de verificação de soma"
failed_modulus_check: "não passou na verificação do módulo"
has_invalid_length: "o comprimento é inválido"
bank_code_does_not_exist: "o código do banco não existe"
has_invalid_clearing_code_length: "o comprimento do código de libertação é inválido"
has_invalid_serial_number: "o número de série é inválido"
7 changes: 7 additions & 0 deletions config/locales/sl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ sl:
invalid_format: "Nepričakovana oblika zapisa %{country_code} v IBAN."
is_invalid: "ni veljavno"
does_not_support_payments: "ne podpira plačil"
has_invalid_format: "oblika zapisa ni veljavna"
failed_checksum_test: "neuspešen preizkus kontrolne vsote"
failed_modulus_check: "neuspešno preverjanje modula"
has_invalid_length: "dolžina ni veljavna"
bank_code_does_not_exist: "koda banke ne obstaja"
has_invalid_clearing_code_length: "dolžina klirinške kode ni veljavna"
has_invalid_serial_number: "serijska številka ni veljavna"
7 changes: 7 additions & 0 deletions config/locales/sv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ sv:
invalid_format: "Oväntat format för %{country_code} IBAN."
is_invalid: "är ogiltig"
does_not_support_payments: "stödjer inte betalningar"
has_invalid_format: "ogiltigt format"
failed_checksum_test: "felaktig kontrollsumma"
failed_modulus_check: "felaktig modulkontroll"
has_invalid_length: "ogiltig längd"
bank_code_does_not_exist: "bankkoden existerar inte"
has_invalid_clearing_code_length: "clearingnumrets längd är ogiltigt"
has_invalid_serial_number: "ogiltigt serienummer"
22 changes: 11 additions & 11 deletions lib/ibandit/iban.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def valid_bank_code_format?
)
true
else
@errors[:bank_code] = Ibandit.translate(:is_invalid)
@errors[:bank_code] = Ibandit.translate(:has_invalid_format)
false
end
end
Expand All @@ -261,7 +261,7 @@ def valid_branch_code_format?
)
true
else
@errors[:branch_code] = Ibandit.translate(:is_invalid)
@errors[:branch_code] = Ibandit.translate(:has_invalid_format)
false
end
end
Expand All @@ -274,7 +274,7 @@ def valid_account_number_format?
)
true
else
@errors[:account_number] = Ibandit.translate(:is_invalid)
@errors[:account_number] = Ibandit.translate(:has_invalid_format)
false
end
end
Expand Down Expand Up @@ -332,7 +332,7 @@ def valid_swedish_details?
def valid_swedish_swift_details?
unless Sweden::Validator.bank_code_exists?(swift_bank_code)
bank_code_field = bank_code.nil? ? :account_number : :bank_code
@errors[bank_code_field] = Ibandit.translate(:is_invalid)
@errors[bank_code_field] = Ibandit.translate(:bank_code_does_not_exist)
@errors.delete(:bank_code) if bank_code.nil?
return false
end
Expand All @@ -344,7 +344,7 @@ def valid_swedish_swift_details?
)

unless length_valid
@errors[:account_number] = Ibandit.translate(:is_invalid)
@errors[:account_number] = Ibandit.translate(:has_invalid_length)
return false
end

Expand All @@ -353,7 +353,7 @@ def valid_swedish_swift_details?

def valid_swedish_local_details?
unless Sweden::Validator.valid_clearing_code_length?(branch_code)
@errors[:branch_code] = Ibandit.translate(:is_invalid)
@errors[:branch_code] = Ibandit.translate(:has_invalid_clearing_code_length)
return false
end

Expand All @@ -363,7 +363,7 @@ def valid_swedish_local_details?
)

unless valid_serial_number
@errors[:account_number] = Ibandit.translate(:is_invalid)
@errors[:account_number] = Ibandit.translate(:has_invalid_serial_number)
return false
end

Expand Down Expand Up @@ -410,7 +410,7 @@ def bank_code_passes_checksum_test?
(1 * (code_digits[2] + code_digits[5] + code_digits[8]))
) % 10

@errors[:bank_code] = Ibandit.translate(:is_invalid) unless mod.zero?
@errors[:bank_code] = Ibandit.translate(:failed_checksum_test) unless mod.zero?

mod.zero?
end
Expand Down Expand Up @@ -518,21 +518,21 @@ def formatted
def valid_modulus_check_bank_code?
return true if Ibandit.modulus_checker.valid_bank_code?(self)

@errors[:bank_code] = Ibandit.translate(:is_invalid)
@errors[:bank_code] = Ibandit.translate(:failed_modulus_check)
false
end

def valid_modulus_check_branch_code?
return true if Ibandit.modulus_checker.valid_branch_code?(self)

@errors[:branch_code] = Ibandit.translate(:is_invalid)
@errors[:branch_code] = Ibandit.translate(:failed_modulus_check)
false
end

def valid_modulus_check_account_number?
return true if Ibandit.modulus_checker.valid_account_number?(self)

@errors[:account_number] = Ibandit.translate(:is_invalid)
@errors[:account_number] = Ibandit.translate(:failed_modulus_check)
false
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ibandit/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Ibandit
VERSION = "1.14.0"
VERSION = "1.15.0"
end
39 changes: 21 additions & 18 deletions spec/ibandit/iban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@

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

Expand Down Expand Up @@ -715,7 +715,7 @@

it "returns an error on bank_code attribute" do
expect(subject.valid?).to eq(false)
expect(subject.errors).to eq(bank_code: "is invalid")
expect(subject.errors).to eq(bank_code: "did not pass checksum test")
end
end

Expand Down Expand Up @@ -810,7 +810,7 @@

it "is invalid and has an error populated" do
expect(subject.valid?).to eq(false)
expect(subject.errors).to eq(account_number: "is invalid")
expect(subject.errors).to eq(account_number: "format is invalid")
end
end
end
Expand Down Expand Up @@ -1144,7 +1144,7 @@

it "sets errors on the IBAN" do
iban.valid_bank_code_format?
expect(iban.errors).to include(bank_code: "is invalid")
expect(iban.errors).to include(bank_code: "format is invalid")
end
end

Expand Down Expand Up @@ -1185,7 +1185,7 @@

it "sets errors on the IBAN" do
iban.valid_branch_code_format?
expect(iban.errors).to include(branch_code: "is invalid")
expect(iban.errors).to include(branch_code: "format is invalid")
end
end

Expand Down Expand Up @@ -1225,7 +1225,7 @@

it "sets errors on the IBAN" do
iban.valid_account_number_format?
expect(iban.errors).to include(account_number: "is invalid")
expect(iban.errors).to include(account_number: "format is invalid")
end
end

Expand Down Expand Up @@ -1285,7 +1285,7 @@
it { is_expected.to be(false) }

it "sets the errors on the IBAN" do
expect(iban.errors).to include(bank_code: "is invalid")
expect(iban.errors).to include(bank_code: "did not pass modulus check")
end
end

Expand All @@ -1312,7 +1312,7 @@
it { is_expected.to be(false) }

it "sets the errors on the IBAN" do
expect(iban.errors).to include(branch_code: "is invalid")
expect(iban.errors).to include(branch_code: "did not pass modulus check")
end
end

Expand All @@ -1332,7 +1332,7 @@
it { is_expected.to be(false) }

it "sets the errors on the IBAN" do
expect(iban.errors).to include(account_number: "is invalid")
expect(iban.errors).to include(account_number: "did not pass modulus check")
end
end
end
Expand Down Expand Up @@ -1376,7 +1376,7 @@

it "sets the errors on the IBAN" do
iban.valid_swedish_details?
expect(iban.errors).to eq(account_number: "is invalid")
expect(iban.errors).to eq(account_number: "length is invalid")
end
end

Expand All @@ -1393,7 +1393,10 @@

it "sets the errors on the IBAN" do
iban.valid?
expect(iban.errors).to include(account_number: "is invalid")
expect(iban.errors).to include(
account_number: "bank code does not exist",
format: "Unexpected format for a SE IBAN.",
)
expect(iban.errors).to_not include(:bank_code)
end
end
Expand All @@ -1411,7 +1414,7 @@

it "sets the errors on the IBAN" do
iban.valid_swedish_details?
expect(iban.errors).to eq(account_number: "is invalid")
expect(iban.errors).to eq(account_number: "length is invalid")
end
end
end
Expand Down Expand Up @@ -1441,7 +1444,7 @@

it "sets the errors on the IBAN" do
iban.valid_swedish_details?
expect(iban.errors).to eq(branch_code: "is invalid")
expect(iban.errors).to eq(branch_code: "clearing code length is invalid")
end
end

Expand All @@ -1458,7 +1461,7 @@

it "sets the errors on the IBAN" do
iban.valid_swedish_details?
expect(iban.errors).to eq(account_number: "is invalid")
expect(iban.errors).to eq(account_number: "serial number is invalid")
end
end
end
Expand Down Expand Up @@ -1522,7 +1525,7 @@
it { is_expected.to be(false) }

it "sets the errors on the IBAN" do
expect(iban.errors).to include(branch_code: "is invalid")
expect(iban.errors).to include(branch_code: "did not pass modulus check")
end
end
end
Expand Down Expand Up @@ -1587,7 +1590,7 @@
it { is_expected.to be(false) }

it "sets the errors on the IBAN" do
expect(iban.errors).to include(branch_code: "is invalid")
expect(iban.errors).to include(branch_code: "did not pass modulus check")
end
end
end
Expand Down Expand Up @@ -1652,7 +1655,7 @@
it { is_expected.to be(false) }

it "sets the errors on the IBAN" do
expect(iban.errors).to include(branch_code: "is invalid")
expect(iban.errors).to include(branch_code: "did not pass modulus check")
end
end
end
Expand Down

0 comments on commit 8b0904f

Please sign in to comment.