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

[BEP-17997] add transactions export #12

Merged
merged 3 commits into from
Nov 28, 2024
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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ response = client.transactions_list(params)
response.status # 200
response.success? # true
response.data
# {"pagination"=>{"date_from"=>"2023-02-20T09:02:54.516000Z", "date_to"=>"2023-02-20T09:02:54.516000Z", "date_type"=>"created_at", "has_next_page"=>true, "next_date"=>"2023-02-20T09:36:15.175000Z"}, "transactions"=>[{"amount"=>123, "created_at"=>"2023-02-270T09:12:54.516000Z", "currency"=>"trx_cur", "merchant_id"=>123, "paid_at"=>"2023-02-12T09:02:59.669000Z", "shop_id"=>123, "status"=>"trx_status", "type"=>"trx_type", "uid"=>"xxxxxxx-fa21-xxxx-xxxx-xxxxeec8661f"}ruby
# {"pagination"=>{"date_from"=>"2023-02-20T09:02:54.516000Z", "date_to"=>"2023-02-20T09:02:54.516000Z", "date_type"=>"created_at", "has_next_page"=>true, "next_date"=>"2023-02-20T09:36:15.175000Z"}, "transactions"=>[{"amount"=>123, "created_at"=>"2023-02-270T09:12:54.516000Z", "currency"=>"trx_cur", "merchant_id"=>123, "paid_at"=>"2023-02-12T09:02:59.669000Z", "shop_id"=>123, "status"=>"trx_status", "type"=>"trx_type", "uid"=>"xxxxxxx-fa21-xxxx-xxxx-xxxxeec8661f"}
```

Transactions list with response params
Expand Down Expand Up @@ -111,6 +111,17 @@ response.data
# {"pagination"=>{"date_from"=>"2023-02-20T09:02:59.669000Z", "date_to"=>"2023-02-20T09:02:59.669000Z", "date_type"=>"paid_at", "has_next_page"=>true, "next_date"=>"2023-02-20T09:36:15.994000Z"}, "transactions"=>[{"paid_at"=>"2023-02-20T09:12:34.567000Z", "provider_raw"=>{"ref_id"=>nil}, "shop_id"=>123, "uid"=>"e4800e1b-xxxx-xxxx-ae25-16f1xxxx661f"}]}
```

Transactions export with response params

```ruby
params = { response_parameters: "main", filter: { date_from: '2024-11-01T00:00:00.000000', date_to: '2024-11-02T00:00:00.000000', date_type: 'created_at', type: 'p2p' }, options: { limit: 1, sort_direction: 'desc' } }
response = client.transactions_export(params)
response.status # 200
response.success? # true
response.data
# {"data":{"pagination":{"date_type":"created_at","has_next_page":false,"date_from":"2024-11-01T08:58:46.705000Z","date_to":"2024-11-01T08:58:46.705000Z","uid_from":"6ca3d635-6841-4ac9-b583-a3bf0eafc160","uid_to":"6ca3d635-6841-4ac9-b583-a3bf0eafc160"},"transactions":[{"amount":100,"closed_at":null,"code":"S.0000","converted_amount":null,"converted_currency":null,"created_at":"2024-11-01T08:58:46.705000Z","currency":"BYN","description":"Testtransactionp2psLAA","expired_at":null,"fraud":"","friendly_message":"Транзакцияпроведенауспешно.","language":"ru","manually_corrected_at":null,"merchant_id":55,"message":"Successfullyprocessed","paid_at":"2024-11-01T08:58:50.589000Z","parent_uid":null,"product_id":null,"reason":null,"recurring_type":null,"settled_at":null,"shop_id":1990,"status":"successful","subscription_id":null,"test":false,"tracking_id":"tracking_id_000","type":"p2p","uid":"6ca3d635-6841-4ac9-b583-a3bf0eafc160","updated_at":"2024-11-01T08:58:50.644000Z"}]}}
```

Create rate

```ruby
Expand Down
4 changes: 4 additions & 0 deletions lib/boapi/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def transactions_deep_search(params)
send_request(:post, '/api/v2/transactions/deep_search', params)
end

def transactions_export(params)
send_request(:post, '/api/v2/transactions/export', params)
end

def merchant_balances_for_psp(merchant_id, params)
send_request(:get, "/api/v2/psp/merchants/#{merchant_id}/balances", params)
end
Expand Down
36 changes: 36 additions & 0 deletions spec/boapi/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,42 @@
end
end

describe '.transactions_export' do
let(:response) do
Boapi::Client.new(account_id: account_id, account_secret: account_secret).transactions_export(params)
end

let(:url) { "#{Boapi.configuration.api_host}/api/v2/transactions/export" }

context 'when valid params given' do
let(:params) do
{
filter: {
status: 'successful',
date_from: '2024-11-01T00:00:00.000000',
date_to: '2024-11-02T00:00:00.000000',
type: 'p2p'
},
options: { limit: 1 }
}
end
let(:http_status) { 200 }

before do
stub_request(:post, url)
.to_return(status: http_status, body: TransactionFixtures.successful_transactions_export_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(TransactionFixtures.successful_transactions_export_response_message)
end
end
end

describe '.merchant_balances_for_psp' do
let(:response) do
Boapi::Client.new(account_id: account_id, account_secret: account_secret)
Expand Down
30 changes: 30 additions & 0 deletions spec/fixtures/transaction_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,34 @@ def successful_transactions_list_response_message
def successful_transactions_list_response
%({"data":#{successful_transactions_list_response_message.to_json}})
end

# rubocop:disable Metrics/MethodLength
def successful_transactions_export_response_message
{
'transactions' => [
{
'amount' => 100, 'closed_at' => nil, 'code' => 'S.0000', 'converted_amount' => nil,
'converted_currency' => nil, 'created_at' => '2024-11-01T08:58:46.705000Z', 'currency' => 'BYN',
'description' => 'Test transaction p2ps LAA', 'expired_at' => nil, 'fraud' => '',
'friendly_message' => 'Транзакция проведена успешно.', 'language' => 'ru',
'manually_corrected_at' => nil, 'merchant_id' => 55, 'message' => 'Successfully processed',
'paid_at' => '2024-11-01T08:58:50.589000Z', 'parent_uid' => nil, 'product_id' => nil,
'reason' => nil, 'recurring_type' => nil, 'settled_at' => nil, 'shop_id' => 1990,
'status' => 'successful', 'subscription_id' => nil, 'test' => false,
'tracking_id' => 'tracking_id_000', 'type' => 'p2p', 'uid' => '6ca3d635-6841-4ac9-b583-a3bf0eafc160',
'updated_at' => '2024-11-01T08:58:50.644000Z'
}
],
'pagination' => {
'date_type' => 'created_at', 'has_next_page' => false, 'date_from' => '2024-11-01T08:58:46.705000Z',
'date_to' => '2024-11-01T08:58:46.705000Z', 'uid_from' => '6ca3d635-6841-4ac9-b583-a3bf0eafc160',
'uid_to' => '6ca3d635-6841-4ac9-b583-a3bf0eafc160'
}
}
end
# rubocop:enable Metrics/MethodLength

def successful_transactions_export_response
%({"data":#{successful_transactions_export_response_message.to_json}})
end
end