added link generator into admin part

This commit is contained in:
olegphenomenon 2022-01-26 13:24:58 +02:00
parent 9f4942e522
commit 9b6b8a5e2f
8 changed files with 135 additions and 2 deletions

View file

@ -13,6 +13,7 @@ module Admin
if @invoice&.persisted? if @invoice&.persisted?
flash[:notice] = t(:record_created) flash[:notice] = t(:record_created)
send_invoice_data_to_billing_system
redirect_to [:admin, @invoice] redirect_to [:admin, @invoice]
else else
flash.now[:alert] = t(:failed_to_create_record) flash.now[:alert] = t(:failed_to_create_record)
@ -100,5 +101,14 @@ module Admin
invoices.where(account_activities: { created_at: date_from..date_until }) invoices.where(account_activities: { created_at: date_from..date_until })
end end
def send_invoice_data_to_billing_system
add_invoice_instance = EisBilling::AddDeposits.new(@invoice)
result = add_invoice_instance.send_invoice
link = JSON.parse(result.body)['everypay_link']
@invoice.update(payment_link: link)
end
end end
end end

View file

@ -54,6 +54,17 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
end end
def test_can_bind_statement_transactions def test_can_bind_statement_transactions
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
registrar = registrars(:bestnames) registrar = registrars(:bestnames)
registrar.issue_prepayment_invoice(500) registrar.issue_prepayment_invoice(500)
invoice = registrar.invoices.last invoice = registrar.invoices.last

View file

@ -11,6 +11,17 @@ class AddDepositsTest < ApplicationSystemTestCase
end end
def test_should_send_request_for_creating_invoice_to_eis_system def test_should_send_request_for_creating_invoice_to_eis_system
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response) Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)

View file

@ -14,6 +14,17 @@ class BalanceTopUpTest < ApplicationSystemTestCase
end end
def test_creates_new_invoice def test_creates_new_invoice
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
Setting.registry_vat_prc = 0.1 Setting.registry_vat_prc = 0.1
visit registrar_invoices_url visit registrar_invoices_url

View file

@ -27,6 +27,17 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase
end end
def test_create_new_SEB_payment def test_create_new_SEB_payment
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
create_invoice_and_visit_its_page create_invoice_and_visit_its_page
click_link_or_button 'seb' click_link_or_button 'seb'
form = page.find('form') form = page.find('form')
@ -36,6 +47,17 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase
end end
def test_create_new_Every_Pay_payment def test_create_new_Every_Pay_payment
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
create_invoice_and_visit_its_page create_invoice_and_visit_its_page
click_link_or_button 'every_pay' click_link_or_button 'every_pay'
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' + expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +

View file

@ -17,6 +17,17 @@ class NewInvoiceTest < ApplicationSystemTestCase
end end
def test_create_new_invoice_with_positive_amount def test_create_new_invoice_with_positive_amount
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
visit registrar_invoices_path visit registrar_invoices_path
click_link_or_button 'Add deposit' click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00' fill_in 'Amount', with: '200.00'
@ -27,12 +38,23 @@ class NewInvoiceTest < ApplicationSystemTestCase
end end
assert_text 'Please pay the following invoice' assert_text 'Please pay the following invoice'
assert_text 'Invoice no. 131050' assert_text "Invoice no. #{invoice_n + 3}"
assert_text 'Subtotal 200,00 €' assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice' assert_text 'Pay invoice'
end end
def test_create_new_invoice_with_comma_in_number def test_create_new_invoice_with_comma_in_number
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
visit registrar_invoices_path visit registrar_invoices_path
click_link_or_button 'Add deposit' click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200,00' fill_in 'Amount', with: '200,00'
@ -43,7 +65,7 @@ class NewInvoiceTest < ApplicationSystemTestCase
end end
assert_text 'Please pay the following invoice' assert_text 'Please pay the following invoice'
assert_text 'Invoice no. 131050' assert_text "Invoice no. #{invoice_n + 3}"
assert_text 'Subtotal 200,00 €' assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice' assert_text 'Pay invoice'
end end

View file

@ -44,6 +44,19 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase
end end
def test_if_invoice_unpaid_should_be_present_everypay_link def test_if_invoice_unpaid_should_be_present_everypay_link
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
invoice = invoices(:unpaid) invoice = invoices(:unpaid)
visit registrar_invoice_url(invoice) visit registrar_invoice_url(invoice)

View file

@ -20,6 +20,17 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
reload_amount = 100 reload_amount = 100
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount) registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
@ -50,6 +61,17 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end end
def test_marks_registrar_as_pending_balance_reload def test_marks_registrar_as_pending_balance_reload
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
registrar = registrar_with_auto_reload_enabled_and_threshold_reached registrar = registrar_with_auto_reload_enabled_and_threshold_reached
capture_io { run_task } capture_io { run_task }
@ -59,6 +81,17 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end end
def test_output def test_output
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
reload_amount = 100 reload_amount = 100
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount) registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
assert_equal 'Best Names', registrar.name assert_equal 'Best Names', registrar.name