diff --git a/CHANGELOG.md b/CHANGELOG.md index 7176bcc..bf08b64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Released] +## [0.13.0] - 2025-08-1 + +- Add aggregation request + ## [0.12.0] - 2025-06-26 - Add timeout error diff --git a/lib/boapi/client.rb b/lib/boapi/client.rb index 3ff2d3f..e547255 100644 --- a/lib/boapi/client.rb +++ b/lib/boapi/client.rb @@ -85,6 +85,10 @@ def create_report(params) send_request(:post, '/api/v2/reports', params) end + def reports_aggregation(params) + send_request(:post, '/api/v2/reports/aggregation', params) + end + # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/MethodLength def send_request(method, path, params = nil) diff --git a/lib/boapi/version.rb b/lib/boapi/version.rb index 7f8e863..1fcd357 100644 --- a/lib/boapi/version.rb +++ b/lib/boapi/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Boapi - VERSION = '0.12.0' + VERSION = '0.13.0' end diff --git a/spec/boapi/client_spec.rb b/spec/boapi/client_spec.rb index f121cf7..2417709 100644 --- a/spec/boapi/client_spec.rb +++ b/spec/boapi/client_spec.rb @@ -605,4 +605,46 @@ expect(response.data).to eq(ReportFixtures.successful_create_report_response_message) end end + + describe '.create_aggregation' do + let(:response) do + Boapi::Client.new(account_id: account_id, account_secret: account_secret).reports_aggregation(params) + end + let(:http_status) { 201 } + + let(:url) { "#{Boapi.configuration.api_host}/api/v2/reports/aggregation" } + + let(:params) do + { + type: 'credit_card', + language: 'en', + format: 'csv', + date_from: '2025-01-01T00:00:00+00:00', + date_to: '2025-03-16T23:59:59+00:00', + date_type: 'created_at', + group_by: nil, + transaction_parameters: { + gateway_type: %w[Bapb Bgpb], + currency: 'all', + type: %w[p2p payment capture] + } + } + end + + before do + stub_request(:post, url).with(body: params.to_json) + .to_return( + status: http_status, + body: AggregationFixtures.successful_create_aggregation_response + ) + end + + it 'returns successful response' do + expect(response.status).to be http_status + + expect(response.success?).to be true + expect(response.error?).to be false + expect(response.data).to eq(AggregationFixtures.successful_create_aggregation_response_message) + end + end end diff --git a/spec/fixtures/aggregation_fixtures.rb b/spec/fixtures/aggregation_fixtures.rb new file mode 100644 index 0000000..9350449 --- /dev/null +++ b/spec/fixtures/aggregation_fixtures.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +# rubocop:disable Metrics/MethodLength +module AggregationFixtures + module_function + + def successful_create_aggregation_response_message + { + 'grouped_data' => [ + { + 'count' => 6, + 'currency' => 'BYN', + 'gateway_type' => 'Bapb', + 'status' => 'successful', + 'type' => 'payment', + 'volume' => 5 + }, { + 'count' => 9, + 'currency' => 'BYN', + 'gateway_type' => 'Bgpb', + 'status' => 'successful', + 'type' => 'p2p', + 'volume' => 29.23 + }, { + 'count' => 1, + 'currency' => 'BYN', + 'gateway_type' => 'Bgpb', + 'status' => 'failed', + 'type' => 'payment', + 'volume' => 5 + }, { + 'count' => 1, + 'currency' => 'USD', + 'gateway_type' => 'Bgpb', + 'status' => 'failed', + 'type' => 'payment', + 'volume' => 5.93 + }, { + 'count' => 3, + 'currency' => 'BYN', + 'gateway_type' => 'Bgpb', + 'status' => 'incomplete', + 'type' => 'p2p', + 'volume' => 0.3 + }, { + 'count' => 57, + 'currency' => 'BYN', + 'gateway_type' => 'Bgpb', + 'status' => 'failed', + 'type' => 'p2p', + 'volume' => 486.1 + } + ], + 'total_count' => 46_892 + } + end + + def successful_create_aggregation_response + %({"data":#{successful_create_aggregation_response_message.to_json}}) + end +end +# rubocop:enable Metrics/MethodLength diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6886cf2..3366508 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,7 @@ require 'fixtures/balance_fixtures' require 'fixtures/balance_record_fixtures' require 'fixtures/report_fixtures' +require 'fixtures/aggregation_fixtures' WebMock.disable_net_connect!(allow_localhost: false)