fintoc 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 125043d067ac8281433e37d16a8376d3b25f581b3a4fc7f31b30e1b96623e570
4
- data.tar.gz: 909b347cacb35dfd8e495be517e7c6320ce8aa9930c592215651cd813636e256
3
+ metadata.gz: 18a0e42f4e865dc3c9a5effb821f75cd8c0df2fd1cc74d438b70cb25197db7c3
4
+ data.tar.gz: d88a84f2581d693274770e4de27df625851116d896538f519eb4184f061e92aa
5
5
  SHA512:
6
- metadata.gz: b4fe705e12286af83f27d6fbdae257f334f65b98122d16cb187b6d2c326b10c482356d30e4962faa2395e3e0199d83fc287b2d40a213cf8ff3f780eda714c7c7
7
- data.tar.gz: 8ff1d5bb3d658081d9dc3086ab8a2c0b01051c7cd5a30776a150960365191c33879016f5fb2738e63e15c9ca767adc1a5ee48c915f92b40837351c284f988312
6
+ metadata.gz: 47a1a45fdd60049a311cc7aa6458c5942de82a4a2ae4a05139d3ebe92f96da5a2b8bdff7544d5195536575cc7fa209b54092cfaa3c5e0caf2a1e463b1389fed8
7
+ data.tar.gz: 7e8677a9c72a33803a98c44ac8adedc86ed835d9bfa99505f8c17c9e8d77e0b8b6c41bbe1ad5681feefff7e88c995eb6a710b61ad8d573af29696777e13f3fe2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fintoc (1.4.0)
4
+ fintoc (1.6.0)
5
5
  http
6
6
  money-rails
7
7
  tabulate
data/README.md CHANGED
@@ -31,6 +31,7 @@ Do yourself a favor: go grab some ice cubes by installing this refreshing librar
31
31
  - [Accounts](#accounts)
32
32
  - [Account Numbers](#account-numbers)
33
33
  - [Transfers](#transfers)
34
+ - [Transfer Batches](#transfer-batches)
34
35
  - [Simulate](#simulate)
35
36
  - [Account Verifications](#account-verifications)
36
37
  - [Entity onboardings API Examples](#entity-onboardings-api-examples)
@@ -139,6 +140,15 @@ transfer = client.v2.transfers.create(
139
140
  )
140
141
  client.v2.transfers.return('transfer_id')
141
142
 
143
+ # Transfer Batches
144
+ transfer_batches = client.v2.transfer_batches.list
145
+ transfer_batch = client.v2.transfer_batches.get('transfer_batch_id')
146
+ transfer_batch = client.v2.transfer_batches.create(
147
+ description: 'Supplier payments',
148
+ currency: 'MXN',
149
+ transfers: [{...}]
150
+ )
151
+
142
152
  # Simulate
143
153
  simulated_transfer = client.v2.simulate.receive_transfer(
144
154
  account_number_id: 'account_number_id',
@@ -360,6 +370,42 @@ transfers = client.v2.transfers.list
360
370
  returned_transfer = client.v2.transfers.return('transfer_id')
361
371
  ```
362
372
 
373
+ #### Transfer Batches
374
+
375
+ ```ruby
376
+ require 'fintoc'
377
+
378
+ client = Fintoc::Client.new('api_key', jws_private_key: 'jws_private_key')
379
+
380
+ # Create a transfer batch. Each transfer has the same shape as `transfers.create`, without `currency`
381
+ transfer_batch = client.v2.transfer_batches.create(
382
+ description: 'Supplier payments',
383
+ currency: 'MXN',
384
+ transfers: [
385
+ {
386
+ account_id: 'account_id',
387
+ amount: 10000,
388
+ comment: 'Invoice 1234',
389
+ reference_id: '123456',
390
+ counterparty: { account_number: '735969000000203297' }
391
+ }
392
+ ]
393
+ )
394
+
395
+ # Get a specific transfer batch
396
+ transfer_batch = client.v2.transfer_batches.get('transfer_batch_id')
397
+
398
+ # List transfer batches, optionally filtered by status and creation date
399
+ transfer_batches = client.v2.transfer_batches.list(
400
+ 'status[]': %w[succeeded partially_succeeded],
401
+ since: '2026-10-01T00:00:00Z',
402
+ until: '2026-10-31T23:59:59Z'
403
+ )
404
+
405
+ # List the transfers of a batch
406
+ transfers = client.v2.transfers.list(transfer_batch_id: 'transfer_batch_id')
407
+ ```
408
+
363
409
  #### Simulate
364
410
 
365
411
  ```ruby
@@ -46,6 +46,8 @@ module Fintoc
46
46
  proc do |resource, form: nil, **kwargs|
47
47
  parameters = form ? { form: build_form(form) } : params(method, **kwargs)
48
48
  response = make_request(method, resource, parameters, version:, use_jws:, idempotency_key:)
49
+ next nil if response.status.no_content?
50
+
49
51
  content = JSON.parse(response.body, symbolize_names: true)
50
52
 
51
53
  if response.status.client_error? || response.status.server_error?
data/lib/fintoc/errors.rb CHANGED
@@ -66,6 +66,9 @@ module Fintoc
66
66
  class InvalidInstallmentsCurrencyError < FintocError; end
67
67
  class InvalidClabeError < FintocError; end
68
68
  class MismatchTransferAccountCurrencyError < FintocError; end
69
+ class InvalidTransfersError < FintocError; end
70
+ class InvalidTransfersSizeError < FintocError; end
71
+ class InvalidDescriptionSizeError < FintocError; end
69
72
 
70
73
  # 401 Unauthorized Errors
71
74
  class AuthenticationError < FintocError; end
@@ -124,6 +127,7 @@ module Fintoc
124
127
  class InvalidTransferDirectionError < FintocError; end
125
128
  class AccountNumberLimitReachedError < FintocError; end
126
129
  class AccountCannotBeBlockedError < FintocError; end
130
+ class InvalidSenderAccountsError < FintocError; end
127
131
 
128
132
  # 422 Unprocessable Entity Errors
129
133
  class InvalidOtpCodeError < FintocError; end
@@ -150,6 +154,9 @@ module Fintoc
150
154
  class UnrecognizedRequestError < FintocError; end
151
155
  class CoreResponseError < FintocError; end
152
156
 
157
+ # 501 Not Implemented Errors
158
+ class OperationNotImplementedError < FintocError; end
159
+
153
160
  # Webhook Errors
154
161
  class WebhookSignatureError < FintocError; end
155
162
 
@@ -1,8 +1,10 @@
1
1
  require 'fintoc/base_client'
2
2
  require 'fintoc/v2/managers/entities_manager'
3
+ require 'fintoc/v2/managers/recipients_manager'
3
4
  require 'fintoc/v2/managers/accounts_manager'
4
5
  require 'fintoc/v2/managers/account_numbers_manager'
5
6
  require 'fintoc/v2/managers/transfers_manager'
7
+ require 'fintoc/v2/managers/transfer_batches_manager'
6
8
  require 'fintoc/v2/managers/simulate_manager'
7
9
  require 'fintoc/v2/managers/account_verifications_manager'
8
10
 
@@ -13,6 +15,10 @@ module Fintoc
13
15
  @entities ||= Managers::EntitiesManager.new(self)
14
16
  end
15
17
 
18
+ def recipients
19
+ @recipients ||= Managers::RecipientsManager.new(self)
20
+ end
21
+
16
22
  def accounts
17
23
  @accounts ||= Managers::AccountsManager.new(self)
18
24
  end
@@ -25,6 +31,10 @@ module Fintoc
25
31
  @transfers ||= Managers::TransfersManager.new(self)
26
32
  end
27
33
 
34
+ def transfer_batches
35
+ @transfer_batches ||= Managers::TransferBatchesManager.new(self)
36
+ end
37
+
28
38
  def simulate
29
39
  @simulate ||= Managers::SimulateManager.new(self)
30
40
  end
@@ -0,0 +1,47 @@
1
+ require 'fintoc/v2/resources/recipient'
2
+
3
+ module Fintoc
4
+ module V2
5
+ module Managers
6
+ class RecipientsManager
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def create(entity_id:, account_number:, holder_name:, idempotency_key: nil, **params)
12
+ data = @client.post(version: :v2, idempotency_key:).call(
13
+ 'recipients', entity_id:, account_number:, holder_name:, **params
14
+ )
15
+ build_recipient(data)
16
+ end
17
+
18
+ def get(recipient_id)
19
+ data = @client.get(version: :v2).call("recipients/#{recipient_id}")
20
+ build_recipient(data)
21
+ end
22
+
23
+ def list(**params)
24
+ @client.get(version: :v2).call('recipients', **params).map do |data|
25
+ build_recipient(data)
26
+ end
27
+ end
28
+
29
+ def update(recipient_id, idempotency_key: nil, **params)
30
+ data = @client.patch(version: :v2, idempotency_key:)
31
+ .call("recipients/#{recipient_id}", **params)
32
+ build_recipient(data)
33
+ end
34
+
35
+ def delete(recipient_id)
36
+ @client.delete(version: :v2).call("recipients/#{recipient_id}")
37
+ end
38
+
39
+ private
40
+
41
+ def build_recipient(data)
42
+ Fintoc::V2::Recipient.new(**data, client: @client)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ require 'fintoc/v2/resources/transfer_batch'
2
+
3
+ module Fintoc
4
+ module V2
5
+ module Managers
6
+ class TransferBatchesManager
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def create(description:, currency:, transfers:, idempotency_key: nil)
12
+ data = _create_transfer_batch(description:, currency:, transfers:, idempotency_key:)
13
+ build_transfer_batch(data)
14
+ end
15
+
16
+ def get(transfer_batch_id)
17
+ data = _get_transfer_batch(transfer_batch_id)
18
+ build_transfer_batch(data)
19
+ end
20
+
21
+ def list(**params)
22
+ _list_transfer_batches(**params).map { |data| build_transfer_batch(data) }
23
+ end
24
+
25
+ private
26
+
27
+ def _create_transfer_batch(description:, currency:, transfers:, idempotency_key: nil)
28
+ @client
29
+ .post(version: :v2, use_jws: true, idempotency_key:)
30
+ .call('transfer_batches', description:, currency:, transfers:)
31
+ end
32
+
33
+ def _get_transfer_batch(transfer_batch_id)
34
+ @client.get(version: :v2).call("transfer_batches/#{transfer_batch_id}")
35
+ end
36
+
37
+ def _list_transfer_batches(**params)
38
+ @client.get(version: :v2).call('transfer_batches', **params)
39
+ end
40
+
41
+ def build_transfer_batch(data)
42
+ Fintoc::V2::TransferBatch.new(**data, client: @client)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,62 @@
1
+ module Fintoc
2
+ module V2
3
+ class Recipient
4
+ attr_reader :id, :object, :account_number, :account_type, :alias, :created_at,
5
+ :email, :holder_id, :holder_name, :holder_type, :updated_at, :institution
6
+
7
+ def initialize(
8
+ id:, object:, account_number:, account_type:, holder_name:, institution:,
9
+ created_at: nil, email: nil, holder_id: nil, holder_type: nil,
10
+ updated_at: nil, client: nil, **attributes
11
+ )
12
+ @id = id
13
+ @object = object
14
+ @account_number = account_number
15
+ @account_type = account_type
16
+ @alias = attributes[:alias]
17
+ @created_at = created_at
18
+ @email = email
19
+ @holder_id = holder_id
20
+ @holder_name = holder_name
21
+ @holder_type = holder_type
22
+ @updated_at = updated_at
23
+ @institution = institution
24
+ @client = client
25
+ end
26
+
27
+ def refresh
28
+ refresh_from_recipient(@client.recipients.get(@id))
29
+ end
30
+
31
+ def update(idempotency_key: nil, **params)
32
+ refresh_from_recipient(@client.recipients.update(@id, idempotency_key:, **params))
33
+ end
34
+
35
+ def delete
36
+ @client.recipients.delete(@id)
37
+ end
38
+
39
+ private
40
+
41
+ def refresh_from_recipient(recipient)
42
+ unless recipient.id == @id
43
+ raise ArgumentError, 'Recipient must be the same instance'
44
+ end
45
+
46
+ @object = recipient.object
47
+ @account_number = recipient.account_number
48
+ @account_type = recipient.account_type
49
+ @alias = recipient.alias
50
+ @created_at = recipient.created_at
51
+ @email = recipient.email
52
+ @holder_id = recipient.holder_id
53
+ @holder_name = recipient.holder_name
54
+ @holder_type = recipient.holder_type
55
+ @updated_at = recipient.updated_at
56
+ @institution = recipient.institution
57
+
58
+ self
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,114 @@
1
+ require 'money'
2
+
3
+ module Fintoc
4
+ module V2
5
+ class TransferBatch
6
+ attr_reader :id, :object, :mode, :description, :status, :currency, :transfer_count,
7
+ :amount, :succeeded_count, :settled_amount, :created_at, :authorized_at,
8
+ :rejected_at, :expired_at, :succeeded_at, :partially_succeeded_at
9
+
10
+ def initialize( # rubocop:disable Metrics/MethodLength
11
+ id:,
12
+ object:,
13
+ mode:,
14
+ status:,
15
+ currency:,
16
+ transfer_count:,
17
+ amount:,
18
+ description: nil,
19
+ succeeded_count: nil,
20
+ settled_amount: nil,
21
+ created_at: nil,
22
+ authorized_at: nil,
23
+ rejected_at: nil,
24
+ expired_at: nil,
25
+ succeeded_at: nil,
26
+ partially_succeeded_at: nil,
27
+ client: nil,
28
+ **
29
+ )
30
+ @id = id
31
+ @object = object
32
+ @mode = mode
33
+ @description = description
34
+ @status = status
35
+ @currency = currency
36
+ @transfer_count = transfer_count
37
+ @amount = amount
38
+ @succeeded_count = succeeded_count
39
+ @settled_amount = settled_amount
40
+ @created_at = created_at
41
+ @authorized_at = authorized_at
42
+ @rejected_at = rejected_at
43
+ @expired_at = expired_at
44
+ @succeeded_at = succeeded_at
45
+ @partially_succeeded_at = partially_succeeded_at
46
+ @client = client
47
+ end
48
+
49
+ def to_s
50
+ amount_str = Money.from_cents(@amount, @currency).format
51
+ "📦 #{amount_str} (#{@id}) - #{@status}"
52
+ end
53
+
54
+ def refresh
55
+ fresh_transfer_batch = @client.transfer_batches.get(@id)
56
+ refresh_from_transfer_batch(fresh_transfer_batch)
57
+ end
58
+
59
+ def pending_authorization?
60
+ @status == 'pending_authorization'
61
+ end
62
+
63
+ def in_progress?
64
+ @status == 'in_progress'
65
+ end
66
+
67
+ def rejected?
68
+ @status == 'rejected'
69
+ end
70
+
71
+ def expired?
72
+ @status == 'expired'
73
+ end
74
+
75
+ def succeeded?
76
+ @status == 'succeeded'
77
+ end
78
+
79
+ def partially_succeeded?
80
+ @status == 'partially_succeeded'
81
+ end
82
+
83
+ def failed?
84
+ @status == 'failed'
85
+ end
86
+
87
+ private
88
+
89
+ def refresh_from_transfer_batch(transfer_batch) # rubocop:disable Metrics/MethodLength
90
+ unless transfer_batch.id == @id
91
+ raise ArgumentError, 'Transfer batch must be the same instance'
92
+ end
93
+
94
+ @object = transfer_batch.object
95
+ @mode = transfer_batch.mode
96
+ @description = transfer_batch.description
97
+ @status = transfer_batch.status
98
+ @currency = transfer_batch.currency
99
+ @transfer_count = transfer_batch.transfer_count
100
+ @amount = transfer_batch.amount
101
+ @succeeded_count = transfer_batch.succeeded_count
102
+ @settled_amount = transfer_batch.settled_amount
103
+ @created_at = transfer_batch.created_at
104
+ @authorized_at = transfer_batch.authorized_at
105
+ @rejected_at = transfer_batch.rejected_at
106
+ @expired_at = transfer_batch.expired_at
107
+ @succeeded_at = transfer_batch.succeeded_at
108
+ @partially_succeeded_at = transfer_batch.partially_succeeded_at
109
+
110
+ self
111
+ end
112
+ end
113
+ end
114
+ end
@@ -1,3 +1,3 @@
1
1
  module Fintoc
2
- VERSION = '1.4.0'
2
+ VERSION = '1.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fintoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Ca Sardin
@@ -100,7 +100,9 @@ files:
100
100
  - lib/fintoc/v2/managers/entities_manager.rb
101
101
  - lib/fintoc/v2/managers/movements_manager.rb
102
102
  - lib/fintoc/v2/managers/onboardings_manager.rb
103
+ - lib/fintoc/v2/managers/recipients_manager.rb
103
104
  - lib/fintoc/v2/managers/simulate_manager.rb
105
+ - lib/fintoc/v2/managers/transfer_batches_manager.rb
104
106
  - lib/fintoc/v2/managers/transfers_manager.rb
105
107
  - lib/fintoc/v2/resources/account.rb
106
108
  - lib/fintoc/v2/resources/account_number.rb
@@ -109,7 +111,9 @@ files:
109
111
  - lib/fintoc/v2/resources/entity.rb
110
112
  - lib/fintoc/v2/resources/movement.rb
111
113
  - lib/fintoc/v2/resources/onboarding.rb
114
+ - lib/fintoc/v2/resources/recipient.rb
112
115
  - lib/fintoc/v2/resources/transfer.rb
116
+ - lib/fintoc/v2/resources/transfer_batch.rb
113
117
  - lib/fintoc/version.rb
114
118
  - lib/fintoc/webhook_signature.rb
115
119
  - lib/tasks/simplecov_config.rb