mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 13:36:15 +02:00
added encryptor and service object status invoice request
This commit is contained in:
parent
28dcf047ef
commit
ee1408e49f
5 changed files with 53 additions and 10 deletions
|
@ -40,6 +40,11 @@ class Invoice < ApplicationRecord
|
|||
|
||||
attribute :vat_rate, ::Type::VatRate.new
|
||||
|
||||
def get_status_from_billing
|
||||
response = EisBilling::GetInvoiceStatus.send_invoice(invoice_number: number)
|
||||
JSON.parse(response.body, symbolize_names: true)[:status]
|
||||
end
|
||||
|
||||
def set_invoice_number
|
||||
if Feature.billing_system_integrated?
|
||||
result = EisBilling::GetInvoiceNumber.send_invoice
|
||||
|
|
18
app/presenters/registrar/invoice_status_presenter.rb
Normal file
18
app/presenters/registrar/invoice_status_presenter.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
class Registrar::InvoiceStatusPresenter
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
attr_reader :invoice
|
||||
|
||||
def initialize(invoice:)
|
||||
@invoice = invoice
|
||||
end
|
||||
|
||||
def display
|
||||
case invoice.get_status_from_billing
|
||||
when 'unpaid'
|
||||
content_tag(:span, 'Unpaid', style: 'color: red;')
|
||||
when 'paid'
|
||||
content_tag(:span, 'Unpaid', style: 'color: red;')
|
||||
end
|
||||
end
|
||||
end
|
18
app/services/eis_billing/get_invoice_status.rb
Normal file
18
app/services/eis_billing/get_invoice_status.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module EisBilling
|
||||
class GetInvoiceStatus < EisBilling::Base
|
||||
def self.send_invoice(invoice_number:)
|
||||
send_request(invoice_number: invoice_number)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.send_request(invoice_number:)
|
||||
http = EisBilling::Base.base_request(url: invoice_number_generator_url)
|
||||
http.get(invoice_number_generator_url + "/#{invoice_number}", EisBilling::Base.headers)
|
||||
end
|
||||
|
||||
def self.invoice_number_generator_url
|
||||
"#{BASE_URL}/api/v1/invoice_generator/invoice_status"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -34,3 +34,7 @@
|
|||
|
||||
%dt= Invoice.human_attribute_name :reference_no
|
||||
%dd= @invoice.reference_no
|
||||
|
||||
- invoice_presenter = Registrar::InvoiceStatusPresenter.new(invoice: @invoice)
|
||||
%dt Billing system
|
||||
%dd= invoice_presenter.display
|
|
@ -1,10 +1,5 @@
|
|||
TOKEN = ENV['eis_token']
|
||||
BASE_URL = ""
|
||||
if Rails.env.staging?
|
||||
BASE_URL = ENV['eis_billing_system_base_url_staging']
|
||||
else
|
||||
BASE_URL = ENV['eis_billing_system_base_url_dev']
|
||||
end
|
||||
BASE_URL = ENV['eis_billing_system_base_url']
|
||||
INITIATOR = 'registry'.freeze
|
||||
|
||||
namespace :eis_billing do
|
||||
desc 'One time task to export invoice data to billing system'
|
||||
|
@ -56,11 +51,11 @@ def base_request(url:, json_obj:)
|
|||
end
|
||||
|
||||
def generate_token
|
||||
JWT.encode(payload, ENV['secret_word'])
|
||||
JWT.encode(payload, billing_secret)
|
||||
end
|
||||
|
||||
def payload
|
||||
{ data: ENV['secret_access_word'] }
|
||||
{ initiator: INITIATOR }
|
||||
end
|
||||
|
||||
def headers
|
||||
|
@ -70,3 +65,6 @@ def headers
|
|||
}
|
||||
end
|
||||
|
||||
def self.billing_secret
|
||||
Rails.application.credentials.config[:billing_secret]
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue