mirror of
https://github.com/internetee/registry.git
synced 2025-07-31 23:16:23 +02:00
refactoring lhv connect
This commit is contained in:
parent
ab8c911da1
commit
a9ea8e92a1
5 changed files with 7 additions and 102 deletions
|
@ -1,15 +1,14 @@
|
|||
class EisBilling::EInvoiceResponseController < EisBilling::BaseController
|
||||
def update
|
||||
invoice_number = params[:invoice_number]
|
||||
date = params[:date]
|
||||
|
||||
set_e_invoice_sent_at(date, invoice_number)
|
||||
set_e_invoice_sent_at(invoice_number)
|
||||
render status: 200, json: { messege: 'Response received', status: :ok }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_e_invoice_sent_at(date, invoice_number)
|
||||
def set_e_invoice_sent_at(invoice_number)
|
||||
invoice = Invoice.find_by(number: invoice_number)
|
||||
invoice.update(e_invoice_sent_at: Time.zone.now)
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ module EisBilling
|
|||
class LhvConnectTransactionsController < EisBilling::BaseController
|
||||
def create
|
||||
params["_json"].each do |incoming_transaction|
|
||||
process_transactions(incoming_transaction["table"])
|
||||
process_transactions(incoming_transaction)
|
||||
end
|
||||
|
||||
render status: 200, json: { message: 'RECEIVED', status: :ok, params: params }
|
||||
|
|
|
@ -51,98 +51,6 @@ class DirectoInvoiceForwardTwoJob < ApplicationJob
|
|||
registrars_data
|
||||
end
|
||||
|
||||
# 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)
|
||||
|
|
|
@ -15,7 +15,7 @@ module EisBilling
|
|||
seller_country_code: invoice.seller_country_code,
|
||||
buyer_country_code: invoice.buyer_country_code,
|
||||
payable: payable,
|
||||
initiator: INITIATOR
|
||||
initiator: EisBilling::Base::INITIATOR
|
||||
}
|
||||
|
||||
invoice.items.each do |invoice_item|
|
||||
|
|
|
@ -5,15 +5,14 @@ class DirectoResponseTest < ApplicationIntegrationTest
|
|||
sign_in users(:api_bestnames)
|
||||
|
||||
@invoice = invoices(:one)
|
||||
@response_xml = '<?xml version="1.0" encoding="UTF-8"?><results><Result Type="0" Desc="OK" docid="1" doctype="ARVE" submit="Invoices"/></results>'
|
||||
@response_xml = "<?xml version='1.0' encoding='UTF-8'?><results><Result Type='0' Desc='OK' docid='#{@invoice.number}' doctype='ARVE' submit='Invoices'/></results>"
|
||||
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||
end
|
||||
|
||||
def test_should_created_directo_instance
|
||||
if Feature.billing_system_integrated?
|
||||
directo_response_from_billing = {
|
||||
response: 'this is response',
|
||||
xml_data: @response_xml,
|
||||
response: @response_xml,
|
||||
month: true
|
||||
}
|
||||
|
||||
|
@ -27,8 +26,7 @@ class DirectoResponseTest < ApplicationIntegrationTest
|
|||
def test_should_update_related_invoice
|
||||
if Feature.billing_system_integrated?
|
||||
directo_response_from_billing = {
|
||||
response: 'this is response',
|
||||
xml_data: @response_xml
|
||||
response: @response_xml
|
||||
}
|
||||
|
||||
refute @invoice.in_directo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue