Class: StarkBank::BoletoPayment

Inherits:
StarkCore::Utils::Resource
  • Object
show all
Defined in:
lib/boleto_payment/boleto_payment.rb,
lib/boleto_payment/log.rb

Overview

# BoletoPayment object

When you initialize a BoletoPayment, 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 (conditionally required):

  • line [string, default nil]: Number sequence that describes the payment. Either ‘line’ or ‘bar_code’ parameters are required. If both are sent, they must match. ex: ‘34191.09008 63571.277308 71444.640008 5 81960000000062’

  • bar_code [string, default nil]: Bar code number that describes the payment. Either ‘line’ or ‘barCode’ parameters are required. If both are sent, they must match. ex: ‘34195819600000000621090063571277307144464000’

## Parameters (required):

  • tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: ‘01234567890’ or ‘20.018.183/0001-80’

  • description [string]: Text to be displayed in your statement (min. 10 characters). ex: ‘payment ABC’

## Parameters (optional):

  • amount [int, default nil]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)

  • scheduled [Date, DateTime, Time or string, default today]: payment scheduled date. ex: Date.new(2020, 3, 10)

  • tags [list of strings]: list of strings for tagging

## Attributes (return-only):

  • id [string]: unique id returned when payment is created. ex: ‘5656565656565656’

  • status [string]: current payment status. ex: ‘success’ or ‘failed’

  • fee [integer]: fee charged when the boleto payment is created. ex: 200 (= R$ 2.00)

  • transaction_ids [list of strings]: ledger transaction ids linked to this BoletoPayment. ex: [“19827356981273”]

  • created [DateTime]: creation datetime for the payment. 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

Constructor Details

#initialize(tax_id:, description:, line: nil, bar_code: nil, scheduled: nil, tags: nil, id: nil, status: nil, amount: nil, fee: nil, transaction_ids: nil, created: nil) ⇒ BoletoPayment



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

def initialize(tax_id:, description:, line: nil, bar_code: nil, scheduled: nil, tags: nil, id: nil, status: nil, amount: nil, fee: nil, transaction_ids: nil, created: nil)
  super(id)
  @tax_id = tax_id
  @description = description
  @line = line
  @bar_code = bar_code
  @amount = amount
  @scheduled = StarkCore::Utils::Checks.check_date(scheduled)
  @tags = tags
  @status = status
  @fee = fee
  @transaction_ids = transaction_ids
  @created = StarkCore::Utils::Checks.check_datetime(created)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def amount
  @amount
end

#bar_codeObject (readonly)

Returns the value of attribute bar_code.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def bar_code
  @bar_code
end

#createdObject (readonly)

Returns the value of attribute created.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def created
  @created
end

#descriptionObject (readonly)

Returns the value of attribute description.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def description
  @description
end

#feeObject (readonly)

Returns the value of attribute fee.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def fee
  @fee
end

#idObject (readonly)

Returns the value of attribute id.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def id
  @id
end

#lineObject (readonly)

Returns the value of attribute line.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def line
  @line
end

#scheduledObject (readonly)

Returns the value of attribute scheduled.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def scheduled
  @scheduled
end

#statusObject (readonly)

Returns the value of attribute status.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def tags
  @tags
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def tax_id
  @tax_id
end

#transaction_idsObject (readonly)

Returns the value of attribute transaction_ids.



34
35
36
# File 'lib/boleto_payment/boleto_payment.rb', line 34

def transaction_ids
  @transaction_ids
end

Class Method Details

.create(payments, user: nil) ⇒ Object

# Create BoletoPayments

Send a list of BoletoPayment objects for creation in the Stark Bank API

## Parameters (required):

  • payments [list of BoletoPayment objects]: list of BoletoPayment 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 BoletoPayment objects with updated attributes



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

def self.create(payments, user: nil)
  StarkBank::Utils::Rest.post(entities: payments, user: user, **resource)
end

.delete(id, user: nil) ⇒ Object

# Delete a BoletoPayment entity

Delete a BoletoPayment entity previously created in the Stark Bank API

Parameters (required):

  • id [string]: BoletoPayment 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 BoletoPayment object



172
173
174
# File 'lib/boleto_payment/boleto_payment.rb', line 172

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 BoletoPayment

Receive a single BoletoPayment object previously created by 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:

  • BoletoPayment object with updated attributes



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

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, tags: nil, ids: nil, status: nil, user: nil) ⇒ Object

# Retrieve paged BoletoPayments

Receive a list of up to 100 BoletoPayment 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)

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

  • ids [list of strings, default nil]: list of strings to get specific entities by ids. ex: [‘12376517623’, ‘1928367198236’]

  • status [string, default nil]: filter for status of retrieved objects. ex: ‘paid’

  • user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • list of BoletoPayment objects with updated attributes and cursor to retrieve the next page of BoletoPayment objects



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

def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: 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,
    user: user,
    limit: limit,
    after: after,
    before: before,
    tags: tags,
    ids: ids,
    status: status,
    **resource
  )
end

.pdf(id, user: nil) ⇒ Object

# Retrieve a specific BoletoPayment pdf file

Receive a single BoletoPayment pdf file generated in the Stark Bank API by passing its id. Only valid for boleto payments with ‘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:

  • BoletoPayment pdf file



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

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, tags: nil, ids: nil, status: nil, user: nil) ⇒ Object

# Retrieve BoletoPayments

Receive a generator of BoletoPayment 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 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)

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

  • ids [list of strings, default nil]: list of strings to get specific entities by ids. ex: [‘12376517623’, ‘1928367198236’]

  • status [string, default nil]: filter for status of retrieved objects. ex: ‘paid’

  • user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • generator of BoletoPayment objects with updated attributes



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

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

.resourceObject



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

def self.resource
  {
    resource_name: 'BoletoPayment',
    resource_maker: proc { |json|
      BoletoPayment.new(
        id: json['id'],
        tax_id: json['tax_id'],
        description: json['description'],
        line: json['line'],
        bar_code: json['bar_code'],
        amount: json['amount'],
        scheduled: json['scheduled'],
        tags: json['tags'],
        status: json['status'],
        fee: json['fee'],
        transaction_ids: json['transaction_ids'],
        created: json['created']
      )
    }
  }
end