-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for Financial Actions API
- Loading branch information
1 parent
47227a0
commit 35d2a67
Showing
11 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'checkout_sdk/financial/financial_client' | ||
require 'checkout_sdk/financial/financial_actions_query' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module CheckoutSdk | ||
module Financial | ||
# @!attribute payment_id | ||
# @return [String] | ||
# @!attribute action_id | ||
# @return [String] | ||
# @!attribute limit | ||
# @return [Integer] | ||
# @!attribute pagination_token | ||
# @return [String] | ||
class FinancialActionsQuery | ||
attr_accessor :payment_id, | ||
:action_id, | ||
:limit, | ||
:pagination_token | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module CheckoutSdk | ||
module Financial | ||
class FinancialClient < Client | ||
FINANCIAL_ACTIONS = 'financial-actions' | ||
private_constant :FINANCIAL_ACTIONS | ||
|
||
# @param [ApiClient] api_client | ||
# @param [CheckoutConfiguration] configuration | ||
def initialize(api_client, configuration) | ||
super api_client, configuration, CheckoutSdk::AuthorizationType::SECRET_KEY_OR_OAUTH | ||
end | ||
|
||
# @param [FinancialActionsQuery] query_filter | ||
def query(query_filter) | ||
api_client.invoke_get(FINANCIAL_ACTIONS, sdk_authorization, query_filter) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,6 +269,5 @@ | |
end | ||
|
||
private def there_are_disputes(response) | ||
sleep 10 | ||
response.total_count > 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe CheckoutSdk::Financial do | ||
include PaymentsHelper | ||
|
||
describe '.query' do | ||
context 'when querying with valid filters' do | ||
it 'returns valid financial actions' do | ||
payment = make_card_payment(amount: 100, capture: true) | ||
|
||
query = CheckoutSdk::Financial::FinancialActionsQuery.new | ||
query.limit = 5 | ||
query.payment_id = payment.id | ||
|
||
proc = -> { oauth_sdk.financial.query(query) } | ||
predicate = ->(response) { there_are_financial_actions response } | ||
|
||
response = retriable proc, predicate, 5 | ||
|
||
assert_response response, | ||
%w[metadata | ||
count | ||
data | ||
_links] | ||
|
||
response.data&.each do |action| | ||
assert_response action, | ||
%w[payment_id | ||
action_id | ||
action_type | ||
entity_id | ||
currency_account_id | ||
processed_on | ||
requested_on] | ||
end | ||
end | ||
|
||
context 'when querying with invalid filters' do | ||
it 'raises an error' do | ||
query = CheckoutSdk::Financial::FinancialActionsQuery.new | ||
query.limit = 300 | ||
|
||
expect { oauth_sdk.financial.query(query) }.to raise_error(CheckoutSdk::CheckoutApiException) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
private def there_are_financial_actions(response) | ||
response.count > 0 | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters