diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 4b6b6eda0..0370ad666 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -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 diff --git a/app/models/billing/reference_no.rb b/app/models/billing/reference_no.rb index 263100e79..d164f7565 100644 --- a/app/models/billing/reference_no.rb +++ b/app/models/billing/reference_no.rb @@ -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