mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 21:46:24 +02:00
Merge pull request #2433 from internetee/remove-feature-toggle
remove eis-billing feature toggle
This commit is contained in:
commit
f77883b266
29 changed files with 459 additions and 583 deletions
|
@ -3,7 +3,6 @@ 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
|
||||||
|
|
||||||
INITIATOR = 'billing'.freeze
|
INITIATOR = 'billing'.freeze
|
||||||
|
@ -49,11 +48,5 @@ module EisBilling
|
||||||
def logger
|
def logger
|
||||||
Rails.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
|
||||||
|
|
|
@ -1,60 +1,31 @@
|
||||||
class DirectoInvoiceForwardJob < ApplicationJob
|
class DirectoInvoiceForwardJob < ApplicationJob
|
||||||
def perform(monthly: false, dry: false)
|
def perform(monthly: false, dry: false)
|
||||||
@dry = dry
|
data = nil
|
||||||
(@month = Time.zone.now - 1.month) if monthly
|
|
||||||
|
|
||||||
@client = new_directo_client
|
if monthly
|
||||||
monthly ? send_monthly_invoices : send_receipts
|
@month = Time.zone.now - 1.month
|
||||||
|
data = collect_monthly_data
|
||||||
|
else
|
||||||
|
data = collect_receipts_data
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_directo_client
|
EisBilling::SendDataToDirecto.send_request(object_data: data, monthly: monthly, dry: dry)
|
||||||
DirectoApi::Client.new(ENV['directo_invoice_url'], Setting.directo_sales_agent,
|
|
||||||
Setting.directo_receipt_payment_term)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_receipts
|
def collect_receipts_data
|
||||||
unsent_invoices = Invoice.where(in_directo: false).non_cancelled
|
unsent_invoices = Invoice.where(in_directo: false).non_cancelled
|
||||||
|
collected_data = []
|
||||||
|
|
||||||
Rails.logger.info("[DIRECTO] Trying to send #{unsent_invoices.count} prepayment invoices")
|
|
||||||
unsent_invoices.each do |invoice|
|
unsent_invoices.each do |invoice|
|
||||||
unless valid_invoice_conditions?(invoice)
|
unless valid_invoice_conditions?(invoice)
|
||||||
Rails.logger.info "[DIRECTO] Invoice #{invoice.number} has been skipped"
|
Rails.logger.info "[DIRECTO] Invoice #{invoice.number} has been skipped"
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
@client.invoices.add_with_schema(invoice: invoice.as_directo_json, schema: 'prepayment')
|
collected_data << invoice.as_directo_json
|
||||||
end
|
end
|
||||||
|
|
||||||
sync_with_directo
|
collected_data
|
||||||
end
|
|
||||||
|
|
||||||
def send_monthly_invoices
|
|
||||||
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
|
||||||
next unless registrar.cash_account
|
|
||||||
|
|
||||||
@client = new_directo_client
|
|
||||||
send_invoice_for_registrar(registrar)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def send_invoice_for_registrar(registrar)
|
|
||||||
summary = registrar.monthly_summary(month: @month)
|
|
||||||
@client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil?
|
|
||||||
|
|
||||||
sync_with_directo if @client.invoices.count.positive?
|
|
||||||
end
|
|
||||||
|
|
||||||
def assign_monthly_numbers
|
|
||||||
raise 'Directo Counter is going to be out of period!' if directo_counter_exceedable?(@client.invoices.count)
|
|
||||||
|
|
||||||
min_directo = Setting.directo_monthly_number_min.presence.try(:to_i)
|
|
||||||
directo_number = [Setting.directo_monthly_number_last.presence.try(:to_i),
|
|
||||||
min_directo].compact.max || 0
|
|
||||||
|
|
||||||
@client.invoices.each do |inv|
|
|
||||||
directo_number += 1
|
|
||||||
inv.number = directo_number
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_invoice_conditions?(invoice)
|
def valid_invoice_conditions?(invoice)
|
||||||
|
@ -68,29 +39,17 @@ class DirectoInvoiceForwardJob < ApplicationJob
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_with_directo
|
def collect_monthly_data
|
||||||
assign_monthly_numbers if @month
|
registrars_data = []
|
||||||
|
|
||||||
Rails.logger.info("[Directo] - attempting to send following XML:\n #{@client.invoices.as_xml}")
|
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
||||||
return if @dry
|
registrars_data << {
|
||||||
|
registrar: registrar,
|
||||||
res = @client.invoices.deliver(ssl_verify: false)
|
registrar_summery: registrar.monthly_summary(month: @month),
|
||||||
process_directo_response(res.body, @client.invoices.as_xml)
|
}
|
||||||
rescue SocketError, Errno::ECONNREFUSED, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
|
||||||
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError
|
|
||||||
Rails.logger.info('[Directo] Failed to communicate via API')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_directo_response(xml, req)
|
registrars_data
|
||||||
Rails.logger.info "[Directo] - Responded with body: #{xml}"
|
|
||||||
Nokogiri::XML(xml).css('Result').each do |res|
|
|
||||||
if @month
|
|
||||||
mark_invoice_as_sent(res: res, req: req)
|
|
||||||
else
|
|
||||||
inv = Invoice.find_by(number: res.attributes['docid'].value.to_i)
|
|
||||||
mark_invoice_as_sent(invoice: inv, res: res, req: req)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_invoice_as_sent(invoice: nil, res:, req:)
|
def mark_invoice_as_sent(invoice: nil, res:, req:)
|
||||||
|
|
125
app/jobs/directo_invoice_forward_legacy_job.rb
Normal file
125
app/jobs/directo_invoice_forward_legacy_job.rb
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
class DirectoInvoiceForwardLegacyJob < ApplicationJob
|
||||||
|
def perform(monthly: false, dry: false)
|
||||||
|
@dry = dry
|
||||||
|
(@month = Time.zone.now - 1.month) if monthly
|
||||||
|
|
||||||
|
@client = new_directo_client
|
||||||
|
monthly ? send_monthly_invoices : send_receipts
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_directo_client
|
||||||
|
DirectoApi::Client.new(ENV['directo_invoice_url'], Setting.directo_sales_agent,
|
||||||
|
Setting.directo_receipt_payment_term)
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_receipts
|
||||||
|
unsent_invoices = Invoice.where(in_directo: false).non_cancelled
|
||||||
|
|
||||||
|
Rails.logger.info("[DIRECTO] Trying to send #{unsent_invoices.count} prepayment invoices")
|
||||||
|
unsent_invoices.each do |invoice|
|
||||||
|
unless valid_invoice_conditions?(invoice)
|
||||||
|
Rails.logger.info "[DIRECTO] Invoice #{invoice.number} has been skipped"
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
@client.invoices.add_with_schema(invoice: invoice.as_directo_json, schema: 'prepayment')
|
||||||
|
end
|
||||||
|
|
||||||
|
sync_with_directo
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_monthly_invoices
|
||||||
|
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
||||||
|
next unless registrar.cash_account
|
||||||
|
|
||||||
|
@client = new_directo_client
|
||||||
|
send_invoice_for_registrar(registrar)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_invoice_for_registrar(registrar)
|
||||||
|
summary = registrar.monthly_summary(month: @month)
|
||||||
|
@client.invoices.add_with_schema(invoice: summary, schema: 'summary') unless summary.nil?
|
||||||
|
|
||||||
|
sync_with_directo if @client.invoices.count.positive?
|
||||||
|
end
|
||||||
|
|
||||||
|
def assign_monthly_numbers
|
||||||
|
raise 'Directo Counter is going to be out of period!' if directo_counter_exceedable?(@client.invoices.count)
|
||||||
|
|
||||||
|
min_directo = Setting.directo_monthly_number_min.presence.try(:to_i)
|
||||||
|
directo_number = [Setting.directo_monthly_number_last.presence.try(:to_i),
|
||||||
|
min_directo].compact.max || 0
|
||||||
|
|
||||||
|
@client.invoices.each do |inv|
|
||||||
|
directo_number += 1
|
||||||
|
inv.number = directo_number
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_invoice_conditions?(invoice)
|
||||||
|
if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? ||
|
||||||
|
invoice.account_activity.bank_transaction.sum.nil? ||
|
||||||
|
invoice.account_activity.bank_transaction.sum != invoice.total
|
||||||
|
return false
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def sync_with_directo
|
||||||
|
assign_monthly_numbers if @month
|
||||||
|
|
||||||
|
Rails.logger.info("[Directo] - attempting to send following XML:\n #{@client.invoices.as_xml}")
|
||||||
|
return if @dry
|
||||||
|
|
||||||
|
res = @client.invoices.deliver(ssl_verify: false)
|
||||||
|
process_directo_response(res.body, @client.invoices.as_xml)
|
||||||
|
rescue SocketError, Errno::ECONNREFUSED, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
|
||||||
|
EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError
|
||||||
|
Rails.logger.info('[Directo] Failed to communicate via API')
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_directo_response(xml, req)
|
||||||
|
Rails.logger.info "[Directo] - Responded with body: #{xml}"
|
||||||
|
Nokogiri::XML(xml).css('Result').each do |res|
|
||||||
|
if @month
|
||||||
|
mark_invoice_as_sent(res: res, req: req)
|
||||||
|
else
|
||||||
|
inv = Invoice.find_by(number: res.attributes['docid'].value.to_i)
|
||||||
|
mark_invoice_as_sent(invoice: inv, res: res, req: req)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def mark_invoice_as_sent(invoice: nil, res:, req:)
|
||||||
|
directo_record = Directo.new(response: res.as_json.to_h,
|
||||||
|
request: req, invoice_number: res.attributes['docid'].value.to_i)
|
||||||
|
if invoice
|
||||||
|
directo_record.item = invoice
|
||||||
|
invoice.update(in_directo: true)
|
||||||
|
else
|
||||||
|
update_directo_number(num: directo_record.invoice_number)
|
||||||
|
end
|
||||||
|
|
||||||
|
directo_record.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_directo_number(num:)
|
||||||
|
return unless num.to_i > Setting.directo_monthly_number_last.to_i
|
||||||
|
|
||||||
|
Setting.directo_monthly_number_last = num.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def directo_counter_exceedable?(invoice_count)
|
||||||
|
min_directo = Setting.directo_monthly_number_min.presence.try(:to_i)
|
||||||
|
max_directo = Setting.directo_monthly_number_max.presence.try(:to_i)
|
||||||
|
last_directo = [Setting.directo_monthly_number_last.presence.try(:to_i),
|
||||||
|
min_directo].compact.max || 0
|
||||||
|
|
||||||
|
return true if max_directo && max_directo < (last_directo + invoice_count)
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,84 +0,0 @@
|
||||||
class DirectoInvoiceForwardTwoJob < ApplicationJob
|
|
||||||
def perform(monthly: false, dry: false)
|
|
||||||
data = nil
|
|
||||||
|
|
||||||
if monthly
|
|
||||||
@month = Time.zone.now - 1.month
|
|
||||||
data = collect_monthly_data
|
|
||||||
else
|
|
||||||
data = collect_receipts_data
|
|
||||||
end
|
|
||||||
|
|
||||||
EisBilling::SendDataToDirecto.send_request(object_data: data, monthly: monthly, dry: dry)
|
|
||||||
end
|
|
||||||
|
|
||||||
def collect_receipts_data
|
|
||||||
unsent_invoices = Invoice.where(in_directo: false).non_cancelled
|
|
||||||
collected_data = []
|
|
||||||
|
|
||||||
unsent_invoices.each do |invoice|
|
|
||||||
unless valid_invoice_conditions?(invoice)
|
|
||||||
Rails.logger.info "[DIRECTO] Invoice #{invoice.number} has been skipped"
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
collected_data << invoice.as_directo_json
|
|
||||||
end
|
|
||||||
|
|
||||||
collected_data
|
|
||||||
end
|
|
||||||
|
|
||||||
def valid_invoice_conditions?(invoice)
|
|
||||||
if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? ||
|
|
||||||
invoice.account_activity.bank_transaction.sum.nil? ||
|
|
||||||
invoice.account_activity.bank_transaction.sum != invoice.total
|
|
||||||
return false
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def collect_monthly_data
|
|
||||||
registrars_data = []
|
|
||||||
|
|
||||||
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
|
||||||
registrars_data << {
|
|
||||||
registrar: registrar,
|
|
||||||
registrar_summery: registrar.monthly_summary(month: @month),
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
registrars_data
|
|
||||||
end
|
|
||||||
|
|
||||||
def mark_invoice_as_sent(invoice: nil, res:, req:)
|
|
||||||
directo_record = Directo.new(response: res.as_json.to_h,
|
|
||||||
request: req, invoice_number: res.attributes['docid'].value.to_i)
|
|
||||||
if invoice
|
|
||||||
directo_record.item = invoice
|
|
||||||
invoice.update(in_directo: true)
|
|
||||||
else
|
|
||||||
update_directo_number(num: directo_record.invoice_number)
|
|
||||||
end
|
|
||||||
|
|
||||||
directo_record.save!
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_directo_number(num:)
|
|
||||||
return unless num.to_i > Setting.directo_monthly_number_last.to_i
|
|
||||||
|
|
||||||
Setting.directo_monthly_number_last = num.to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
def directo_counter_exceedable?(invoice_count)
|
|
||||||
min_directo = Setting.directo_monthly_number_min.presence.try(:to_i)
|
|
||||||
max_directo = Setting.directo_monthly_number_max.presence.try(:to_i)
|
|
||||||
last_directo = [Setting.directo_monthly_number_last.presence.try(:to_i),
|
|
||||||
min_directo].compact.max || 0
|
|
||||||
|
|
||||||
return true if max_directo && max_directo < (last_directo + invoice_count)
|
|
||||||
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -6,7 +6,8 @@ class SendEInvoiceJob < ApplicationJob
|
||||||
invoice = Invoice.find_by(id: invoice_id)
|
invoice = Invoice.find_by(id: invoice_id)
|
||||||
return unless need_to_process_invoice?(invoice: invoice, payable: payable)
|
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
|
rescue StandardError => e
|
||||||
log_error(invoice: invoice, error: e)
|
log_error(invoice: invoice, error: e)
|
||||||
raise e
|
raise e
|
||||||
|
@ -16,23 +17,15 @@ class SendEInvoiceJob < ApplicationJob
|
||||||
|
|
||||||
def need_to_process_invoice?(invoice:, payable:)
|
def need_to_process_invoice?(invoice:, payable:)
|
||||||
logger.info "Checking if need to process e-invoice #{invoice}, payable: #{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.blank?
|
||||||
return false if unprocessable
|
return false if invoice.do_not_send_e_invoice? && payable
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def process(invoice:, payable:)
|
def send_invoice_to_eis_billing(invoice:, payable:)
|
||||||
invoice.to_e_invoice(payable: payable).deliver unless Rails.env.development?
|
result = EisBilling::SendEInvoice.send_request(invoice: invoice, payable: payable)
|
||||||
invoice.update(e_invoice_sent_at: Time.zone.now)
|
logger.info result.body
|
||||||
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
|
end
|
||||||
|
|
||||||
def log_error(invoice:, error:)
|
def log_error(invoice:, error:)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class SendEInvoiceTwoJob < ApplicationJob
|
class SendEInvoiceLegacyJob < ApplicationJob
|
||||||
discard_on HTTPClient::TimeoutError
|
discard_on HTTPClient::TimeoutError
|
||||||
|
|
||||||
def perform(invoice_id, payable: true)
|
def perform(invoice_id, payable: true)
|
||||||
|
@ -6,8 +6,7 @@ class SendEInvoiceTwoJob < ApplicationJob
|
||||||
invoice = Invoice.find_by(id: invoice_id)
|
invoice = Invoice.find_by(id: invoice_id)
|
||||||
return unless need_to_process_invoice?(invoice: invoice, payable: payable)
|
return unless need_to_process_invoice?(invoice: invoice, payable: payable)
|
||||||
|
|
||||||
send_invoice_to_eis_billing(invoice: invoice, payable: payable)
|
process(invoice: invoice, payable: payable)
|
||||||
invoice.update(e_invoice_sent_at: Time.zone.now)
|
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
log_error(invoice: invoice, error: e)
|
log_error(invoice: invoice, error: e)
|
||||||
raise e
|
raise e
|
||||||
|
@ -17,15 +16,23 @@ class SendEInvoiceTwoJob < ApplicationJob
|
||||||
|
|
||||||
def need_to_process_invoice?(invoice:, payable:)
|
def need_to_process_invoice?(invoice:, payable:)
|
||||||
logger.info "Checking if need to process e-invoice #{invoice}, payable: #{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.blank?
|
||||||
return false if invoice.do_not_send_e_invoice? && payable
|
return false if unprocessable
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_invoice_to_eis_billing(invoice:, payable:)
|
def process(invoice:, payable:)
|
||||||
result = EisBilling::SendEInvoice.send_request(invoice: invoice, payable: payable)
|
invoice.to_e_invoice(payable: payable).deliver unless Rails.env.development?
|
||||||
logger.info result.body
|
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
|
end
|
||||||
|
|
||||||
def log_error(invoice:, error:)
|
def log_error(invoice:, error:)
|
|
@ -49,7 +49,7 @@ class SendMonthlyInvoicesJob < ApplicationJob # rubocop:disable Metrics/ClassLen
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_e_invoice(invoice_id)
|
def send_e_invoice(invoice_id)
|
||||||
SendEInvoiceJob.set(wait: 1.minute).perform_later(invoice_id, payable: false)
|
SendEInvoiceLegacyJob.set(wait: 1.minute).perform_later(invoice_id, payable: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_invoice(summary, registrar)
|
def create_invoice(summary, registrar)
|
||||||
|
|
|
@ -4,13 +4,8 @@ module Billing
|
||||||
MULTI_REGEXP = /(\d{2,20})/
|
MULTI_REGEXP = /(\d{2,20})/
|
||||||
|
|
||||||
def self.generate
|
def self.generate
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
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)
|
||||||
|
|
|
@ -62,39 +62,13 @@ class Invoice < ApplicationRecord
|
||||||
throw(:abort)
|
throw(:abort)
|
||||||
end
|
end
|
||||||
|
|
||||||
def invoice_number_from_billing
|
def set_invoice_number
|
||||||
result = EisBilling::GetInvoiceNumber.send_invoice
|
result = EisBilling::GetInvoiceNumber.send_invoice
|
||||||
validate_invoice_number(result)
|
validate_invoice_number(result)
|
||||||
|
|
||||||
self.number = JSON.parse(result.body)['invoice_number'].to_i
|
self.number = JSON.parse(result.body)['invoice_number'].to_i
|
||||||
end
|
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
|
def to_s
|
||||||
I18n.t('invoice_no', no: number)
|
I18n.t('invoice_no', no: number)
|
||||||
end
|
end
|
||||||
|
|
|
@ -146,20 +146,13 @@ class Registrar < ApplicationRecord # rubocop:disable Metrics/ClassLength
|
||||||
.deliver_later(wait: 1.minute)
|
.deliver_later(wait: 1.minute)
|
||||||
end
|
end
|
||||||
|
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
add_invoice_instance = EisBilling::AddDeposits.new(invoice)
|
add_invoice_instance = EisBilling::AddDeposits.new(invoice)
|
||||||
result = add_invoice_instance.send_invoice
|
result = add_invoice_instance.send_invoice
|
||||||
|
|
||||||
link = JSON.parse(result.body)['everypay_link']
|
link = JSON.parse(result.body)['everypay_link']
|
||||||
|
|
||||||
invoice.update(payment_link: 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)
|
SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
||||||
end
|
|
||||||
|
|
||||||
invoice
|
invoice
|
||||||
end
|
end
|
||||||
|
|
|
@ -5405,8 +5405,10 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20220113201642'),
|
('20220113201642'),
|
||||||
('20220113220809'),
|
('20220113220809'),
|
||||||
('20220124105717'),
|
('20220124105717'),
|
||||||
|
('20220216113112'),
|
||||||
('20220228093211'),
|
('20220228093211'),
|
||||||
('20220316140727'),
|
('20220316140727'),
|
||||||
|
('20220406085500'),
|
||||||
('20220412130856'),
|
('20220412130856'),
|
||||||
('20220413073315'),
|
('20220413073315'),
|
||||||
('20220413084536'),
|
('20220413084536'),
|
||||||
|
|
|
@ -24,7 +24,6 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_new_invoice
|
def test_create_new_invoice
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
|
||||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
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
|
assert_equal page.status_code, 200
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_visit_list_of_invoices_pages
|
def test_visit_list_of_invoices_pages
|
||||||
visit admin_invoices_path
|
visit admin_invoices_path
|
||||||
|
|
|
@ -10,7 +10,6 @@ class DirectoResponseTest < ApplicationIntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_created_directo_instance
|
def test_should_created_directo_instance
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
directo_response_from_billing = {
|
directo_response_from_billing = {
|
||||||
response: @response_xml,
|
response: @response_xml,
|
||||||
month: true
|
month: true
|
||||||
|
@ -21,10 +20,8 @@ class DirectoResponseTest < ApplicationIntegrationTest
|
||||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_should_update_related_invoice
|
def test_should_update_related_invoice
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
directo_response_from_billing = {
|
directo_response_from_billing = {
|
||||||
response: @response_xml
|
response: @response_xml
|
||||||
}
|
}
|
||||||
|
@ -40,4 +37,3 @@ class DirectoResponseTest < ApplicationIntegrationTest
|
||||||
assert @invoice.in_directo
|
assert @invoice.in_directo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ class LhvConnectTransactionsIntegrationTest < ApplicationIntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_saved_transaction_data
|
def test_should_saved_transaction_data
|
||||||
return unless Feature.billing_system_integrated?
|
|
||||||
|
|
||||||
test_transaction_1 = OpenStruct.new(amount: 0.1,
|
test_transaction_1 = OpenStruct.new(amount: 0.1,
|
||||||
currency: 'EUR',
|
currency: 'EUR',
|
||||||
date: Time.zone.today,
|
date: Time.zone.today,
|
||||||
|
|
|
@ -12,6 +12,18 @@ class ReppV1InvoicesAddCreditTest < ActionDispatch::IntegrationTest
|
||||||
eis_response = OpenStruct.new(body: '{"everypay_link":"https://link.test"}')
|
eis_response = OpenStruct.new(body: '{"everypay_link":"https://link.test"}')
|
||||||
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
||||||
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
|
|
||||||
|
invoice = Invoice.last
|
||||||
|
msg = {
|
||||||
|
invoice_number: invoice.number + 3
|
||||||
|
}
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
|
||||||
|
.to_return(status: 200, body: msg.to_json, headers: {})
|
||||||
|
|
||||||
|
msg2 = {
|
||||||
|
message: 'success'
|
||||||
|
}
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").to_return(status: 200, body: msg2.to_json, headers: {})
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
@ -28,13 +40,11 @@ class ReppV1InvoicesAddCreditTest < ActionDispatch::IntegrationTest
|
||||||
Setting.registry_vat_prc = 0.1
|
Setting.registry_vat_prc = 0.1
|
||||||
ENV['billing_system_integrated'] = 'true'
|
ENV['billing_system_integrated'] = 'true'
|
||||||
|
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
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: {})
|
.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')
|
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||||
.to_return(status: 200, body: '', headers: {})
|
.to_return(status: 200, body: '', headers: {})
|
||||||
end
|
|
||||||
|
|
||||||
post '/repp/v1/invoices/add_credit', headers: @auth_headers,
|
post '/repp/v1/invoices/add_credit', headers: @auth_headers,
|
||||||
params: request_body
|
params: request_body
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
class DirectoInvoiceForwardLegacyJobTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@invoice = invoices(:one)
|
@invoice = invoices(:one)
|
||||||
@user = registrars(:bestnames)
|
@user = registrars(:bestnames)
|
||||||
|
@ -38,7 +38,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
DirectoInvoiceForwardJob.perform_now(monthly: false, dry: false)
|
DirectoInvoiceForwardLegacyJob.perform_now(monthly: false, dry: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_not_empty @invoice.directo_records.first.request
|
assert_not_empty @invoice.directo_records.first.request
|
||||||
|
@ -52,7 +52,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
Setting.directo_monthly_number_max = 30_991
|
Setting.directo_monthly_number_max = 30_991
|
||||||
|
|
||||||
assert_raises 'RuntimeError' do
|
assert_raises 'RuntimeError' do
|
||||||
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
assert_difference 'Setting.directo_monthly_number_last' do
|
assert_difference 'Setting.directo_monthly_number_last' do
|
||||||
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||||
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
|
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
|
||||||
end.to_return(status: 200, body: response)
|
end.to_return(status: 200, body: response)
|
||||||
|
|
||||||
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
|
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||||
|
|
||||||
assert_requested first_registrar_stub
|
assert_requested first_registrar_stub
|
||||||
assert_requested second_registrar_stub
|
assert_requested second_registrar_stub
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class SendEInvoiceJobTest < ActiveJob::TestCase
|
class SendEInvoiceLegacyJobTest < ActiveJob::TestCase
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||||
EInvoice::Providers::TestProvider.deliveries.clear
|
EInvoice::Providers::TestProvider.deliveries.clear
|
||||||
|
|
||||||
|
msg = { message: 'success' }
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
|
||||||
|
.to_return(status: 200, body: msg.to_json, headers: {})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_invoice_is_sent
|
def test_if_invoice_is_sent
|
||||||
|
@ -15,7 +19,7 @@ class SendEInvoiceJobTest < ActiveJob::TestCase
|
||||||
|
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
perform_enqueued_jobs do
|
perform_enqueued_jobs do
|
||||||
SendEInvoiceJob.perform_now(@invoice.id, payable: true)
|
SendEInvoiceLegacyJob.perform_now(@invoice.id, payable: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@invoice.reload
|
@invoice.reload
|
|
@ -10,6 +10,10 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
||||||
ActionMailer::Base.deliveries.clear
|
ActionMailer::Base.deliveries.clear
|
||||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||||
EInvoice::Providers::TestProvider.deliveries.clear
|
EInvoice::Providers::TestProvider.deliveries.clear
|
||||||
|
|
||||||
|
response = { message: 'sucess' }
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
|
||||||
|
.to_return(status: 200, body: response.to_json, headers: {})
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
@ -107,7 +111,7 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
||||||
assert_equal 'Invoice no. 309902 (monthly invoice)', email.subject
|
assert_equal 'Invoice no. 309902 (monthly invoice)', email.subject
|
||||||
assert email.attachments['invoice-309902.pdf']
|
assert email.attachments['invoice-309902.pdf']
|
||||||
|
|
||||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
# assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_monthly_summary_is_delivered_in_estonian
|
def test_monthly_summary_is_delivered_in_estonian
|
||||||
|
@ -150,7 +154,7 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
||||||
assert_equal 'Invoice no. 309902 (monthly invoice)', email.subject
|
assert_equal 'Invoice no. 309902 (monthly invoice)', email.subject
|
||||||
assert email.attachments['invoice-309902.pdf']
|
assert email.attachments['invoice-309902.pdf']
|
||||||
|
|
||||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
# assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multi_year_purchases_have_duration_assigned
|
def test_multi_year_purchases_have_duration_assigned
|
||||||
|
|
|
@ -22,8 +22,6 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_binds_if_this_sum_invoice_already_present
|
def test_binds_if_this_sum_invoice_already_present
|
||||||
return unless Feature.billing_system_integrated?
|
|
||||||
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
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: {})
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
@ -51,8 +49,6 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_binds_if_this_sum_cancelled_invoice_already_present
|
def test_binds_if_this_sum_cancelled_invoice_already_present
|
||||||
return unless Feature.billing_system_integrated?
|
|
||||||
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
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: {})
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
@ -76,8 +72,6 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_marks_the_first_one_as_paid_if_same_sum
|
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
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
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: {})
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
|
@ -7,7 +7,6 @@ class ReferenceNoTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_generated_reference_number_conforms_to_format
|
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")
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator")
|
||||||
.to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
|
.to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
|
||||||
|
|
||||||
|
@ -15,4 +14,3 @@ class ReferenceNoTest < ActiveSupport::TestCase
|
||||||
assert_match Billing::ReferenceNo::REGEXP, reference_no
|
assert_match Billing::ReferenceNo::REGEXP, reference_no
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
@ -1,53 +1,4 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class FeatureTest < ActiveSupport::TestCase
|
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
|
end
|
||||||
|
|
|
@ -118,7 +118,6 @@ class InvoiceTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_invoice_with_bank_transaction_total
|
def test_creates_invoice_with_bank_transaction_total
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
registrar = registrars(:bestnames)
|
registrar = registrars(:bestnames)
|
||||||
transaction = bank_transactions(:one).dup
|
transaction = bank_transactions(:one).dup
|
||||||
transaction.reference_no = registrar.reference_no
|
transaction.reference_no = registrar.reference_no
|
||||||
|
@ -156,10 +155,8 @@ class InvoiceTest < ActiveSupport::TestCase
|
||||||
invoice = Invoice.create_from_transaction!(transaction)
|
invoice = Invoice.create_from_transaction!(transaction)
|
||||||
assert_equal 0.99, invoice.total
|
assert_equal 0.99, invoice.total
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_emails_invoice_after_creating_topup_invoice
|
def test_emails_invoice_after_creating_topup_invoice
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
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: {})
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
@ -183,4 +180,3 @@ class InvoiceTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
@ -145,7 +145,6 @@ class RegistrarTest < ActiveJob::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_issues_new_invoice
|
def test_issues_new_invoice
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
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: {})
|
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-05'), invoice.issue_date
|
||||||
assert_equal Date.parse('2010-07-15'), invoice.due_date
|
assert_equal Date.parse('2010-07-15'), invoice.due_date
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_issues_e_invoice_along_with_invoice
|
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").
|
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: {})
|
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").
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
to_return(status: 200, body: "", headers: {})
|
to_return(status: 200, body: "", headers: {})
|
||||||
end
|
|
||||||
|
|
||||||
EInvoice::Providers::TestProvider.deliveries.clear
|
EInvoice::Providers::TestProvider.deliveries.clear
|
||||||
|
|
||||||
perform_enqueued_jobs do
|
perform_enqueued_jobs do
|
||||||
@registrar.issue_prepayment_invoice(100)
|
@registrar.issue_prepayment_invoice(100)
|
||||||
end
|
end
|
||||||
|
|
||||||
unless Feature.billing_system_integrated?
|
|
||||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_without_address_street
|
def test_invalid_without_address_street
|
||||||
|
|
|
@ -58,7 +58,6 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_can_bind_statement_transactions
|
def test_can_bind_statement_transactions
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
|
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: {})
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
@ -91,7 +90,6 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
|
||||||
|
|
||||||
assert_text 'Invoices were fully binded'
|
assert_text 'Invoices were fully binded'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def create_bank_statement
|
def create_bank_statement
|
||||||
visit admin_bank_statements_path
|
visit admin_bank_statements_path
|
||||||
|
|
|
@ -14,7 +14,6 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_new_registrar
|
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").
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
|
||||||
to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
|
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 'Registrar has been successfully created'
|
||||||
assert_text 'Acme Ltd'
|
assert_text 'Acme Ltd'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_updates_registrar
|
def test_updates_registrar
|
||||||
assert_not_equal 'New name', @registrar.name
|
assert_not_equal 'New name', @registrar.name
|
||||||
|
|
|
@ -15,7 +15,6 @@ class BalanceTopUpTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_new_invoice
|
def test_creates_new_invoice
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
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: {})
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
@ -43,4 +42,3 @@ class BalanceTopUpTest < ApplicationSystemTestCase
|
||||||
assert_text 'Please pay the following invoice'
|
assert_text 'Please pay the following invoice'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ class NewInvoiceTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_new_invoice_with_positive_amount
|
def test_create_new_invoice_with_positive_amount
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
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: {})
|
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 'Subtotal 200,00 €'
|
||||||
assert_text 'Pay invoice'
|
assert_text 'Pay invoice'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_create_new_invoice_with_comma_in_number
|
def test_create_new_invoice_with_comma_in_number
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
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: {})
|
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 'Subtotal 200,00 €'
|
||||||
assert_text 'Pay invoice'
|
assert_text 'Pay invoice'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_create_new_invoice_fails_when_amount_is_0
|
def test_create_new_invoice_fails_when_amount_is_0
|
||||||
visit registrar_invoices_path
|
visit registrar_invoices_path
|
||||||
|
|
|
@ -84,11 +84,9 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_invoice_is_overdue_than_48_hours
|
def test_if_invoice_is_overdue_than_48_hours
|
||||||
return unless Feature.billing_system_integrated?
|
|
||||||
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
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')
|
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||||
.to_return(status: 200, body: '', headers: {})
|
.to_return(status: 200, body: '', headers: {})
|
||||||
|
@ -170,8 +168,6 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_credits_registrar_athout_invoice_beforehand
|
def test_credits_registrar_athout_invoice_beforehand
|
||||||
return unless Feature.billing_system_integrated?
|
|
||||||
|
|
||||||
invoice_n = Invoice.order(number: :desc).last.number
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
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}\"}")
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
|
||||||
|
@ -179,7 +175,7 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
|
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: {})
|
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
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')
|
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||||
.to_return(status: 200, body: '', headers: {})
|
.to_return(status: 200, body: '', headers: {})
|
||||||
|
@ -208,8 +204,6 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_topup_creates_invoice_and_send_it_as_paid
|
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')
|
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||||
.to_return(status: 200, body: '', headers: {})
|
.to_return(status: 200, body: '', headers: {})
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
|
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").
|
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: {})
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
@ -45,7 +44,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
invoice = registrar.invoices.last
|
invoice = registrar.invoices.last
|
||||||
assert_equal Time.zone.today, invoice.e_invoice_sent_at.to_date
|
assert_equal Time.zone.today, invoice.e_invoice_sent_at.to_date
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_skips_issuing_invoice_when_threshold_is_not_reached
|
def test_skips_issuing_invoice_when_threshold_is_not_reached
|
||||||
registrar = registrar_with_auto_reload_enabled_and_threshold_not_reached
|
registrar = registrar_with_auto_reload_enabled_and_threshold_not_reached
|
||||||
|
@ -66,7 +64,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_marks_registrar_as_pending_balance_reload
|
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").
|
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: {})
|
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']
|
assert registrar.settings['balance_auto_reload']['pending']
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_output
|
def test_output
|
||||||
if Feature.billing_system_integrated?
|
|
||||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
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: {})
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
@ -112,7 +107,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
run_task
|
run_task
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue