From 9cd9b8102656c59db5319977a27f8eb9d75b0e1d Mon Sep 17 00:00:00 2001 From: Caio Dottori Date: Thu, 21 Jan 2021 12:28:55 -0300 Subject: [PATCH] Add external_id and account_type to Transfer resource --- CHANGELOG.md | 3 +++ README.md | 2 ++ lib/transfer/transfer.rb | 16 +++++++++++----- test/example_generator.rb | 2 ++ test/starkbank/test_transfer.rb | 5 ++--- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8d6751..42b7300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index d119db3..e98bdf9 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/lib/transfer/transfer.rb b/lib/transfer/transfer.rb index d16ed78..bdced3f 100644 --- a/lib/transfer/transfer.rb +++ b/lib/transfer/transfer.rb @@ -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' @@ -31,8 +33,8 @@ 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 @@ -40,6 +42,8 @@ def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number @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 @@ -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 @@ -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'], diff --git a/test/example_generator.rb b/test/example_generator.rb index 66904fb..880855c 100644 --- a/test/example_generator.rb +++ b/test/example_generator.rb @@ -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 diff --git a/test/starkbank/test_transfer.rb b/test/starkbank/test_transfer.rb index e2586a7..f252cd1 100644 --- a/test/starkbank/test_transfer.rb +++ b/test/starkbank/test_transfer.rb @@ -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 @@ -46,5 +46,4 @@ expect(transfer.id).must_equal(delete_transfer.id) expect(delete_transfer.status).must_equal('canceled') end - end