Class: StarkBank::CorporateInvoice
- Inherits:
-
StarkCore::Utils::Resource
- Object
- StarkCore::Utils::Resource
- StarkBank::CorporateInvoice
- Defined in:
- lib/corporate_invoice/corporateinvoice.rb
Overview
# CorporateInvoice object
The CorporateInvoice objects created in your Workspace load your Corporate balance when paid.
When you initialize a CorporateInvoice, 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 created object.
## Parameters (required):
-
amount [integer]: CorporateInvoice value in cents. ex: 1234 (= R$ 12.34)
## Parameters (optional):
-
tags [list of strings, default nil]: list of strings for tagging. ex: [‘travel’, ‘food’]
## Attributes (return-only):
-
id [string]: unique id returned when CorporateInvoice is created. ex: ‘5656565656565656’
-
name [string, default sub-issuer name]: payer name. ex: ‘Iron Bank S.A.’
-
tax_id [string, default sub-issuer tax ID]: payer tax ID (CPF or CNPJ) with or without formatting. ex: ‘01234567890’ or ‘20.018.183/0001-80’
-
brcode [string]: BR Code for the Invoice payment. ex: ‘00020101021226930014br.gov.bcb.pix2571brcode-h.development.starkbank.com/v2/d7f6546e194d4c64a153e8f79f1c41ac5204000053039865802BR5925Stark Bank S.A. - Institu6009Sao Paulo62070503***63042109’
-
due [DateTime, Date or string]: Invoice due and expiration date in UTC ISO format. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0), Date.new(2020, 3, 10) or ‘2020-03-10T10:30:00.000000+00:00’
-
link [string]: public Invoice webpage URL. ex: ‘starkbank-card-issuer.development.starkbank.com/invoicelink/d7f6546e194d4c64a153e8f79f1c41ac’
-
status [string]: current CorporateInvoice status. ex: ‘created’, ‘expired’, ‘overdue’, ‘paid’
-
corporate_transaction_id [string]: ledger transaction ids linked to this CorporateInvoice. ex: ‘corporate-invoice/5656565656565656’
-
updated [DateTime]: latest update datetime for the CorporateInvoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
-
created [DateTime]: creation datetime for the CorporateInvoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#brcode ⇒ Object
readonly
Returns the value of attribute brcode.
-
#corporate_transaction_id ⇒ Object
readonly
Returns the value of attribute corporate_transaction_id.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#due ⇒ Object
readonly
Returns the value of attribute due.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#tax_id ⇒ Object
readonly
Returns the value of attribute tax_id.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Class Method Summary collapse
-
.create(invoice, user: nil) ⇒ Object
# Create a CorporateInvoice.
-
.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, user: nil) ⇒ Object
# Retrieve paged CorporateInvoices.
-
.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, user: nil) ⇒ Object
# Retrieve CorporateInvoices.
- .resource ⇒ Object
Instance Method Summary collapse
-
#initialize(amount:, id: nil, tax_id: nil, name: nil, tags: nil, brcode: nil, due: nil, link: nil, status: nil, corporate_transaction_id: nil, updated: nil, created: nil) ⇒ CorporateInvoice
constructor
A new instance of CorporateInvoice.
Constructor Details
#initialize(amount:, id: nil, tax_id: nil, name: nil, tags: nil, brcode: nil, due: nil, link: nil, status: nil, corporate_transaction_id: nil, updated: nil, created: nil) ⇒ CorporateInvoice
Returns a new instance of CorporateInvoice.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 34 def initialize( amount:, id: nil, tax_id: nil, name: nil, tags: nil, brcode: nil, due: nil, link: nil, status: nil, corporate_transaction_id: nil, updated: nil, created: nil ) super(id) @amount = amount @tax_id = tax_id @name = name @tags = @brcode = brcode @due = due @link = link @status = status @corporate_transaction_id = corporate_transaction_id @updated = StarkCore::Utils::Checks.check_datetime(updated) @created = StarkCore::Utils::Checks.check_datetime(created) end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def amount @amount end |
#brcode ⇒ Object (readonly)
Returns the value of attribute brcode.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def brcode @brcode end |
#corporate_transaction_id ⇒ Object (readonly)
Returns the value of attribute corporate_transaction_id.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def corporate_transaction_id @corporate_transaction_id end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def created @created end |
#due ⇒ Object (readonly)
Returns the value of attribute due.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def due @due end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def id @id end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def link @link end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def name @name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def status @status end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def @tags end |
#tax_id ⇒ Object (readonly)
Returns the value of attribute tax_id.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def tax_id @tax_id end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
33 34 35 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 33 def updated @updated end |
Class Method Details
.create(invoice, user: nil) ⇒ Object
# Create a CorporateInvoice
Send a single CorporateInvoice object for creation in the Stark Bank API
## Parameters (required):
-
invoice [CorporateInvoice object]: CorporateInvoice object 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:
-
CorporateInvoice object with updated attributes
64 65 66 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 64 def self.create(invoice, user: nil) StarkBank::Utils::Rest.post_single(entity: invoice, user: user, **resource) end |
.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, user: nil) ⇒ Object
# Retrieve paged CorporateInvoices
Receive a list of up to 100 CorporateInvoices 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 logs.
## Parameters (optional):
-
cursor [string, default nil]: cursor returned on the previous page function call.
-
limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
-
after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
-
before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
-
status [list of strings, default nil]: filter for status of retrieved objects. ex: [‘created’, ‘expired’, ‘overdue’, ‘paid’]
-
tags [list of strings, default nil]: tags to filter retrieved objects. ex: [‘tony’, ‘stark’]
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
## Return:
-
list of CorporateInvoice objects with updated attributes
-
cursor to retrieve the next page of CorporateInvoice objects
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 113 def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, user: nil) after = StarkCore::Utils::Checks.check_date(after) before = StarkCore::Utils::Checks.check_date(before) StarkBank::Utils::Rest.get_page( cursor: cursor, limit: limit, after: after, before: before, status: status, tags: , user: user, **resource ) end |
.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, user: nil) ⇒ Object
# Retrieve CorporateInvoices
Receive a generator of CorporateInvoices 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 or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
-
before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
-
status [list of strings, default nil]: filter for status of retrieved objects. ex: [‘created’, ‘expired’, ‘overdue’, ‘paid’]
-
tags [list of strings, default nil]: tags to filter retrieved objects. ex: [‘tony’, ‘stark’]
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
## Return:
-
generator of CorporateInvoices objects with updated attributes
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 82 def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, user: nil) after = StarkCore::Utils::Checks.check_date(after) before = StarkCore::Utils::Checks.check_date(before) StarkBank::Utils::Rest.get_stream( limit: limit, after: after, before: before, status: status, tags: , user: user, **resource ) end |
.resource ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/corporate_invoice/corporateinvoice.rb', line 128 def self.resource { resource_name: 'CorporateInvoice', resource_maker: proc { |json| CorporateInvoice.new( id: json['id'], amount: json['amount'], tax_id: json['tax_id'], name: json['name'], tags: json['tags'], brcode: json['brcode'], due: json['due'], link: json['link'], status: json['status'], corporate_transaction_id: json['corporate_transaction_id'], updated: json['updated'], created: json['created'] ) } } end |