mirror of
https://github.com/internetee/registry.git
synced 2025-07-31 15:06:23 +02:00
added generator reference number which comes from billing system
This commit is contained in:
parent
9b6b8a5e2f
commit
84669297b5
8 changed files with 86 additions and 26 deletions
|
@ -4,8 +4,10 @@ module Billing
|
|||
MULTI_REGEXP = /(\d{2,20})/
|
||||
|
||||
def self.generate
|
||||
base = Base.generate
|
||||
"#{base}#{base.check_digit}"
|
||||
# base = Base.generate
|
||||
# "#{base}#{base.check_digit}"
|
||||
result = EisBilling::GetReferenceNumber.send_request
|
||||
JSON.parse(result.body)['reference_number']
|
||||
end
|
||||
|
||||
def self.valid?(ref)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
module EisBilling
|
||||
class GetInvoiceNumber < EisBilling::Base
|
||||
attr_reader :invoice
|
||||
|
||||
def self.send_invoice
|
||||
base_request
|
||||
end
|
||||
|
|
31
app/services/eis_billing/get_reference_number.rb
Normal file
31
app/services/eis_billing/get_reference_number.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module EisBilling
|
||||
class GetReferenceNumber < EisBilling::Base
|
||||
def self.send_request
|
||||
base_request
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.obj_data
|
||||
{
|
||||
initiator: 'registry'
|
||||
}
|
||||
end
|
||||
|
||||
def self.base_request
|
||||
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, obj_data.to_json, headers)
|
||||
end
|
||||
|
||||
def self.invoice_generator_url
|
||||
"#{BASE_URL}/api/v1/invoice_generator/reference_number_generator"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,6 +25,19 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
|
|||
|
||||
def test_create_new_invoice
|
||||
invoice_n = Invoice.order(number: :desc).last.number
|
||||
|
||||
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||
with(
|
||||
body: "{\"transaction_amount\":\"1200.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":\"\",\"custom_field_2\":\"registry\",\"invoice_number\":4}",
|
||||
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: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||
|
||||
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||
with(
|
||||
headers: {
|
||||
|
|
|
@ -7,6 +7,18 @@ class ReferenceNoTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_generated_reference_number_conforms_to_format
|
||||
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
|
||||
with(
|
||||
body: "{\"initiator\":\"registry\"}",
|
||||
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: "{\"reference_number\":\"12332\"}", headers: {})
|
||||
|
||||
reference_no = Billing::ReferenceNo.generate
|
||||
assert_match Billing::ReferenceNo::REGEXP, reference_no
|
||||
end
|
||||
|
|
|
@ -14,6 +14,18 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
def test_creates_new_registrar
|
||||
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
|
||||
with(
|
||||
body: "{\"initiator\":\"registry\"}",
|
||||
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: "{\"reference_number\":\"12332\"}", headers: {})
|
||||
|
||||
assert_nil Registrar.find_by(name: 'Acme Ltd')
|
||||
|
||||
visit admin_registrars_path
|
||||
|
|
|
@ -12,6 +12,18 @@ class AddDepositsTest < ApplicationSystemTestCase
|
|||
|
||||
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_generator").
|
||||
with(
|
||||
body: "{\"transaction_amount\":\"120.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":\"\",\"custom_field_2\":\"registry\",\"invoice_number\":4}",
|
||||
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: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||
|
||||
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||
with(
|
||||
headers: {
|
||||
|
@ -22,8 +34,8 @@ class AddDepositsTest < ApplicationSystemTestCase
|
|||
'User-Agent'=>'Ruby'
|
||||
}).
|
||||
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
|
||||
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
||||
# eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
|
||||
# Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
||||
|
||||
visit new_registrar_deposit_url
|
||||
fill_in 'Amount', with: '100.0'
|
||||
|
|
|
@ -43,26 +43,6 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase
|
|||
assert_text 'Invoice has been sent'
|
||||
end
|
||||
|
||||
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)
|
||||
visit registrar_invoice_url(invoice)
|
||||
|
||||
assert_text 'Everypay link'
|
||||
end
|
||||
|
||||
def test_if_invoice_unpaid_and_not_generated_link_comes_then_should_render_no_everypay_link
|
||||
invoice = invoices(:unpaid)
|
||||
visit registrar_invoice_url(invoice)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue