mirror of
https://github.com/internetee/registry.git
synced 2025-07-31 15:06:23 +02:00
added directo handler for interaction with billing system
This commit is contained in:
parent
d9696014ff
commit
0259dd7fec
8 changed files with 286 additions and 1 deletions
35
app/controllers/eis_billing/directo_response_controller.rb
Normal file
35
app/controllers/eis_billing/directo_response_controller.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
class EisBilling::DirectoResponseController < EisBilling::BaseController
|
||||
def update
|
||||
response = params[:response]
|
||||
xml_data = params[:xml_data]
|
||||
@month = params.fetch(:month, false)
|
||||
|
||||
process_directo_response(xml_data, response)
|
||||
render status: 200, json: { messege: 'Should return new directo number', status: :ok }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
directo_record.save!
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue