Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always generate reference number of length 7 #1679

Merged
merged 5 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions app/models/bank_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ def autobind_invoice(manual: false)
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
Expand Down Expand Up @@ -121,7 +117,8 @@ def parsed_ref_number
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 || Billing::ReferenceNo.valid?(match)
end
end
end
8 changes: 7 additions & 1 deletion app/models/billing/reference_no.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion app/models/billing/reference_no/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down