Repository navigation
[BA-8916] Add transfer batches support to fintoc-ruby #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
731f9f0
feat(v2): add TransferBatch resource and TransferBatchesManager
SimonOyaneder 3cc2e0c
feat(errors): add transfer batch error classes
SimonOyaneder b6b5bdc
test(v2): cover transfer_batches in v2 client
SimonOyaneder a58519c
docs(v2): document transfer batches in README
SimonOyaneder 4ae761a
refactor(v2): rename transfer batch amounts to amount and settled_amount
SimonOyaneder 824d8bf
feat(v2): expose succeeded_at and partially_succeeded_at on transfer …
SimonOyaneder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| require 'fintoc/v2/resources/transfer_batch' | ||
|
|
||
| module Fintoc | ||
| module V2 | ||
| module Managers | ||
| class TransferBatchesManager | ||
| def initialize(client) | ||
| @client = client | ||
| end | ||
|
|
||
| def create(description:, currency:, transfers:, idempotency_key: nil) | ||
| data = _create_transfer_batch(description:, currency:, transfers:, idempotency_key:) | ||
| build_transfer_batch(data) | ||
| end | ||
|
|
||
| def get(transfer_batch_id) | ||
| data = _get_transfer_batch(transfer_batch_id) | ||
| build_transfer_batch(data) | ||
| end | ||
|
|
||
| def list(**params) | ||
| _list_transfer_batches(**params).map { |data| build_transfer_batch(data) } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def _create_transfer_batch(description:, currency:, transfers:, idempotency_key: nil) | ||
| @client | ||
| .post(version: :v2, use_jws: true, idempotency_key:) | ||
| .call('transfer_batches', description:, currency:, transfers:) | ||
| end | ||
|
|
||
| def _get_transfer_batch(transfer_batch_id) | ||
| @client.get(version: :v2).call("transfer_batches/#{transfer_batch_id}") | ||
| end | ||
|
|
||
| def _list_transfer_batches(**params) | ||
| @client.get(version: :v2).call('transfer_batches', **params) | ||
| end | ||
|
|
||
| def build_transfer_batch(data) | ||
| Fintoc::V2::TransferBatch.new(**data, client: @client) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| require 'money' | ||
|
|
||
| module Fintoc | ||
| module V2 | ||
| class TransferBatch | ||
| attr_reader :id, :object, :mode, :description, :status, :currency, :transfer_count, | ||
| :amount, :succeeded_count, :settled_amount, :created_at, :authorized_at, | ||
| :rejected_at, :expired_at, :succeeded_at, :partially_succeeded_at | ||
|
|
||
| def initialize( # rubocop:disable Metrics/MethodLength | ||
| id:, | ||
| object:, | ||
| mode:, | ||
| status:, | ||
| currency:, | ||
| transfer_count:, | ||
| amount:, | ||
| description: nil, | ||
| succeeded_count: nil, | ||
| settled_amount: nil, | ||
| created_at: nil, | ||
| authorized_at: nil, | ||
| rejected_at: nil, | ||
| expired_at: nil, | ||
| succeeded_at: nil, | ||
| partially_succeeded_at: nil, | ||
| client: nil, | ||
| ** | ||
| ) | ||
| @id = id | ||
| @object = object | ||
| @mode = mode | ||
| @description = description | ||
| @status = status | ||
| @currency = currency | ||
| @transfer_count = transfer_count | ||
| @amount = amount | ||
| @succeeded_count = succeeded_count | ||
| @settled_amount = settled_amount | ||
| @created_at = created_at | ||
| @authorized_at = authorized_at | ||
| @rejected_at = rejected_at | ||
| @expired_at = expired_at | ||
| @succeeded_at = succeeded_at | ||
| @partially_succeeded_at = partially_succeeded_at | ||
| @client = client | ||
| end | ||
|
|
||
| def to_s | ||
| amount_str = Money.from_cents(@amount, @currency).format | ||
| "📦 #{amount_str} (#{@id}) - #{@status}" | ||
| end | ||
|
|
||
| def refresh | ||
| fresh_transfer_batch = @client.transfer_batches.get(@id) | ||
| refresh_from_transfer_batch(fresh_transfer_batch) | ||
| end | ||
|
|
||
| def pending_authorization? | ||
| @status == 'pending_authorization' | ||
| end | ||
|
|
||
| def in_progress? | ||
| @status == 'in_progress' | ||
| end | ||
|
|
||
| def rejected? | ||
| @status == 'rejected' | ||
| end | ||
|
|
||
| def expired? | ||
| @status == 'expired' | ||
| end | ||
|
|
||
| def succeeded? | ||
| @status == 'succeeded' | ||
| end | ||
|
|
||
| def partially_succeeded? | ||
| @status == 'partially_succeeded' | ||
| end | ||
|
|
||
| def failed? | ||
| @status == 'failed' | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def refresh_from_transfer_batch(transfer_batch) # rubocop:disable Metrics/MethodLength | ||
| unless transfer_batch.id == @id | ||
| raise ArgumentError, 'Transfer batch must be the same instance' | ||
| end | ||
|
|
||
| @object = transfer_batch.object | ||
| @mode = transfer_batch.mode | ||
| @description = transfer_batch.description | ||
| @status = transfer_batch.status | ||
| @currency = transfer_batch.currency | ||
| @transfer_count = transfer_batch.transfer_count | ||
| @amount = transfer_batch.amount | ||
| @succeeded_count = transfer_batch.succeeded_count | ||
| @settled_amount = transfer_batch.settled_amount | ||
| @created_at = transfer_batch.created_at | ||
| @authorized_at = transfer_batch.authorized_at | ||
| @rejected_at = transfer_batch.rejected_at | ||
| @expired_at = transfer_batch.expired_at | ||
| @succeeded_at = transfer_batch.succeeded_at | ||
| @partially_succeeded_at = transfer_batch.partially_succeeded_at | ||
|
|
||
| self | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usamos emoticones en otra parte? no sea que rompa alguna integración
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sii en el sdk se usan jaja nose porque pero seguí el patrón nomas