Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ vendor/gems
.cursorindexingignore
.specstory/
Dockerfile.dev.v2

/docs
.repowise
18 changes: 15 additions & 3 deletions app/jobs/payment_lhv_connect_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ def open_ssl_keystore
def send_transactions(params:, payment_reference_number:)
reference = Reference.find_by(reference_number: payment_reference_number)

uri = URI.parse(url[reference.initiator.to_sym])
target_url = url[reference&.initiator&.to_sym]
if target_url.nil?
Rails.logger.error "No transaction endpoint for initiator #{reference&.initiator.inspect} " \
"(reference #{payment_reference_number}); skipping"
return
end

uri = URI.parse(target_url)
http = Net::HTTP.new(uri.host, uri.port)

http.use_ssl = true
Expand All @@ -130,7 +137,7 @@ def send_transactions(params:, payment_reference_number:)
OpenSSL::SSL::VERIFY_PEER
end

res = http.post(url[reference.initiator.to_sym], params.to_json, headers)
res = http.post(target_url, params.to_json, headers)

Rails.logger.info '>>>>>>'
Rails.logger.info res.body
Expand All @@ -155,7 +162,8 @@ def headers
def url
{
registry: registry_url_transaction,
auction: auction_url_transaction
auction: auction_url_transaction,
eeid: eeid_url_transaction
}
end

Expand All @@ -167,6 +175,10 @@ def auction_url_transaction
"#{ENV['base_auction']}/eis_billing/lhv_connect_transactions"
end

def eeid_url_transaction
"#{ENV['base_eeid']}/eis_billing/lhv_connect_transactions"
end

def billing_secret
ENV['billing_secret']
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/invoice/synchronization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def synchronize(status:)
end

def allow_to_synchronize?
initiator == 'registry' || initiator == 'auction'
%w[registry auction eeid].include?(initiator)
end

def restricted_statuses
Expand Down
2 changes: 1 addition & 1 deletion app/services/invoice_data_sender_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def to_whom
when 'registry'
"#{GlobalVariable::BASE_REGISTRY}/eis_billing/invoices"
when 'eeid'
"#{GlobalVariable::BASE_EEID}/#"
"#{GlobalVariable::BASE_EEID}/eis_billing/invoices"
when 'auction'
"#{GlobalVariable::BASE_AUCTION}/eis_billing/invoices"
else
Expand Down
32 changes: 32 additions & 0 deletions spec/jobs/payment_lhv_connect_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,36 @@
expect(result).to eq(ref)
end
end

describe 'routing transactions by initiator' do
let(:job) { PaymentLhvConnectJob.new }

it 'includes the eeid endpoint in the routing table' do
expect(job.send(:url)[:eeid]).to eq "#{ENV['base_eeid']}/eis_billing/lhv_connect_transactions"
end

it 'posts eeid transactions to the eeid endpoint without crashing' do
Reference.create(reference_number: '778', initiator: 'eeid')
allow(job).to receive(:headers).and_return({})

posted_to = nil
allow_any_instance_of(Net::HTTP).to receive(:post) do |_http, path, _body, _headers|
posted_to = path
OpenStruct.new(body: '200 - ok')
end

params = [OpenStruct.new(amount: '10.0', currency: 'EUR', payment_reference_number: '778')]
job.send(:send_transactions, params: params, payment_reference_number: '778')

expect(posted_to).to eq "#{ENV['base_eeid']}/eis_billing/lhv_connect_transactions"
end

it 'does not crash the batch for an unknown initiator' do
Reference.create(reference_number: '779', initiator: 'unknown_app')

expect do
job.send(:send_transactions, params: [], payment_reference_number: '779')
end.not_to raise_error
end
end
end
2 changes: 1 addition & 1 deletion spec/services/invoice_data_sender_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
invoice_sender = InvoiceDataSenderService.new(invoice: invoice, status: 'paid')
initiator = invoice_sender.send(:to_whom)

expect(initiator).to eq "#{GlobalVariable::BASE_EEID}/#"
expect(initiator).to eq "#{GlobalVariable::BASE_EEID}/eis_billing/invoices"
end
end

Expand Down
Loading