Class: StarkInfra::Invoice

Inherits:
StarkCore::Utils::Resource
  • Object
show all
Defined in:
lib/creditnote/invoice/invoice.rb

Overview

CreditNote::Invoice object

Invoice issued after the contract is signed, to be paid by the credit receiver.

## Parameters (required):

  • amount [integer]: Invoice value in cents. Minimum = 1 (any value will be accepted). ex: 1234 (= R$ 12.34)

## Parameters (optional):

  • due [DateTime, Date or string, default now + 2 days]: Invoice due date in UTC ISO format. DateTime.new(2020, 3, 10, 10, 30, 0, 0) for immediate invoices and ‘2020-10-28’ for scheduled invoices

  • expiration [integer, default 604800]: time interval in seconds between scheduled date and expiration date. ex: 123456789

  • tags [list of strings, default nil]: list of strings for tagging. ex: [‘employees’, ‘monthly’]

  • descriptions [list of CreditNote::Invoice::Description objects or hash, default nil]: list Description objects. ex: [Description.new()]

## Attributes (return-only):

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

  • name [string]: payer name. ex: ‘Iron Bank S.A.’

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

  • pdf [string]: public Invoice PDF URL. ex: ‘invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8

  • link [string]: public Invoice webpage URL. ex: ‘my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8

  • fine [float, default 2.0]: Invoice fine for overdue payment in %. ex: 2.5

  • interest [float, default 1.0]: Invoice monthly interest in overdue payment in %. ex: 5.2

  • nominal_amount [integer]: Invoice emission value in cents (will change if invoice is updated, but not if it’s paid). ex: 400000

  • fine_amount [integer]: Invoice fine value calculated over nominal_amount. ex: 20000

  • interest_amount [integer]: Invoice interest value calculated over nominal_amount. ex: 10000

  • discount_amount [integer]: Invoice discount value calculated over nominal_amount. ex: 3000

  • discounts [list of CreditNote::Invoice::Discount objects]: list of Discount objects. ex: [Discount.new()]

  • brcode [string]: BR Code for the Invoice payment. ex: ‘00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0’

  • status [string]: current Invoice status. ex: ‘registered’ or ‘paid’

  • fee [integer]: fee charged by this Invoice. ex: 200 (= R$ 2.00).

  • transaction_ids [list of strings]: ledger transaction ids linked to this Invoice (if there are more than one, all but the first are reversals or failed reversal chargebacks). ex: [‘19827356981273’]

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

  • updated [DateTime]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount:, id: nil, due: nil, expiration: nil, tags: nil, descriptions: nil, name: nil, tax_id: nil, pdf: nil, link: nil, fine: nil, interest: nil, nominal_amount: nil, fine_amount: nil, interest_amount: nil, discount_amount: nil, discounts: nil, brcode: nil, status: nil, fee: nil, transaction_ids: nil, created: nil, updated: nil) ⇒ Invoice

Returns a new instance of Invoice.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/creditnote/invoice/invoice.rb', line 44

def initialize(
  amount:, id: nil,  due: nil, expiration: nil, tags: nil, descriptions: nil, name: nil, tax_id: nil,
  pdf: nil, link: nil, fine: nil, interest: nil, nominal_amount: nil, fine_amount: nil,
  interest_amount: nil, discount_amount: nil, discounts: nil, brcode: nil, status: nil, fee: nil,
  transaction_ids: nil, created: nil, updated: nil
)
  super(id)
  @tax_id = tax_id
  @amount = amount
  @due = due
  @expiration = expiration
  @tags = tags
  @descriptions = Description.parse_descriptions(descriptions)
  @name = name
  @tax_id = tax_id
  @pdf = pdf
  @link = link
  @fine = fine
  @interest = interest
  @nominal_amount = nominal_amount
  @fine_amount = fine_amount
  @interest_amount = interest_amount
  @discount_amount = discount_amount
  @discounts = Discount.parse_discounts(discounts)
  @brcode = brcode
  @status = status
  @fee = fee
  @transaction_ids = transaction_ids
  @created = StarkCore::Utils::Checks.check_datetime(created)
  @updated = StarkCore::Utils::Checks.check_datetime(updated)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def amount
  @amount
end

#brcodeObject (readonly)

Returns the value of attribute brcode.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def brcode
  @brcode
end

#createdObject (readonly)

Returns the value of attribute created.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def created
  @created
end

#descriptionsObject (readonly)

Returns the value of attribute descriptions.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def descriptions
  @descriptions
end

#discount_amountObject (readonly)

Returns the value of attribute discount_amount.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def discount_amount
  @discount_amount
end

#discountsObject (readonly)

Returns the value of attribute discounts.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def discounts
  @discounts
end

#dueObject (readonly)

Returns the value of attribute due.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def due
  @due
end

#expirationObject (readonly)

Returns the value of attribute expiration.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def expiration
  @expiration
end

#feeObject (readonly)

Returns the value of attribute fee.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def fee
  @fee
end

#fineObject (readonly)

Returns the value of attribute fine.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def fine
  @fine
end

#fine_amountObject (readonly)

Returns the value of attribute fine_amount.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def fine_amount
  @fine_amount
end

#idObject (readonly)

Returns the value of attribute id.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def id
  @id
end

#interestObject (readonly)

Returns the value of attribute interest.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def interest
  @interest
end

#interest_amountObject (readonly)

Returns the value of attribute interest_amount.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def interest_amount
  @interest_amount
end

Returns the value of attribute link.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def link
  @link
end

#nameObject (readonly)

Returns the value of attribute name.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def name
  @name
end

#nominal_amountObject (readonly)

Returns the value of attribute nominal_amount.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def nominal_amount
  @nominal_amount
end

#pdfObject (readonly)

Returns the value of attribute pdf.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def pdf
  @pdf
end

#statusObject (readonly)

Returns the value of attribute status.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def tags
  @tags
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def tax_id
  @tax_id
end

#transaction_idsObject (readonly)

Returns the value of attribute transaction_ids.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def transaction_ids
  @transaction_ids
end

#updatedObject (readonly)

Returns the value of attribute updated.



41
42
43
# File 'lib/creditnote/invoice/invoice.rb', line 41

def updated
  @updated
end

Class Method Details

.parse_invoices(invoices) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/creditnote/invoice/invoice.rb', line 76

def self.parse_invoices(invoices)
  resource_maker = StarkInfra::Invoice.resource[:resource_maker]
  return invoices if invoices.nil?

  parsed_invoices = []
  invoices.each do |invoice|
    unless invoice.is_a? Invoice
      invoice = StarkCore::Utils::API.from_api_json(resource_maker, invoice)
    end
    parsed_invoices << invoice
  end
  parsed_invoices
end

.resourceObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/creditnote/invoice/invoice.rb', line 90

def self.resource
  {
    resource_name: 'Invoice',
    resource_maker: proc { |json|
      Invoice.new(
        id: json['id'],
        amount: json['amount'],
        due: json['due'],
        expiration: json['expiration'],
        fine: json['fine'],
        interest: json['interest'],
        tags: json['tags'],
        descriptions: json['descriptions'],
        name: json['name'],
        tax_id: json['tax_id'],
        pdf: json['pdf'],
        link: json['link'],
        nominal_amount: json['nominal_amount'],
        fine_amount: json['fine_amount'],
        interest_amount: json['interest_amount'],
        discount_amount: json['discount_amount'],
        discounts: json['discounts'],
        brcode: json['brcode'],
        status: json['status'],
        fee: json['fee'],
        transaction_ids: json['transaction_ids'],
        created: json['created'],
        updated: json['updated']
      )
    }
  }
end