Class: StarkInfra::CreditNote::Invoice

Inherits:
Utils::Resource show all
Defined in:
lib/creditnote/creditnote.rb

Overview

CreditNote::Invoice object Invoice object to be issued after contract signature and 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. ex: ‘2020-10-28T17:59:26.249976+00:00’ for immediate invoices and ‘2020-10-28’ for scheduled invoices

  • expiration [integer, default 5097600 (59 days)]: time interval in seconds between due date and expiration date. ex: 123456789

  • 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

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

  • descriptions [list of CreditNote::Invoice::Description objects, default nil]: list Description objects. ex: [CreditNote::Invoice::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

  • 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: [CreditNote::Invoice::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)

Defined Under Namespace

Classes: Description, Discount

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::SubResource

#inspect, #to_s

Constructor Details

#initialize(amount:, due: nil, expiration: nil, fine: nil, interest: nil, tags: nil, descriptions: nil, id: nil, name: nil, tax_id: nil, pdf: nil, link: 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.



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/creditnote/creditnote.rb', line 424

def initialize(
  amount:, due: nil, expiration: nil, fine: nil, interest: nil, tags: nil, descriptions: nil,
  id: nil, name: nil, tax_id: nil, pdf: nil, link: 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
  @fine = fine
  @interest = interest
  @tags = tags
  @descriptions = Description.parse_descriptions(descriptions)
  @name = name
  @tax_id = tax_id
  @pdf = pdf
  @link = link
  @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 = StarkInfra::Utils::Checks.check_datetime(created)
  @updated = StarkInfra::Utils::Checks.check_datetime(updated)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def amount
  @amount
end

#brcodeObject (readonly)

Returns the value of attribute brcode.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def brcode
  @brcode
end

#createdObject (readonly)

Returns the value of attribute created.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def created
  @created
end

#descriptionsObject (readonly)

Returns the value of attribute descriptions.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def descriptions
  @descriptions
end

#discount_amountObject (readonly)

Returns the value of attribute discount_amount.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def discount_amount
  @discount_amount
end

#discountsObject (readonly)

Returns the value of attribute discounts.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def discounts
  @discounts
end

#dueObject (readonly)

Returns the value of attribute due.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def due
  @due
end

#expirationObject (readonly)

Returns the value of attribute expiration.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def expiration
  @expiration
end

#feeObject (readonly)

Returns the value of attribute fee.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def fee
  @fee
end

#fineObject (readonly)

Returns the value of attribute fine.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def fine
  @fine
end

#fine_amountObject (readonly)

Returns the value of attribute fine_amount.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def fine_amount
  @fine_amount
end

#idObject (readonly)

Returns the value of attribute id.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def id
  @id
end

#interestObject (readonly)

Returns the value of attribute interest.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def interest
  @interest
end

#interest_amountObject (readonly)

Returns the value of attribute interest_amount.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def interest_amount
  @interest_amount
end

Returns the value of attribute link.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def link
  @link
end

#nameObject (readonly)

Returns the value of attribute name.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def name
  @name
end

#nominal_amountObject (readonly)

Returns the value of attribute nominal_amount.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def nominal_amount
  @nominal_amount
end

#pdfObject (readonly)

Returns the value of attribute pdf.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def pdf
  @pdf
end

#statusObject (readonly)

Returns the value of attribute status.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def tags
  @tags
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def tax_id
  @tax_id
end

#transaction_idsObject (readonly)

Returns the value of attribute transaction_ids.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def transaction_ids
  @transaction_ids
end

#updatedObject (readonly)

Returns the value of attribute updated.



423
424
425
# File 'lib/creditnote/creditnote.rb', line 423

def updated
  @updated
end

Class Method Details

.parse_invoices(invoices) ⇒ Object



456
457
458
459
460
461
462
463
464
465
466
# File 'lib/creditnote/creditnote.rb', line 456

def self.parse_invoices(invoices)
  return invoices if invoices.nil?
  parsed_invoices = []
  invoices.each do |invoice|
    unless invoice.is_a? Invoice
      invoice = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], invoice)
    end
    parsed_invoices << invoice
  end
  parsed_invoices
end

.resourceObject



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/creditnote/creditnote.rb', line 468

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