Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CM-278] allow retrieve all sub merch #50

Merged
merged 5 commits into from
Dec 1, 2023

Conversation

jazziining
Copy link
Contributor

@jazziining jazziining commented Dec 1, 2023

Description:
This PR is to allow passing sub merchant id when calling the .show where we use the rpt_merchant_id like all other query elements. This will enable retrieving the report not only for a specific sub merchant but also for all live sub merchants.

This update should not affect any current usage, as you should still be able to pass the sub_merchant_id when calling the Bambora::Client.new. In the mean time, you can also get rid of that and pass additional element when calling the client.show where you can specify the sub merchant id by using the key rpt_merchant_id

Jira: CM-216

Test:

  • I have added the test in the spec
  • Test by adding the following in the console file and run ./bin/console
elements = {
  service_name: 'BatchPaymentsEFT',
  rpt_filter_by_1: 'returned_date',
  rpt_operation_type_1: 'GT',
  rpt_filter_value_1: '2023-08-01',
  rpt_merchant_id: 'AllLive',
}

client ||= begin
  url = ENV.fetch('BAMBORA_SCRIPTS_API_BASE_URL')
  partner_merchant_id = ENV.fetch("BAMBORA_CAD_MERCHANT_ID")
  reporting_api_key = ENV.fetch("BAMBORA_CAD_REPORTING_API_KEY")

  ::Bambora::Client
    .new(scripts_api_base_url: url, merchant_id: partner_merchant_id)
    .batch_reports(api_key: reporting_api_key)
end

response = client.show(elements)

puts response
  • Test by adding the following in the console file and run ./bin/console
elements = {
  service_name: 'BatchPaymentsEFT',
  rpt_filter_by_1: 'batch_id',
  rpt_operation_type_1: 'EQ',
  rpt_filter_value_1: 10000004,
}

client ||= begin
  url = ENV.fetch('BAMBORA_SCRIPTS_API_BASE_URL')
  partner_merchant_id = ENV.fetch("BAMBORA_CAD_MERCHANT_ID")
  reporting_api_key = ENV.fetch("BAMBORA_CAD_REPORTING_API_KEY")

  ::Bambora::Client
    .new(scripts_api_base_url: url, merchant_id: partner_merchant_id, sub_merchant_id: sub_merchan_id)
    .batch_reports(api_key: reporting_api_key)
end

response = client.show(elements)

puts response

@@ -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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change here as you can see from the line 168 the expected return is Bambora::Bank::BatchReportResource not Bambora::Bank::PaymentProfileResource


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 } }
Copy link
Contributor Author

@jazziining jazziining Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line as it is not used or needed.

@jazziining jazziining marked this pull request as ready for review December 1, 2023 15:18
Copy link
Contributor

@cristianoventura cristianoventura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

If we are planning to release this publicly right away I'd recommend bumping the patch or minor version as well as updating the changelog. If we do this, we probably need to make a release in ruby gems too, but if there are more related changes coming up, we can pack all of them together and release all at once.


params = DEFAULT_REQUEST_PARAMS.merge(additional_data).merge(request_data)

client.sub_merchant_id.nil? ? params : params.merge(sub_merchant_id: client.sub_merchant_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but an alternative could be using .compact to remove sub_merchant_id if it's nil.

https://ruby-doc.org/core-2.4.2/Hash.html#method-i-compact

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, does this new behaviour need to be documented in the Readme?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion from @cristianoventura is really good here. It may remove the need for the conditional logic, as long as we change the merge order, and then call #compact.

additional_data = {
  merchant_id: client.merchant_id,
  pass_code: api_key,
  sub_merchant_id: client.sub_merchant_id,
}

DEFAULT_REQUEST_PARAMS.merge(additional_data).merge(request_data).compact

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cristianoventura that's a good idea to update the README, although it needs some work in general. I'll note this for future work to update the README. Is that cool with you?

@@ -96,6 +99,15 @@ module Bank
)
end

let(:client_withot_sub_merchant_id) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let(:client_withot_sub_merchant_id) do
let(:client_without_sub_merchant_id) do

@harrylewis
Copy link
Member

@cristianoventura good call on the gem versioning. Since this is a change we are still going to be exercising and evaluating, I suggest we leave the versioning out for now until it has been living in production for some time, and then we can cut a new release.

Does that sound reasonable to you?

@harrylewis
Copy link
Member

@cristianoventura @jazziining that being said, I think we could update the CHANGELOG, with a new Unreleased heading, with a point about this new change. Do you mind doing that Jasmine?

@jazziining jazziining force-pushed the CM-278/allow-retrieve-all-sub-merch branch from cf3d542 to 5eb1707 Compare December 1, 2023 19:19
)
).compact
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, we can even keep the previous implementation mostly intact with that suggestion 🙏🏻

Copy link
Member

@harrylewis harrylewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change, lots of testing, and a much more flexible API! Great work @jazziining!

@jazziining jazziining merged commit ec6b0a3 into main Dec 1, 2023
3 checks passed
@jazziining jazziining deleted the CM-278/allow-retrieve-all-sub-merch branch December 1, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants