Class: StarkBank::Transfer
- Inherits:
-
StarkCore::Utils::Resource
- Object
- StarkCore::Utils::Resource
- StarkBank::Transfer
- Defined in:
- lib/transfer/transfer.rb,
lib/transfer/log.rb,
lib/transfer/rule.rb
Overview
# Transfer object
When you initialize a Transfer, the entity will not be automatically created in the Stark Bank API. The ‘create’ function sends the objects to the Stark Bank API and returns the list of created objects.
## Parameters (required):
-
amount [integer]: amount in cents to be transferred. ex: 1234 (= R$ 12.34)
-
name [string]: receiver full name. ex: ‘Anthony Edward Stark’
-
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’
## Parameters (optional):
-
account_type [string, default ‘checking’]: receiver bank account type. This parameter only has effect on Pix Transfers. ex: ‘checking’, ‘savings’, ‘salary’ or ‘payment’
-
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)
-
description [string, default nil]: optional description to override default description to be shown in the bank statement. ex: ‘Payment for service #1234’
-
display_description [string, default nil]: optional description to be shown in the receiver bank interface. ex: ‘Payment for service #1234’
-
tags [list of strings]: list of strings for reference when searching for transfers. ex: [‘employees’, ‘monthly’]
-
rules [list of Transfer::Rules, default []]: list of Transfer::Rule objects for modifying transfer behavior. ex: [Transfer::Rule(key: “resendingLimit”, value: 5)]
## Attributes (return-only):
-
id [string]: unique id returned when Transfer is created. ex: ‘5656565656565656’
-
fee [integer]: fee charged when transfer is created. ex: 200 (= R$ 2.00)
-
status [string]: current transfer status. ex: ‘success’ or ‘failed’
-
transaction_ids [list of strings]: ledger transaction ids linked to this transfer (if there are two, second is the chargeback). ex: [‘19827356981273’]
-
metadata [dictionary object]: dictionary object used to store additional information about the Transfer object.
-
created [DateTime]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
-
updated [DateTime]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
Defined Under Namespace
Instance Attribute Summary collapse
-
#account_number ⇒ Object
readonly
Returns the value of attribute account_number.
-
#account_type ⇒ Object
readonly
Returns the value of attribute account_type.
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#bank_code ⇒ Object
readonly
Returns the value of attribute bank_code.
-
#branch_code ⇒ Object
readonly
Returns the value of attribute branch_code.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#display_description ⇒ Object
readonly
Returns the value of attribute display_description.
-
#external_id ⇒ Object
readonly
Returns the value of attribute external_id.
-
#fee ⇒ Object
readonly
Returns the value of attribute fee.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#scheduled ⇒ Object
readonly
Returns the value of attribute scheduled.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#tax_id ⇒ Object
readonly
Returns the value of attribute tax_id.
-
#transaction_ids ⇒ Object
readonly
Returns the value of attribute transaction_ids.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Class Method Summary collapse
-
.create(transfers, user: nil) ⇒ Object
# Create Transfers.
-
.delete(id, user: nil) ⇒ Object
# Delete a Transfer entity.
-
.get(id, user: nil) ⇒ Object
# Retrieve a specific Transfer.
-
.page(cursor: nil, limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil) ⇒ Object
# Retrieve paged Transfers.
-
.pdf(id, user: nil) ⇒ Object
# Retrieve a specific Transfer pdf file.
-
.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil) ⇒ Object
# Retrieve Transfers.
- .resource ⇒ Object
Instance Method Summary collapse
-
#initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, description: nil, display_description: nil, transaction_ids: nil, metadata: nil, fee: nil, tags: nil, rules: nil, status: nil, id: nil, created: nil, updated: nil) ⇒ Transfer
constructor
A new instance of Transfer.
Constructor Details
#initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, description: nil, display_description: nil, transaction_ids: nil, metadata: nil, fee: nil, tags: nil, rules: nil, status: nil, id: nil, created: nil, updated: nil) ⇒ Transfer
Returns a new instance of Transfer.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/transfer/transfer.rb', line 41 def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, description: nil, display_description: nil, transaction_ids: nil, metadata: nil, fee: nil, tags: nil, rules: 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 = StarkCore::Utils::Checks.check_date_or_datetime(scheduled) @description = description @display_description = display_description @tags = @rules = StarkBank::Transfer::Rule.parse_rules(rules) @fee = fee @status = status @transaction_ids = transaction_ids @metadata = @created = StarkCore::Utils::Checks.check_datetime(created) @updated = StarkCore::Utils::Checks.check_datetime(updated) end |
Instance Attribute Details
#account_number ⇒ Object (readonly)
Returns the value of attribute account_number.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def account_number @account_number end |
#account_type ⇒ Object (readonly)
Returns the value of attribute account_type.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def account_type @account_type end |
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def amount @amount end |
#bank_code ⇒ Object (readonly)
Returns the value of attribute bank_code.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def bank_code @bank_code end |
#branch_code ⇒ Object (readonly)
Returns the value of attribute branch_code.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def branch_code @branch_code end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def created @created end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def description @description end |
#display_description ⇒ Object (readonly)
Returns the value of attribute display_description.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def display_description @display_description end |
#external_id ⇒ Object (readonly)
Returns the value of attribute external_id.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def external_id @external_id end |
#fee ⇒ Object (readonly)
Returns the value of attribute fee.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def fee @fee end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def name @name end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def rules @rules end |
#scheduled ⇒ Object (readonly)
Returns the value of attribute scheduled.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def scheduled @scheduled end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def status @status end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def @tags end |
#tax_id ⇒ Object (readonly)
Returns the value of attribute tax_id.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def tax_id @tax_id end |
#transaction_ids ⇒ Object (readonly)
Returns the value of attribute transaction_ids.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def transaction_ids @transaction_ids end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
40 41 42 |
# File 'lib/transfer/transfer.rb', line 40 def updated @updated end |
Class Method Details
.create(transfers, user: nil) ⇒ Object
# Create Transfers
Send a list of Transfer objects for creation in the Stark Bank API
## Parameters (required):
-
transfers [list of Transfer objects]: list of Transfer objects to be created in the API
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
list of Transfer objects with updated attributes
76 77 78 |
# File 'lib/transfer/transfer.rb', line 76 def self.create(transfers, user: nil) StarkBank::Utils::Rest.post(entities: transfers, user: user, **resource) end |
.delete(id, user: nil) ⇒ Object
# Delete a Transfer entity
Delete a Transfer entity previously created in the Stark Bank API
## Parameters (required):
-
id [string]: Transfer unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
deleted Transfer object
108 109 110 |
# File 'lib/transfer/transfer.rb', line 108 def self.delete(id, user: nil) StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource) end |
.get(id, user: nil) ⇒ Object
# Retrieve a specific Transfer
Receive a single Transfer object previously created in the Stark Bank API by passing its id
## Parameters (required):
-
id [string]: object unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
Transfer object with updated attributes
92 93 94 |
# File 'lib/transfer/transfer.rb', line 92 def self.get(id, user: nil) StarkBank::Utils::Rest.get_id(id: id, user: user, **resource) end |
.page(cursor: nil, limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil) ⇒ Object
# Retrieve paged Transfers
Receive a list of up to 100 Transfer objects previously created in the Stark Bank API and the cursor to the next page. Use this function instead of query if you want to manually page your requests.
## Parameters (optional):
-
cursor [string, default nil]: cursor returned on the previous page function call
-
limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
-
after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
-
before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
-
status [string, default nil]: filter for status of retrieved objects. ex: ‘paid’ or ‘registered’
-
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
## Return:
-
list of Transfer objects with updated attributes and cursor to retrieve the next page of Transfer objects
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/transfer/transfer.rb', line 181 def self.page(cursor: nil, limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil) after = StarkCore::Utils::Checks.check_date(after) before = StarkCore::Utils::Checks.check_date(before) return StarkBank::Utils::Rest.get_page( cursor: cursor, limit: limit, after: after, before: before, transaction_ids: transaction_ids, status: status, tax_id: tax_id, sort: sort, tags: , ids: ids, user: user, **resource ) end |
.pdf(id, user: nil) ⇒ Object
# Retrieve a specific Transfer pdf file
Receive a single Transfer pdf receipt file generated in the Stark Bank API by passing its id. Only valid for transfers with ‘processing’ and ‘success’ status.
## Parameters (required):
-
id [string]: object unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
Transfer pdf file
125 126 127 |
# File 'lib/transfer/transfer.rb', line 125 def self.pdf(id, user: nil) StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource) end |
.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil) ⇒ Object
# Retrieve Transfers
Receive a generator of Transfer objects previously created in the Stark Bank API
## Parameters (optional):
-
limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
-
after [Date, DateTime, Time or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
-
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’
-
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
## Return:
-
generator of Transfer objects with updated attributes
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/transfer/transfer.rb', line 146 def self.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil) after = StarkCore::Utils::Checks.check_date(after) before = StarkCore::Utils::Checks.check_date(before) StarkBank::Utils::Rest.get_stream( limit: limit, after: after, before: before, transaction_ids: transaction_ids, status: status, tax_id: tax_id, sort: sort, tags: , ids: ids, user: user, **resource ) end |
.resource ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/transfer/transfer.rb', line 200 def self.resource { resource_name: 'Transfer', resource_maker: proc { |json| Transfer.new( amount: json['amount'], name: json['name'], tax_id: json['tax_id'], 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'], description: json['description'], display_description: json['display_description'], tags: json['tags'], rules: json['rules'], id: json['id'], fee: json['fee'], status: json['status'], transaction_ids: json['transaction_ids'], metadata: json['metadata'], created: json['created'], updated: json['updated'] ) } } end |