Skip to content

Commit

Permalink
Merge pull request #25 from starkbank/feature/transfer-features
Browse files Browse the repository at this point in the history
Add external_id and account_type to Transfer resource
  • Loading branch information
cdottori-stark authored Jan 21, 2021
2 parents 89f1443 + 9cd9b81 commit 5522967
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Given a version number MAJOR.MINOR.PATCH, increment:


## [Unreleased]
### Added
- Transfer.account_type property to allow 'checking', 'salary' or 'savings' account specification
- Transfer.external_id property to allow users to take control over duplication filters

## [2.3.0] - 2021-01-20
### Added
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ transfers = StarkBank::Transfer.create(
bank_code: '20018183', # Pix
branch_code: '1234',
account_number: '123456-7',
account_type: 'salary',
external_id: 'my-internal-id-12345',
tax_id: '012.345.678-90',
name: 'Jon Snow',
scheduled: Time.now + 24 * 3600,
Expand Down
16 changes: 11 additions & 5 deletions lib/transfer/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ module StarkBank
# - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
# - bank_code [string]: code of the receiver bank institution in Brazil. If an ISPB (8 digits) is informed, a PIX transfer will be created, else a TED will be issued. ex: '20018183' or '260'
# - branch_code [string]: receiver bank account branch. Use '-' in case there is a verifier digit. ex: '1357-9'
# - account_number [string]: Receiver Bank Account number. Use '-' before the verifier digit. ex: '876543-2'
# - account_number [string]: receiver bank account number. Use '-' before the verifier digit. ex: '876543-2'
#
# ## Parameters (optional):
# - tags [list of strings]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
# - account_type [string, default 'checking']: receiver bank account type. This parameter only has effect on Pix Transfers. ex: 'checking', 'savings' or 'salary'
# - external_id [string, default nil]: url safe string that must be unique among all your transfers. Duplicated external_ids will cause failures. By default, this parameter will block any transfer that repeats amount and receiver information on the same date. ex: 'my-internal-id-123456'
# - scheduled [string, default now]: datetime when the transfer will be processed. May be pushed to next business day if necessary. ex: DateTime.new(2020, 3, 11, 8, 13, 12, 11)
# - tags [list of strings]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
#
# ## Attributes (return-only):
# - id [string, default nil]: unique id returned when Transfer is created. ex: '5656565656565656'
Expand All @@ -31,15 +33,17 @@ module StarkBank
# - created [DateTime, default nil]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
# - updated [DateTime, default nil]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
class Transfer < StarkBank::Utils::Resource
attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :scheduled, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, scheduled: nil, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :external_id, :scheduled, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
super(id)
@amount = amount
@name = name
@tax_id = tax_id
@bank_code = bank_code
@branch_code = branch_code
@account_number = account_number
@account_type = account_type
@external_id = external_id
@scheduled = StarkBank::Utils::Checks.check_date_or_datetime(scheduled)
@transaction_ids = transaction_ids
@fee = fee
Expand Down Expand Up @@ -124,7 +128,7 @@ def self.pdf(id, user: nil)
# - before [Date, DateTime, Time or string, default nil] date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
# - transactionIds [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
# - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
# - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex: "012.345.678-90"
# - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex: '012.345.678-90'
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
Expand Down Expand Up @@ -161,6 +165,8 @@ def self.resource
bank_code: json['bank_code'],
branch_code: json['branch_code'],
account_number: json['account_number'],
account_type: json['account_type'],
external_id: json['external_id'],
scheduled: json['scheduled'],
transaction_ids: json['transaction_ids'],
fee: json['fee'],
Expand Down
2 changes: 2 additions & 0 deletions test/example_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def self.transfer_example(schedule: false)
bank_code: '01',
branch_code: '0001',
account_number: '10000-0',
account_type: 'checking',
external_id: 'ruby-' + rand(1e10).to_s,
scheduled: schedule ? Time.now + 24 * 3600 : nil
)
end
Expand Down
5 changes: 2 additions & 3 deletions test/starkbank/test_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
transfers_ids_result.push(transfer.id)
end

transfers_ids_expected = transfers_ids_expected.sort()
transfers_ids_result = transfers_ids_result.sort()
transfers_ids_expected = transfers_ids_expected.sort
transfers_ids_result = transfers_ids_result.sort
expect(transfers_ids_expected).must_equal(transfers_ids_result)
end

Expand All @@ -46,5 +46,4 @@
expect(transfer.id).must_equal(delete_transfer.id)
expect(delete_transfer.status).must_equal('canceled')
end

end

0 comments on commit 5522967

Please sign in to comment.