mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
Merge branch 'master' into 1101-topping-up-credit-account-without-an-invoice
This commit is contained in:
commit
df79982881
4 changed files with 18 additions and 4 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
10.09.2020
|
||||||
|
* New registrar ref nr are now always created 7 digits long [#1679](https://github.com/internetee/registry/pull/1679)
|
||||||
|
|
||||||
08.09.2020
|
08.09.2020
|
||||||
* Removed bank statement import option [#1674](https://github.com/internetee/registry/pull/1674)
|
* Removed bank statement import option [#1674](https://github.com/internetee/registry/pull/1674)
|
||||||
* Fixed error with reference nr not being found in the transaction [#1677](https://github.com/internetee/registry/issues/1677)
|
* Fixed error with reference nr not being found in the transaction [#1677](https://github.com/internetee/registry/issues/1677)
|
||||||
|
|
|
@ -120,7 +120,12 @@ class BankTransaction < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def ref_number_from_description
|
def ref_number_from_description
|
||||||
match_data = /(\d{7})/.match(description)
|
(Billing::ReferenceNo::MULTI_REGEXP.match(description) || []).captures.each do |match|
|
||||||
match_data[0] if match_data.present?
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
module Billing
|
module Billing
|
||||||
class ReferenceNo
|
class ReferenceNo
|
||||||
REGEXP = /\A\d{2,20}\z/
|
REGEXP = /\A\d{2,20}\z/.freeze
|
||||||
|
MULTI_REGEXP = /(\d{2,20})/.freeze
|
||||||
|
|
||||||
def self.generate
|
def self.generate
|
||||||
base = Base.generate
|
base = Base.generate
|
||||||
"#{base}#{base.check_digit}"
|
"#{base}#{base.check_digit}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.valid?(ref)
|
||||||
|
base = Base.new(ref.to_s[0...-1])
|
||||||
|
ref.to_s == "#{base}#{base.check_digit}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ module Billing
|
||||||
class ReferenceNo
|
class ReferenceNo
|
||||||
class Base
|
class Base
|
||||||
def self.generate
|
def self.generate
|
||||||
new(SecureRandom.random_number(1..1_000_000))
|
new((SecureRandom.random_number(9e5) + 1e5).to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(base)
|
def initialize(base)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue