Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Released]

## [0.11.0] - 2025-06-25

- Add create report request

## [0.10.0] - 2025-02-19

- Change get_balances method
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ response.data
# {"balances"=>{"generated_at"=>"2024-08-30T13:02:00Z", "as_of_date"=>"2024-09-13T00:00:00.145823Z", "currencies"=>[{"currency"=>"BYN", "merchants"=>[{"id"=>47, "company_name"=>"John Deere LTD", "available_balance"=>100, "shops"=>[{ ...
```

Create report
```ruby
params = { user_id: 1, type: 'balance_records_report', format: 'csv',
request_params: { currency: 'USD', merchant_id: 12, date_from: '2025-01-01T00:00:00', date_to: '2025-03-16T23:59:59' } }
client.create_report(params)
response.data
# "{\"data\":{\"report\":{\"id\":\"961c3be2-c7b0-44ab-9f79-48cabd30c519\",\"status\":\"pending\",\"type\":\"balance_records_report\",\"format\":\"csv\",\"engine\":\"oban\",\"user_id\":1,\"language\":\"en\",\"updated_at\":\"2025-06-25T13:41:38.976093Z\",\"created_at\":\"2025-06-25T13:41:38.976093Z\",\"psp_id\":1,\"generated_at\":null,\"expiry_date\":null,\"file_url\":null,\"notification_email\":null,\"request_params\":{...}}}}"
```

## Errors

Unauthorized
Expand Down
4 changes: 4 additions & 0 deletions lib/boapi/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def delete_rate(id)
send_request(:delete, rate_path(id))
end

def create_report(params)
send_request(:post, '/api/v2/reports', params)
end

def send_request(method, path, params = nil)
response =
begin
Expand Down
41 changes: 41 additions & 0 deletions spec/boapi/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,45 @@
end
end
end

describe '.create_report' do
let(:response) do
Boapi::Client.new(account_id: account_id, account_secret: account_secret).create_report(params)
end
let(:http_status) { 201 }

let(:url) { "#{Boapi.configuration.api_host}/api/v2/reports" }
let(:report_request_params) do
{
date_from: '2025-01-01T00:00:00+00:00',
date_to: '2025-03-16T23:59:59+00:00',
currency: 'USD',
merchant_id: 12,
shop_id: 12,
gateway_id: 12
}
end
let(:params) do
{
id: '961c3be2-c7b0-44ab-9f79-48cabd30c519',
user_id: 1,
type: 'balance_records_report',
format: 'csv',
request_params: report_request_params
}
end

before do
stub_request(:post, url).with(body: params.to_json)
.to_return(status: http_status, body: ReportFixtures.successful_create_report_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(ReportFixtures.successful_create_report_response_message)
end
end
end
40 changes: 40 additions & 0 deletions spec/fixtures/report_fixtures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

# rubocop:disable Metrics/MethodLength
module ReportFixtures
module_function

def successful_create_report_response_message
{
'report' => {
'id' => '961c3be2-c7b0-44ab-9f79-48cabd30c519',
'status' => 'pending',
'type' => 'balance_records_report',
'format' => 'csv',
'engine' => 'oban',
'user_id' => 1,
'language' => 'en',
'updated_at' => '2025-06-25T13:41:38.976093Z',
'created_at' => '2025-06-25T13:41:38.976093Z',
'psp_id' => 1,
'generated_at' => nil,
'expiry_date' => nil,
'file_url' => nil,
'notification_email' => nil,
'request_params' => {
'currency' => 'USD',
'merchant_id' => 12,
'shop_id' => 12,
'gateway_id' => 12,
'date_from' => '2025-01-01T00:00:00+00:00',
'date_to' => '2025-03-16T23:59:59+00:00'
}
}
}
end

def successful_create_report_response
%({"data":#{successful_create_report_response_message.to_json}})
end
end
# rubocop:enable Metrics/MethodLength
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'fixtures/transaction_fixtures'
require 'fixtures/balance_fixtures'
require 'fixtures/balance_record_fixtures'
require 'fixtures/report_fixtures'

WebMock.disable_net_connect!(allow_localhost: false)

Expand Down