mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 22:46:22 +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
|
||||
skip_authorization_check # Temporary solution
|
||||
# skip_before_action :verify_authenticity_token # Temporary solution
|
||||
before_action :persistent
|
||||
before_action :authorized
|
||||
|
||||
def encode_token(payload)
|
||||
|
@ -47,5 +48,11 @@ module EisBilling
|
|||
def logger
|
||||
@logger ||= Rails.logger
|
||||
end
|
||||
|
||||
def persistent
|
||||
return true if Feature.billing_system_integrated?
|
||||
|
||||
render json: { message: "We don't work yet!" }, status: :unauthorized
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,13 @@ module Billing
|
|||
MULTI_REGEXP = /(\d{2,20})/
|
||||
|
||||
def self.generate
|
||||
# base = Base.generate
|
||||
# "#{base}#{base.check_digit}"
|
||||
result = EisBilling::GetReferenceNumber.send_request
|
||||
JSON.parse(result.body)['reference_number']
|
||||
if Feature.billing_system_integrated?
|
||||
result = EisBilling::GetReferenceNumber.send_request
|
||||
JSON.parse(result.body)['reference_number']
|
||||
else
|
||||
base = Base.generate
|
||||
"#{base}#{base.check_digit}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.valid?(ref)
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
class Feature
|
||||
# def self.obj_and_extensions_statuses_enabled?
|
||||
# return false if ENV['obj_and_extensions_prohibited'] == 'false'
|
||||
#
|
||||
# ENV['obj_and_extensions_prohibited'] || false
|
||||
# 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
|
||||
def self.billing_system_integrated?
|
||||
return false if ENV['billing_system_integrated'] == 'false'
|
||||
|
||||
ENV['billing_system_integrated'] || false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,21 +41,41 @@ class Invoice < ApplicationRecord
|
|||
attribute :vat_rate, ::Type::VatRate.new
|
||||
|
||||
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'
|
||||
errors.add(:base, I18n.t('cannot get access'))
|
||||
logger.error('PROBLEM WITH TOKEN')
|
||||
throw(:abort)
|
||||
end
|
||||
if JSON.parse(result.body)['code'] == '403'
|
||||
errors.add(:base, I18n.t('cannot get access'))
|
||||
logger.error('PROBLEM WITH TOKEN')
|
||||
throw(:abort)
|
||||
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'))
|
||||
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
||||
throw(:abort)
|
||||
end
|
||||
|
||||
self.number = JSON.parse(result.body)['invoice_number'].to_i
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
|
@ -107,21 +107,20 @@ class Registrar < ApplicationRecord
|
|||
.deliver_later(wait: 1.minute)
|
||||
end
|
||||
|
||||
unless Rails.env.staging?
|
||||
SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
||||
if Feature.billing_system_integrated?
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
Rails.logger.info "Invoice created from transaction ------->"
|
||||
Rails.logger.info invoice
|
||||
Rails.logger.info result.body
|
||||
Rails.logger.info "-----------------------------------------"
|
||||
if Feature.billing_system_integrated?
|
||||
SendEInvoiceTwoJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
||||
else
|
||||
SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
||||
end
|
||||
|
||||
invoice
|
||||
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_staging: 'https://st-billing.infra.tld.ee'
|
||||
eis_token:
|
||||
billing_system_integrated: 'true'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue