diff --git a/CHANGELOG.md b/CHANGELOG.md index aaee500..653dfb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased (2023-12-01) + +- Update `BatchReportResource#batch_report_body` to allow `sub merchant id` to be received from `Bambora::Client` or `elements` + ## 0.6.0 (2023-05-02) - Updating minimum Ruby version to Ruby 2.7.7 diff --git a/lib/bambora/bank/batch_report_resource.rb b/lib/bambora/bank/batch_report_resource.rb index 4684833..bd19b37 100644 --- a/lib/bambora/bank/batch_report_resource.rb +++ b/lib/bambora/bank/batch_report_resource.rb @@ -83,7 +83,7 @@ def batch_report_body(request_data) merchant_id: client.merchant_id, pass_code: api_key, sub_merchant_id: client.sub_merchant_id, - ) + ).compact end end end diff --git a/lib/bambora/client.rb b/lib/bambora/client.rb index ff19dc0..d6d7587 100644 --- a/lib/bambora/client.rb +++ b/lib/bambora/client.rb @@ -163,7 +163,7 @@ def bank_profiles(api_key:) # # @param api_key [String] API key for the bank profiles endpoint. # - # @return [Bambora::Bank::PaymentProfileResource] + # @return [Bambora::Bank::BatchReportResource] def batch_reports(api_key:) @batch_reports = Bambora::Bank::BatchReportResource.new( client: xml_client, diff --git a/spec/bambora/bank/batch_report_resource_spec.rb b/spec/bambora/bank/batch_report_resource_spec.rb index 6708362..76a6a15 100644 --- a/spec/bambora/bank/batch_report_resource_spec.rb +++ b/spec/bambora/bank/batch_report_resource_spec.rb @@ -6,12 +6,15 @@ module Bambora module Bank describe BatchReportResource do subject(:reports) { described_class.new(client: client, api_key: api_key) } + subject(:reports_without_sub_merchant_id) do + described_class.new(client: client_without_sub_merchant_id, api_key: api_key) + end let(:api_key) { 'fakekey' } let(:merchant_id) { 1 } let(:sub_merchant_id) { 2 } let(:base_url) { 'https://sandbox-web.na.bambora.com' } - let(:headers) { { 'Authorization' => 'Passcode MTpmYWtla2V5', 'Sub-Merchant-ID' => sub_merchant_id } } + let(:response_body) do { response: { @@ -96,6 +99,15 @@ module Bank ) end + let(:client_without_sub_merchant_id) do + instance_double( + 'Bambora::Rest::XMLClient', + merchant_id: merchant_id, + sub_merchant_id: nil, + post: response_body, + ) + end + describe '#show' do let(:batch_id) { 1 } let(:from_date) { Time.now.to_s } @@ -112,6 +124,7 @@ module Bank service_name: service_name, } end + let(:posted_data) do { body: { @@ -132,6 +145,34 @@ module Bank } end + let(:request_data_with_rpt_merchant_id) do + { + service_name: service_name, + rpt_filter_by_1: 'returned_date', + rpt_operation_type_1: 'GT', + rpt_filter_value_1: '2023-08-01', + rpt_merchant_id: 'AllLive', + } + end + + let(:posted_data_with_rpt_merchant_id) do + { + body: { + merchant_id: 1, + pass_code: 'fakekey', + rpt_filter_by_1: 'returned_date', + rpt_filter_value_1: '2023-08-01', + rpt_format: 'JSON', + rpt_operation_type_1: 'GT', + rpt_version: '2.0', + rpt_merchant_id: 'AllLive', + service_name: service_name, + session_source: 'external', + }, + path: '/scripts/reporting/report.aspx', + } + end + context 'with no messageId' do it 'sends `post` to the client with the correct data' do reports.show(request_data) @@ -141,6 +182,15 @@ module Bank it 'returns the expected response' do expect(reports.show(request_data)).to eq expected_response end + + it 'sends `post` to the client with the correct data where the sub merchant id comes from elements' do + reports_without_sub_merchant_id.show(request_data_with_rpt_merchant_id) + expect(client_without_sub_merchant_id).to have_received(:post).with(posted_data_with_rpt_merchant_id) + end + + it 'returns the expected response' do + expect(reports_without_sub_merchant_id.show(request_data_with_rpt_merchant_id)).to eq expected_response + end end context 'with messageIds' do