mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 09:21:43 +02:00
added jobs for send e invoice data to billing system and received response
This commit is contained in:
parent
3242fb1da0
commit
5e0d1ff619
9 changed files with 117 additions and 3 deletions
|
@ -19,7 +19,7 @@ module EisBilling
|
|||
data[:customer_name] = invoice.buyer_name
|
||||
data[:customer_email] = invoice.buyer_email
|
||||
data[:custom_field_1] = invoice.description
|
||||
data[:custom_field_2] = 'registry'
|
||||
data[:custom_field_2] = INITIATOR
|
||||
data[:invoice_number] = invoice.number
|
||||
|
||||
data
|
||||
|
|
|
@ -8,5 +8,6 @@ module EisBilling
|
|||
# =>
|
||||
TOKEN = 'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw=='.freeze
|
||||
BASE_URL = ENV['eis_billing_system_base_url']
|
||||
INITIATOR = 'registry'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module EisBilling
|
|||
|
||||
def self.obj_data
|
||||
{
|
||||
initiator: 'registry'
|
||||
initiator: INITIATOR
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ module EisBilling
|
|||
invoice_data: object_data,
|
||||
monthly: monthly,
|
||||
dry: dry,
|
||||
initiator: 'registry'
|
||||
initiator: INITIATOR
|
||||
}
|
||||
|
||||
uri = URI(invoice_generator_url)
|
||||
|
|
51
app/services/eis_billing/send_e_invoice.rb
Normal file
51
app/services/eis_billing/send_e_invoice.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
module EisBilling
|
||||
class SendEInvoice < EisBilling::Base
|
||||
def self.send_request(invoice:, payable:)
|
||||
base_request(invoice: invoice, payable: payable)
|
||||
end
|
||||
|
||||
def self.base_request(invoice:, payable:)
|
||||
items = []
|
||||
prepared_data = {
|
||||
invoice: invoice,
|
||||
vat_amount: invoice.vat_amount,
|
||||
invoice_subtotal: invoice.subtotal,
|
||||
buyer_billing_email: invoice.buyer.billing_email,
|
||||
buyer_e_invoice_iban: invoice.buyer.e_invoice_iban,
|
||||
seller_country: invoice.seller_country,
|
||||
buyer_country: invoice.buyer_country,
|
||||
payable: payable,
|
||||
initiator: INITIATOR
|
||||
}
|
||||
|
||||
invoice.items.each do |invoice_item|
|
||||
items << {
|
||||
description: invoice_item.description,
|
||||
price: invoice_item.price,
|
||||
quantity: invoice_item.quantity,
|
||||
unit: invoice_item.unit,
|
||||
subtotal: invoice_item.subtotal,
|
||||
vat_rate: invoice_item.vat_rate,
|
||||
vat_amount: invoice_item.vat_amount,
|
||||
total: invoice_item.total
|
||||
}
|
||||
end
|
||||
|
||||
prepared_data[:items] = items
|
||||
|
||||
uri = URI(invoice_generator_url)
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
headers = {
|
||||
'Authorization' => 'Bearer foobar',
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => TOKEN
|
||||
}
|
||||
|
||||
http.post(invoice_generator_url, prepared_data.to_json, headers)
|
||||
end
|
||||
|
||||
def self.invoice_generator_url
|
||||
"#{BASE_URL}/api/v1/e_invoice/e_invoice"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue