mirror of
https://github.com/internetee/registry.git
synced 2025-08-11 12:09:34 +02:00
refactoring
This commit is contained in:
parent
29e7f954f3
commit
9856a2a5c0
10 changed files with 31 additions and 33 deletions
|
@ -18,13 +18,13 @@ module EisBilling
|
||||||
end
|
end
|
||||||
|
|
||||||
def decoded_token
|
def decoded_token
|
||||||
if auth_header
|
return unless auth_header
|
||||||
token = auth_header.split(' ')[1]
|
|
||||||
begin
|
token = auth_header.split(' ')[1]
|
||||||
JWT.decode(token, billing_secret_key, true, algorithm: 'HS256')
|
begin
|
||||||
rescue JWT::DecodeError
|
JWT.decode(token, billing_secret_key, true, algorithm: 'HS256')
|
||||||
nil
|
rescue JWT::DecodeError
|
||||||
end
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ class EisBilling::EInvoiceResponseController < EisBilling::BaseController
|
||||||
invoice_number = params[:invoice_number]
|
invoice_number = params[:invoice_number]
|
||||||
|
|
||||||
set_e_invoice_sent_at(invoice_number)
|
set_e_invoice_sent_at(invoice_number)
|
||||||
render status: 200, json: { messege: 'Response received', status: :ok }
|
render status: :ok, json: { messege: 'Response received' }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
module EisBilling
|
module EisBilling
|
||||||
class LhvConnectTransactionsController < EisBilling::BaseController
|
class LhvConnectTransactionsController < EisBilling::BaseController
|
||||||
def create
|
def create
|
||||||
params["_json"].each do |incoming_transaction|
|
params['_json'].each do |incoming_transaction|
|
||||||
process_transactions(incoming_transaction)
|
process_transactions(incoming_transaction)
|
||||||
end
|
end
|
||||||
|
|
||||||
render status: 200, json: { message: 'RECEIVED', status: :ok, params: params }
|
render status: :ok, json: { message: 'RECEIVED', params: params }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -15,16 +15,16 @@ module EisBilling
|
||||||
logger.info incoming_transaction
|
logger.info incoming_transaction
|
||||||
|
|
||||||
bank_statement = BankStatement.new(bank_code: Setting.registry_bank_code,
|
bank_statement = BankStatement.new(bank_code: Setting.registry_bank_code,
|
||||||
iban: Setting.registry_iban)
|
iban: Setting.registry_iban)
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
bank_statement.save!
|
bank_statement.save!
|
||||||
|
|
||||||
transaction_attributes = { sum: incoming_transaction["amount"],
|
transaction_attributes = { sum: incoming_transaction['amount'],
|
||||||
currency: incoming_transaction["currency"],
|
currency: incoming_transaction['currency'],
|
||||||
paid_at: incoming_transaction["date"],
|
paid_at: incoming_transaction['date'],
|
||||||
reference_no: incoming_transaction["payment_reference_number"],
|
reference_no: incoming_transaction['payment_reference_number'],
|
||||||
description: incoming_transaction["payment_description"] }
|
description: incoming_transaction['payment_description'] }
|
||||||
transaction = bank_statement.bank_transactions.create!(transaction_attributes)
|
transaction = bank_statement.bank_transactions.create!(transaction_attributes)
|
||||||
|
|
||||||
next if transaction.registrar.blank?
|
next if transaction.registrar.blank?
|
||||||
|
|
|
@ -18,7 +18,7 @@ module EisBilling
|
||||||
registrar = invoice.buyer
|
registrar = invoice.buyer
|
||||||
bank.create_activity(registrar, invoice)
|
bank.create_activity(registrar, invoice)
|
||||||
|
|
||||||
render status: 200, json: { status: :ok }
|
render status: :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -44,7 +44,7 @@ class DirectoInvoiceForwardTwoJob < ApplicationJob
|
||||||
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
||||||
registrars_data << {
|
registrars_data << {
|
||||||
registrar: registrar,
|
registrar: registrar,
|
||||||
registrar_summery: registrar.monthly_summary(month: @month)
|
registrar_summery: registrar.monthly_summary(month: @month),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
module EisBilling
|
module EisBilling
|
||||||
class Base
|
class Base
|
||||||
BASE_URL = ENV['eis_billing_system_base_url']
|
BASE_URL = ENV['eis_billing_system_base_url'] || 'https://st-billing.infra.tld.ee'
|
||||||
INITIATOR = 'registry'.freeze
|
INITIATOR = 'registry'.freeze
|
||||||
|
|
||||||
def self.base_request(url:)
|
def self.base_request(url:)
|
||||||
uri = URI(url)
|
uri = URI(url)
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
|
||||||
if Rails.env.production?
|
http.use_ssl = true unless Rails.env.development?
|
||||||
http.use_ssl = true
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if Rails.env.development?
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
||||||
end
|
|
||||||
|
|
||||||
http
|
http
|
||||||
end
|
end
|
||||||
|
@ -26,7 +24,7 @@ module EisBilling
|
||||||
def self.headers
|
def self.headers
|
||||||
{
|
{
|
||||||
'Authorization' => "Bearer #{generate_token}",
|
'Authorization' => "Bearer #{generate_token}",
|
||||||
'Content-Type' => 'application/json'
|
'Content-Type' => 'application/json',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ module EisBilling
|
||||||
|
|
||||||
def self.obj_data
|
def self.obj_data
|
||||||
{
|
{
|
||||||
initiator: INITIATOR
|
initiator: INITIATOR,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ module EisBilling
|
||||||
invoice_data: object_data,
|
invoice_data: object_data,
|
||||||
monthly: monthly,
|
monthly: monthly,
|
||||||
dry: dry,
|
dry: dry,
|
||||||
initiator: INITIATOR
|
initiator: INITIATOR,
|
||||||
}
|
}
|
||||||
|
|
||||||
http = EisBilling::Base.base_request(url: directo_url)
|
http = EisBilling::Base.base_request(url: directo_url)
|
||||||
|
|
|
@ -15,7 +15,7 @@ module EisBilling
|
||||||
seller_country_code: invoice.seller_country_code,
|
seller_country_code: invoice.seller_country_code,
|
||||||
buyer_country_code: invoice.buyer_country_code,
|
buyer_country_code: invoice.buyer_country_code,
|
||||||
payable: payable,
|
payable: payable,
|
||||||
initiator: EisBilling::Base::INITIATOR
|
initiator: EisBilling::Base::INITIATOR,
|
||||||
}
|
}
|
||||||
|
|
||||||
invoice.items.each do |invoice_item|
|
invoice.items.each do |invoice_item|
|
||||||
|
@ -27,7 +27,7 @@ module EisBilling
|
||||||
subtotal: invoice_item.subtotal,
|
subtotal: invoice_item.subtotal,
|
||||||
vat_rate: invoice_item.vat_rate,
|
vat_rate: invoice_item.vat_rate,
|
||||||
vat_amount: invoice_item.vat_amount,
|
vat_amount: invoice_item.vat_amount,
|
||||||
total: invoice_item.total
|
total: invoice_item.total,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
BASE_URL = ENV['eis_billing_system_base_url']
|
BASE_URL = ENV['eis_billing_system_base_url'] || 'https://st-billing.infra.tld.ee'
|
||||||
INITIATOR = 'registry'.freeze
|
INITIATOR = 'registry'.freeze
|
||||||
|
|
||||||
namespace :eis_billing do
|
namespace :eis_billing do
|
||||||
|
@ -9,7 +9,7 @@ namespace :eis_billing do
|
||||||
parsed_data << {
|
parsed_data << {
|
||||||
invoice_number: invoice.number,
|
invoice_number: invoice.number,
|
||||||
initiator: 'registry',
|
initiator: 'registry',
|
||||||
transaction_amount: invoice.total
|
transaction_amount: invoice.total,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ namespace :eis_billing do
|
||||||
Registrar.all.each do |registrar|
|
Registrar.all.each do |registrar|
|
||||||
parsed_data << {
|
parsed_data << {
|
||||||
reference_number: registrar.reference_no,
|
reference_number: registrar.reference_no,
|
||||||
initiator: 'registry'
|
initiator: 'registry',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue