Class: StarkBank::BrcodePayment
- Inherits:
-
StarkCore::Utils::Resource
- Object
- StarkCore::Utils::Resource
- StarkBank::BrcodePayment
- Defined in:
- lib/brcode_payment/brcode_payment.rb,
lib/brcode_payment/log.rb,
lib/brcode_payment/rule.rb
Overview
# BrcodePayment object
When you initialize a BrcodePayment, 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):
-
brcode [string]: String loaded directly from the QRCode or copied from the invoice. ex: ‘00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T’Challa6009Sao Paulo62090505123456304B14A’
-
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 (conditionally required):
-
amount [int, default nil]: If the BRCode does not provide an amount, this parameter is mandatory, else it is optional. ex: 23456 (= R$ 234.56)
## Parameters (optional):
-
scheduled [datetime.date, datetime.datetime or string, default now]: payment scheduled date or datetime. ex: datetime.datetime(2020, 3, 10, 15, 17, 3)
-
tags [list of strings, default nil]: list of strings for tagging
-
rules [list of BrcodePayment::Rules, default []]: list of BrcodePayment::Rule objects for modifying transfer behavior. ex: [BrcodePayment::Rule(key: “resendingLimit”, value: 5)]
## Attributes (return-only):
-
id [string]: unique id returned when payment is created. ex: ‘5656565656565656’
-
name [string]: receiver name. ex: ‘Jon Snow’
-
status [string]: current payment status. ex: ‘success’ or ‘failed’
-
type [string]: brcode type. ex: ‘static’ or ‘dynamic’
-
transaction_ids [list of strings]: ledger transaction ids linked to this payment. ex: [‘19827356981273’]
-
fee [integer]: fee charged when the brcode payment is created. ex: 200 (= R$ 2.00)
-
updated [datetime.datetime]: latest update datetime for the payment. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0)
-
created [datetime.datetime]: creation datetime for the payment. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0)
Defined Under Namespace
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#brcode ⇒ Object
readonly
Returns the value of attribute brcode.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#fee ⇒ Object
readonly
Returns the value of attribute fee.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#scheduled ⇒ Object
readonly
Returns the value of attribute scheduled.
-
#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.
-
#transaction_ids ⇒ Object
readonly
Returns the value of attribute transaction_ids.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Class Method Summary collapse
-
.create(payments, user: nil) ⇒ Object
# Create BrcodePayments.
-
.get(id, user: nil) ⇒ Object
# Retrieve a specific BrcodePayment.
-
.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil) ⇒ Object
# Retrieve paged BrcodePayments.
-
.pdf(id, user: nil) ⇒ Object
# Retrieve a specific BrcodePayment pdf file.
-
.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil) ⇒ Object
# Retrieve BrcodePayments.
- .resource ⇒ Object
-
.update(id, status: nil, user: nil) ⇒ Object
# Update a BrcodePayment entity.
Instance Method Summary collapse
-
#initialize(brcode:, tax_id:, description:, amount: nil, scheduled: nil, tags: nil, rules: nil, id: nil, name: nil, status: nil, type: nil, transaction_ids: nil, fee: nil, updated: nil, created: nil) ⇒ BrcodePayment
constructor
A new instance of BrcodePayment.
Constructor Details
#initialize(brcode:, tax_id:, description:, amount: nil, scheduled: nil, tags: nil, rules: nil, id: nil, name: nil, status: nil, type: nil, transaction_ids: nil, fee: nil, updated: nil, created: nil) ⇒ BrcodePayment
Returns a new instance of BrcodePayment.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/brcode_payment/brcode_payment.rb', line 38 def initialize(brcode:, tax_id:, description:, amount: nil, scheduled: nil, tags: nil, rules: nil, id: nil, name: nil, status: nil, type: nil, transaction_ids: nil, fee: nil, updated: nil, created: nil) super(id) @brcode = brcode @tax_id = tax_id @description = description @amount = amount @scheduled = StarkCore::Utils::Checks.check_date_or_datetime(scheduled) @tags = @rules = StarkBank::BrcodePayment::Rule.parse_rules(rules) @name = name @status = status @type = type @transaction_ids = transaction_ids @fee = fee @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.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def amount @amount end |
#brcode ⇒ Object (readonly)
Returns the value of attribute brcode.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def brcode @brcode end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def created @created end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def description @description end |
#fee ⇒ Object (readonly)
Returns the value of attribute fee.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def fee @fee end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def name @name end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def rules @rules end |
#scheduled ⇒ Object (readonly)
Returns the value of attribute scheduled.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def scheduled @scheduled end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def status @status end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def @tags end |
#tax_id ⇒ Object (readonly)
Returns the value of attribute tax_id.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def tax_id @tax_id end |
#transaction_ids ⇒ Object (readonly)
Returns the value of attribute transaction_ids.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def transaction_ids @transaction_ids end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def type @type end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
37 38 39 |
# File 'lib/brcode_payment/brcode_payment.rb', line 37 def updated @updated end |
Class Method Details
.create(payments, user: nil) ⇒ Object
# Create BrcodePayments
Send a list of BrcodePayment objects for creation in the Stark Bank API
## Parameters (required):
-
payments [list of BrcodePayment objects]: list of BrcodePayment 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 BrcodePayment objects with updated attributes
68 69 70 |
# File 'lib/brcode_payment/brcode_payment.rb', line 68 def self.create(payments, user: nil) StarkBank::Utils::Rest.post(entities: payments, user: user, **resource) end |
.get(id, user: nil) ⇒ Object
# Retrieve a specific BrcodePayment
Receive a single BrcodePayment 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:
-
BrcodePayment object with updated attributes
84 85 86 |
# File 'lib/brcode_payment/brcode_payment.rb', line 84 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 BrcodePayments
Receive a list of up to 100 BrcodePayment 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 BrcodePayment objects with updated attributes and cursor to retrieve the next page of BrcodePayment objects
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/brcode_payment/brcode_payment.rb', line 168 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, limit: limit, after: after, before: before, tags: , ids: ids, status: status, user: user, **resource ) end |
.pdf(id, user: nil) ⇒ Object
# Retrieve a specific BrcodePayment pdf file
Receive a single BrcodePayment pdf file generated in 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:
-
BrcodePayment pdf file
100 101 102 |
# File 'lib/brcode_payment/brcode_payment.rb', line 100 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 BrcodePayments
Receive a generator of BrcodePayment 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 BrcodePayment objects with updated attributes
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/brcode_payment/brcode_payment.rb', line 136 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( limit: limit, after: after, before: before, tags: , ids: ids, status: status, user: user, **resource ) end |
.resource ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/brcode_payment/brcode_payment.rb', line 184 def self.resource { resource_name: 'BrcodePayment', resource_maker: proc { |json| BrcodePayment.new( brcode: json['brcode'], tax_id: json['tax_id'], description: json['description'], amount: json['amount'], scheduled: json['scheduled'], tags: json['tags'], rules: json['rules'], id: json['id'], name: json['name'], status: json['status'], type: json['type'], transaction_ids: json['transaction_ids'], fee: json['fee'], updated: json['updated'], created: json['created'] ) } } end |
.update(id, status: nil, user: nil) ⇒ Object
# Update a BrcodePayment entity
Update a BrcodePayment entity previously created in the Stark Bank API
## Parameters (required):
-
id [string]: BrcodePayment unique id. ex: ‘5656565656565656’
-
status [string, nil]: You may cancel the payment by passing ‘canceled’ in the status
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
updated BrcodePayment object
117 118 119 |
# File 'lib/brcode_payment/brcode_payment.rb', line 117 def self.update(id, status: nil, user: nil) StarkBank::Utils::Rest.patch_id(id: id, status: status, user: user, **resource) end |