mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 13:44:47 +02:00
Merge pull request #1679 from internetee/fix-reference-no-parsing
Always generate reference number of length 7
This commit is contained in:
commit
19600fee09
3 changed files with 16 additions and 9 deletions
|
@ -38,11 +38,7 @@ class BankTransaction < ApplicationRecord
|
|||
return unless invoice
|
||||
return unless invoice.payable?
|
||||
|
||||
channel = if manual
|
||||
'admin_payment'
|
||||
else
|
||||
'system_payment'
|
||||
end
|
||||
channel = manual ? 'admin_payment' : 'system_payment'
|
||||
create_internal_payment_record(channel: channel, invoice: invoice,
|
||||
registrar: registrar)
|
||||
end
|
||||
|
@ -121,7 +117,12 @@ class BankTransaction < ApplicationRecord
|
|||
end
|
||||
|
||||
def ref_number_from_description
|
||||
match_data = /(\d{7})/.match(description)
|
||||
match_data[0] if match_data.present?
|
||||
(Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match|
|
||||
break match if match.length == 7 || valid_ref_no?(match)
|
||||
end
|
||||
end
|
||||
|
||||
def valid_ref_no?(match)
|
||||
return true if Billing::ReferenceNo.valid?(match) && Registrar.find_by(reference_no: match).any?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
module Billing
|
||||
class ReferenceNo
|
||||
REGEXP = /\A\d{2,20}\z/
|
||||
REGEXP = /\A\d{2,20}\z/.freeze
|
||||
MULTI_REGEXP = /(\d{2,20})/.freeze
|
||||
|
||||
def self.generate
|
||||
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
|
||||
|
|
|
@ -2,7 +2,7 @@ module Billing
|
|||
class ReferenceNo
|
||||
class Base
|
||||
def self.generate
|
||||
new(SecureRandom.random_number(1..1_000_000))
|
||||
new((SecureRandom.random_number(9e5) + 1e5).to_i)
|
||||
end
|
||||
|
||||
def initialize(base)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue