Class: StarkBank::DarfPayment

Inherits:
Utils::Resource show all
Defined in:
lib/darf_payment/darf_payment.rb,
lib/darf_payment/log.rb

Overview

# DarfPayment object

When you initialize a DarfPayment, 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):

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

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

  • revenue_code [string]: 4-digit tax code assigned by Federal Revenue. ex: ‘5948’

  • tax_id [tax_id]: tax id (formatted or unformatted) of the payer. ex: ‘12.345.678/0001-95’

  • competence [Date, DateTime, Time or string, default today]: competence month of the service. ex: Date.new(2020, 3, 10)

  • nominal_amount [int]: amount due in cents without fee or interest. ex: 23456 (= R$ 234.56)

  • fine_amount [int]: fixed amount due in cents for fines. ex: 234 (= R$ 2.34)

  • interest_amount [int]: amount due in cents for interest. ex: 456 (= R$ 4.56)

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

## Parameters (optional):

  • reference_number [string, default nil]: number assigned to the region of the tax. ex: ‘08.1.17.00-4’

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

  • tags [list of strings, default nil]: list of strings for tagging

## Attributes (return-only):

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

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

  • amount [int, default nil]: Total amount due calculated from other amounts. ex: 24146 (= R$ 241.46)

  • fee [integer, default nil]: fee charged when the DarfPayment is processed. ex: 0 (= R$ 0.00)

  • created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)

  • updated [DateTime, default nil]: latest update datetime for the Invoice. 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::SubResource

#inspect, #to_s

Constructor Details

#initialize(id: nil, revenue_code:, tax_id:, competence:, reference_number:, fine_amount:, interest_amount:, due:, description: nil, tags: nil, scheduled: nil, status: nil, amount: nil, nominal_amount: nil, fee: nil, updated: nil, created: nil) ⇒ DarfPayment

Returns a new instance of DarfPayment.



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

def initialize(
    id: nil, revenue_code:, tax_id:, competence:, reference_number:, fine_amount:, interest_amount:, due:, description: nil, 
    tags: nil, scheduled: nil, status: nil, amount: nil, nominal_amount: nil, fee: nil, updated: nil, created: nil
)
  super(id)
  @revenue_code = revenue_code
  @tax_id = tax_id
  @competence = StarkBank::Utils::Checks.check_date(competence)
  @reference_number = reference_number
  @fine_amount = fine_amount
  @interest_amount = interest_amount
  @due = StarkBank::Utils::Checks.check_date(due)
  @description = description
  @tags = tags
  @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
  @status = status
  @amount = amount
  @nominal_amount = nominal_amount
  @fee = fee
  @updated = StarkBank::Utils::Checks.check_datetime(updated)
  @created = StarkBank::Utils::Checks.check_datetime(created)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def amount
  @amount
end

#competenceObject (readonly)

Returns the value of attribute competence.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def competence
  @competence
end

#createdObject (readonly)

Returns the value of attribute created.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def created
  @created
end

#descriptionObject (readonly)

Returns the value of attribute description.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def description
  @description
end

#dueObject (readonly)

Returns the value of attribute due.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def due
  @due
end

#feeObject (readonly)

Returns the value of attribute fee.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def fee
  @fee
end

#fine_amountObject (readonly)

Returns the value of attribute fine_amount.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def fine_amount
  @fine_amount
end

#idObject (readonly)

Returns the value of attribute id.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def id
  @id
end

#interest_amountObject (readonly)

Returns the value of attribute interest_amount.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def interest_amount
  @interest_amount
end

#nominal_amountObject (readonly)

Returns the value of attribute nominal_amount.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def nominal_amount
  @nominal_amount
end

#reference_numberObject (readonly)

Returns the value of attribute reference_number.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def reference_number
  @reference_number
end

#revenue_codeObject (readonly)

Returns the value of attribute revenue_code.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def revenue_code
  @revenue_code
end

#scheduledObject (readonly)

Returns the value of attribute scheduled.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def scheduled
  @scheduled
end

#statusObject (readonly)

Returns the value of attribute status.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def tags
  @tags
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def tax_id
  @tax_id
end

#updatedObject (readonly)

Returns the value of attribute updated.



38
39
40
# File 'lib/darf_payment/darf_payment.rb', line 38

def updated
  @updated
end

Class Method Details

.create(payments, user: nil) ⇒ Object

# Create DarfPayments

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

## Parameters (required):

  • payments [list of DarfPayment objects]: list of DarfPayment objects to be created in the API

## Parameters (optional):

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

## Return:

  • list of DarfPayment objects with updated attributes



75
76
77
# File 'lib/darf_payment/darf_payment.rb', line 75

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

.delete(id, user: nil) ⇒ Object

# Delete a DarfPayment entity

Delete a DarfPayment entity previously created in the Stark Bank API

## Parameters (required):

  • id [string]: UtilityPayment unique id. ex:‘5656565656565656’

## Parameters (optional):

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

## Return:

  • deleted TaxPayment object



187
188
189
# File 'lib/darf_payment/darf_payment.rb', line 187

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 DarfPayment

Receive a single DarfPayment 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, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • DarfPayment object with updated attributes



91
92
93
# File 'lib/darf_payment/darf_payment.rb', line 91

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

# Retrieve paged Darf Payments

Receive a list of up to 100 Darf Payment 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 ids to filter retrieved objects. ex: [‘5656565656565656’, ‘4545454545454545’]

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

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

## Return:

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



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/darf_payment/darf_payment.rb', line 159

def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
  after = StarkBank::Utils::Checks.check_date(after)
  before = StarkBank::Utils::Checks.check_date(before)
  return StarkBank::Utils::Rest.get_page(
    cursor: cursor,
    limit: limit,
    after: after,
    before: before,
    tags: tags,
    ids: ids,
    status: status,
    user: user,
    **resource
  )
end

.pdf(id, user: nil) ⇒ Object

# Retrieve a specific DarfPayment pdf file

Receive a single DarfPayment pdf file generated in the Stark Bank API by passing its id. Only valid for darf payments with ‘success’ status.

## Parameters (required):

  • id [string]: object unique id. ex: ‘5656565656565656’

## Parameters (optional):

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

## Return:

  • DarfPayment pdf file



108
109
110
# File 'lib/darf_payment/darf_payment.rb', line 108

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

# Retrieve DarfPayments

Receive a generator of DarfPayment 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 ids to filter retrieved objects. ex: [‘5656565656565656’, ‘4545454545454545’]

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

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

## Return:

  • generator of DarfPayment objects with updated attributes



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/darf_payment/darf_payment.rb', line 127

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

.resourceObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/darf_payment/darf_payment.rb', line 191

def self.resource
  {
    resource_name: 'DarfPayment',
    resource_maker: proc { |json|
      DarfPayment.new(
        id: json['id'],
        revenue_code: json['revenue_code'],
        tax_id: json['tax_id'],
        competence: json['competence'],
        reference_number: json['reference_number'],
        fine_amount: json['fine_amount'],
        interest_amount: json['interest_amount'],
        due: json['due'],
        description: json['description'],
        tags: json['tags'],
        scheduled: json['scheduled'],
        status: json['status'],
        amount: json['amount'],
        nominal_amount: json['nominal_amount'],
        fee: json['fee'],
        updated: json['updated'],
        created: json['created'],          
      )
    }
  }
end