Validate given reference number

This commit is contained in:
Karl Erik Õunapuu 2020-09-09 13:42:29 +03:00
parent 15470b7ec4
commit 166ff44491
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 6 additions and 1 deletions

View file

@ -118,7 +118,7 @@ class BankTransaction < ApplicationRecord
def ref_number_from_description
(Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match|
break match if match.length == 7 || Registrar.where(reference_no: match).present?
break match if match.length == 7 || Billing::ReferenceNo.valid?(match)
end
end
end

View file

@ -7,5 +7,10 @@ module Billing
base = Base.generate
"#{base}#{base.check_digit}"
end
def self.valid?(ref)
base = Base.new(ref.to_s[0...-1])
ref.to_s == "#{base}#{base.check_digit}"
end
end
end