From 905a90dc4883a1c2099ae2ce615f622f3cd4d053 Mon Sep 17 00:00:00 2001 From: Pavlo Demchenko Date: Mon, 11 Aug 2025 15:08:33 +0300 Subject: [PATCH 1/6] Add aggregation request --- CHANGELOG.md | 4 ++ lib/boapi/client.rb | 4 ++ spec/boapi/client_spec.rb | 41 ++++++++++++++++++ spec/fixtures/aggregation_fixtures.rb | 60 +++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 5 files changed, 110 insertions(+) create mode 100644 spec/fixtures/aggregation_fixtures.rb 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/spec/boapi/client_spec.rb b/spec/boapi/client_spec.rb index f121cf7..3c687e9 100644 --- a/spec/boapi/client_spec.rb +++ b/spec/boapi/client_spec.rb @@ -605,4 +605,45 @@ 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: [ + "Bapb", "Bgpb" + ], + currency: "all", + type: ["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..01877b3 --- /dev/null +++ b/spec/fixtures/aggregation_fixtures.rb @@ -0,0 +1,60 @@ +# 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" => 46892 + } + 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) From de4dc188c9a394c491ef4e809e7e2856f014dd4d Mon Sep 17 00:00:00 2001 From: Pavlo Demchenko Date: Mon, 11 Aug 2025 15:11:49 +0300 Subject: [PATCH 2/6] Add aggregation request --- spec/fixtures/aggregation_fixtures.rb | 76 +++++++++++++-------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/spec/fixtures/aggregation_fixtures.rb b/spec/fixtures/aggregation_fixtures.rb index 01877b3..b39db07 100644 --- a/spec/fixtures/aggregation_fixtures.rb +++ b/spec/fixtures/aggregation_fixtures.rb @@ -6,50 +6,50 @@ module AggregationFixtures def successful_create_aggregation_response_message { - "grouped_data" => [{ - "count" => 6, - "currency" => "BYN", - "gateway_type" => "Bapb", - "status" => "successful", - "type" => "payment", - "volume" => 5 + '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' => 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' => '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' => 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' => 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 + 'count' => 57, + 'currency' => 'BYN', + 'gateway_type' => 'Bgpb', + 'status' => 'failed', + 'type' => 'p2p', + 'volume' => 486.1 }], - "total_count" => 46892 + 'total_count' => 46892 } end From 60a33a5fffc9666b29ba8fc4613a4dadb0a29687 Mon Sep 17 00:00:00 2001 From: Pavlo Demchenko Date: Mon, 11 Aug 2025 15:16:18 +0300 Subject: [PATCH 3/6] Add aggregation request --- spec/boapi/client_spec.rb | 14 +++++++------- spec/fixtures/aggregation_fixtures.rb | 16 +++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/spec/boapi/client_spec.rb b/spec/boapi/client_spec.rb index 3c687e9..b41f150 100644 --- a/spec/boapi/client_spec.rb +++ b/spec/boapi/client_spec.rb @@ -616,19 +616,19 @@ let(:params) do { - type: "credit_card", - language: "en", - format: "csv", + 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", + date_type: 'created_at', group_by: nil, transaction_parameters: { gateway_type: [ - "Bapb", "Bgpb" + 'Bapb', 'Bgpb' ], - currency: "all", - type: ["p2p","payment","capture"] + currency: 'all', + type: ['p2p','payment','capture'] } } end diff --git a/spec/fixtures/aggregation_fixtures.rb b/spec/fixtures/aggregation_fixtures.rb index b39db07..87dceca 100644 --- a/spec/fixtures/aggregation_fixtures.rb +++ b/spec/fixtures/aggregation_fixtures.rb @@ -6,49 +6,51 @@ module AggregationFixtures def successful_create_aggregation_response_message { - 'grouped_data' => [{ + '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' => 46892 } end From 0635df654af36bf7c2ea4d9a2d5861ab6ed8c5cb Mon Sep 17 00:00:00 2001 From: Pavlo Demchenko Date: Mon, 11 Aug 2025 15:21:21 +0300 Subject: [PATCH 4/6] Add aggregation request --- spec/boapi/client_spec.rb | 8 +++----- spec/fixtures/aggregation_fixtures.rb | 10 +++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/spec/boapi/client_spec.rb b/spec/boapi/client_spec.rb index b41f150..e12d633 100644 --- a/spec/boapi/client_spec.rb +++ b/spec/boapi/client_spec.rb @@ -624,18 +624,16 @@ date_type: 'created_at', group_by: nil, transaction_parameters: { - gateway_type: [ - 'Bapb', 'Bgpb' - ], + gateway_type: %w[Bapb Bgpb], currency: 'all', - type: ['p2p','payment','capture'] + 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) + .to_return(status: http_status, body: AggregationFixtures.successful_create_aggregation_response) end it 'returns successful response' do diff --git a/spec/fixtures/aggregation_fixtures.rb b/spec/fixtures/aggregation_fixtures.rb index 87dceca..8e35b9a 100644 --- a/spec/fixtures/aggregation_fixtures.rb +++ b/spec/fixtures/aggregation_fixtures.rb @@ -14,35 +14,35 @@ def successful_create_aggregation_response_message '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', From bbf2d53681119e42ab49df5d3d7cd98f8e430462 Mon Sep 17 00:00:00 2001 From: Pavlo Demchenko Date: Mon, 11 Aug 2025 15:23:33 +0300 Subject: [PATCH 5/6] Add aggregation request --- spec/boapi/client_spec.rb | 5 ++++- spec/fixtures/aggregation_fixtures.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/boapi/client_spec.rb b/spec/boapi/client_spec.rb index e12d633..2417709 100644 --- a/spec/boapi/client_spec.rb +++ b/spec/boapi/client_spec.rb @@ -633,7 +633,10 @@ before do stub_request(:post, url).with(body: params.to_json) - .to_return(status: http_status, body: AggregationFixtures.successful_create_aggregation_response) + .to_return( + status: http_status, + body: AggregationFixtures.successful_create_aggregation_response + ) end it 'returns successful response' do diff --git a/spec/fixtures/aggregation_fixtures.rb b/spec/fixtures/aggregation_fixtures.rb index 8e35b9a..9350449 100644 --- a/spec/fixtures/aggregation_fixtures.rb +++ b/spec/fixtures/aggregation_fixtures.rb @@ -51,7 +51,7 @@ def successful_create_aggregation_response_message 'volume' => 486.1 } ], - 'total_count' => 46892 + 'total_count' => 46_892 } end From 02b70841435555a7cfae125334589fab2f8aa88c Mon Sep 17 00:00:00 2001 From: Pavlo Demchenko Date: Thu, 21 Aug 2025 10:21:35 +0300 Subject: [PATCH 6/6] Upd VERSION to 0.13.0 --- lib/boapi/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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