Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/fintoc/transfers/client/account_verifications_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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
2 changes: 2 additions & 0 deletions lib/fintoc/transfers/client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand All @@ -13,6 +14,7 @@ class Client < BaseClient
include AccountNumbersMethods
include TransfersMethods
include SimulationMethods
include AccountVerificationsMethods
end
end
end
7 changes: 3 additions & 4 deletions lib/fintoc/transfers/resources/account.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require 'money'
require 'fintoc/utils'

module Fintoc
module Transfers
class Account
include Utils

attr_reader :id, :object, :mode, :description, :available_balance, :currency,
:is_root, :root_account_number_id, :root_account_number, :status, :entity

Expand Down Expand Up @@ -86,7 +83,9 @@ def simulate_receive_transfer(amount:)
private

def refresh_from_account(account)
raise 'Account must be the same instance' unless account.id == @id
unless account.id == @id
raise ArgumentError, 'Account must be the same instance'
end

@object = account.object
@mode = account.mode
Expand Down
8 changes: 3 additions & 5 deletions lib/fintoc/transfers/resources/account_number.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
require 'fintoc/utils'

module Fintoc
module Transfers
class AccountNumber
include Utils

attr_reader :id, :object, :description, :number, :created_at, :updated_at,
:mode, :status, :is_root, :account_id, :metadata

Expand Down Expand Up @@ -87,7 +83,9 @@ def simulate_receive_transfer(amount:, currency: 'MXN')
private

def refresh_from_account_number(account_number)
raise 'AccountNumber must be the same instance' unless account_number.id == @id
unless account_number.id == @id
raise ArgumentError, 'AccountNumber must be the same instance'
end

@object = account_number.object
@description = account_number.description
Expand Down
73 changes: 73 additions & 0 deletions lib/fintoc/transfers/resources/account_verification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module Fintoc
module Transfers
class AccountVerification
attr_reader :id, :object, :status, :reason, :transfer_id, :counterparty, :mode, :receipt_url,
:transaction_date

def initialize(
id:,
object:,
status:,
reason:,
transfer_id:,
counterparty:,
mode:,
receipt_url:,
transaction_date:,
client: nil,
**
)
@id = id
@object = object
@status = status
@reason = reason
@transfer_id = transfer_id
@counterparty = counterparty
@mode = mode
@receipt_url = receipt_url
@transaction_date = transaction_date
@client = client
end

def to_s
"🔍 Account Verification (#{@id}) - #{@status}"
end

def refresh
fresh_verification = @client.get_account_verification(@id)
refresh_from_verification(fresh_verification)
end

def pending?
@status == 'pending'
end

def succeeded?
@status == 'succeeded'
end

def failed?
@status == 'failed'
end

private

def refresh_from_verification(verification)
unless verification.id == @id
raise ArgumentError, 'Account verification must be the same instance'
end

@object = verification.object
@status = verification.status
@reason = verification.reason
@transfer_id = verification.transfer_id
@counterparty = verification.counterparty
@mode = verification.mode
@receipt_url = verification.receipt_url
@transaction_date = verification.transaction_date

self
end
end
end
end
8 changes: 3 additions & 5 deletions lib/fintoc/transfers/resources/entity.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
require 'fintoc/utils'

module Fintoc
module Transfers
class Entity
include Utils

attr_reader :object, :mode, :id, :holder_name, :holder_id, :is_root

def initialize(
Expand Down Expand Up @@ -38,7 +34,9 @@ def refresh
private

def refresh_from_entity(entity)
raise 'Entity must be the same instance' unless entity.id == @id
unless entity.id == @id
raise ArgumentError, 'Entity must be the same instance'
end

@object = entity.object
@mode = entity.mode
Expand Down
7 changes: 3 additions & 4 deletions lib/fintoc/transfers/resources/transfer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require 'money'
require 'fintoc/utils'

module Fintoc
module Transfers
class Transfer
include Utils

attr_reader :id, :object, :amount, :currency, :direction, :status, :mode,
:post_date, :transaction_date, :comment, :reference_id, :receipt_url,
:tracking_key, :return_reason, :counterparty, :account_number,
Expand Down Expand Up @@ -105,7 +102,9 @@ def outbound?
private

def refresh_from_transfer(transfer) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
raise 'Transfer must be the same instance' unless transfer.id == @id
unless transfer.id == @id
raise ArgumentError, 'Transfer must be the same instance'
end

@object = transfer.object
@amount = transfer.amount
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/fintoc/transfers/account_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@
account_number.refresh
expect(client).to have_received(:get_account_number).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)
.with('acno_Kasf91034gj1AD')
.and_return(wrong_account_number)

expect { account_number.refresh }
.to raise_error(ArgumentError, 'AccountNumber must be the same instance')
end
end

describe '#update' do
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/fintoc/transfers/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@

expect(account.description).to eq('Updated account description')
end

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)

expect { account.refresh }.to raise_error(ArgumentError, 'Account must be the same instance')
end
end

describe '#update' do
Expand Down
Loading