mirror of
https://github.com/internetee/registry.git
synced 2025-08-11 12:09:34 +02:00
added toggle feature
This commit is contained in:
parent
7e0c6b3afb
commit
ef03166fee
6 changed files with 61 additions and 38 deletions
|
@ -3,6 +3,7 @@ module EisBilling
|
||||||
protect_from_forgery with: :null_session
|
protect_from_forgery with: :null_session
|
||||||
skip_authorization_check # Temporary solution
|
skip_authorization_check # Temporary solution
|
||||||
# skip_before_action :verify_authenticity_token # Temporary solution
|
# skip_before_action :verify_authenticity_token # Temporary solution
|
||||||
|
before_action :persistent
|
||||||
before_action :authorized
|
before_action :authorized
|
||||||
|
|
||||||
def encode_token(payload)
|
def encode_token(payload)
|
||||||
|
@ -47,5 +48,11 @@ module EisBilling
|
||||||
def logger
|
def logger
|
||||||
@logger ||= Rails.logger
|
@logger ||= Rails.logger
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def persistent
|
||||||
|
return true if Feature.billing_system_integrated?
|
||||||
|
|
||||||
|
render json: { message: "We don't work yet!" }, status: :unauthorized
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,10 +4,13 @@ module Billing
|
||||||
MULTI_REGEXP = /(\d{2,20})/
|
MULTI_REGEXP = /(\d{2,20})/
|
||||||
|
|
||||||
def self.generate
|
def self.generate
|
||||||
# base = Base.generate
|
if Feature.billing_system_integrated?
|
||||||
# "#{base}#{base.check_digit}"
|
result = EisBilling::GetReferenceNumber.send_request
|
||||||
result = EisBilling::GetReferenceNumber.send_request
|
JSON.parse(result.body)['reference_number']
|
||||||
JSON.parse(result.body)['reference_number']
|
else
|
||||||
|
base = Base.generate
|
||||||
|
"#{base}#{base.check_digit}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.valid?(ref)
|
def self.valid?(ref)
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
class Feature
|
class Feature
|
||||||
# def self.obj_and_extensions_statuses_enabled?
|
def self.billing_system_integrated?
|
||||||
# return false if ENV['obj_and_extensions_prohibited'] == 'false'
|
return false if ENV['billing_system_integrated'] == 'false'
|
||||||
#
|
|
||||||
# ENV['obj_and_extensions_prohibited'] || false
|
ENV['billing_system_integrated'] || false
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# def self.enable_lock_domain_with_new_statuses?
|
|
||||||
# return false if ENV['enable_lock_domain_with_new_statuses'] == 'false'
|
|
||||||
#
|
|
||||||
# ENV['enable_lock_domain_with_new_statuses'] || false
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,21 +41,41 @@ class Invoice < ApplicationRecord
|
||||||
attribute :vat_rate, ::Type::VatRate.new
|
attribute :vat_rate, ::Type::VatRate.new
|
||||||
|
|
||||||
def set_invoice_number
|
def set_invoice_number
|
||||||
result = EisBilling::GetInvoiceNumber.send_invoice
|
if Feature.billing_system_integrated?
|
||||||
|
result = EisBilling::GetInvoiceNumber.send_invoice
|
||||||
|
|
||||||
if JSON.parse(result.body)['code'] == '403'
|
if JSON.parse(result.body)['code'] == '403'
|
||||||
errors.add(:base, I18n.t('cannot get access'))
|
errors.add(:base, I18n.t('cannot get access'))
|
||||||
logger.error('PROBLEM WITH TOKEN')
|
logger.error('PROBLEM WITH TOKEN')
|
||||||
throw(:abort)
|
throw(:abort)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if JSON.parse(result.body)['error'] == 'out of range'
|
||||||
|
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
|
||||||
|
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
||||||
|
throw(:abort)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.number = JSON.parse(result.body)['invoice_number'].to_i
|
||||||
|
else
|
||||||
|
last_no = Invoice.all
|
||||||
|
.where(number: Setting.invoice_number_min.to_i...Setting.invoice_number_max.to_i)
|
||||||
|
.order(number: :desc)
|
||||||
|
.limit(1)
|
||||||
|
.pick(:number)
|
||||||
|
|
||||||
|
if last_no && last_no >= Setting.invoice_number_min.to_i
|
||||||
|
self.number = last_no + 1
|
||||||
|
else
|
||||||
|
self.number = Setting.invoice_number_min.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
return if number <= Setting.invoice_number_max.to_i
|
||||||
|
|
||||||
if JSON.parse(result.body)['error'] == 'out of range'
|
|
||||||
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
|
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
|
||||||
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
||||||
throw(:abort)
|
throw(:abort)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.number = JSON.parse(result.body)['invoice_number'].to_i
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
@ -107,21 +107,20 @@ class Registrar < ApplicationRecord
|
||||||
.deliver_later(wait: 1.minute)
|
.deliver_later(wait: 1.minute)
|
||||||
end
|
end
|
||||||
|
|
||||||
unless Rails.env.staging?
|
if Feature.billing_system_integrated?
|
||||||
SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
add_invoice_instance = EisBilling::AddDeposits.new(invoice)
|
||||||
|
result = add_invoice_instance.send_invoice
|
||||||
|
|
||||||
|
link = JSON.parse(result.body)['everypay_link']
|
||||||
|
|
||||||
|
invoice.update(payment_link: link)
|
||||||
end
|
end
|
||||||
|
|
||||||
add_invoice_instance = EisBilling::AddDeposits.new(invoice)
|
if Feature.billing_system_integrated?
|
||||||
result = add_invoice_instance.send_invoice
|
SendEInvoiceTwoJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
||||||
|
else
|
||||||
link = JSON.parse(result.body)['everypay_link']
|
SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
||||||
|
end
|
||||||
invoice.update(payment_link: link)
|
|
||||||
|
|
||||||
Rails.logger.info "Invoice created from transaction ------->"
|
|
||||||
Rails.logger.info invoice
|
|
||||||
Rails.logger.info result.body
|
|
||||||
Rails.logger.info "-----------------------------------------"
|
|
||||||
|
|
||||||
invoice
|
invoice
|
||||||
end
|
end
|
||||||
|
|
|
@ -237,4 +237,4 @@ nameserver_validation_timeout: '1'
|
||||||
|
|
||||||
eis_billing_system_base_url_dev: 'http://eis_billing_system:3000'
|
eis_billing_system_base_url_dev: 'http://eis_billing_system:3000'
|
||||||
eis_billing_system_base_url_staging: 'https://st-billing.infra.tld.ee'
|
eis_billing_system_base_url_staging: 'https://st-billing.infra.tld.ee'
|
||||||
eis_token:
|
billing_system_integrated: 'true'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue