remove eis-billing feature toggle

This commit is contained in:
olegphenomenon 2022-09-02 13:32:02 +03:00
parent 3ae8993313
commit c52da86865
22 changed files with 278 additions and 422 deletions

View file

@ -3,7 +3,6 @@ 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
INITIATOR = 'billing'.freeze
@ -49,11 +48,5 @@ module EisBilling
def 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

View file

@ -6,7 +6,8 @@ class SendEInvoiceJob < ApplicationJob
invoice = Invoice.find_by(id: invoice_id)
return unless need_to_process_invoice?(invoice: invoice, payable: payable)
process(invoice: invoice, payable: payable)
send_invoice_to_eis_billing(invoice: invoice, payable: payable)
invoice.update(e_invoice_sent_at: Time.zone.now)
rescue StandardError => e
log_error(invoice: invoice, error: e)
raise e
@ -16,23 +17,15 @@ class SendEInvoiceJob < ApplicationJob
def need_to_process_invoice?(invoice:, payable:)
logger.info "Checking if need to process e-invoice #{invoice}, payable: #{payable}"
unprocessable = invoice.do_not_send_e_invoice? && (invoice.monthly_invoice ? true : payable)
return false if invoice.blank?
return false if unprocessable
return false if invoice.do_not_send_e_invoice? && payable
true
end
def process(invoice:, payable:)
invoice.to_e_invoice(payable: payable).deliver unless Rails.env.development?
invoice.update(e_invoice_sent_at: Time.zone.now)
log_success(invoice)
end
def log_success(invoice)
id = invoice.try(:id) || invoice
message = "E-Invoice for an invoice with ID # #{id} was sent successfully"
logger.info message
def send_invoice_to_eis_billing(invoice:, payable:)
result = EisBilling::SendEInvoice.send_request(invoice: invoice, payable: payable)
logger.info result.body
end
def log_error(invoice:, error:)

View file

@ -1,4 +1,4 @@
class SendEInvoiceTwoJob < ApplicationJob
class SendEInvoiceLegacyJob < ApplicationJob
discard_on HTTPClient::TimeoutError
def perform(invoice_id, payable: true)
@ -6,8 +6,7 @@ class SendEInvoiceTwoJob < ApplicationJob
invoice = Invoice.find_by(id: invoice_id)
return unless need_to_process_invoice?(invoice: invoice, payable: payable)
send_invoice_to_eis_billing(invoice: invoice, payable: payable)
invoice.update(e_invoice_sent_at: Time.zone.now)
process(invoice: invoice, payable: payable)
rescue StandardError => e
log_error(invoice: invoice, error: e)
raise e
@ -17,15 +16,23 @@ class SendEInvoiceTwoJob < ApplicationJob
def need_to_process_invoice?(invoice:, payable:)
logger.info "Checking if need to process e-invoice #{invoice}, payable: #{payable}"
unprocessable = invoice.do_not_send_e_invoice? && (invoice.monthly_invoice ? true : payable)
return false if invoice.blank?
return false if invoice.do_not_send_e_invoice? && payable
return false if unprocessable
true
end
def send_invoice_to_eis_billing(invoice:, payable:)
result = EisBilling::SendEInvoice.send_request(invoice: invoice, payable: payable)
logger.info result.body
def process(invoice:, payable:)
invoice.to_e_invoice(payable: payable).deliver unless Rails.env.development?
invoice.update(e_invoice_sent_at: Time.zone.now)
log_success(invoice)
end
def log_success(invoice)
id = invoice.try(:id) || invoice
message = "E-Invoice for an invoice with ID # #{id} was sent successfully"
logger.info message
end
def log_error(invoice:, error:)

View file

@ -4,13 +4,8 @@ module Billing
MULTI_REGEXP = /(\d{2,20})/
def self.generate
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)

View file

@ -62,39 +62,13 @@ class Invoice < ApplicationRecord
throw(:abort)
end
def invoice_number_from_billing
def set_invoice_number
result = EisBilling::GetInvoiceNumber.send_invoice
validate_invoice_number(result)
self.number = JSON.parse(result.body)['invoice_number'].to_i
end
def generate_invoice_number_legacy
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
billing_out_of_range_issue
end
def set_invoice_number
if Feature.billing_system_integrated?
invoice_number_from_billing
else
generate_invoice_number_legacy
end
end
def to_s
I18n.t('invoice_no', no: number)
end

View file

@ -146,20 +146,13 @@ class Registrar < ApplicationRecord # rubocop:disable Metrics/ClassLength
.deliver_later(wait: 1.minute)
end
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
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

View file

@ -5405,8 +5405,10 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220113201642'),
('20220113220809'),
('20220124105717'),
('20220216113112'),
('20220228093211'),
('20220316140727'),
('20220406085500'),
('20220412130856'),
('20220413073315'),
('20220413084536'),

View file

@ -24,7 +24,6 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
end
def test_create_new_invoice
if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
@ -48,7 +47,6 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
assert_equal page.status_code, 200
end
end
def test_visit_list_of_invoices_pages
visit admin_invoices_path

View file

@ -10,7 +10,6 @@ class DirectoResponseTest < ApplicationIntegrationTest
end
def test_should_created_directo_instance
if Feature.billing_system_integrated?
directo_response_from_billing = {
response: @response_xml,
month: true
@ -21,10 +20,8 @@ class DirectoResponseTest < ApplicationIntegrationTest
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end
end
def test_should_update_related_invoice
if Feature.billing_system_integrated?
directo_response_from_billing = {
response: @response_xml
}
@ -39,5 +36,4 @@ class DirectoResponseTest < ApplicationIntegrationTest
@invoice.reload
assert @invoice.in_directo
end
end
end

View file

@ -8,8 +8,6 @@ class LhvConnectTransactionsIntegrationTest < ApplicationIntegrationTest
end
def test_should_saved_transaction_data
return unless Feature.billing_system_integrated?
test_transaction_1 = OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Time.zone.today,

View file

@ -28,13 +28,11 @@ class ReppV1InvoicesAddCreditTest < ActionDispatch::IntegrationTest
Setting.registry_vat_prc = 0.1
ENV['billing_system_integrated'] = 'true'
if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})
end
post '/repp/v1/invoices/add_credit', headers: @auth_headers,
params: request_body

View file

@ -16,8 +16,6 @@ class BankTransactionTest < ActiveSupport::TestCase
end
def test_binds_if_this_sum_invoice_already_present
return unless Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
@ -45,8 +43,6 @@ class BankTransactionTest < ActiveSupport::TestCase
end
def test_binds_if_this_sum_cancelled_invoice_already_present
return unless Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
@ -70,8 +66,6 @@ class BankTransactionTest < ActiveSupport::TestCase
end
def test_marks_the_first_one_as_paid_if_same_sum
return unless Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})

View file

@ -7,12 +7,10 @@ class ReferenceNoTest < ActiveSupport::TestCase
end
def test_generated_reference_number_conforms_to_format
if Feature.billing_system_integrated?
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator")
.to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
reference_no = Billing::ReferenceNo.generate
assert_match Billing::ReferenceNo::REGEXP, reference_no
end
end
end

View file

@ -1,53 +1,4 @@
require 'test_helper'
class FeatureTest < ActiveSupport::TestCase
# setup do
# @domain = domains(:shop)
# @domain.apply_registry_lock(extensions_prohibited: false)
# end
#
# def test_if_obj_and_extensions_prohibited_enabled
# ENV['obj_and_extensions_prohibited'] = 'true'
#
# assert Feature.obj_and_extensions_statuses_enabled?
#
# statuses = DomainStatus.admin_statuses
# assert statuses.include? DomainStatus::SERVER_OBJ_UPDATE_PROHIBITED
# end
#
# def test_if_obj_and_extensions_prohibited_is_nil
# ENV['obj_and_extensions_prohibited'] = nil
#
# assert_not Feature.obj_and_extensions_statuses_enabled?
#
# statuses = DomainStatus.admin_statuses
# assert_not statuses.include? DomainStatus::SERVER_OBJ_UPDATE_PROHIBITED
# end
#
# def test_if_obj_and_extensions_prohibited_is_false
# ENV['obj_and_extensions_prohibited'] = 'false'
#
# assert_not Feature.obj_and_extensions_statuses_enabled?
#
# statuses = DomainStatus.admin_statuses
# assert_not statuses.include? DomainStatus::SERVER_OBJ_UPDATE_PROHIBITED
# end
#
# def test_if_enable_lock_domain_with_new_statuses_is_nil
# ENV['enable_lock_domain_with_new_statuses'] = nil
#
# assert_not Feature.enable_lock_domain_with_new_statuses?
#
# assert_equal @domain.statuses, ["serverObjUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited"]
# assert @domain.locked_by_registrant?
# end
#
# def test_if_enable_lock_domain_with_new_statuses_is_false
# ENV['enable_lock_domain_with_new_statuses'] = 'false'
#
# assert_not Feature.enable_lock_domain_with_new_statuses?
#
# assert_equal @domain.statuses, ["serverObjUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited"]
# assert @domain.locked_by_registrant?
# end
end

View file

@ -118,7 +118,6 @@ class InvoiceTest < ActiveSupport::TestCase
end
def test_creates_invoice_with_bank_transaction_total
if Feature.billing_system_integrated?
registrar = registrars(:bestnames)
transaction = bank_transactions(:one).dup
transaction.reference_no = registrar.reference_no
@ -156,10 +155,8 @@ class InvoiceTest < ActiveSupport::TestCase
invoice = Invoice.create_from_transaction!(transaction)
assert_equal 0.99, invoice.total
end
end
def test_emails_invoice_after_creating_topup_invoice
if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
@ -182,5 +179,4 @@ class InvoiceTest < ActiveSupport::TestCase
Invoice.create_from_transaction!(transaction)
end
end
end
end

View file

@ -145,7 +145,6 @@ class RegistrarTest < ActiveJob::TestCase
end
def test_issues_new_invoice
if Feature.billing_system_integrated?
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
@ -167,10 +166,8 @@ class RegistrarTest < ActiveJob::TestCase
assert_equal Date.parse('2010-07-05'), invoice.issue_date
assert_equal Date.parse('2010-07-15'), invoice.due_date
end
end
def test_issues_e_invoice_along_with_invoice
if Feature.billing_system_integrated?
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
@ -183,17 +180,12 @@ class RegistrarTest < ActiveJob::TestCase
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
end
EInvoice::Providers::TestProvider.deliveries.clear
perform_enqueued_jobs do
@registrar.issue_prepayment_invoice(100)
end
unless Feature.billing_system_integrated?
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
end
end
def test_invalid_without_address_street

View file

@ -55,7 +55,6 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
end
def test_can_bind_statement_transactions
if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
@ -88,7 +87,6 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
assert_text 'Invoices were fully binded'
end
end
def create_bank_statement
visit admin_bank_statements_path

View file

@ -14,7 +14,6 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
end
def test_creates_new_registrar
if Feature.billing_system_integrated?
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
@ -38,7 +37,6 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
assert_text 'Registrar has been successfully created'
assert_text 'Acme Ltd'
end
end
def test_updates_registrar
assert_not_equal 'New name', @registrar.name

View file

@ -15,7 +15,6 @@ class BalanceTopUpTest < ApplicationSystemTestCase
end
def test_creates_new_invoice
if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
@ -42,5 +41,4 @@ class BalanceTopUpTest < ApplicationSystemTestCase
assert_equal BigDecimal('28.05'), invoice.total
assert_text 'Please pay the following invoice'
end
end
end

View file

@ -17,7 +17,6 @@ class NewInvoiceTest < ApplicationSystemTestCase
end
def test_create_new_invoice_with_positive_amount
if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
@ -42,10 +41,8 @@ class NewInvoiceTest < ApplicationSystemTestCase
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end
end
def test_create_new_invoice_with_comma_in_number
if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
@ -70,7 +67,6 @@ class NewInvoiceTest < ApplicationSystemTestCase
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end
end
def test_create_new_invoice_fails_when_amount_is_0
visit registrar_invoices_path

View file

@ -78,11 +78,9 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end
def test_if_invoice_is_overdue_than_48_hours
return unless Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
Spy.on_instance_method(SendEInvoiceTwoJob, :perform_now).and_return(true)
Spy.on_instance_method(SendEInvoiceJob, :perform_now).and_return(true)
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})
@ -164,8 +162,6 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end
def test_credits_registrar_athout_invoice_beforehand
return unless Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
@ -202,8 +198,6 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end
def test_topup_creates_invoice_and_send_it_as_paid
return unless Feature.billing_system_integrated?
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})

View file

@ -21,7 +21,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
if Feature.billing_system_integrated?
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
@ -45,7 +44,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
invoice = registrar.invoices.last
assert_equal Time.zone.today, invoice.e_invoice_sent_at.to_date
end
end
def test_skips_issuing_invoice_when_threshold_is_not_reached
registrar = registrar_with_auto_reload_enabled_and_threshold_not_reached
@ -66,7 +64,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end
def test_marks_registrar_as_pending_balance_reload
if Feature.billing_system_integrated?
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
@ -87,10 +84,8 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
assert registrar.settings['balance_auto_reload']['pending']
end
end
def test_output
if Feature.billing_system_integrated?
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
@ -112,7 +107,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
run_task
end
end
end
private