mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 13:06:18 +02:00
added one time tasks for import data to billing system
This commit is contained in:
parent
84669297b5
commit
dbc7525dd5
2 changed files with 53 additions and 2 deletions
|
@ -3,9 +3,9 @@ module EisBilling
|
||||||
|
|
||||||
# crypt = ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base[0..31])
|
# crypt = ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base[0..31])
|
||||||
# irb(main):047:0> encrypted_data = crypt.encrypt_and_sign('PLEASE CREATE INVOICE')
|
# irb(main):047:0> encrypted_data = crypt.encrypt_and_sign('PLEASE CREATE INVOICE')
|
||||||
# => "HFW8ADSIrjyD9cbH4H5Rk3MY/ZfhV85IlnGl7YI2CQ==--OvlWMMiTLLotgdfT--/ffejEDaIGFfz7FzzNSlYA=="
|
# =>
|
||||||
# irb(main):048:0> decrypted_back = crypt.decrypt_and_verify(encrypted_data)
|
# irb(main):048:0> decrypted_back = crypt.decrypt_and_verify(encrypted_data)
|
||||||
# => "PLEASE CREATE INVOICE"
|
# =>
|
||||||
TOKEN = 'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw=='.freeze
|
TOKEN = 'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw=='.freeze
|
||||||
BASE_URL = ENV['eis_billing_system_base_url']
|
BASE_URL = ENV['eis_billing_system_base_url']
|
||||||
end
|
end
|
||||||
|
|
51
lib/tasks/eis_billing_import_data.rake
Normal file
51
lib/tasks/eis_billing_import_data.rake
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
TOKEN = ENV['eis_token']
|
||||||
|
BASE_URL = ENV['eis_billing_system_base_url']
|
||||||
|
|
||||||
|
namespace :eis_billing do
|
||||||
|
desc 'One time task to export invoice data to billing system'
|
||||||
|
task import_invoices: :environment do
|
||||||
|
parsed_data = []
|
||||||
|
Invoice.all.each do |invoice|
|
||||||
|
parsed_data << {
|
||||||
|
invoice_number: invoice.number,
|
||||||
|
initiator: 'registry',
|
||||||
|
transaction_amount: invoice.total
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
base_request(url: import_invoice_data_url, json_obj: parsed_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'One time task to export reference number of registrars to billing system'
|
||||||
|
task import_references: :environment do
|
||||||
|
parsed_data = []
|
||||||
|
Registrar.all.each do |registrar|
|
||||||
|
parsed_data << {
|
||||||
|
reference_number: registrar.reference_no,
|
||||||
|
initiator: 'registry'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
base_request(url: import_reference_data_url, json_obj: parsed_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def import_reference_data_url
|
||||||
|
"#{BASE_URL}/api/v1/import_data/reference_data"
|
||||||
|
end
|
||||||
|
|
||||||
|
def import_invoice_data_url
|
||||||
|
"#{BASE_URL}/api/v1/import_data/invoice_data"
|
||||||
|
end
|
||||||
|
|
||||||
|
def base_request(url:, json_obj:)
|
||||||
|
uri = URI(url)
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
headers = {
|
||||||
|
'Authorization' => 'Bearer foobar',
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => TOKEN
|
||||||
|
}
|
||||||
|
|
||||||
|
http.post(url, json_obj.to_json, headers)
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue