Class: StarkBank::Transfer

Inherits:
Utils::Resource show all
Defined in:
lib/transfer/transfer.rb,
lib/transfer/log.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]: receiver 1 to 3 digits of the bank institution in Brazil. ex: ‘200’ or ‘341’

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

  • 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’

  • fee [integer, default nil]: fee charged when transfer is created. ex: 200 (= R$ 2.00)

  • status [string, default nil]: current boleto status. ex: ‘registered’ or ‘paid’

  • transaction_ids [list of strings, default nil]: ledger transaction ids linked to this transfer (if there are two, second is the chargeback). ex: [‘19827356981273’]

  • 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)

Defined Under Namespace

Classes: Log

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::Resource

#inspect, #to_s

Constructor Details

#initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil) ⇒ Transfer

Returns a new instance of Transfer.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/transfer/transfer.rb', line 34

def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, 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 = 
  @transaction_ids = transaction_ids
  @fee = fee
  @tags = tags
  @status = status
  @created = StarkBank::Utils::Checks.check_datetime(created)
  @updated = StarkBank::Utils::Checks.check_datetime(updated)
end

Instance Attribute Details

#account_numberObject (readonly)

Returns the value of attribute account_number.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def 
  @account_number
end

#amountObject (readonly)

Returns the value of attribute amount.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def amount
  @amount
end

#bank_codeObject (readonly)

Returns the value of attribute bank_code.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def bank_code
  @bank_code
end

#branch_codeObject (readonly)

Returns the value of attribute branch_code.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def branch_code
  @branch_code
end

#createdObject (readonly)

Returns the value of attribute created.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def created
  @created
end

#feeObject (readonly)

Returns the value of attribute fee.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def fee
  @fee
end

#idObject (readonly)

Returns the value of attribute id.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def name
  @name
end

#statusObject (readonly)

Returns the value of attribute status.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def tags
  @tags
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def tax_id
  @tax_id
end

#transaction_idsObject (readonly)

Returns the value of attribute transaction_ids.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

def transaction_ids
  @transaction_ids
end

#updatedObject (readonly)

Returns the value of attribute updated.



33
34
35
# File 'lib/transfer/transfer.rb', line 33

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 [Project object]: Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • list of Transfer objects with updated attributes



62
63
64
# File 'lib/transfer/transfer.rb', line 62

def self.create(transfers, user: nil)
  StarkBank::Utils::Rest.post(entities: transfers, 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 [Project object]: Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • Transfer object with updated attributes



78
79
80
# File 'lib/transfer/transfer.rb', line 78

def self.get(id, user: nil)
  StarkBank::Utils::Rest.get_id(id: id, 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 [Project object]: Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • Transfer pdf file



95
96
97
# File 'lib/transfer/transfer.rb', line 95

def self.pdf(id, user: nil)
  StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
end

.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, sort: nil, tags: 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: ‘paid’ or ‘registered’

  • tags [list of strings, default nil]: tags to filter retrieved objects. ex: [‘tony’, ‘stark’]

  • user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • generator of Transfer objects with updated attributes



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/transfer/transfer.rb', line 114

def self.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, sort: nil, tags: nil, user: nil)
  after = StarkBank::Utils::Checks.check_date(after)
  before = StarkBank::Utils::Checks.check_date(before)
  StarkBank::Utils::Rest.get_list(
    limit: limit,
    after: after,
    before: before,
    transaction_ids: transaction_ids,
    status: status,
    sort: sort,
    tags: tags,
    user: user,
    **resource
  )
end

.resourceObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/transfer/transfer.rb', line 130

def self.resource
  {
    resource_name: 'Transfer',
    resource_maker: proc { |json|
      Transfer.new(
        id: json['id'],
        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'],
        transaction_ids: json['transaction_ids'],
        fee: json['fee'],
        tags: json['tags'],
        status: json['status'],
        created: json['created'],
        updated: json['updated']
      )
    }
  }
end