diff --git a/README.md b/README.md index d468f76..d308eb3 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Do yourself a favor: go grab some ice cubes by installing this refreshing librar - [How to Install](#how-to-install) - [Quickstart](#quickstart) - [Client Architecture](#client-architecture) - - [**Movements API Client**](#movements-api-client) - - [**Transfers API Client**](#transfers-api-client) + - [**API V1 Client**](#api-v1-client) + - [**API V2 Client**](#api-v2-client) - [**Backward compatibility**](#backward-compatibility) - [Documentation](#documentation) - [Examples](#examples) @@ -31,7 +31,7 @@ Do yourself a favor: go grab some ice cubes by installing this refreshing librar - [Transfer Accounts](#transfer-accounts) - [Account Numbers](#account-numbers) - [Transfers](#transfers) - - [Simulation](#simulation) + - [Simulate](#simulate) - [Account Verifications](#account-verifications) - [Development](#development) - [Dependencies](#dependencies) @@ -63,16 +63,15 @@ Or install it yourself as: ```ruby require 'fintoc' -movements_client = - Fintoc::Movements::Client.new('sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx') -link = movements_client.get_link('6n12zLmai3lLE9Dq_token_gvEJi8FrBge4fb3cz7Wp856W') +client_v1 = Fintoc::V1::Client.new('api_key') +link = client_v1.links.get('link_token') account = link.find(type: 'checking_account') # Get the last 30 movements -movements = account.get_movements +movements = account.movements.list # Or get all the movements since a specific date -movements = account.get_movements(since: '2020-08-15') +movements = account.movements.list(since: '2020-08-15') ``` And that’s it! @@ -81,73 +80,87 @@ And that’s it! The Fintoc Ruby client is organized into separate clients that mirror the official API structure: -### **Movements API Client** +### **API V1 Client** -The Movements API client provides access to bank account data and movements: +The API client currently provides access to part of the Movements API: ```ruby -movements_client = Fintoc::Movements::Client.new('api_key') +client = Fintoc::V1::Client.new('api_key') # Link management -links = movements_client.get_links -link = movements_client.get_link('link_token') -movements_client.delete_link('link_id') +links = client_v1.links.list +link = client_v1.links.get('link_token') +client_v1.links.delete('link_id') # Account access -account = movements_client.get_account('link_token', 'account_id') +account = link.find(id: account_id) ``` -### **Transfers API Client** +### **API V2 Client** -The Transfers API client provides access to transfer accounts, entities, and transfer operations: +The API V2 client currently provides access to part of the Transfers API: ```ruby -transfers_client = Fintoc::Transfers::Client.new('api_key') +client = Fintoc::V1::Client.new('api_key') # Entities -entities = transfers_client.get_entities -entity = transfers_client.get_entity('entity_id') +entities = client_v2.entities.list +entity = client_v2.entities.get('entity_id') # Transfer Accounts -accounts = transfers_client.list_accounts -account = transfers_client.get_account('account_id') -account = transfers_client.create_account(entity_id: 'entity_id', description: 'My Account') -transfers_client.update_account('account_id', description: 'Updated') +accounts = client_v2.accounts.list +account = client_v2.accounts.get('account_id') +account = client_v2.accounts.create(entity_id: 'entity_id', description: 'My Account') +client_v2.accounts.update('account_id', description: 'Updated') # Account Numbers -account_numbers = transfers_client.list_account_numbers -account_number = transfers_client.get_account_number('account_number_id') -account_number = transfers_client.create_account_number(account_id: 'account_id', description: 'Main') -transfers_client.update_account_number('account_number_id', description: 'Updated') +account_numbers = client_v2.account_numbers.list +account_number = client_v2.account_numbers.get('account_number_id') +account_number = client_v2.account_numbers.create(account_id: 'account_id', description: 'Main') +client_v2.account_numbers.update('account_number_id', description: 'Updated') # Transfers -transfers = transfers_client.list_transfers -transfer = transfers_client.get_transfer('transfer_id') -transfer = transfers_client.create_transfer(amount: 1000, currency: 'CLP', account_id: 'account_id', counterparty: {...}) -transfers_client.return_transfer('transfer_id') +transfers = client_v2.transfers.list +transfer = client_v2.transfers.get('transfer_id') +transfer = client_v2.transfers.create( + amount: 1000, + currency: 'CLP', + account_id: 'account_id', + counterparty: {...} +) +client_v2.transfers.return('transfer_id') -# Simulation -simulation = transfers_client.simulate_receive_transfer(account_number_id: 'account_number_id', amount: 1000, currency: 'CLP') +# Simulate +simulated_transfer = client_v2.simulate.receive_transfer( + account_number_id: 'account_number_id', + amount: 1000, + currency: 'CLP' +) # Account Verifications -account_verifications = transfers_client.list_account_verifications -account_verification = transfers_client.get_account_verification('account_verification_id') -account_verification = transfers_client.create_account_verification(account_number: 'account_number') +account_verifications = client_v2.account_verifications.list +account_verification = client_v2.account_verifications.get('account_verification_id') +account_verification = client_v2.account_verifications.create(account_number: 'account_number') + +# TODO: Movements ``` ### **Backward compatibility** -The previous `Fintoc::Client` class is kept for backward compatibility purposes. +The methods of the previous `Fintoc::Client` class implementation are kept for backward compatibility purposes. ```ruby -client = Fintoc::Client.new('api_key') +client = Fintoc::V1::Client.new('api_key') +link = client.get_link('link_token') links = client.get_links +client.delete_link(link.id) +account = client.get_account('link_token', 'account_id') ``` ## Documentation -This client supports all Fintoc API endpoints. For complete information about the API, head to the [docs](https://docs.fintoc.com/reference). +This client does not support all Fintoc API endpoints yet. For complete information about the API, head to the [docs](https://docs.fintoc.com/reference). ## Examples @@ -158,13 +171,13 @@ This client supports all Fintoc API endpoints. For complete information about th ```ruby require 'fintoc' -client = Fintoc::Movements::Client.new('api_key') -link = client.get_link('link_token') +client = Fintoc::V1::Client.new('api_key') +link = client_v1.links.get('link_token') puts link.accounts # Or... you can pretty print all the accounts in a Link -link = client.get_link('link_token') +link = client_v1.links.get('link_token') link.show_accounts ``` @@ -174,8 +187,8 @@ If you want to find a specific account in a link, you can use **find**. You can ```ruby require 'fintoc' -client = Fintoc::Movements::Client.new('api_key') -link = client.get_link('link_token') +client = Fintoc::V1::Client.new('api_key') +link = client_v1.links.get('link_token') account = link.find(type: 'checking_account') # Or by number @@ -190,8 +203,8 @@ You can also search for multiple accounts matching a specific criteria with **fi ```ruby require 'fintoc' -client = Fintoc::Movements::Client.new('api_key') -link = client.get_link('link_token') +client = Fintoc::V1::Client.new('api_key') +link = client_v1.links.get('link_token') accounts = link.find_all(currency: 'CLP') ``` @@ -200,8 +213,8 @@ To update the account balance you can use **update_balance**: ```ruby require 'fintoc' -client = Fintoc::Movements::Client.new('api_key') -link = client.get_link('link_token') +client = Fintoc::V1::Client.new('api_key') +link = client_v1.links.get('link_token') account = link.find(number: '1111111') account.update_balance ``` @@ -212,22 +225,22 @@ account.update_balance require 'fintoc' require 'time' -client = Fintoc::Movements::Client.new('api_key') -link = client.get_link('link_token') +client = Fintoc::V1::Client.new('api_key') +link = client_v1.links.get('link_token') account = link.find(type: 'checking_account') # You can get the account movements since a specific DateTime yesterday = DateTime.now - 1 -account.get_movements(since: yesterday) +account.movements.list(since: yesterday) # Or you can use an ISO 8601 formatted string representation of the Date -account.get_movements(since: '2020-01-01') +account.movements.list(since: '2020-01-01') # You can also set how many movements you want per_page -account.get_movements(since: '2020-01-01', per_page: 100) +account.movements.list(since: '2020-01-01', per_page: 100) ``` -Calling **get_movements** without arguments gets the last 30 movements of the account +Calling **movements.list** without arguments gets the last 30 movements of the account ### Transfers API Examples @@ -236,24 +249,20 @@ Calling **get_movements** without arguments gets the last 30 movements of the ac ```ruby require 'fintoc' -client = Fintoc::Transfers::Client.new('api_key') +client_v2 = Fintoc::V2::Client.new('api_key', 'jws_private_key') # Get all entities -entities = client.get_entities +entities = client_v2.entities.list # Get a specific entity -entity = client.get_entity('entity_id') - -puts entity.holder_name # => "My Company LLC" -puts entity.holder_id # => "12345678-9" -puts entity.is_root # => true +entity = client_v2.entities.get('entity_id') ``` You can also list entities with pagination: ```ruby # Get entities with pagination -entities = client.get_entities(limit: 10, starting_after: 'entity_id') +entities = client_v2.entities.list(limit: 10, starting_after: 'entity_id') ``` #### Transfer Accounts @@ -261,22 +270,22 @@ entities = client.get_entities(limit: 10, starting_after: 'entity_id') ```ruby require 'fintoc' -client = Fintoc::Transfers::Client.new('api_key') +client_v2 = Fintoc::V2::Client.new('api_key', 'jws_private_key') # Create a transfer account -account = client.create_account( +account = client_v2.accounts.create( entity_id: 'entity_id', description: 'My Business Account' ) # Get a specific account -account = client.get_account('account_id') +account = client_v2.accounts.get('account_id') # List all accounts -accounts = client.list_accounts +accounts = client_v2.accounts.list # Update an account -updated_account = client.update_account('account_id', description: 'Updated Description') +updated_account = client_v2.accounts.update('account_id', description: 'Updated Description') ``` #### Account Numbers @@ -284,22 +293,22 @@ updated_account = client.update_account('account_id', description: 'Updated Desc ```ruby require 'fintoc' -client = Fintoc::Transfers::Client.new('api_key') +client_v2 = Fintoc::V2::Client.new('api_key', 'jws_private_key') # Create an account number -account_number = client.create_account_number( +account_number = client_v2.account_numbers.create( account_id: 'account_id', description: 'Main account number' ) # Get a specific account number -account_number = client.get_account_number('account_number_id') +account_number = client_v2.account_numbers.get('account_number_id') # List all account numbers -account_numbers = client.list_account_numbers +account_numbers = client_v2.account_numbers.list # Update an account number -updated_account_number = client.update_account_number( +updated_account_number = client_v2.account_numbers.update( 'account_number_id', description: 'Updated account number' ) @@ -310,10 +319,10 @@ updated_account_number = client.update_account_number( ```ruby require 'fintoc' -client = Fintoc::Transfers::Client.new('api_key') +client_v2 = Fintoc::V2::Client.new('api_key', 'jws_private_key') # Create a transfer -transfer = client.create_transfer( +transfer = client_v2.transfers.create( amount: 10000, currency: 'CLP', account_id: 'account_id', @@ -328,24 +337,24 @@ transfer = client.create_transfer( ) # Get a specific transfer -transfer = client.get_transfer('transfer_id') +transfer = client_v2.transfers.get('transfer_id') # List all transfers -transfers = client.list_transfers +transfers = client_v2.transfers.list # Return a transfer -returned_transfer = client.return_transfer('transfer_id') +returned_transfer = client_v2.transfers.return('transfer_id') ``` -#### Simulation +#### Simulate ```ruby require 'fintoc' -client = Fintoc::Transfers::Client.new('api_key') +client_v2 = Fintoc::V2::Client.new('api_key', 'jws_private_key') # Simulate receiving a transfer -simulation = client.simulate_receive_transfer( +simulated_transfer = client_v2.simulate.receive_transfer( account_number_id: 'account_number_id', amount: 5000, currency: 'CLP' @@ -357,16 +366,16 @@ simulation = client.simulate_receive_transfer( ```ruby require 'fintoc' -client = Fintoc::Transfers::Client.new('api_key') +client_v2 = Fintoc::V2::Client.new('api_key', 'jws_private_key') # Create an account verification -account_verification = client.create_account_verification(account_number: 'account_number') +account_verification = client_v2.account_verifications.create(account_number: 'account_number') # Get a specific account verification -account_verification = client.get_account_verification('account_verification_id') +account_verification = client_v2.account_verifications.get('account_verification_id') # List all account verifications -account_verifications = client.list_account_verifications +account_verifications = client_v2.account_verifications.list ``` ## Development diff --git a/lib/fintoc/base_client.rb b/lib/fintoc/base_client.rb index ebe01f5..2bf40d9 100644 --- a/lib/fintoc/base_client.rb +++ b/lib/fintoc/base_client.rb @@ -10,6 +10,8 @@ module Fintoc class BaseClient include Utils + attr_accessor :default_params + def initialize(api_key, jws_private_key: nil) @api_key = api_key @user_agent = "fintoc-ruby/#{Fintoc::VERSION}" diff --git a/lib/fintoc/client.rb b/lib/fintoc/client.rb index 166d31c..b24bae7 100644 --- a/lib/fintoc/client.rb +++ b/lib/fintoc/client.rb @@ -1,45 +1,40 @@ -require 'fintoc/movements/client/client' -require 'fintoc/transfers/client/client' +require 'fintoc/v1/client/client' +require 'fintoc/v2/client/client' module Fintoc class Client - # Deprecated in favor of Fintoc::Movements::Client and Fintoc::Transfers::Client - # It should not be used anymore, but it will be kept for now for backward compatibility + def initialize(api_key, jws_private_key: nil) + @api_key = api_key + @jws_private_key = jws_private_key + end - attr_reader :movements, :transfers + def v1 + @v1 ||= Fintoc::V1::Client.new(@api_key) + end - def initialize(api_key, jws_private_key: nil) - @movements = Fintoc::Movements::Client.new(api_key) - @transfers = Fintoc::Transfers::Client.new(api_key, jws_private_key: jws_private_key) + def v2 + @v2 ||= Fintoc::V2::Client.new(@api_key, jws_private_key: @jws_private_key) end - # Delegate common methods to maintain backward compatibility + # These methods are kept for backward compatibility def get_link(link_token) - @movements.get_link(link_token) + @v1.links.get(link_token) end def get_links - @movements.get_links + @v1.links.list end def delete_link(link_id) - @movements.delete_link(link_id) + @v1.links.delete(link_id) end def get_account(link_token, account_id) - @movements.get_account(link_token, account_id) - end - - def get_entity(entity_id) - @transfers.get_entity(entity_id) - end - - def get_entities(**params) - @transfers.get_entities(**params) + @v1.links.get(link_token).find(id: account_id) end def to_s - "Fintoc::Client(movements: #{@movements}, transfers: #{@transfers})" + "Fintoc::Client(v1: #{@v1}, v2: #{@v2})" end end end diff --git a/lib/fintoc/movements/client/client.rb b/lib/fintoc/movements/client/client.rb deleted file mode 100644 index fef5bf2..0000000 --- a/lib/fintoc/movements/client/client.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'fintoc/base_client' -require 'fintoc/movements/client/links_methods' - -module Fintoc - module Movements - class Client < BaseClient - include LinksMethods - end - end -end diff --git a/lib/fintoc/movements/client/links_methods.rb b/lib/fintoc/movements/client/links_methods.rb deleted file mode 100644 index 632b1b6..0000000 --- a/lib/fintoc/movements/client/links_methods.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'fintoc/movements/resources/link' - -module Fintoc - module Movements - module LinksMethods - def get_link(link_token) - data = { **_get_link(link_token), link_token: link_token } - build_link(data) - end - - def get_links - _get_links.map { |data| build_link(data) } - end - - def delete_link(link_id) - delete.call("links/#{link_id}") - end - - def get_account(link_token, account_id) - get_link(link_token).find(id: account_id) - end - - private - - def _get_link(link_token) - get.call("links/#{link_token}") - end - - def _get_links - get.call('links') - end - - def build_link(data) - param = Utils.pick(data, 'link_token') - @default_params.update(param) - Fintoc::Movements::Link.new(**data, client: self) - end - end - end -end diff --git a/lib/fintoc/transfers/client/account_numbers_methods.rb b/lib/fintoc/transfers/client/account_numbers_methods.rb deleted file mode 100644 index 956b30b..0000000 --- a/lib/fintoc/transfers/client/account_numbers_methods.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'fintoc/transfers/resources/account_number' - -module Fintoc - module Transfers - module AccountNumbersMethods - def create_account_number(account_id:, description: nil, metadata: nil, **params) - data = _create_account_number(account_id:, description:, metadata:, **params) - build_account_number(data) - end - - def get_account_number(account_number_id) - data = _get_account_number(account_number_id) - build_account_number(data) - end - - def list_account_numbers(**params) - _list_account_numbers(**params).map { |data| build_account_number(data) } - end - - def update_account_number(account_number_id, **params) - data = _update_account_number(account_number_id, **params) - build_account_number(data) - end - - private - - def _create_account_number(account_id:, description: nil, metadata: nil, **params) - request_params = { account_id: } - request_params[:description] = description if description - request_params[:metadata] = metadata if metadata - request_params.merge!(params) - - post(version: :v2).call('account_numbers', **request_params) - end - - def _get_account_number(account_number_id) - get(version: :v2).call("account_numbers/#{account_number_id}") - end - - def _list_account_numbers(**params) - get(version: :v2).call('account_numbers', **params) - end - - def _update_account_number(account_number_id, **params) - patch(version: :v2).call("account_numbers/#{account_number_id}", **params) - end - - def build_account_number(data) - Fintoc::Transfers::AccountNumber.new(**data, client: self) - end - end - end -end diff --git a/lib/fintoc/transfers/client/account_verifications_methods.rb b/lib/fintoc/transfers/client/account_verifications_methods.rb deleted file mode 100644 index 3f43e5b..0000000 --- a/lib/fintoc/transfers/client/account_verifications_methods.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'fintoc/transfers/resources/account_verification' - -module Fintoc - module Transfers - module AccountVerificationsMethods - def create_account_verification(account_number:) - data = _create_account_verification(account_number:) - build_account_verification(data) - end - - def get_account_verification(account_verification_id) - data = _get_account_verification(account_verification_id) - build_account_verification(data) - end - - def list_account_verifications(**params) - _list_account_verifications(**params).map { |data| build_account_verification(data) } - end - - private - - def _create_account_verification(account_number:) - post(version: :v2, use_jws: true).call('account_verifications', account_number:) - end - - def _get_account_verification(account_verification_id) - get(version: :v2).call("account_verifications/#{account_verification_id}") - end - - def _list_account_verifications(**params) - get(version: :v2).call('account_verifications', **params) - end - - def build_account_verification(data) - Fintoc::Transfers::AccountVerification.new(**data, client: self) - end - end - end -end diff --git a/lib/fintoc/transfers/client/accounts_methods.rb b/lib/fintoc/transfers/client/accounts_methods.rb deleted file mode 100644 index ee9e683..0000000 --- a/lib/fintoc/transfers/client/accounts_methods.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'fintoc/transfers/resources/account' - -module Fintoc - module Transfers - module AccountsMethods - def create_account(entity_id:, description:, **params) - data = _create_account(entity_id:, description:, **params) - build_account(data) - end - - def get_account(account_id) - data = _get_account(account_id) - build_account(data) - end - - def list_accounts(**params) - _list_accounts(**params).map { |data| build_account(data) } - end - - def update_account(account_id, **params) - data = _update_account(account_id, **params) - build_account(data) - end - - private - - def _create_account(entity_id:, description:, **params) - post(version: :v2).call('accounts', entity_id:, description:, **params) - end - - def _get_account(account_id) - get(version: :v2).call("accounts/#{account_id}") - end - - def _list_accounts(**params) - get(version: :v2).call('accounts', **params) - end - - def _update_account(account_id, **params) - patch(version: :v2).call("accounts/#{account_id}", **params) - end - - def build_account(data) - Fintoc::Transfers::Account.new(**data, client: self) - end - end - end -end diff --git a/lib/fintoc/transfers/client/client.rb b/lib/fintoc/transfers/client/client.rb deleted file mode 100644 index 2f0c817..0000000 --- a/lib/fintoc/transfers/client/client.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'fintoc/base_client' -require 'fintoc/transfers/client/entities_methods' -require 'fintoc/transfers/client/accounts_methods' -require 'fintoc/transfers/client/account_numbers_methods' -require 'fintoc/transfers/client/transfers_methods' -require 'fintoc/transfers/client/simulation_methods' -require 'fintoc/transfers/client/account_verifications_methods' - -module Fintoc - module Transfers - class Client < BaseClient - include EntitiesMethods - include AccountsMethods - include AccountNumbersMethods - include TransfersMethods - include SimulationMethods - include AccountVerificationsMethods - end - end -end diff --git a/lib/fintoc/transfers/client/entities_methods.rb b/lib/fintoc/transfers/client/entities_methods.rb deleted file mode 100644 index 5821508..0000000 --- a/lib/fintoc/transfers/client/entities_methods.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'fintoc/transfers/resources/entity' - -module Fintoc - module Transfers - module EntitiesMethods - def get_entity(entity_id) - data = _get_entity(entity_id) - build_entity(data) - end - - def get_entities(**params) - _get_entities(**params).map { |data| build_entity(data) } - end - - private - - def _get_entity(entity_id) - get(version: :v2).call("entities/#{entity_id}") - end - - def _get_entities(**params) - get(version: :v2).call('entities', **params) - end - - def build_entity(data) - Fintoc::Transfers::Entity.new(**data, client: self) - end - end - end -end diff --git a/lib/fintoc/transfers/client/simulation_methods.rb b/lib/fintoc/transfers/client/simulation_methods.rb deleted file mode 100644 index 58d7b90..0000000 --- a/lib/fintoc/transfers/client/simulation_methods.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'fintoc/transfers/resources/transfer' - -module Fintoc - module Transfers - module SimulationMethods - def simulate_receive_transfer(account_number_id:, amount:, currency:) - data = _simulate_receive_transfer(account_number_id:, amount:, currency:) - build_transfer(data) - end - - private - - def _simulate_receive_transfer(account_number_id:, amount:, currency:) - post(version: :v2) - .call('simulate/receive_transfer', account_number_id:, amount:, currency:) - end - - def build_transfer(data) - Fintoc::Transfers::Transfer.new(**data, client: self) - end - end - end -end diff --git a/lib/fintoc/transfers/client/transfers_methods.rb b/lib/fintoc/transfers/client/transfers_methods.rb deleted file mode 100644 index 7ab1e07..0000000 --- a/lib/fintoc/transfers/client/transfers_methods.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'fintoc/transfers/resources/transfer' - -module Fintoc - module Transfers - module TransfersMethods - def create_transfer(amount:, currency:, account_id:, counterparty:, **params) - data = _create_transfer(amount:, currency:, account_id:, counterparty:, **params) - build_transfer(data) - end - - def get_transfer(transfer_id) - data = _get_transfer(transfer_id) - build_transfer(data) - end - - def list_transfers(**params) - _list_transfers(**params).map { |data| build_transfer(data) } - end - - def return_transfer(transfer_id) - data = _return_transfer(transfer_id) - build_transfer(data) - end - - private - - def _create_transfer(amount:, currency:, account_id:, counterparty:, **params) - post(version: :v2, use_jws: true) - .call('transfers', amount:, currency:, account_id:, counterparty:, **params) - end - - def _get_transfer(transfer_id) - get(version: :v2).call("transfers/#{transfer_id}") - end - - def _list_transfers(**params) - get(version: :v2).call('transfers', **params) - end - - def _return_transfer(transfer_id) - post(version: :v2, use_jws: true).call('transfers/return', transfer_id:) - end - - def build_transfer(data) - Fintoc::Transfers::Transfer.new(**data, client: self) - end - end - end -end diff --git a/lib/fintoc/v1/client/client.rb b/lib/fintoc/v1/client/client.rb new file mode 100644 index 0000000..b9c8c37 --- /dev/null +++ b/lib/fintoc/v1/client/client.rb @@ -0,0 +1,12 @@ +require 'fintoc/base_client' +require 'fintoc/v1/managers/links_manager' + +module Fintoc + module V1 + class Client < BaseClient + def links + @links ||= Managers::LinksManager.new(self) + end + end + end +end diff --git a/lib/fintoc/v1/managers/links_manager.rb b/lib/fintoc/v1/managers/links_manager.rb new file mode 100644 index 0000000..e7c53d3 --- /dev/null +++ b/lib/fintoc/v1/managers/links_manager.rb @@ -0,0 +1,46 @@ +require 'fintoc/v1/resources/link' + +module Fintoc + module V1 + module Managers + class LinksManager + def initialize(client) + @client = client + end + + def get(link_token) + data = { **_get_link(link_token), link_token: link_token } + build_link(data) + end + + def list + _get_links.map { |data| build_link(data) } + end + + def delete(link_id) + _delete_link(link_id) + end + + private + + def _get_link(link_token) + @client.get(version: :v1).call("links/#{link_token}") + end + + def _get_links + @client.get(version: :v1).call('links') + end + + def _delete_link(link_id) + @client.delete(version: :v1).call("links/#{link_id}") + end + + def build_link(data) + param = Utils.pick(data, 'link_token') + @client.default_params.update(param) + Fintoc::V1::Link.new(**data, client: @client) + end + end + end + end +end diff --git a/lib/fintoc/movements/resources/account.rb b/lib/fintoc/v1/resources/account.rb similarity index 80% rename from lib/fintoc/movements/resources/account.rb rename to lib/fintoc/v1/resources/account.rb index c76f1d9..eb214e0 100644 --- a/lib/fintoc/movements/resources/account.rb +++ b/lib/fintoc/v1/resources/account.rb @@ -1,10 +1,10 @@ require 'tabulate' require 'fintoc/utils' -require 'fintoc/movements/resources/movement' -require 'fintoc/movements/resources/balance' +require 'fintoc/v1/resources/movement' +require 'fintoc/v1/resources/balance' module Fintoc - module Movements + module V1 class Account include Utils @@ -35,17 +35,19 @@ def initialize( @type = type @currency = currency @refreshed_at = DateTime.iso8601(refreshed_at) if refreshed_at - @balance = Fintoc::Movements::Balance.new(**balance) + @balance = Fintoc::V1::Balance.new(**balance) @movements = movements || [] @client = client end def update_balance - @balance = Fintoc::Movements::Balance.new(**get_account[:balance]) + @balance = Fintoc::V1::Balance.new(**get_account[:balance]) end def get_movements(**params) - _get_movements(**params).lazy.map { |movement| Fintoc::Movements::Movement.new(**movement) } + _get_movements(**params).lazy.map do + |movement| Fintoc::V1::Movement.new(**movement, client: @client) + end end def update_movements(**params) @@ -77,11 +79,11 @@ def to_s private def get_account - @client.get.call("accounts/#{@id}") + @client.get(version: :v1).call("accounts/#{@id}") end def _get_movements(**params) - first = @client.get.call("accounts/#{@id}/movements", **params) + first = @client.get(version: :v1).call("accounts/#{@id}/movements", **params) return first if params.empty? first + Utils.flatten(@client.fetch_next) diff --git a/lib/fintoc/movements/resources/balance.rb b/lib/fintoc/v1/resources/balance.rb similarity index 82% rename from lib/fintoc/movements/resources/balance.rb rename to lib/fintoc/v1/resources/balance.rb index 9e83490..4811a77 100644 --- a/lib/fintoc/movements/resources/balance.rb +++ b/lib/fintoc/v1/resources/balance.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Fintoc - module Movements + module V1 class Balance attr_reader :available, :current, :limit @@ -20,7 +20,7 @@ def to_s end def inspect - "" + "" end end end diff --git a/lib/fintoc/movements/resources/institution.rb b/lib/fintoc/v1/resources/institution.rb similarity index 80% rename from lib/fintoc/movements/resources/institution.rb rename to lib/fintoc/v1/resources/institution.rb index ad8dad8..b4b6737 100644 --- a/lib/fintoc/movements/resources/institution.rb +++ b/lib/fintoc/v1/resources/institution.rb @@ -1,5 +1,5 @@ module Fintoc - module Movements + module V1 class Institution attr_reader :id, :name, :country @@ -14,7 +14,7 @@ def to_s end def inspect - "" + "" end end end diff --git a/lib/fintoc/movements/resources/link.rb b/lib/fintoc/v1/resources/link.rb similarity index 87% rename from lib/fintoc/movements/resources/link.rb rename to lib/fintoc/v1/resources/link.rb index ed55d21..ec390ce 100644 --- a/lib/fintoc/movements/resources/link.rb +++ b/lib/fintoc/v1/resources/link.rb @@ -1,11 +1,11 @@ require 'date' require 'tabulate' require 'fintoc/utils' -require 'fintoc/movements/resources/account' -require 'fintoc/movements/resources/institution' +require 'fintoc/v1/resources/account' +require 'fintoc/v1/resources/institution' module Fintoc - module Movements + module V1 class Link attr_reader :id, :username, :holder_type, :institution, :created_at, :mode, :accounts, :link_token @@ -27,13 +27,13 @@ def initialize( @id = id @username = username @holder_type = holder_type - @institution = Fintoc::Movements::Institution.new(**institution) + @institution = Fintoc::V1::Institution.new(**institution) @created_at = Date.iso8601(created_at) @mode = mode @accounts = if accounts.nil? [] else - accounts.map { |data| Fintoc::Movements::Account.new(**data, client: client) } + accounts.map { |data| Fintoc::V1::Account.new(**data, client:) } end @token = link_token @client = client diff --git a/lib/fintoc/movements/resources/movement.rb b/lib/fintoc/v1/resources/movement.rb similarity index 82% rename from lib/fintoc/movements/resources/movement.rb rename to lib/fintoc/v1/resources/movement.rb index 45bd93f..f752858 100644 --- a/lib/fintoc/movements/resources/movement.rb +++ b/lib/fintoc/v1/resources/movement.rb @@ -1,8 +1,8 @@ require 'date' -require 'fintoc/movements/resources/transfer_account' +require 'fintoc/v1/resources/transfer_account' module Fintoc - module Movements + module V1 class Movement attr_reader :id, :amount, :currency, :description, :reference_id, :post_date, :transaction_date, :type, :recipient_account, @@ -20,6 +20,7 @@ def initialize( recipient_account:, sender_account:, comment:, + client: nil, ** ) @id = id @@ -32,10 +33,11 @@ def initialize( @reference_id = reference_id @recipient_account = if recipient_account - Fintoc::Movements::TransferAccount.new(**recipient_account) + Fintoc::V1::TransferAccount.new(**recipient_account) end - @sender_account = Fintoc::Movements::TransferAccount.new(**sender_account) if sender_account + @sender_account = Fintoc::V1::TransferAccount.new(**sender_account) if sender_account @comment = comment + @client = client end def ==(other) diff --git a/lib/fintoc/movements/resources/transfer_account.rb b/lib/fintoc/v1/resources/transfer_account.rb similarity index 71% rename from lib/fintoc/movements/resources/transfer_account.rb rename to lib/fintoc/v1/resources/transfer_account.rb index 077bc2c..ff11d69 100644 --- a/lib/fintoc/movements/resources/transfer_account.rb +++ b/lib/fintoc/v1/resources/transfer_account.rb @@ -1,7 +1,7 @@ -require 'fintoc/movements/resources/institution' +require 'fintoc/v1/resources/institution' module Fintoc - module Movements + module V1 class TransferAccount attr_reader :holder_id, :holder_name, :number, :institution @@ -9,7 +9,7 @@ def initialize(holder_id:, holder_name:, number:, institution:, **) @holder_id = holder_id @holder_name = holder_name @number = number - @institution = institution && Fintoc::Movements::Institution.new(**institution) + @institution = institution && Fintoc::V1::Institution.new(**institution) end def id diff --git a/lib/fintoc/v2/client/client.rb b/lib/fintoc/v2/client/client.rb new file mode 100644 index 0000000..7e17cb8 --- /dev/null +++ b/lib/fintoc/v2/client/client.rb @@ -0,0 +1,37 @@ +require 'fintoc/base_client' +require 'fintoc/v2/managers/entities_manager' +require 'fintoc/v2/managers/accounts_manager' +require 'fintoc/v2/managers/account_numbers_manager' +require 'fintoc/v2/managers/transfers_manager' +require 'fintoc/v2/managers/simulate_manager' +require 'fintoc/v2/managers/account_verifications_manager' + +module Fintoc + module V2 + class Client < BaseClient + def entities + @entities ||= Managers::EntitiesManager.new(self) + end + + def accounts + @accounts ||= Managers::AccountsManager.new(self) + end + + def account_numbers + @account_numbers ||= Managers::AccountNumbersManager.new(self) + end + + def transfers + @transfers ||= Managers::TransfersManager.new(self) + end + + def simulate + @simulate ||= Managers::SimulateManager.new(self) + end + + def account_verifications + @account_verifications ||= Managers::AccountVerificationsManager.new(self) + end + end + end +end diff --git a/lib/fintoc/v2/managers/account_numbers_manager.rb b/lib/fintoc/v2/managers/account_numbers_manager.rb new file mode 100644 index 0000000..58ec4e7 --- /dev/null +++ b/lib/fintoc/v2/managers/account_numbers_manager.rb @@ -0,0 +1,59 @@ +require 'fintoc/v2/resources/account_number' + +module Fintoc + module V2 + module Managers + class AccountNumbersManager + def initialize(client) + @client = client + end + + def create(account_id:, description: nil, metadata: nil, **params) + data = _create_account_number(account_id:, description:, metadata:, **params) + build_account_number(data) + end + + def get(account_number_id) + data = _get_account_number(account_number_id) + build_account_number(data) + end + + def list(**params) + _list_account_numbers(**params).map { |data| build_account_number(data) } + end + + def update(account_number_id, **params) + data = _update_account_number(account_number_id, **params) + build_account_number(data) + end + + private + + def _create_account_number(account_id:, description: nil, metadata: nil, **params) + request_params = { account_id: } + request_params[:description] = description if description + request_params[:metadata] = metadata if metadata + request_params.merge!(params) + + @client.post(version: :v2).call('account_numbers', **request_params) + end + + def _get_account_number(account_number_id) + @client.get(version: :v2).call("account_numbers/#{account_number_id}") + end + + def _list_account_numbers(**params) + @client.get(version: :v2).call('account_numbers', **params) + end + + def _update_account_number(account_number_id, **params) + @client.patch(version: :v2).call("account_numbers/#{account_number_id}", **params) + end + + def build_account_number(data) + Fintoc::V2::AccountNumber.new(**data, client: @client) + end + end + end + end +end diff --git a/lib/fintoc/v2/managers/account_verifications_manager.rb b/lib/fintoc/v2/managers/account_verifications_manager.rb new file mode 100644 index 0000000..ffd8e15 --- /dev/null +++ b/lib/fintoc/v2/managers/account_verifications_manager.rb @@ -0,0 +1,45 @@ +require 'fintoc/v2/resources/account_verification' + +module Fintoc + module V2 + module Managers + class AccountVerificationsManager + def initialize(client) + @client = client + end + + def create(account_number:) + data = _create_account_verification(account_number:) + build_account_verification(data) + end + + def get(account_verification_id) + data = _get_account_verification(account_verification_id) + build_account_verification(data) + end + + def list(**params) + _list_account_verifications(**params).map { |data| build_account_verification(data) } + end + + private + + def _create_account_verification(account_number:) + @client.post(version: :v2, use_jws: true).call('account_verifications', account_number:) + end + + def _get_account_verification(account_verification_id) + @client.get(version: :v2).call("account_verifications/#{account_verification_id}") + end + + def _list_account_verifications(**params) + @client.get(version: :v2).call('account_verifications', **params) + end + + def build_account_verification(data) + Fintoc::V2::AccountVerification.new(**data, client: @client) + end + end + end + end +end diff --git a/lib/fintoc/v2/managers/accounts_manager.rb b/lib/fintoc/v2/managers/accounts_manager.rb new file mode 100644 index 0000000..6761f79 --- /dev/null +++ b/lib/fintoc/v2/managers/accounts_manager.rb @@ -0,0 +1,54 @@ +require 'fintoc/v2/resources/account' + +module Fintoc + module V2 + module Managers + class AccountsManager + def initialize(client) + @client = client + end + + def create(entity_id:, description:, **params) + data = _create_account(entity_id:, description:, **params) + build_account(data) + end + + def get(account_id) + data = _get_account(account_id) + build_account(data) + end + + def list(**params) + _list_accounts(**params).map { |data| build_account(data) } + end + + def update(account_id, **params) + data = _update_account(account_id, **params) + build_account(data) + end + + private + + def _create_account(entity_id:, description:, **params) + @client.post(version: :v2).call('accounts', entity_id:, description:, **params) + end + + def _get_account(account_id) + @client.get(version: :v2).call("accounts/#{account_id}") + end + + def _list_accounts(**params) + @client.get(version: :v2).call('accounts', **params) + end + + def _update_account(account_id, **params) + @client.patch(version: :v2).call("accounts/#{account_id}", **params) + end + + def build_account(data) + Fintoc::V2::Account.new(**data, client: @client) + end + end + end + end +end diff --git a/lib/fintoc/v2/managers/entities_manager.rb b/lib/fintoc/v2/managers/entities_manager.rb new file mode 100644 index 0000000..4cd0071 --- /dev/null +++ b/lib/fintoc/v2/managers/entities_manager.rb @@ -0,0 +1,36 @@ +require 'fintoc/v2/resources/entity' + +module Fintoc + module V2 + module Managers + class EntitiesManager + def initialize(client) + @client = client + end + + def get(entity_id) + data = _get_entity(entity_id) + build_entity(data) + end + + def list(**params) + _list_entities(**params).map { |data| build_entity(data) } + end + + private + + def _get_entity(entity_id) + @client.get(version: :v2).call("entities/#{entity_id}") + end + + def _list_entities(**params) + @client.get(version: :v2).call('entities', **params) + end + + def build_entity(data) + Fintoc::V2::Entity.new(**data, client: @client) + end + end + end + end +end diff --git a/lib/fintoc/v2/managers/simulate_manager.rb b/lib/fintoc/v2/managers/simulate_manager.rb new file mode 100644 index 0000000..b9bbd03 --- /dev/null +++ b/lib/fintoc/v2/managers/simulate_manager.rb @@ -0,0 +1,30 @@ +require 'fintoc/v2/resources/transfer' + +module Fintoc + module V2 + module Managers + class SimulateManager + def initialize(client) + @client = client + end + + def receive_transfer(account_number_id:, amount:, currency:) + data = _simulate_receive_transfer(account_number_id:, amount:, currency:) + build_transfer(data) + end + + private + + def _simulate_receive_transfer(account_number_id:, amount:, currency:) + @client + .post(version: :v2) + .call('simulate/receive_transfer', account_number_id:, amount:, currency:) + end + + def build_transfer(data) + Fintoc::V2::Transfer.new(**data, client: @client) + end + end + end + end +end diff --git a/lib/fintoc/v2/managers/transfers_manager.rb b/lib/fintoc/v2/managers/transfers_manager.rb new file mode 100644 index 0000000..adb5a5c --- /dev/null +++ b/lib/fintoc/v2/managers/transfers_manager.rb @@ -0,0 +1,56 @@ +require 'fintoc/v2/resources/transfer' + +module Fintoc + module V2 + module Managers + class TransfersManager + def initialize(client) + @client = client + end + + def create(amount:, currency:, account_id:, counterparty:, **params) + data = _create_transfer(amount:, currency:, account_id:, counterparty:, **params) + build_transfer(data) + end + + def get(transfer_id) + data = _get_transfer(transfer_id) + build_transfer(data) + end + + def list(**params) + _list_transfers(**params).map { |data| build_transfer(data) } + end + + def return(transfer_id) + data = _return_transfer(transfer_id) + build_transfer(data) + end + + private + + def _create_transfer(amount:, currency:, account_id:, counterparty:, **params) + @client + .post(version: :v2, use_jws: true) + .call('transfers', amount:, currency:, account_id:, counterparty:, **params) + end + + def _get_transfer(transfer_id) + @client.get(version: :v2).call("transfers/#{transfer_id}") + end + + def _list_transfers(**params) + @client.get(version: :v2).call('transfers', **params) + end + + def _return_transfer(transfer_id) + @client.post(version: :v2, use_jws: true).call('transfers/return', transfer_id:) + end + + def build_transfer(data) + Fintoc::V2::Transfer.new(**data, client: @client) + end + end + end + end +end diff --git a/lib/fintoc/transfers/resources/account.rb b/lib/fintoc/v2/resources/account.rb similarity index 93% rename from lib/fintoc/transfers/resources/account.rb rename to lib/fintoc/v2/resources/account.rb index 00094a3..9601a71 100644 --- a/lib/fintoc/transfers/resources/account.rb +++ b/lib/fintoc/v2/resources/account.rb @@ -1,7 +1,7 @@ require 'money' module Fintoc - module Transfers + module V2 class Account attr_reader :id, :object, :mode, :description, :available_balance, :currency, :is_root, :root_account_number_id, :root_account_number, :status, :entity @@ -40,7 +40,7 @@ def to_s end def refresh - fresh_account = @client.get_account(@id) + fresh_account = @client.accounts.get(@id) refresh_from_account(fresh_account) end @@ -48,7 +48,7 @@ def update(description: nil) params = {} params[:description] = description if description - updated_account = @client.update_account(@id, **params) + updated_account = @client.accounts.update(@id, **params) refresh_from_account(updated_account) end @@ -73,7 +73,7 @@ def simulate_receive_transfer(amount:) raise Fintoc::Errors::InvalidRequestError, 'Simulation is only available in test mode' end - @client.simulate_receive_transfer( + @client.simulate.receive_transfer( account_number_id: @root_account_number_id, amount:, currency: @currency diff --git a/lib/fintoc/transfers/resources/account_number.rb b/lib/fintoc/v2/resources/account_number.rb similarity index 92% rename from lib/fintoc/transfers/resources/account_number.rb rename to lib/fintoc/v2/resources/account_number.rb index 82aff76..a0e4df1 100644 --- a/lib/fintoc/transfers/resources/account_number.rb +++ b/lib/fintoc/v2/resources/account_number.rb @@ -1,5 +1,5 @@ module Fintoc - module Transfers + module V2 class AccountNumber attr_reader :id, :object, :description, :number, :created_at, :updated_at, :mode, :status, :is_root, :account_id, :metadata @@ -38,7 +38,7 @@ def to_s end def refresh - fresh_account_number = @client.get_account_number(@id) + fresh_account_number = @client.account_numbers.get(@id) refresh_from_account_number(fresh_account_number) end @@ -48,7 +48,7 @@ def update(description: nil, status: nil, metadata: nil) params[:status] = status if status params[:metadata] = metadata if metadata - updated_account_number = @client.update_account_number(@id, **params) + updated_account_number = @client.account_numbers.update(@id, **params) refresh_from_account_number(updated_account_number) end @@ -73,7 +73,7 @@ def simulate_receive_transfer(amount:, currency: 'MXN') raise Fintoc::Errors::InvalidRequestError, 'Simulation is only available in test mode' end - @client.simulate_receive_transfer( + @client.simulate.receive_transfer( account_number_id: @id, amount:, currency: diff --git a/lib/fintoc/transfers/resources/account_verification.rb b/lib/fintoc/v2/resources/account_verification.rb similarity index 95% rename from lib/fintoc/transfers/resources/account_verification.rb rename to lib/fintoc/v2/resources/account_verification.rb index 1881411..f326809 100644 --- a/lib/fintoc/transfers/resources/account_verification.rb +++ b/lib/fintoc/v2/resources/account_verification.rb @@ -1,5 +1,5 @@ module Fintoc - module Transfers + module V2 class AccountVerification attr_reader :id, :object, :status, :reason, :transfer_id, :counterparty, :mode, :receipt_url, :transaction_date @@ -34,7 +34,7 @@ def to_s end def refresh - fresh_verification = @client.get_account_verification(@id) + fresh_verification = @client.account_verifications.get(@id) refresh_from_verification(fresh_verification) end diff --git a/lib/fintoc/transfers/resources/entity.rb b/lib/fintoc/v2/resources/entity.rb similarity index 93% rename from lib/fintoc/transfers/resources/entity.rb rename to lib/fintoc/v2/resources/entity.rb index 88cebc5..29cc562 100644 --- a/lib/fintoc/transfers/resources/entity.rb +++ b/lib/fintoc/v2/resources/entity.rb @@ -1,5 +1,5 @@ module Fintoc - module Transfers + module V2 class Entity attr_reader :object, :mode, :id, :holder_name, :holder_id, :is_root @@ -27,7 +27,7 @@ def to_s end def refresh - fresh_entity = @client.get_entity(@id) + fresh_entity = @client.entities.get(@id) refresh_from_entity(fresh_entity) end diff --git a/lib/fintoc/transfers/resources/transfer.rb b/lib/fintoc/v2/resources/transfer.rb similarity index 96% rename from lib/fintoc/transfers/resources/transfer.rb rename to lib/fintoc/v2/resources/transfer.rb index c0f525c..0d78514 100644 --- a/lib/fintoc/transfers/resources/transfer.rb +++ b/lib/fintoc/v2/resources/transfer.rb @@ -1,7 +1,7 @@ require 'money' module Fintoc - module Transfers + module V2 class Transfer attr_reader :id, :object, :amount, :currency, :direction, :status, :mode, :post_date, :transaction_date, :comment, :reference_id, :receipt_url, @@ -58,12 +58,12 @@ def to_s end def refresh - fresh_transfer = @client.get_transfer(@id) + fresh_transfer = @client.transfers.get(@id) refresh_from_transfer(fresh_transfer) end def return_transfer - returned_transfer = @client.return_transfer(@id) + returned_transfer = @client.transfers.return(@id) refresh_from_transfer(returned_transfer) end diff --git a/spec/lib/fintoc/client_spec.rb b/spec/lib/fintoc/client_spec.rb index 169ca46..39d7fb3 100644 --- a/spec/lib/fintoc/client_spec.rb +++ b/spec/lib/fintoc/client_spec.rb @@ -1,11 +1,12 @@ require 'fintoc/client' -require 'fintoc/movements/resources/link' -require 'fintoc/movements/resources/account' -require 'fintoc/movements/resources/movement' +require 'fintoc/v1/resources/link' +require 'fintoc/v1/resources/account' +require 'fintoc/v1/resources/movement' RSpec.describe Fintoc::Client do let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - let(:client) { described_class.new(api_key) } + let(:jws_private_key) { OpenSSL::PKey::RSA.new(2048) } + let(:client) { described_class.new(api_key, jws_private_key: jws_private_key) } describe '.new' do it 'create an instance Client' do @@ -13,24 +14,25 @@ end it 'creates movements and transfers clients' do - expect(client.movements).to be_an_instance_of(Fintoc::Movements::Client) - expect(client.transfers).to be_an_instance_of(Fintoc::Transfers::Client) + expect(client).to respond_to(:v1) + expect(client.v1).to be_an_instance_of(Fintoc::V1::Client) + expect(client).to respond_to(:v2) + expect(client.v2).to be_an_instance_of(Fintoc::V2::Client) end end describe 'client separation' do it 'allows direct access to movements client' do - expect(client.movements) - .to respond_to(:get_link) - .and respond_to(:get_links) - .and respond_to(:delete_link) - .and respond_to(:get_account) + expect(client.v1.links) + .to respond_to(:get) + .and respond_to(:list) + .and respond_to(:delete) end it 'allows direct access to transfers client' do - expect(client.transfers) - .to respond_to(:get_entity) - .and respond_to(:get_entities) + expect(client.v2.entities) + .to respond_to(:get) + .and respond_to(:list) end it 'maintains backward compatibility through delegation' do @@ -39,37 +41,25 @@ .and respond_to(:get_links) .and respond_to(:delete_link) .and respond_to(:get_account) - .and respond_to(:get_entity) - .and respond_to(:get_entities) end end describe 'delegation to movements client' do + let(:link) { instance_double(Fintoc::V1::Link) } + let(:account) { instance_double(Fintoc::V1::Account) } + before do - allow(client.movements).to receive(:get_link).with('token').and_return('link') - allow(client.movements).to receive(:get_links).and_return(['links']) - allow(client.movements).to receive(:delete_link).with('link_id').and_return(true) - allow(client.movements) - .to receive(:get_account).with('token', 'account_id').and_return('account') + allow(client.v1.links).to receive(:get).with('token').and_return(link) + allow(client.v1.links).to receive(:list).and_return([link]) + allow(client.v1.links).to receive(:delete).with('link_id').and_return(true) + allow(link).to receive(:find).with(id: 'account_id').and_return(account) end it 'delegates movements methods to movements client' do - expect(client.get_link('token')).to eq('link') - expect(client.get_links).to eq(['links']) + expect(client.get_link('token')).to eq(link) + expect(client.get_links).to eq([link]) expect(client.delete_link('link_id')).to be(true) - expect(client.get_account('token', 'account_id')).to eq('account') - end - end - - describe 'delegation to transfers client' do - before do - allow(client.transfers).to receive(:get_entity).with('entity_id').and_return('entity') - allow(client.transfers).to receive(:get_entities).with(limit: 10).and_return(['entities']) - end - - it 'delegates transfers methods to transfers client' do - expect(client.get_entity('entity_id')).to eq('entity') - expect(client.get_entities(limit: 10)).to eq(['entities']) + expect(client.get_account('token', 'account_id')).to eq(account) end end end diff --git a/spec/lib/fintoc/movements/links_methods_spec.rb b/spec/lib/fintoc/movements/links_methods_spec.rb deleted file mode 100644 index 16b187b..0000000 --- a/spec/lib/fintoc/movements/links_methods_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'fintoc/movements/client/links_methods' - -RSpec.describe Fintoc::Movements::LinksMethods do - # Test class that includes the module for testing - let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - let(:client) { test_class.new(api_key) } - - let(:test_class) do - Class.new do - include Fintoc::Movements::LinksMethods - - def initialize(api_key) - @api_key = api_key - end - - # Mock the base client methods needed for testing - def get(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - - def delete - proc { |_resource, **_kwargs| { mock: 'deleted' } } - end - - def pick(data, key) - { key => data[key] } if data[key] - end - end - end - - describe 'module inclusion' do - it 'provides link-related methods' do - expect(client) - .to respond_to(:get_link) - .and respond_to(:get_links) - .and respond_to(:delete_link) - .and respond_to(:get_account) - end - end - - describe 'private methods' do - it 'provides private helper methods' do - expect(client.private_methods) - .to include(:_get_link, :_get_links, :build_link) - end - end -end diff --git a/spec/lib/fintoc/transfers/account_numbers_methods_spec.rb b/spec/lib/fintoc/transfers/account_numbers_methods_spec.rb deleted file mode 100644 index a297712..0000000 --- a/spec/lib/fintoc/transfers/account_numbers_methods_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'fintoc/transfers/client/account_numbers_methods' - -RSpec.describe Fintoc::Transfers::AccountNumbersMethods do - let(:client) { test_class.new(api_key) } - - let(:test_class) do - Class.new do - include Fintoc::Transfers::AccountNumbersMethods - - def initialize(api_key) - @api_key = api_key - end - - # Mock the base client methods needed for testing - def get(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - - def post(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - - def patch(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - end - end - - let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - - describe '#create_account_number' do - before do - allow(Fintoc::Transfers::AccountNumber).to receive(:new) - end - - it 'calls build_account_number with the response' do - client.create_account_number(account_id: 'acc_123') - expect(Fintoc::Transfers::AccountNumber) - .to have_received(:new).with(mock: 'response', client:) - end - end - - describe '#get_account_number' do - before do - allow(Fintoc::Transfers::AccountNumber).to receive(:new) - end - - it 'calls build_account_number with the response' do - client.get_account_number('acno_123') - expect(Fintoc::Transfers::AccountNumber) - .to have_received(:new).with(mock: 'response', client:) - end - end - - describe '#list_account_numbers' do - before do - allow(client) - .to receive(:_list_account_numbers) - .and_return([{ mock: 'response1' }, { mock: 'response2' }]) - allow(Fintoc::Transfers::AccountNumber).to receive(:new) - end - - it 'calls build_account_number for each response' do - client.list_account_numbers - expect(Fintoc::Transfers::AccountNumber) - .to have_received(:new).with(mock: 'response1', client:) - expect(Fintoc::Transfers::AccountNumber) - .to have_received(:new).with(mock: 'response2', client:) - end - end - - describe '#update_account_number' do - before do - allow(Fintoc::Transfers::AccountNumber).to receive(:new) - end - - it 'calls build_account_number with the response' do - client.update_account_number('acno_123', description: 'Updated') - expect(Fintoc::Transfers::AccountNumber) - .to have_received(:new).with(mock: 'response', client:) - end - end -end diff --git a/spec/lib/fintoc/transfers/account_verifications_methods_spec.rb b/spec/lib/fintoc/transfers/account_verifications_methods_spec.rb deleted file mode 100644 index 5b172a6..0000000 --- a/spec/lib/fintoc/transfers/account_verifications_methods_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -require 'fintoc/transfers/client/account_verifications_methods' - -RSpec.describe Fintoc::Transfers::AccountVerificationsMethods do - let(:client) { test_class.new(api_key) } - - let(:test_class) do - Class.new do - include Fintoc::Transfers::AccountVerificationsMethods - - def initialize(api_key) - @api_key = api_key - end - - # Mock the base client methods needed for testing - def get(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - - def post(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - end - end - - let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - - describe '#create_account_verification' do - before do - allow(Fintoc::Transfers::AccountVerification).to receive(:new) - end - - it 'calls build_account_verification with the response' do - client.create_account_verification(account_number: '735969000000203226') - expect(Fintoc::Transfers::AccountVerification) - .to have_received(:new).with(mock: 'response', client:) - end - end - - describe '#get_account_verification' do - before do - allow(Fintoc::Transfers::AccountVerification).to receive(:new) - end - - it 'calls build_account_verification with the response' do - client.get_account_verification('accv_123') - expect(Fintoc::Transfers::AccountVerification) - .to have_received(:new).with(mock: 'response', client:) - end - end - - describe '#list_account_verifications' do - before do - allow(client) - .to receive(:_list_account_verifications) - .and_return([{ mock: 'response1' }, { mock: 'response2' }]) - allow(Fintoc::Transfers::AccountVerification).to receive(:new) - end - - it 'calls build_account_verification for each response item' do - client.list_account_verifications - expect(Fintoc::Transfers::AccountVerification) - .to have_received(:new).with(mock: 'response1', client:) - expect(Fintoc::Transfers::AccountVerification) - .to have_received(:new).with(mock: 'response2', client:) - end - end -end diff --git a/spec/lib/fintoc/transfers/accounts_methods_spec.rb b/spec/lib/fintoc/transfers/accounts_methods_spec.rb deleted file mode 100644 index b244b66..0000000 --- a/spec/lib/fintoc/transfers/accounts_methods_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'fintoc/transfers/client/accounts_methods' - -RSpec.describe Fintoc::Transfers::AccountsMethods do - let(:client) { test_class.new(api_key) } - - let(:test_class) do - Class.new do - include Fintoc::Transfers::AccountsMethods - - def initialize(api_key) - @api_key = api_key - end - - # Mock the base client methods needed for testing - def get(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - - def post(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - - def patch(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - end - end - - let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - - describe 'module inclusion' do - it 'provides account-related methods' do - expect(client) - .to respond_to(:create_account) - .and respond_to(:get_account) - .and respond_to(:list_accounts) - .and respond_to(:update_account) - end - end - - describe 'private methods' do - it 'provides private helper methods' do - expect(client.private_methods) - .to include( - :_create_account, :_get_account, :_list_accounts, :_update_account, :build_account - ) - end - end -end diff --git a/spec/lib/fintoc/transfers/entities_methods_spec.rb b/spec/lib/fintoc/transfers/entities_methods_spec.rb deleted file mode 100644 index 2fe143a..0000000 --- a/spec/lib/fintoc/transfers/entities_methods_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'fintoc/transfers/client/entities_methods' - -RSpec.describe Fintoc::Transfers::EntitiesMethods do - let(:client) { test_class.new(api_key) } - - let(:test_class) do - Class.new do - include Fintoc::Transfers::EntitiesMethods - - def initialize(api_key) - @api_key = api_key - end - - # Mock the base client methods needed for testing - def get(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - end - end - - let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - - describe 'module inclusion' do - it 'provides entity-related methods' do - expect(client) - .to respond_to(:get_entity) - .and respond_to(:get_entities) - end - end - - describe 'private methods' do - it 'provides private helper methods' do - expect(client.private_methods) - .to include(:_get_entity, :_get_entities, :build_entity) - end - end -end diff --git a/spec/lib/fintoc/transfers/simulation_methods_spec.rb b/spec/lib/fintoc/transfers/simulation_methods_spec.rb deleted file mode 100644 index 5aa4068..0000000 --- a/spec/lib/fintoc/transfers/simulation_methods_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'fintoc/transfers/client/simulation_methods' - -RSpec.describe Fintoc::Transfers::SimulationMethods do - let(:client) { test_class.new(api_key) } - - let(:test_class) do - Class.new do - include Fintoc::Transfers::SimulationMethods - - def initialize(api_key) - @api_key = api_key - end - - # Mock the base client methods needed for testing - def post(*, **) - proc { |_resource, **_kwargs| { mock: 'response' } } - end - end - end - - let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - - describe '#simulate_receive_transfer' do - before do - allow(Fintoc::Transfers::Transfer).to receive(:new) - end - - it 'calls build_transfer with the response' do - client.simulate_receive_transfer( - account_number_id: 'acno_123', - amount: 10000, - currency: 'MXN' - ) - expect(Fintoc::Transfers::Transfer) - .to have_received(:new).with(mock: 'response', client:) - end - end -end diff --git a/spec/lib/fintoc/movements/account_spec.rb b/spec/lib/fintoc/v1/account_spec.rb similarity index 81% rename from spec/lib/fintoc/movements/account_spec.rb rename to spec/lib/fintoc/v1/account_spec.rb index a900edd..889a889 100644 --- a/spec/lib/fintoc/movements/account_spec.rb +++ b/spec/lib/fintoc/v1/account_spec.rb @@ -1,8 +1,8 @@ -require 'fintoc/movements/resources/account' +require 'fintoc/v1/resources/account' -RSpec.describe Fintoc::Movements::Account do +RSpec.describe Fintoc::V1::Account do let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - let(:client) { Fintoc::Client.new(api_key) } + let(:client) { Fintoc::V1::Client.new(api_key) } let(:data) do { @@ -25,7 +25,7 @@ end let(:link_token) { '6n12zLmai3lLE9Dq_token_gvEJi8FrBge4fb3cz7Wp856W' } - let(:link) { client.get_link(link_token) } + let(:link) { client.links.get(link_token) } let(:account) { described_class.new(**data) } let(:linked_account) { link.find(type: 'checking_account') } @@ -49,7 +49,7 @@ it "get the last 30 account's movements", :vcr do movements = linked_account.get_movements expect(movements.size).to be <= 30 - expect(movements).to all(be_a(Fintoc::Movements::Movement)) + expect(movements).to all(be_a(Fintoc::V1::Movement)) end end @@ -57,14 +57,14 @@ it "get account's movements with arguments", :vcr do movements = linked_account.get_movements(since: '2020-08-15') linked_account.show_movements - expect(movements).to all(be_a(Fintoc::Movements::Movement)) + expect(movements).to all(be_a(Fintoc::V1::Movement)) end end describe '#update_balance' do it "update account's movements", :vcr do movements = linked_account.update_movements - expect(movements).to all(be_a(Fintoc::Movements::Movement)) + expect(movements).to all(be_a(Fintoc::V1::Movement)) end end end diff --git a/spec/lib/fintoc/movements/balance_spec.rb b/spec/lib/fintoc/v1/balance_spec.rb similarity index 78% rename from spec/lib/fintoc/movements/balance_spec.rb rename to spec/lib/fintoc/v1/balance_spec.rb index 199d52a..30675d7 100644 --- a/spec/lib/fintoc/movements/balance_spec.rb +++ b/spec/lib/fintoc/v1/balance_spec.rb @@ -1,6 +1,6 @@ -require 'fintoc/movements/resources/balance' +require 'fintoc/v1/resources/balance' -RSpec.describe Fintoc::Movements::Balance do +RSpec.describe Fintoc::V1::Balance do let(:data) { { available: 1000, current: 500, limit: 10 } } let(:balance) { described_class.new(**data) } diff --git a/spec/lib/fintoc/movements/client_spec.rb b/spec/lib/fintoc/v1/client_spec.rb similarity index 58% rename from spec/lib/fintoc/movements/client_spec.rb rename to spec/lib/fintoc/v1/client_spec.rb index d2a4026..7754cae 100644 --- a/spec/lib/fintoc/movements/client_spec.rb +++ b/spec/lib/fintoc/v1/client_spec.rb @@ -1,6 +1,6 @@ -require 'fintoc/movements/client/client' +require 'fintoc/v1/client/client' -RSpec.describe Fintoc::Movements::Client do +RSpec.describe Fintoc::V1::Client do let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } let(:client) { described_class.new(api_key) } @@ -13,18 +13,17 @@ describe '#to_s' do it 'returns a formatted string representation' do expect(client.to_s) - .to include('Fintoc::Movements::Client') + .to include('Fintoc::V1::Client') .and include('🔑=') end end it 'responds to movements-specific methods' do - expect(client) - .to respond_to(:get_link) - .and respond_to(:get_links) - .and respond_to(:delete_link) - .and respond_to(:get_account) + expect(client.links) + .to respond_to(:get) + .and respond_to(:list) + .and respond_to(:delete) end - it_behaves_like 'a client with links methods' + it_behaves_like 'a client with links manager' end diff --git a/spec/lib/fintoc/movements/institution_spec.rb b/spec/lib/fintoc/v1/institution_spec.rb similarity index 79% rename from spec/lib/fintoc/movements/institution_spec.rb rename to spec/lib/fintoc/v1/institution_spec.rb index 93e42f1..d2aa9f2 100644 --- a/spec/lib/fintoc/movements/institution_spec.rb +++ b/spec/lib/fintoc/v1/institution_spec.rb @@ -1,6 +1,6 @@ -require 'fintoc/movements/resources/institution' +require 'fintoc/v1/resources/institution' -RSpec.describe Fintoc::Movements::Institution do +RSpec.describe Fintoc::V1::Institution do let(:data) do { id: 'cl_banco_de_chile', name: 'Banco de Chile', country: 'cl' } end diff --git a/spec/lib/fintoc/movements/link_spec.rb b/spec/lib/fintoc/v1/link_spec.rb similarity index 92% rename from spec/lib/fintoc/movements/link_spec.rb rename to spec/lib/fintoc/v1/link_spec.rb index 5d357c0..3a04446 100644 --- a/spec/lib/fintoc/movements/link_spec.rb +++ b/spec/lib/fintoc/v1/link_spec.rb @@ -1,6 +1,6 @@ -require 'fintoc/movements/resources/link' +require 'fintoc/v1/resources/link' -RSpec.describe Fintoc::Movements::Link do +RSpec.describe Fintoc::V1::Link do let(:data) do { id: 'nMNejK7BT8oGbvO4', @@ -60,7 +60,7 @@ it 'returns and valid checking account if the arg is type: "checking_account"' do checking_account = link.find(type: 'checking_account') data_acc = data[:accounts][0] - expect(checking_account).to be_an_instance_of(Fintoc::Movements::Account) + expect(checking_account).to be_an_instance_of(Fintoc::V1::Account) expect(checking_account.to_s) .to( eq( diff --git a/spec/lib/fintoc/v1/managers/links_manager_spec.rb b/spec/lib/fintoc/v1/managers/links_manager_spec.rb new file mode 100644 index 0000000..725c637 --- /dev/null +++ b/spec/lib/fintoc/v1/managers/links_manager_spec.rb @@ -0,0 +1,77 @@ +require 'fintoc/v1/managers/links_manager' + +RSpec.describe Fintoc::V1::Managers::LinksManager do + let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } + let(:client) { Fintoc::V1::Client.new(api_key) } + let(:get_proc) { instance_double(Proc) } + let(:post_proc) { instance_double(Proc) } + let(:delete_proc) { instance_double(Proc) } + let(:manager) { described_class.new(client) } + let(:link_id) { 'link_123' } + let(:link_token) { '6n12zLmai3lLE9Dq_token_gvEJi8FrBge4fb3cz7Wp856W' } + let(:first_link_data) do + { + id: link_id, + object: 'link', + link_token: link_token + } + end + let(:second_link_data) do + { + id: 'link_456', + object: 'link', + link_token: link_token + } + end + + before do + allow(client).to receive(:get).with(version: :v1).and_return(get_proc) + allow(client).to receive(:post).with(version: :v1).and_return(post_proc) + allow(client).to receive(:delete).with(version: :v1).and_return(delete_proc) + + allow(get_proc) + .to receive(:call) + .with("links/#{link_token}") + .and_return(first_link_data) + allow(get_proc) + .to receive(:call) + .with('links') + .and_return([first_link_data, second_link_data]) + allow(post_proc) + .to receive(:call) + .with('links', link_token:) + .and_return(first_link_data) + allow(delete_proc) + .to receive(:call) + .with("links/#{link_id}") + .and_return(true) + + allow(Fintoc::V1::Link).to receive(:new) + end + + describe '#links' do + describe '#get' do + it 'calls build_link with the response' do + manager.get(link_token) + expect(Fintoc::V1::Link) + .to have_received(:new).with(**first_link_data, client:) + end + end + + describe '#list' do + it 'calls build_link with the response' do + manager.list + expect(Fintoc::V1::Link) + .to have_received(:new).with(**first_link_data, client:) + expect(Fintoc::V1::Link) + .to have_received(:new).with(**second_link_data, client:) + end + end + + describe '#delete' do + it 'calls build_link with the response' do + expect(manager.delete(link_id)).to be true + end + end + end +end diff --git a/spec/lib/fintoc/movements/movement_spec.rb b/spec/lib/fintoc/v1/movement_spec.rb similarity index 97% rename from spec/lib/fintoc/movements/movement_spec.rb rename to spec/lib/fintoc/v1/movement_spec.rb index 6ba258b..5b9872c 100644 --- a/spec/lib/fintoc/movements/movement_spec.rb +++ b/spec/lib/fintoc/v1/movement_spec.rb @@ -1,6 +1,6 @@ -require 'fintoc/movements/resources/movement' +require 'fintoc/v1/resources/movement' -RSpec.describe Fintoc::Movements::Movement do +RSpec.describe Fintoc::V1::Movement do let(:data) do { id: 'BO381oEATXonG6bj', diff --git a/spec/lib/fintoc/movements/transfer_account_spec.rb b/spec/lib/fintoc/v1/transfer_account_spec.rb similarity index 78% rename from spec/lib/fintoc/movements/transfer_account_spec.rb rename to spec/lib/fintoc/v1/transfer_account_spec.rb index eab3037..20ee680 100644 --- a/spec/lib/fintoc/movements/transfer_account_spec.rb +++ b/spec/lib/fintoc/v1/transfer_account_spec.rb @@ -1,6 +1,6 @@ -require 'fintoc/movements/resources/transfer_account' +require 'fintoc/v1/resources/transfer_account' -RSpec.describe Fintoc::Movements::TransferAccount do +RSpec.describe Fintoc::V1::TransferAccount do let(:data) do { holder_id: '771806538', diff --git a/spec/lib/fintoc/transfers/account_number_spec.rb b/spec/lib/fintoc/v2/account_number_spec.rb similarity index 89% rename from spec/lib/fintoc/transfers/account_number_spec.rb rename to spec/lib/fintoc/v2/account_number_spec.rb index 3ef5403..4446f77 100644 --- a/spec/lib/fintoc/transfers/account_number_spec.rb +++ b/spec/lib/fintoc/v2/account_number_spec.rb @@ -1,10 +1,10 @@ -require 'fintoc/transfers/resources/account_number' +require 'fintoc/v2/resources/account_number' -RSpec.describe Fintoc::Transfers::AccountNumber do +RSpec.describe Fintoc::V2::AccountNumber do subject(:account_number) { described_class.new(**data) } let(:api_key) { 'sk_test_SeCreT-aPi_KeY' } - let(:client) { Fintoc::Transfers::Client.new(api_key) } + let(:client) { Fintoc::V2::Client.new(api_key) } let(:data) do { @@ -111,8 +111,8 @@ let(:refreshed_account_number) { described_class.new(**refreshed_data) } before do - allow(client) - .to receive(:get_account_number) + allow(client.account_numbers) + .to receive(:get) .with('acno_Kasf91034gj1AD') .and_return(refreshed_account_number) end @@ -124,14 +124,14 @@ it 'calls get_account_number with the correct id' do account_number.refresh - expect(client).to have_received(:get_account_number).with('acno_Kasf91034gj1AD') + expect(client.account_numbers).to have_received(:get).with('acno_Kasf91034gj1AD') end it 'raises an error if the account number ID does not match' do wrong_account_number = described_class.new(**data, id: 'wrong_id') - allow(client) - .to receive(:get_account_number) + allow(client.account_numbers) + .to receive(:get) .with('acno_Kasf91034gj1AD') .and_return(wrong_account_number) @@ -150,7 +150,7 @@ let(:updated_account_number) { described_class.new(**updated_data) } before do - allow(client).to receive(:update_account_number).and_return(updated_account_number) + allow(client.account_numbers).to receive(:update).and_return(updated_account_number) end it 'updates all provided parameters' do @@ -166,7 +166,7 @@ account_number .update(description: new_description, status: new_status, metadata: new_metadata) - expect(client).to have_received(:update_account_number).with( + expect(client.account_numbers).to have_received(:update).with( account_number.id, description: new_description, status: new_status, @@ -187,12 +187,12 @@ end describe '#simulate_receive_transfer' do - let(:expected_transfer) { instance_double(Fintoc::Transfers::Transfer) } + let(:expected_transfer) { instance_double(Fintoc::V2::Transfer) } context 'when in test mode' do before do - allow(client) - .to receive(:simulate_receive_transfer) + allow(client.simulate) + .to receive(:receive_transfer) .with(account_number_id: account_number.id, amount: 10000, currency: 'MXN') .and_return(expected_transfer) end diff --git a/spec/lib/fintoc/transfers/account_spec.rb b/spec/lib/fintoc/v2/account_spec.rb similarity index 88% rename from spec/lib/fintoc/transfers/account_spec.rb rename to spec/lib/fintoc/v2/account_spec.rb index c06d4ba..956af9c 100644 --- a/spec/lib/fintoc/transfers/account_spec.rb +++ b/spec/lib/fintoc/v2/account_spec.rb @@ -1,8 +1,8 @@ -require 'fintoc/transfers/resources/account' +require 'fintoc/v2/resources/account' -RSpec.describe Fintoc::Transfers::Account do +RSpec.describe Fintoc::V2::Account do let(:api_key) { 'sk_test_SeCreT-aPi_KeY' } - let(:client) { Fintoc::Transfers::Client.new(api_key) } + let(:client) { Fintoc::V2::Client.new(api_key) } let(:entity_data) do { @@ -112,7 +112,7 @@ let(:updated_account) { described_class.new(**updated_data, client: client) } before do - allow(client).to receive(:get_account).with('acc_123').and_return(updated_account) + allow(client.accounts).to receive(:get).with('acc_123').and_return(updated_account) end it 'refreshes the account with updated data from the API' do @@ -120,7 +120,7 @@ account.refresh - expect(client).to have_received(:get_account).with('acc_123') + expect(client.accounts).to have_received(:get).with('acc_123') expect(account.description).to eq('Updated account description') end @@ -128,7 +128,7 @@ it 'raises an error if the account ID does not match' do wrong_account = described_class.new(**data, id: 'wrong_id') - allow(client).to receive(:get_account).with('acc_123').and_return(wrong_account) + allow(client.accounts).to receive(:get).with('acc_123').and_return(wrong_account) expect { account.refresh }.to raise_error(ArgumentError, 'Account must be the same instance') end @@ -140,7 +140,7 @@ let(:updated_account) { described_class.new(**updated_data, client: client) } before do - allow(client).to receive(:update_account) do |_id, params| + allow(client.accounts).to receive(:update) do |_id, params| updated_data_for_call = { **data, **params } described_class.new(**updated_data_for_call, client: client) end @@ -151,8 +151,8 @@ account.update(description: 'New account description') - expect(client) - .to have_received(:update_account) + expect(client.accounts) + .to have_received(:update) .with('acc_123', description: 'New account description') expect(account.description).to eq('New account description') @@ -160,8 +160,8 @@ it 'only sends provided parameters' do account.update(description: 'Test description') - expect(client) - .to have_received(:update_account) + expect(client.accounts) + .to have_received(:update) .with('acc_123', description: 'Test description') end end @@ -178,12 +178,12 @@ end describe '#simulate_receive_transfer' do - let(:expected_transfer) { instance_double(Fintoc::Transfers::Transfer) } + let(:expected_transfer) { instance_double(Fintoc::V2::Transfer) } context 'when in test mode' do before do - allow(client) - .to receive(:simulate_receive_transfer) + allow(client.simulate) + .to receive(:receive_transfer) .with( account_number_id: account.root_account_number_id, amount: 10000, diff --git a/spec/lib/fintoc/transfers/account_verification_spec.rb b/spec/lib/fintoc/v2/account_verification_spec.rb similarity index 92% rename from spec/lib/fintoc/transfers/account_verification_spec.rb rename to spec/lib/fintoc/v2/account_verification_spec.rb index 97f4148..50bf6e6 100644 --- a/spec/lib/fintoc/transfers/account_verification_spec.rb +++ b/spec/lib/fintoc/v2/account_verification_spec.rb @@ -1,8 +1,8 @@ -require 'fintoc/transfers/resources/account_verification' +require 'fintoc/v2/resources/account_verification' -RSpec.describe Fintoc::Transfers::AccountVerification do +RSpec.describe Fintoc::V2::AccountVerification do let(:api_key) { 'sk_test_SeCreT-aPi_KeY' } - let(:client) { Fintoc::Transfers::Client.new(api_key) } + let(:client) { Fintoc::V2::Client.new(api_key) } let(:counterparty_data) do { @@ -121,8 +121,8 @@ let(:fresh_verification) { described_class.new(**fresh_data) } before do - allow(client) - .to receive(:get_account_verification) + allow(client.account_verifications) + .to receive(:get) .with('accv_fdme30s11j5k7l1mekq4') .and_return(fresh_verification) end @@ -140,8 +140,8 @@ it 'raises an error if the verification ID does not match' do wrong_verification = described_class.new(**fresh_data, id: 'wrong_id') - allow(client) - .to receive(:get_account_verification) + allow(client.account_verifications) + .to receive(:get) .with('accv_fdme30s11j5k7l1mekq4') .and_return(wrong_verification) diff --git a/spec/lib/fintoc/transfers/client_spec.rb b/spec/lib/fintoc/v2/client_spec.rb similarity index 50% rename from spec/lib/fintoc/transfers/client_spec.rb rename to spec/lib/fintoc/v2/client_spec.rb index 44775ad..7c53eb1 100644 --- a/spec/lib/fintoc/transfers/client_spec.rb +++ b/spec/lib/fintoc/v2/client_spec.rb @@ -1,6 +1,6 @@ -require 'fintoc/transfers/client/client' +require 'fintoc/v2/client/client' -RSpec.describe Fintoc::Transfers::Client do +RSpec.describe Fintoc::V2::Client do let(:api_key) { 'sk_test_SeCreT-aPi_KeY' } let(:jws_private_key) { nil } let(:client) { described_class.new(api_key, jws_private_key: jws_private_key) } @@ -14,20 +14,20 @@ describe '#to_s' do it 'returns a formatted string representation' do expect(client.to_s) - .to include('Fintoc::Transfers::Client') + .to include('Fintoc::V2::Client') .and include('🔑=') end end - it_behaves_like 'a client with entities methods' + it_behaves_like 'a client with entities manager' - it_behaves_like 'a client with accounts methods' + it_behaves_like 'a client with accounts manager' - it_behaves_like 'a client with account numbers methods' + it_behaves_like 'a client with account numbers manager' - it_behaves_like 'a client with transfers methods' + it_behaves_like 'a client with transfers manager' - it_behaves_like 'a client with simulation methods' + it_behaves_like 'a client with simulate manager' - it_behaves_like 'a client with account verifications methods' + it_behaves_like 'a client with account verifications manager' end diff --git a/spec/lib/fintoc/transfers/entity_spec.rb b/spec/lib/fintoc/v2/entity_spec.rb similarity index 80% rename from spec/lib/fintoc/transfers/entity_spec.rb rename to spec/lib/fintoc/v2/entity_spec.rb index f2cddc0..067d3de 100644 --- a/spec/lib/fintoc/transfers/entity_spec.rb +++ b/spec/lib/fintoc/v2/entity_spec.rb @@ -1,8 +1,8 @@ -require 'fintoc/transfers/resources/entity' +require 'fintoc/v2/resources/entity' -RSpec.describe Fintoc::Transfers::Entity do +RSpec.describe Fintoc::V2::Entity do let(:api_key) { 'sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx' } - let(:client) { Fintoc::Transfers::Client.new(api_key) } + let(:client) { Fintoc::V2::Client.new(api_key) } let(:data) do { @@ -52,7 +52,7 @@ let(:updated_entity) { described_class.new(**updated_data, client: client) } before do - allow(client).to receive(:get_entity).with('ent_12345').and_return(updated_entity) + allow(client.entities).to receive(:get).with('ent_12345').and_return(updated_entity) end it 'refreshes the entity with updated data from the API' do @@ -62,7 +62,7 @@ entity.refresh - expect(client).to have_received(:get_entity).with('ent_12345') + expect(client.entities).to have_received(:get).with('ent_12345') expect(entity).to have_attributes( holder_name: 'Updated Company LLC' @@ -72,7 +72,7 @@ it 'raises an error if the entity ID does not match' do wrong_entity = described_class.new(**data, id: 'wrong_id') - allow(client).to receive(:get_entity).with('ent_12345').and_return(wrong_entity) + allow(client.entities).to receive(:get).with('ent_12345').and_return(wrong_entity) expect { entity.refresh }.to raise_error(ArgumentError, 'Entity must be the same instance') end diff --git a/spec/lib/fintoc/v2/managers/account_numbers_manager_spec.rb b/spec/lib/fintoc/v2/managers/account_numbers_manager_spec.rb new file mode 100644 index 0000000..9a83494 --- /dev/null +++ b/spec/lib/fintoc/v2/managers/account_numbers_manager_spec.rb @@ -0,0 +1,103 @@ +require 'fintoc/v2/managers/account_numbers_manager' + +RSpec.describe Fintoc::V2::Managers::AccountNumbersManager do + let(:client) { instance_double(Fintoc::BaseClient) } + let(:get_proc) { instance_double(Proc) } + let(:post_proc) { instance_double(Proc) } + let(:patch_proc) { instance_double(Proc) } + let(:manager) { described_class.new(client) } + let(:account_number_id) { 'acno_123' } + let(:account_id) { 'acc_123' } + let(:first_account_number_data) do + { + id: account_number_id, + object: 'account_number', + description: 'My account number', + number: '1234567890', + created_at: '2021-01-01', + updated_at: '2021-01-01', + mode: 'test', + status: 'enabled', + is_root: false, + account_id: account_id, + metadata: {} + } + end + let(:second_account_number_data) do + { + id: 'acno_456', + object: 'account_number', + description: 'My second account number', + number: '0987654321', + created_at: '2021-01-02', + updated_at: '2021-01-02', + mode: 'test', + status: 'enabled', + is_root: false, + account_id: account_id, + metadata: {} + } + end + let(:updated_account_number_data) do + first_account_number_data.merge(description: 'Updated description') + end + + before do + allow(client).to receive(:get).with(version: :v2).and_return(get_proc) + allow(client).to receive(:post).with(version: :v2).and_return(post_proc) + allow(client).to receive(:patch).with(version: :v2).and_return(patch_proc) + + allow(get_proc) + .to receive(:call) + .with("account_numbers/#{account_number_id}") + .and_return(first_account_number_data) + allow(get_proc) + .to receive(:call) + .with('account_numbers') + .and_return([first_account_number_data, second_account_number_data]) + allow(patch_proc) + .to receive(:call) + .with("account_numbers/#{account_number_id}", description: 'Updated description') + .and_return(updated_account_number_data) + allow(post_proc) + .to receive(:call) + .with('account_numbers', account_id:, description: 'My account number', metadata: {}) + .and_return(first_account_number_data) + + allow(Fintoc::V2::AccountNumber).to receive(:new) + end + + describe '#create' do + it 'calls build_account_number with the response' do + manager.create(account_id: 'acc_123', description: 'My account number', metadata: {}) + expect(Fintoc::V2::AccountNumber) + .to have_received(:new).with(**first_account_number_data, client:) + end + end + + describe '#get' do + it 'calls build_account_number with the response' do + manager.get('acno_123') + expect(Fintoc::V2::AccountNumber) + .to have_received(:new).with(**first_account_number_data, client:) + end + end + + describe '#list' do + it 'calls build_account_number for each response' do + manager.list + expect(Fintoc::V2::AccountNumber) + .to have_received(:new).with(**first_account_number_data, client:) + expect(Fintoc::V2::AccountNumber) + .to have_received(:new).with(**second_account_number_data, client:) + end + end + + describe '#update' do + it 'calls build_account_number with the response' do + manager.update('acno_123', description: 'Updated description') + expect(Fintoc::V2::AccountNumber) + .to have_received(:new).with(**updated_account_number_data, client:) + end + end +end diff --git a/spec/lib/fintoc/v2/managers/account_verifications_manager_spec.rb b/spec/lib/fintoc/v2/managers/account_verifications_manager_spec.rb new file mode 100644 index 0000000..5c524f4 --- /dev/null +++ b/spec/lib/fintoc/v2/managers/account_verifications_manager_spec.rb @@ -0,0 +1,72 @@ +require 'fintoc/v2/managers/account_verifications_manager' + +RSpec.describe Fintoc::V2::Managers::AccountVerificationsManager do + let(:client) { instance_double(Fintoc::BaseClient) } + let(:get_proc) { instance_double(Proc) } + let(:post_proc) { instance_double(Proc) } + let(:manager) { described_class.new(client) } + let(:account_verification_id) { 'accv_123' } + let(:account_number) { '735969000000203226' } + let(:first_account_verification_data) do + { + id: account_verification_id, + object: 'account_verification', + account_number: account_number, + status: 'pending' + } + end + let(:second_account_verification_data) do + { + id: 'accv_456', + object: 'account_verification', + account_number: account_number, + status: 'pending' + } + end + + before do + allow(client).to receive(:get).with(version: :v2).and_return(get_proc) + allow(client).to receive(:post).with(version: :v2, use_jws: true).and_return(post_proc) + + allow(get_proc) + .to receive(:call) + .with("account_verifications/#{account_verification_id}") + .and_return(first_account_verification_data) + allow(get_proc) + .to receive(:call) + .with('account_verifications') + .and_return([first_account_verification_data, second_account_verification_data]) + allow(post_proc) + .to receive(:call) + .with('account_verifications', account_number:) + .and_return(first_account_verification_data) + + allow(Fintoc::V2::AccountVerification).to receive(:new) + end + + describe '#create' do + it 'calls build_account_verification with the response' do + manager.create(account_number: '735969000000203226') + expect(Fintoc::V2::AccountVerification) + .to have_received(:new).with(**first_account_verification_data, client:) + end + end + + describe '#get' do + it 'calls build_account_verification with the response' do + manager.get('accv_123') + expect(Fintoc::V2::AccountVerification) + .to have_received(:new).with(**first_account_verification_data, client:) + end + end + + describe '#list' do + it 'calls build_account_verification for each response item' do + manager.list + expect(Fintoc::V2::AccountVerification) + .to have_received(:new).with(**first_account_verification_data, client:) + expect(Fintoc::V2::AccountVerification) + .to have_received(:new).with(**second_account_verification_data, client:) + end + end +end diff --git a/spec/lib/fintoc/v2/managers/accounts_manager_spec.rb b/spec/lib/fintoc/v2/managers/accounts_manager_spec.rb new file mode 100644 index 0000000..a13e1df --- /dev/null +++ b/spec/lib/fintoc/v2/managers/accounts_manager_spec.rb @@ -0,0 +1,111 @@ +require 'fintoc/v2/managers/accounts_manager' + +RSpec.describe Fintoc::V2::Managers::AccountsManager do + let(:client) { instance_double(Fintoc::BaseClient) } + let(:get_proc) { instance_double(Proc) } + let(:post_proc) { instance_double(Proc) } + let(:patch_proc) { instance_double(Proc) } + let(:manager) { described_class.new(client) } + let(:account_id) { 'acc_123' } + let(:entity_id) { 'ent_123' } + let(:first_account_data) do + { + id: account_id, + name: 'My account', + official_name: 'My account', + number: '1234567890', + holder_id: '1234567890', + holder_name: 'My account', + type: 'checking', + currency: 'MXN', + refreshed_at: '2021-01-01', + balance: { + available: 100000, + current: 100000, + limit: 0 + }, + movements: [] + } + end + let(:second_account_data) do + { + id: 'acc_456', + name: 'My second account', + official_name: 'My second account', + number: '0987654321', + holder_id: '1234567890', + holder_name: 'My account', + type: 'checking', + currency: 'MXN', + refreshed_at: '2021-01-01', + balance: { + available: 100000, + current: 100000, + limit: 0 + }, + movements: [] + } + end + let(:updated_account_data) do + first_account_data.merge(name: 'Updated name') + end + + before do + allow(client).to receive(:get).with(version: :v2).and_return(get_proc) + allow(client).to receive(:post).with(version: :v2).and_return(post_proc) + allow(client).to receive(:patch).with(version: :v2).and_return(patch_proc) + + allow(get_proc) + .to receive(:call) + .with("accounts/#{account_id}") + .and_return(first_account_data) + allow(get_proc) + .to receive(:call) + .with('accounts') + .and_return([first_account_data, second_account_data]) + allow(patch_proc) + .to receive(:call) + .with("accounts/#{account_id}", name: 'Updated name') + .and_return(updated_account_data) + allow(post_proc) + .to receive(:call) + .with('accounts', entity_id:, description: 'My account') + .and_return(first_account_data) + + allow(Fintoc::V2::Account).to receive(:new) + end + + describe '#create' do + it 'calls build_account with the response' do + manager.create(entity_id:, description: 'My account') + expect(Fintoc::V2::Account) + .to have_received(:new).with(**first_account_data, client:) + end + end + + describe '#get' do + it 'calls build_account with the response' do + manager.get(account_id) + expect(Fintoc::V2::Account) + .to have_received(:new).with(**first_account_data, client:) + end + end + + describe '#list' do + it 'calls build_account for each response' do + manager.list + expect(Fintoc::V2::Account) + .to have_received(:new).with(**first_account_data, client:) + expect(Fintoc::V2::Account) + .to have_received(:new).with(**second_account_data, client:) + end + end + + describe '#update' do + it 'calls build_account with the response' do + manager.update(account_id, name: 'Updated name') + expect(Fintoc::V2::Account) + .to have_received(:new).with(**updated_account_data, client:) + end + end +end diff --git a/spec/lib/fintoc/v2/managers/entities_manager_spec.rb b/spec/lib/fintoc/v2/managers/entities_manager_spec.rb new file mode 100644 index 0000000..8a27b47 --- /dev/null +++ b/spec/lib/fintoc/v2/managers/entities_manager_spec.rb @@ -0,0 +1,68 @@ +require 'fintoc/v2/managers/entities_manager' + +RSpec.describe Fintoc::V2::Managers::EntitiesManager do + let(:client) { instance_double(Fintoc::BaseClient) } + let(:get_proc) { instance_double(Proc) } + + let(:manager) { described_class.new(client) } + let(:entity_id) { 'ent_31t0VhhrAXASFQTVYfCfIBnljbT' } + + let(:first_entity_data) do + { + object: 'entity', + mode: 'live', + id: entity_id, + holder_name: 'Fintoc', + holder_id: '12345678-9', + is_root: true + } + end + + let(:second_entity_data) do + { + object: 'entity', + mode: 'live', + id: 'ent_1234567890', + holder_name: 'Fintoc', + holder_id: '12345678-9', + is_root: false + } + end + + let(:entities_data) { [first_entity_data, second_entity_data] } + + before do + allow(client).to receive(:get).with(version: :v2).and_return(get_proc) + + allow(get_proc).to receive(:call).with("entities/#{entity_id}").and_return(first_entity_data) + allow(get_proc).to receive(:call).with('entities').and_return(entities_data) + + allow(Fintoc::V2::Entity).to receive(:new) + end + + describe '#get' do + it 'fetches and builds an entity' do + manager.get(entity_id) + + expect(Fintoc::V2::Entity).to have_received(:new).with(**first_entity_data, client:) + end + end + + describe '#list' do + it 'fetches and builds a list of entities' do + manager.list + + expect(Fintoc::V2::Entity).to have_received(:new).with(**first_entity_data, client:) + expect(Fintoc::V2::Entity).to have_received(:new).with(**second_entity_data, client:) + end + + it 'passes parameters to the API call' do + params = { page: 2, per_page: 50 } + allow(get_proc).to receive(:call).with('entities', **params).and_return(entities_data) + + manager.list(**params) + + expect(get_proc).to have_received(:call).with('entities', **params) + end + end +end diff --git a/spec/lib/fintoc/v2/managers/simulate_manager_spec.rb b/spec/lib/fintoc/v2/managers/simulate_manager_spec.rb new file mode 100644 index 0000000..7e289d7 --- /dev/null +++ b/spec/lib/fintoc/v2/managers/simulate_manager_spec.rb @@ -0,0 +1,39 @@ +require 'fintoc/v2/managers/simulate_manager' + +RSpec.describe Fintoc::V2::Managers::SimulateManager do + let(:client) { instance_double(Fintoc::BaseClient) } + let(:post_proc) { instance_double(Proc) } + let(:manager) { described_class.new(client) } + let(:account_number_id) { 'acno_123' } + let(:amount) { 10000 } + let(:currency) { 'MXN' } + let(:transfer_data) do + { + id: 'trf_123', + object: 'transfer', + amount: 10000, + currency: 'MXN', + account_id: 'acc_123', + reference_id: '123456' + } + end + + before do + allow(client).to receive(:post).with(version: :v2).and_return(post_proc) + + allow(post_proc) + .to receive(:call) + .with('simulate/receive_transfer', account_number_id:, amount:, currency:) + .and_return(transfer_data) + + allow(Fintoc::V2::Transfer).to receive(:new) + end + + describe '#receive_transfer' do + it 'calls build_transfer with the response' do + manager.receive_transfer(account_number_id:, amount:, currency:) + + expect(Fintoc::V2::Transfer).to have_received(:new).with(**transfer_data, client:) + end + end +end diff --git a/spec/lib/fintoc/v2/managers/transfers_manager_spec.rb b/spec/lib/fintoc/v2/managers/transfers_manager_spec.rb new file mode 100644 index 0000000..70fd199 --- /dev/null +++ b/spec/lib/fintoc/v2/managers/transfers_manager_spec.rb @@ -0,0 +1,107 @@ +require 'fintoc/v2/managers/account_verifications_manager' + +RSpec.describe Fintoc::V2::Managers::TransfersManager do + let(:client) { instance_double(Fintoc::BaseClient) } + let(:get_proc) { instance_double(Proc) } + let(:post_proc) { instance_double(Proc) } + let(:manager) { described_class.new(client) } + let(:counterparty) do + { + holder_id: 'LFHU290523OG0', + holder_name: 'Jon Snow', + account_number: '735969000000203297', + account_type: 'clabe', + institution_id: '40012' + } + end + let(:transfer_id) { 'trf_123' } + let(:first_transfer_data) do + { + id: transfer_id, + object: 'transfer', + amount: 10000, + currency: 'MXN', + account_id: 'acc_123', + counterparty:, + reference_id: '123456' + } + end + let(:second_transfer_data) do + { + id: 'trf_456', + object: 'transfer', + amount: 50000, + currency: 'MXN', + account_id: 'acc_456', + counterparty:, + reference_id: '123457' + } + end + let(:returned_transfer_data) do + first_transfer_data.merge(status: 'returned') + end + + before do + allow(client).to receive(:get).with(version: :v2).and_return(get_proc) + allow(client).to receive(:post).with(version: :v2, use_jws: true).and_return(post_proc) + + allow(get_proc) + .to receive(:call) + .with("transfers/#{transfer_id}") + .and_return(first_transfer_data) + allow(get_proc) + .to receive(:call) + .with('transfers') + .and_return([first_transfer_data, second_transfer_data]) + allow(post_proc) + .to receive(:call) + .with( + 'transfers', + amount: 10000, + currency: 'MXN', + account_id: 'acc_123', + counterparty: + ) + .and_return(first_transfer_data) + allow(post_proc) + .to receive(:call) + .with('transfers/return', transfer_id:) + .and_return(first_transfer_data) + + allow(Fintoc::V2::Transfer).to receive(:new) + end + + describe '#create' do + it 'calls build_transfer with the response' do + manager.create(amount: 10000, currency: 'MXN', account_id: 'acc_123', counterparty:) + expect(Fintoc::V2::Transfer) + .to have_received(:new).with(**first_transfer_data, client:) + end + end + + describe '#get' do + it 'calls build_transfer with the response' do + manager.get('trf_123') + expect(Fintoc::V2::Transfer) + .to have_received(:new).with(**first_transfer_data, client:) + end + end + + describe '#list' do + it 'calls build_transfer for each response item' do + manager.list + expect(Fintoc::V2::Transfer) + .to have_received(:new).with(**first_transfer_data, client:) + expect(Fintoc::V2::Transfer) + .to have_received(:new).with(**second_transfer_data, client:) + end + end + + describe '#return' do + it 'calls build_transfer with the response' do + manager.return('trf_123') + expect(Fintoc::V2::Transfer) + .to have_received(:new).with(**first_transfer_data, client:) + end + end +end diff --git a/spec/lib/fintoc/transfers/transfer_spec.rb b/spec/lib/fintoc/v2/transfer_spec.rb similarity index 93% rename from spec/lib/fintoc/transfers/transfer_spec.rb rename to spec/lib/fintoc/v2/transfer_spec.rb index 6ccbc8f..a3ca8e2 100644 --- a/spec/lib/fintoc/transfers/transfer_spec.rb +++ b/spec/lib/fintoc/v2/transfer_spec.rb @@ -1,8 +1,8 @@ -require 'fintoc/transfers/resources/transfer' +require 'fintoc/v2/resources/transfer' -RSpec.describe Fintoc::Transfers::Transfer do +RSpec.describe Fintoc::V2::Transfer do let(:api_key) { 'sk_test_SeCreT-aPi_KeY' } - let(:client) { Fintoc::Transfers::Client.new(api_key) } + let(:client) { Fintoc::V2::Client.new(api_key) } let(:counterparty_data) do { @@ -218,7 +218,7 @@ let(:refreshed_transfer) { described_class.new(**refreshed_data) } before do - allow(client).to receive(:get_transfer).with(data[:id]).and_return(refreshed_transfer) + allow(client.transfers).to receive(:get).with(data[:id]).and_return(refreshed_transfer) end it 'refreshes the transfer data' do @@ -232,8 +232,8 @@ it 'raises an error if the transfer ID does not match' do wrong_transfer = described_class.new(**data, id: 'wrong_id') - allow(client) - .to receive(:get_transfer).with('tr_329NGN1M4If6VvcMRALv4gjAQJx').and_return(wrong_transfer) + allow(client.transfers) + .to receive(:get).with('tr_329NGN1M4If6VvcMRALv4gjAQJx').and_return(wrong_transfer) expect { transfer.refresh } .to raise_error(ArgumentError, 'Transfer must be the same instance') @@ -245,7 +245,7 @@ let(:returned_transfer) { described_class.new(**returned_data) } before do - allow(client).to receive(:return_transfer).with(data[:id]).and_return(returned_transfer) + allow(client.transfers).to receive(:return).with(data[:id]).and_return(returned_transfer) end it 'returns the transfer and updates status' do @@ -255,6 +255,7 @@ it 'returns self' do expect(transfer.return_transfer).to eq(transfer) + expect(transfer.status).to eq('return_pending') end end end diff --git a/spec/support/shared_examples/clients/account_numbers_client_examples.rb b/spec/support/shared_examples/clients/account_numbers_client_examples.rb index c92b4d4..8a96a9e 100644 --- a/spec/support/shared_examples/clients/account_numbers_client_examples.rb +++ b/spec/support/shared_examples/clients/account_numbers_client_examples.rb @@ -1,67 +1,71 @@ -RSpec.shared_examples 'a client with account numbers methods' do +RSpec.shared_examples 'a client with account numbers manager' do let(:account_number_id) { 'acno_326dzRGqxLee3j9TkaBBBMfs2i0' } let(:account_id) { 'acc_31yYL7h9LVPg121AgFtCyJPDsgM' } it 'responds to account number-specific methods' do - expect(client) - .to respond_to(:create_account_number) - .and respond_to(:get_account_number) - .and respond_to(:list_account_numbers) - .and respond_to(:update_account_number) + expect(client).to respond_to(:account_numbers) + expect(client.account_numbers).to be_a(Fintoc::V2::Managers::AccountNumbersManager) + expect(client.account_numbers) + .to respond_to(:create) + .and respond_to(:get) + .and respond_to(:list) + .and respond_to(:update) end - describe '#create_account_number' do - it 'returns an AccountNumber instance', :vcr do - account_number = client.create_account_number( - account_id:, description: 'Test account number', metadata: { test_id: '12345' } - ) - - expect(account_number) - .to be_an_instance_of(Fintoc::Transfers::AccountNumber) - .and have_attributes( - account_id:, - description: 'Test account number', - object: 'account_number' + describe '#account_numbers' do + describe '#create' do + it 'returns an AccountNumber instance', :vcr do + account_number = client.account_numbers.create( + account_id:, description: 'Test account number', metadata: { test_id: '12345' } ) + + expect(account_number) + .to be_an_instance_of(Fintoc::V2::AccountNumber) + .and have_attributes( + account_id:, + description: 'Test account number', + object: 'account_number' + ) + end end - end - describe '#get_account_number' do - it 'returns an AccountNumber instance', :vcr do - account_number = client.get_account_number(account_number_id) + describe '#get' do + it 'returns an AccountNumber instance', :vcr do + account_number = client.account_numbers.get(account_number_id) - expect(account_number) - .to be_an_instance_of(Fintoc::Transfers::AccountNumber) - .and have_attributes( - id: account_number_id, - object: 'account_number' - ) + expect(account_number) + .to be_an_instance_of(Fintoc::V2::AccountNumber) + .and have_attributes( + id: account_number_id, + object: 'account_number' + ) + end end - end - describe '#list_account_numbers' do - it 'returns an array of AccountNumber instances', :vcr do - account_numbers = client.list_account_numbers + describe '#list' do + it 'returns an array of AccountNumber instances', :vcr do + account_numbers = client.account_numbers.list - expect(account_numbers).to all(be_a(Fintoc::Transfers::AccountNumber)) - expect(account_numbers.size).to be >= 1 - expect(account_numbers.first.id).to eq(account_number_id) + expect(account_numbers).to all(be_a(Fintoc::V2::AccountNumber)) + expect(account_numbers.size).to be >= 1 + expect(account_numbers.first.id).to eq(account_number_id) + end end - end - describe '#update_account_number' do - it 'returns an updated AccountNumber instance', :vcr do - updated_description = 'Updated account number description' - account_number = client.update_account_number( - account_number_id, description: updated_description - ) - - expect(account_number) - .to be_an_instance_of(Fintoc::Transfers::AccountNumber) - .and have_attributes( - id: account_number_id, - description: updated_description + describe '#update' do + it 'returns an updated AccountNumber instance', :vcr do + updated_description = 'Updated account number description' + account_number = client.account_numbers.update( + account_number_id, description: updated_description ) + + expect(account_number) + .to be_an_instance_of(Fintoc::V2::AccountNumber) + .and have_attributes( + id: account_number_id, + description: updated_description + ) + end end end end diff --git a/spec/support/shared_examples/clients/account_verifications_client_examples.rb b/spec/support/shared_examples/clients/account_verifications_client_examples.rb index 186ef7d..9dd7082 100644 --- a/spec/support/shared_examples/clients/account_verifications_client_examples.rb +++ b/spec/support/shared_examples/clients/account_verifications_client_examples.rb @@ -1,6 +1,6 @@ require 'openssl' -RSpec.shared_examples 'a client with account verifications methods' do +RSpec.shared_examples 'a client with account verifications manager' do let(:account_verification_id) { 'accv_32F2NLQOOwbeOvfuw8Y1zZCfGdw' } let(:account_number) { '735969000000203226' } let(:jws_private_key) do @@ -36,53 +36,58 @@ end it 'responds to account verification-specific methods' do - expect(client) - .to respond_to(:create_account_verification) - .and respond_to(:get_account_verification) - .and respond_to(:list_account_verifications) + expect(client).to respond_to(:account_verifications) + expect(client.account_verifications) + .to be_a(Fintoc::V2::Managers::AccountVerificationsManager) + expect(client.account_verifications) + .to respond_to(:create) + .and respond_to(:get) + .and respond_to(:list) end - describe '#create_account_verification' do - it 'returns an AccountVerification instance', :vcr do - account_verification = client.create_account_verification(account_number:) + describe '#account_verifications' do + describe '#create' do + it 'returns an AccountVerification instance', :vcr do + account_verification = client.account_verifications.create(account_number:) - expect(account_verification) - .to be_an_instance_of(Fintoc::Transfers::AccountVerification) - .and have_attributes( - object: 'account_verification', - status: 'pending' - ) + expect(account_verification) + .to be_an_instance_of(Fintoc::V2::AccountVerification) + .and have_attributes( + object: 'account_verification', + status: 'pending' + ) + end end - end - describe '#get_account_verification' do - it 'returns an AccountVerification instance', :vcr do - account_verification = client.get_account_verification(account_verification_id) + describe '#get' do + it 'returns an AccountVerification instance', :vcr do + account_verification = client.account_verifications.get(account_verification_id) - expect(account_verification) - .to be_an_instance_of(Fintoc::Transfers::AccountVerification) - .and have_attributes( - id: account_verification_id, - object: 'account_verification' - ) + expect(account_verification) + .to be_an_instance_of(Fintoc::V2::AccountVerification) + .and have_attributes( + id: account_verification_id, + object: 'account_verification' + ) + end end - end - describe '#list_account_verifications' do - it 'returns an array of AccountVerification instances', :vcr do - account_verifications = client.list_account_verifications + describe '#list' do + it 'returns an array of AccountVerification instances', :vcr do + account_verifications = client.account_verifications.list - expect(account_verifications).to all(be_a(Fintoc::Transfers::AccountVerification)) - expect(account_verifications.size).to be >= 1 - end + expect(account_verifications).to all(be_a(Fintoc::V2::AccountVerification)) + expect(account_verifications.size).to be >= 1 + end - it 'accepts filtering parameters', :vcr do - account_verifications = client.list_account_verifications( - since: '2020-01-01T00:00:00.000Z', - limit: 10 - ) + it 'accepts filtering parameters', :vcr do + account_verifications = client.account_verifications.list( + since: '2020-01-01T00:00:00.000Z', + limit: 10 + ) - expect(account_verifications).to all(be_a(Fintoc::Transfers::AccountVerification)) + expect(account_verifications).to all(be_a(Fintoc::V2::AccountVerification)) + end end end end diff --git a/spec/support/shared_examples/clients/accounts_client_examples.rb b/spec/support/shared_examples/clients/accounts_client_examples.rb index 9a5cfe9..d8d5943 100644 --- a/spec/support/shared_examples/clients/accounts_client_examples.rb +++ b/spec/support/shared_examples/clients/accounts_client_examples.rb @@ -1,63 +1,67 @@ -RSpec.shared_examples 'a client with accounts methods' do +RSpec.shared_examples 'a client with accounts manager' do let(:account_id) { 'acc_31yYL7h9LVPg121AgFtCyJPDsgM' } let(:entity_id) { 'ent_31t0VhhrAXASFQTVYfCfIBnljbT' } it 'responds to account-specific methods' do - expect(client) - .to respond_to(:create_account) - .and respond_to(:get_account) - .and respond_to(:list_accounts) - .and respond_to(:update_account) + expect(client).to respond_to(:accounts) + expect(client.accounts).to be_a(Fintoc::V2::Managers::AccountsManager) + expect(client.accounts) + .to respond_to(:create) + .and respond_to(:get) + .and respond_to(:list) + .and respond_to(:update) end - describe '#create_account' do - it 'returns an Account instance', :vcr do - account = client.create_account(entity_id:, description: 'Test account') - - expect(account) - .to be_an_instance_of(Fintoc::Transfers::Account) - .and have_attributes( - description: 'Test account', - currency: 'MXN', - status: 'active' - ) + describe '#accounts' do + describe '#create' do + it 'returns an Account instance', :vcr do + account = client.accounts.create(entity_id:, description: 'Test account') + + expect(account) + .to be_an_instance_of(Fintoc::V2::Account) + .and have_attributes( + description: 'Test account', + currency: 'MXN', + status: 'active' + ) + end end - end - describe '#get_account' do - it 'returns an Account instance', :vcr do - account = client.get_account(account_id) + describe '#get' do + it 'returns an Account instance', :vcr do + account = client.accounts.get(account_id) - expect(account) - .to be_an_instance_of(Fintoc::Transfers::Account) - .and have_attributes( - id: account_id, - description: 'Test account' - ) + expect(account) + .to be_an_instance_of(Fintoc::V2::Account) + .and have_attributes( + id: account_id, + description: 'Test account' + ) + end end - end - describe '#list_accounts' do - it 'returns an array of Account instances', :vcr do - accounts = client.list_accounts + describe '#list' do + it 'returns an array of Account instances', :vcr do + accounts = client.accounts.list - expect(accounts).to all(be_a(Fintoc::Transfers::Account)) - expect(accounts.size).to be >= 1 - expect(accounts.first.id).to eq(account_id) + expect(accounts).to all(be_a(Fintoc::V2::Account)) + expect(accounts.size).to be >= 1 + expect(accounts.first.id).to eq(account_id) + end end - end - describe '#update_account' do - it 'returns an updated Account instance', :vcr do - updated_description = 'Updated account description' - account = client.update_account(account_id, description: updated_description) - - expect(account) - .to be_an_instance_of(Fintoc::Transfers::Account) - .and have_attributes( - id: account_id, - description: updated_description - ) + describe '#update' do + it 'returns an updated Account instance', :vcr do + updated_description = 'Updated account description' + account = client.accounts.update(account_id, description: updated_description) + + expect(account) + .to be_an_instance_of(Fintoc::V2::Account) + .and have_attributes( + id: account_id, + description: updated_description + ) + end end end end diff --git a/spec/support/shared_examples/clients/entities_client_examples.rb b/spec/support/shared_examples/clients/entities_client_examples.rb index f88d071..d237fb3 100644 --- a/spec/support/shared_examples/clients/entities_client_examples.rb +++ b/spec/support/shared_examples/clients/entities_client_examples.rb @@ -1,32 +1,36 @@ -RSpec.shared_examples 'a client with entities methods' do +RSpec.shared_examples 'a client with entities manager' do let(:entity_id) { 'ent_31t0VhhrAXASFQTVYfCfIBnljbT' } - it 'responds to entity-specific methods' do - expect(client) - .to respond_to(:get_entity) - .and respond_to(:get_entities) + it 'provides an entities manager' do + expect(client).to respond_to(:entities) + expect(client.entities).to be_a(Fintoc::V2::Managers::EntitiesManager) + expect(client.entities) + .to respond_to(:get) + .and respond_to(:list) end - describe '#get_entity' do - it 'returns an Entity instance', :vcr do - entity = client.get_entity(entity_id) + describe '#entities' do + describe '#get' do + it 'returns an Entity instance', :vcr do + entity = client.entities.get(entity_id) - expect(entity) - .to be_an_instance_of(Fintoc::Transfers::Entity) - .and have_attributes( - id: entity_id, - holder_name: 'Fintoc' - ) + expect(entity) + .to be_an_instance_of(Fintoc::V2::Entity) + .and have_attributes( + id: entity_id, + holder_name: 'Fintoc' + ) + end end - end - describe '#get_entities' do - it 'returns an array of Entity instances', :vcr do - entities = client.get_entities + describe '#list' do + it 'returns an array of Entity instances', :vcr do + entities = client.entities.list - expect(entities).to all(be_a(Fintoc::Transfers::Entity)) - expect(entities.size).to eq(1) - expect(entities.first.id).to eq('ent_31t0VhhrAXASFQTVYfCfIBnljbT') + expect(entities).to all(be_a(Fintoc::V2::Entity)) + expect(entities.size).to eq(1) + expect(entities.first.id).to eq('ent_31t0VhhrAXASFQTVYfCfIBnljbT') + end end end end diff --git a/spec/support/shared_examples/clients/links_client_examples.rb b/spec/support/shared_examples/clients/links_client_examples.rb index 58a45d3..318350e 100644 --- a/spec/support/shared_examples/clients/links_client_examples.rb +++ b/spec/support/shared_examples/clients/links_client_examples.rb @@ -1,43 +1,28 @@ -RSpec.shared_examples 'a client with links methods' do +RSpec.shared_examples 'a client with links manager' do let(:link_token) { '6n12zLmai3lLE9Dq_token_gvEJi8FrBge4fb3cz7Wp856W' } it 'responds to link-specific methods' do - expect(client) - .to respond_to(:get_link) - .and respond_to(:get_links) - .and respond_to(:delete_link) - .and respond_to(:get_account) + expect(client).to respond_to(:links) + expect(client.links).to be_a(Fintoc::V1::Managers::LinksManager) + expect(client.links) + .to respond_to(:get) + .and respond_to(:list) + .and respond_to(:delete) end - describe '#get_link' do - it 'get the link from a given link token', :vcr do - link = client.get_link(link_token) - expect(link).to be_an_instance_of(Fintoc::Movements::Link) + describe '#links' do + describe '#get' do + it 'get the link from a given link token', :vcr do + link = client.links.get(link_token) + expect(link).to be_an_instance_of(Fintoc::V1::Link) + end end - end - - describe '#get_links' do - it 'get all the links from a given link token', :vcr do - links = client.get_links - expect(links).to all(be_a(Fintoc::Movements::Link)) - end - end - - describe '#get_account' do - it 'get a linked account', :vcr do - link = client.get_link(link_token) - account = link.find(type: 'checking_account') - returned_account = client.get_account(link_token, account.id) - expect(returned_account).to be_an_instance_of(Fintoc::Movements::Account) - end - end - describe '#get_accounts', :vcr do - it 'prints accounts to console' do - link = client.get_link(link_token) - expect do - link.show_accounts - end.to output(start_with('This links has 1 account')).to_stdout + describe '#list' do + it 'get all the links from a given link token', :vcr do + links = client.links.list + expect(links).to all(be_a(Fintoc::V1::Link)) + end end end end diff --git a/spec/support/shared_examples/clients/simulate_client_examples.rb b/spec/support/shared_examples/clients/simulate_client_examples.rb new file mode 100644 index 0000000..ff731be --- /dev/null +++ b/spec/support/shared_examples/clients/simulate_client_examples.rb @@ -0,0 +1,32 @@ +RSpec.shared_examples 'a client with simulate manager' do + it 'responds to simulate-specific methods' do + expect(client).to respond_to(:simulate) + expect(client.simulate).to be_a(Fintoc::V2::Managers::SimulateManager) + expect(client.simulate) + .to respond_to(:receive_transfer) + end + + describe '#simulate' do + describe '#receive_transfer' do + let(:simulate_transfer_data) do + { + account_number_id: 'acno_326dzRGqxLee3j9TkaBBBMfs2i0', + amount: 10000, + currency: 'MXN' + } + end + + it 'simulates receiving a transfer and returns Transfer object', :vcr do + transfer = client.simulate.receive_transfer(**simulate_transfer_data) + + expect(transfer) + .to be_an_instance_of(Fintoc::V2::Transfer) + .and have_attributes( + amount: simulate_transfer_data[:amount], + currency: simulate_transfer_data[:currency], + account_number: include(id: simulate_transfer_data[:account_number_id]) + ) + end + end + end +end diff --git a/spec/support/shared_examples/clients/simulation_client_examples.rb b/spec/support/shared_examples/clients/simulation_client_examples.rb deleted file mode 100644 index 29aacad..0000000 --- a/spec/support/shared_examples/clients/simulation_client_examples.rb +++ /dev/null @@ -1,23 +0,0 @@ -RSpec.shared_examples 'a client with simulation methods' do - describe '#simulate_receive_transfer' do - let(:simulate_transfer_data) do - { - account_number_id: 'acno_326dzRGqxLee3j9TkaBBBMfs2i0', - amount: 10000, - currency: 'MXN' - } - end - - it 'simulates receiving a transfer and returns Transfer object', :vcr do - transfer = client.simulate_receive_transfer(**simulate_transfer_data) - - expect(transfer) - .to be_an_instance_of(Fintoc::Transfers::Transfer) - .and have_attributes( - amount: simulate_transfer_data[:amount], - currency: simulate_transfer_data[:currency], - account_number: include(id: simulate_transfer_data[:account_number_id]) - ) - end - end -end diff --git a/spec/support/shared_examples/clients/transfers_client_examples.rb b/spec/support/shared_examples/clients/transfers_client_examples.rb index fbf6a5d..03f5fff 100644 --- a/spec/support/shared_examples/clients/transfers_client_examples.rb +++ b/spec/support/shared_examples/clients/transfers_client_examples.rb @@ -1,6 +1,6 @@ require 'openssl' -RSpec.shared_examples 'a client with transfers methods' do +RSpec.shared_examples 'a client with transfers manager' do let(:jws_private_key) do key_string = "-----BEGIN PRIVATE KEY----- MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDNLwwQr/uFToDH @@ -57,70 +57,74 @@ end it 'responds to transfer-specific methods' do - expect(client) - .to respond_to(:create_transfer) - .and respond_to(:get_transfer) - .and respond_to(:list_transfers) - .and respond_to(:return_transfer) + expect(client).to respond_to(:transfers) + expect(client.transfers).to be_a(Fintoc::V2::Managers::TransfersManager) + expect(client.transfers) + .to respond_to(:create) + .and respond_to(:get) + .and respond_to(:list) + .and respond_to(:return) end - describe '#create_transfer' do - it 'returns a Transfer instance', :vcr do - transfer = client.create_transfer(**transfer_data) + describe '#transfers' do + describe '#create' do + it 'returns a Transfer instance', :vcr do + transfer = client.transfers.create(**transfer_data) - expect(transfer) - .to be_an_instance_of(Fintoc::Transfers::Transfer) - .and have_attributes( - amount: 50000, - currency: 'MXN', - comment: 'Test payment', - reference_id: '123456', - status: 'pending' - ) + expect(transfer) + .to be_an_instance_of(Fintoc::V2::Transfer) + .and have_attributes( + amount: 50000, + currency: 'MXN', + comment: 'Test payment', + reference_id: '123456', + status: 'pending' + ) + end end - end - describe '#get_transfer' do - it 'returns a Transfer instance', :vcr do - transfer = client.get_transfer(transfer_id) + describe '#get' do + it 'returns a Transfer instance', :vcr do + transfer = client.transfers.get(transfer_id) - expect(transfer) - .to be_an_instance_of(Fintoc::Transfers::Transfer) - .and have_attributes( - id: transfer_id, - object: 'transfer' - ) + expect(transfer) + .to be_an_instance_of(Fintoc::V2::Transfer) + .and have_attributes( + id: transfer_id, + object: 'transfer' + ) + end end - end - describe '#list_transfers' do - it 'returns an array of Transfer instances', :vcr do - transfers = client.list_transfers + describe '#list' do + it 'returns an array of Transfer instances', :vcr do + transfers = client.transfers.list - expect(transfers).to all(be_a(Fintoc::Transfers::Transfer)) - expect(transfers.size).to be >= 1 - end + expect(transfers).to all(be_a(Fintoc::V2::Transfer)) + expect(transfers.size).to be >= 1 + end - it 'accepts filtering parameters', :vcr do - transfers = client.list_transfers(status: 'succeeded', direction: 'outbound') + it 'accepts filtering parameters', :vcr do + transfers = client.transfers.list(status: 'succeeded', direction: 'outbound') - expect(transfers).to all(be_a(Fintoc::Transfers::Transfer)) - expect(transfers).to all(have_attributes(status: 'succeeded', direction: 'outbound')) + expect(transfers).to all(be_a(Fintoc::V2::Transfer)) + expect(transfers).to all(have_attributes(status: 'succeeded', direction: 'outbound')) + end end - end - describe '#return_transfer' do - let(:transfer_id) { 'tr_329R3l5JksDkoevCGTOBsugCsnb' } + describe '#return' do + let(:transfer_id) { 'tr_329R3l5JksDkoevCGTOBsugCsnb' } - it 'returns a Transfer instance with return_pending status', :vcr do - transfer = client.return_transfer(transfer_id) + it 'returns a Transfer instance with return_pending status', :vcr do + transfer = client.transfers.return(transfer_id) - expect(transfer) - .to be_an_instance_of(Fintoc::Transfers::Transfer) - .and have_attributes( - id: transfer_id, - status: 'return_pending' - ) + expect(transfer) + .to be_an_instance_of(Fintoc::V2::Transfer) + .and have_attributes( + id: transfer_id, + status: 'return_pending' + ) + end end end end diff --git a/spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_account/get_a_linked_account.yml b/spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_account/get_a_linked_account.yml deleted file mode 100644 index d3b9db9..0000000 --- a/spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_account/get_a_linked_account.yml +++ /dev/null @@ -1,151 +0,0 @@ ---- -http_interactions: -- request: - method: get - uri: https://api.fintoc.com/v1/links/6n12zLmai3lLE9Dq_token_gvEJi8FrBge4fb3cz7Wp856W - body: - encoding: UTF-8 - string: '' - headers: - Authorization: - - sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx - User-Agent: - - fintoc-ruby/0.1.0 - Connection: - - close - Host: - - api.fintoc.com - response: - status: - code: 200 - message: OK - headers: - Date: - - Fri, 18 Sep 2020 19:32:32 GMT - Content-Type: - - application/json; charset=utf-8 - Transfer-Encoding: - - chunked - Connection: - - close - Set-Cookie: - - __cfduid=def4c4e84aea25dab831e626b094e47e11600457551; expires=Sun, 18-Oct-20 - 19:32:31 GMT; path=/; domain=.fintoc.com; HttpOnly; SameSite=Lax; Secure - X-Frame-Options: - - SAMEORIGIN - X-Xss-Protection: - - 1; mode=block - X-Content-Type-Options: - - nosniff - X-Download-Options: - - noopen - X-Permitted-Cross-Domain-Policies: - - none - Referrer-Policy: - - strict-origin-when-cross-origin - Etag: - - W/"897ae694e5399ed740681eeb2602478d" - Cache-Control: - - max-age=0, private, must-revalidate - X-Request-Id: - - 87980ff7-a12c-4524-89e2-c66062907680 - X-Runtime: - - '0.379295' - Strict-Transport-Security: - - max-age=31536000; includeSubDomains - Vary: - - Origin - Via: - - 1.1 vegur - Cf-Cache-Status: - - DYNAMIC - Cf-Request-Id: - - 05444d46ad0000681fd9284200000001 - Expect-Ct: - - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" - Server: - - cloudflare - Cf-Ray: - - 5d4d7e511dc0681f-EZE - body: - encoding: UTF-8 - string: '{"id":"6n12zLmai3lLE9Dq","holder_id":"782592211","username":"416148503","holder_type":"business","created_at":"2020-08-18T17:37:24.550Z","institution":{"id":"cl_banco_de_chile","name":"Banco - de Chile","country":"cl"},"link_token":null,"mode":"test","accounts":[{"id":"JjEQx2rPTGGKbrP5","type":"checking_account","number":"813990168","name":"Cuenta - Corriente","official_name":"Cuenta Corriente","balance":{"available":23457460,"current":23457460,"limit":23457460},"holder_id":"404276727","holder_name":"Sta. - Francisco Ordóñez Esquivel","currency":"CLP"}]}' - recorded_at: Fri, 18 Sep 2020 19:32:32 GMT -- request: - method: get - uri: https://api.fintoc.com/v1/links/6n12zLmai3lLE9Dq_token_gvEJi8FrBge4fb3cz7Wp856W?link_token=6n12zLmai3lLE9Dq_token_gvEJi8FrBge4fb3cz7Wp856W - body: - encoding: UTF-8 - string: '' - headers: - Authorization: - - sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx - User-Agent: - - fintoc-ruby/0.1.0 - Connection: - - close - Host: - - api.fintoc.com - response: - status: - code: 200 - message: OK - headers: - Date: - - Fri, 18 Sep 2020 19:32:33 GMT - Content-Type: - - application/json; charset=utf-8 - Transfer-Encoding: - - chunked - Connection: - - close - Set-Cookie: - - __cfduid=dbfae5f92e0ae1b5fe843ee4eba3eb1ce1600457552; expires=Sun, 18-Oct-20 - 19:32:32 GMT; path=/; domain=.fintoc.com; HttpOnly; SameSite=Lax; Secure - X-Frame-Options: - - SAMEORIGIN - X-Xss-Protection: - - 1; mode=block - X-Content-Type-Options: - - nosniff - X-Download-Options: - - noopen - X-Permitted-Cross-Domain-Policies: - - none - Referrer-Policy: - - strict-origin-when-cross-origin - Etag: - - W/"897ae694e5399ed740681eeb2602478d" - Cache-Control: - - max-age=0, private, must-revalidate - X-Request-Id: - - 5155665b-825d-4a62-84a4-910f4750e187 - X-Runtime: - - '0.336331' - Strict-Transport-Security: - - max-age=31536000; includeSubDomains - Vary: - - Origin - Via: - - 1.1 vegur - Cf-Cache-Status: - - DYNAMIC - Cf-Request-Id: - - 05444d4bea0000e51adc97e200000001 - Expect-Ct: - - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" - Server: - - cloudflare - Cf-Ray: - - 5d4d7e597cb8e51a-ARI - body: - encoding: UTF-8 - string: '{"id":"6n12zLmai3lLE9Dq","holder_id":"782592211","username":"416148503","holder_type":"business","created_at":"2020-08-18T17:37:24.550Z","institution":{"id":"cl_banco_de_chile","name":"Banco - de Chile","country":"cl"},"link_token":null,"mode":"test","accounts":[{"id":"JjEQx2rPTGGKbrP5","type":"checking_account","number":"813990168","name":"Cuenta - Corriente","official_name":"Cuenta Corriente","balance":{"available":23457460,"current":23457460,"limit":23457460},"holder_id":"404276727","holder_name":"Sta. - Francisco Ordóñez Esquivel","currency":"CLP"}]}' - recorded_at: Fri, 18 Sep 2020 19:32:33 GMT -recorded_with: VCR 6.0.0 diff --git a/spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_accounts/prints_accounts_to_console.yml b/spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_accounts/prints_accounts_to_console.yml deleted file mode 100644 index 33c5caf..0000000 --- a/spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_accounts/prints_accounts_to_console.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- -http_interactions: -- request: - method: get - uri: https://api.fintoc.com/v1/links/6n12zLmai3lLE9Dq_token_gvEJi8FrBge4fb3cz7Wp856W - body: - encoding: UTF-8 - string: '' - headers: - Authorization: - - sk_test_9c8d8CeyBTx1VcJzuDgpm4H-bywJCeSx - User-Agent: - - fintoc-ruby/0.1.0 - Connection: - - close - Host: - - api.fintoc.com - response: - status: - code: 200 - message: OK - headers: - Date: - - Tue, 08 Jun 2021 15:18:13 GMT - Content-Type: - - application/json; charset=utf-8 - Transfer-Encoding: - - chunked - Connection: - - close - X-Frame-Options: - - SAMEORIGIN - X-Xss-Protection: - - 1; mode=block - X-Content-Type-Options: - - nosniff - X-Download-Options: - - noopen - X-Permitted-Cross-Domain-Policies: - - none - Referrer-Policy: - - strict-origin-when-cross-origin - Etag: - - W/"3c5aa7315fb87065354f5169836f2c13" - Cache-Control: - - max-age=0, private, must-revalidate - X-Request-Id: - - '06048509-ff44-4c97-bea5-a0fd0c7cdc63' - X-Runtime: - - '0.296151' - Strict-Transport-Security: - - max-age=31536000; includeSubDomains - Vary: - - Origin - Via: - - 1.1 vegur - Cf-Cache-Status: - - DYNAMIC - Cf-Request-Id: - - 0a8dccf4390000cfbfa3336000000001 - Expect-Ct: - - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" - Report-To: - - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v2?s=Blsb52h5pNeOJDXBJHlt%2Bx3thBGcMHFbdTc3ivN%2FaVZt1fGU9KzIoFH5kwA6zGkcnt2bto%2BwIyUioFDYbOGEa7lO%2B1Gltk8gQI%2BsatfY8X9z1rLlka8ArFY2UQ%3D%3D"}],"group":"cf-nel","max_age":604800}' - Nel: - - '{"report_to":"cf-nel","max_age":604800}' - Server: - - cloudflare - Cf-Ray: - - 65c31766c84fcfbf-SCL - body: - encoding: UTF-8 - string: '{"id":"6n12zLmai3lLE9Dq","holder_id":"782592211","username":"416148503","holder_type":"business","created_at":"2020-08-18T17:37:24.550Z","institution":{"id":"cl_banco_de_chile","name":"Banco - de Chile","country":"cl"},"link_token":null,"mode":"test","active":true,"status":"active","object":"link","accounts":[{"id":"JjEQx2rPTGGKbrP5","type":"checking_account","number":"813990168","name":"Cuenta - Corriente","official_name":"Cuenta Corriente","balance":{"available":78785969,"current":78785969,"limit":78785969},"holder_id":"416148503","holder_name":"Teodoro - Carbajal Hidalgo","currency":"CLP","refreshed_at":null,"object":"account"}]}' - recorded_at: Tue, 08 Jun 2021 15:18:13 GMT -recorded_with: VCR 6.0.0 diff --git a/spec/vcr/Fintoc_Movements_Account/_get_movements/get_the_last_30_account_s_movements.yml b/spec/vcr/Fintoc_V1_Account/_get_movements/get_the_last_30_account_s_movements.yml similarity index 100% rename from spec/vcr/Fintoc_Movements_Account/_get_movements/get_the_last_30_account_s_movements.yml rename to spec/vcr/Fintoc_V1_Account/_get_movements/get_the_last_30_account_s_movements.yml diff --git a/spec/vcr/Fintoc_Movements_Account/_movement_with_since_argument/get_account_s_movements_with_arguments.yml b/spec/vcr/Fintoc_V1_Account/_movement_with_since_argument/get_account_s_movements_with_arguments.yml similarity index 100% rename from spec/vcr/Fintoc_Movements_Account/_movement_with_since_argument/get_account_s_movements_with_arguments.yml rename to spec/vcr/Fintoc_V1_Account/_movement_with_since_argument/get_account_s_movements_with_arguments.yml diff --git a/spec/vcr/Fintoc_Movements_Account/_movements/get_the_last_30_account_s_movements.yml b/spec/vcr/Fintoc_V1_Account/_movements/get_the_last_30_account_s_movements.yml similarity index 100% rename from spec/vcr/Fintoc_Movements_Account/_movements/get_the_last_30_account_s_movements.yml rename to spec/vcr/Fintoc_V1_Account/_movements/get_the_last_30_account_s_movements.yml diff --git a/spec/vcr/Fintoc_Movements_Account/_update_balance/update_account_s_movements.yml b/spec/vcr/Fintoc_V1_Account/_update_balance/update_account_s_movements.yml similarity index 100% rename from spec/vcr/Fintoc_Movements_Account/_update_balance/update_account_s_movements.yml rename to spec/vcr/Fintoc_V1_Account/_update_balance/update_account_s_movements.yml diff --git a/spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_link/get_the_link_from_a_given_link_token.yml b/spec/vcr/Fintoc_V1_Client/behaves_like_a_client_with_links_manager/_links/_get/get_the_link_from_a_given_link_token.yml similarity index 100% rename from spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_link/get_the_link_from_a_given_link_token.yml rename to spec/vcr/Fintoc_V1_Client/behaves_like_a_client_with_links_manager/_links/_get/get_the_link_from_a_given_link_token.yml diff --git a/spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_links/get_all_the_links_from_a_given_link_token.yml b/spec/vcr/Fintoc_V1_Client/behaves_like_a_client_with_links_manager/_links/_list/get_all_the_links_from_a_given_link_token.yml similarity index 100% rename from spec/vcr/Fintoc_Movements_Client/behaves_like_a_client_with_links_methods/_get_links/get_all_the_links_from_a_given_link_token.yml rename to spec/vcr/Fintoc_V1_Client/behaves_like_a_client_with_links_manager/_links/_list/get_all_the_links_from_a_given_link_token.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_numbers_methods/_create_account_number/returns_an_AccountNumber_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_numbers_manager/_account_numbers/_create/returns_an_AccountNumber_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_numbers_methods/_create_account_number/returns_an_AccountNumber_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_numbers_manager/_account_numbers/_create/returns_an_AccountNumber_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_numbers_methods/_get_account_number/returns_an_AccountNumber_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_numbers_manager/_account_numbers/_get/returns_an_AccountNumber_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_numbers_methods/_get_account_number/returns_an_AccountNumber_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_numbers_manager/_account_numbers/_get/returns_an_AccountNumber_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_numbers_methods/_list_account_numbers/returns_an_array_of_AccountNumber_instances.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_numbers_manager/_account_numbers/_list/returns_an_array_of_AccountNumber_instances.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_numbers_methods/_list_account_numbers/returns_an_array_of_AccountNumber_instances.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_numbers_manager/_account_numbers/_list/returns_an_array_of_AccountNumber_instances.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_numbers_methods/_update_account_number/returns_an_updated_AccountNumber_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_numbers_manager/_account_numbers/_update/returns_an_updated_AccountNumber_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_numbers_methods/_update_account_number/returns_an_updated_AccountNumber_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_numbers_manager/_account_numbers/_update/returns_an_updated_AccountNumber_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_verifications_methods/_create_account_verification/returns_an_AccountVerification_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_verifications_manager/_account_verifications/_create/returns_an_AccountVerification_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_verifications_methods/_create_account_verification/returns_an_AccountVerification_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_verifications_manager/_account_verifications/_create/returns_an_AccountVerification_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_verifications_methods/_get_account_verification/returns_an_AccountVerification_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_verifications_manager/_account_verifications/_get/returns_an_AccountVerification_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_verifications_methods/_get_account_verification/returns_an_AccountVerification_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_verifications_manager/_account_verifications/_get/returns_an_AccountVerification_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_verifications_methods/_list_account_verifications/accepts_filtering_parameters.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_verifications_manager/_account_verifications/_list/accepts_filtering_parameters.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_verifications_methods/_list_account_verifications/accepts_filtering_parameters.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_verifications_manager/_account_verifications/_list/accepts_filtering_parameters.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_verifications_methods/_list_account_verifications/returns_an_array_of_AccountVerification_instances.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_verifications_manager/_account_verifications/_list/returns_an_array_of_AccountVerification_instances.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_account_verifications_methods/_list_account_verifications/returns_an_array_of_AccountVerification_instances.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_account_verifications_manager/_account_verifications/_list/returns_an_array_of_AccountVerification_instances.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_accounts_methods/_create_account/returns_an_Account_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_accounts_manager/_accounts/_create/returns_an_Account_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_accounts_methods/_create_account/returns_an_Account_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_accounts_manager/_accounts/_create/returns_an_Account_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_accounts_methods/_get_account/returns_an_Account_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_accounts_manager/_accounts/_get/returns_an_Account_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_accounts_methods/_get_account/returns_an_Account_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_accounts_manager/_accounts/_get/returns_an_Account_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_accounts_methods/_list_accounts/returns_an_array_of_Account_instances.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_accounts_manager/_accounts/_list/returns_an_array_of_Account_instances.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_accounts_methods/_list_accounts/returns_an_array_of_Account_instances.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_accounts_manager/_accounts/_list/returns_an_array_of_Account_instances.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_accounts_methods/_update_account/returns_an_updated_Account_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_accounts_manager/_accounts/_update/returns_an_updated_Account_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_accounts_methods/_update_account/returns_an_updated_Account_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_accounts_manager/_accounts/_update/returns_an_updated_Account_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_entities_methods/_get_entity/returns_an_Entity_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_entities_manager/_entities/_get/returns_an_Entity_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_entities_methods/_get_entity/returns_an_Entity_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_entities_manager/_entities/_get/returns_an_Entity_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_entities_methods/_get_entities/returns_an_array_of_Entity_instances.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_entities_manager/_entities/_list/returns_an_array_of_Entity_instances.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_entities_methods/_get_entities/returns_an_array_of_Entity_instances.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_entities_manager/_entities/_list/returns_an_array_of_Entity_instances.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_simulation_methods/_simulate_receive_transfer/simulates_receiving_a_transfer_and_returns_Transfer_object.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_simulate_manager/_simulate/_receive_transfer/simulates_receiving_a_transfer_and_returns_Transfer_object.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_simulation_methods/_simulate_receive_transfer/simulates_receiving_a_transfer_and_returns_Transfer_object.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_simulate_manager/_simulate/_receive_transfer/simulates_receiving_a_transfer_and_returns_Transfer_object.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_create_transfer/returns_a_Transfer_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_create/returns_a_Transfer_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_create_transfer/returns_a_Transfer_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_create/returns_a_Transfer_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_get_transfer/returns_a_Transfer_instance.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_get/returns_a_Transfer_instance.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_get_transfer/returns_a_Transfer_instance.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_get/returns_a_Transfer_instance.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_list_transfers/accepts_filtering_parameters.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_list/accepts_filtering_parameters.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_list_transfers/accepts_filtering_parameters.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_list/accepts_filtering_parameters.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_list_transfers/returns_an_array_of_Transfer_instances.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_list/returns_an_array_of_Transfer_instances.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_list_transfers/returns_an_array_of_Transfer_instances.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_list/returns_an_array_of_Transfer_instances.yml diff --git a/spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_return_transfer/returns_a_Transfer_instance_with_return_pending_status.yml b/spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_return/returns_a_Transfer_instance_with_return_pending_status.yml similarity index 100% rename from spec/vcr/Fintoc_Transfers_Client/behaves_like_a_client_with_transfers_methods/_return_transfer/returns_a_Transfer_instance_with_return_pending_status.yml rename to spec/vcr/Fintoc_V2_Client/behaves_like_a_client_with_transfers_manager/_transfers/_return/returns_a_Transfer_instance_with_return_pending_status.yml