Class: StarkBank::Transfer

Inherits:
StarkCore::Utils::Resource
  • Object
show all
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’

  • 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

Classes: Log, Rule

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, 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.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/transfer/transfer.rb', line 40

def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, 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_type = 
  @external_id = external_id
  @scheduled = StarkCore::Utils::Checks.check_date_or_datetime(scheduled)
  @description = description
  @tags = tags
  @rules = StarkBank::Transfer::Rule.parse_rules(rules)
  @fee = fee
  @status = status
  @transaction_ids = transaction_ids
   = 
  @created = StarkCore::Utils::Checks.check_datetime(created)
  @updated = StarkCore::Utils::Checks.check_datetime(updated)
end

Instance Attribute Details

#account_numberObject (readonly)

Returns the value of attribute account_number.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def 
  @account_number
end

#account_typeObject (readonly)

Returns the value of attribute account_type.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def 
  @account_type
end

#amountObject (readonly)

Returns the value of attribute amount.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def amount
  @amount
end

#bank_codeObject (readonly)

Returns the value of attribute bank_code.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def bank_code
  @bank_code
end

#branch_codeObject (readonly)

Returns the value of attribute branch_code.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def branch_code
  @branch_code
end

#createdObject (readonly)

Returns the value of attribute created.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def created
  @created
end

#descriptionObject (readonly)

Returns the value of attribute description.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def description
  @description
end

#external_idObject (readonly)

Returns the value of attribute external_id.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def external_id
  @external_id
end

#feeObject (readonly)

Returns the value of attribute fee.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def fee
  @fee
end

#idObject (readonly)

Returns the value of attribute id.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def 
  
end

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def name
  @name
end

#rulesObject (readonly)

Returns the value of attribute rules.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def rules
  @rules
end

#scheduledObject (readonly)

Returns the value of attribute scheduled.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def scheduled
  @scheduled
end

#statusObject (readonly)

Returns the value of attribute status.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def tags
  @tags
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def tax_id
  @tax_id
end

#transaction_idsObject (readonly)

Returns the value of attribute transaction_ids.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

def transaction_ids
  @transaction_ids
end

#updatedObject (readonly)

Returns the value of attribute updated.



39
40
41
# File 'lib/transfer/transfer.rb', line 39

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



74
75
76
# File 'lib/transfer/transfer.rb', line 74

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



106
107
108
# File 'lib/transfer/transfer.rb', line 106

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



90
91
92
# File 'lib/transfer/transfer.rb', line 90

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



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/transfer/transfer.rb', line 179

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: 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



123
124
125
# File 'lib/transfer/transfer.rb', line 123

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



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/transfer/transfer.rb', line 144

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: tags,
    ids: ids,
    user: user,
    **resource
  )
end

.resourceObject



198
199
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
# File 'lib/transfer/transfer.rb', line 198

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'],
        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