Class: StarkBank::DynamicBrcode
- Inherits:
-
StarkCore::Utils::Resource
- Object
- StarkCore::Utils::Resource
- StarkBank::DynamicBrcode
- Defined in:
- lib/dynamic_brcode/dynamic_brcode.rb
Overview
# DynamicBrcode object
When you initialize a DynamicBrcode, the entity will not be automatically sent to the Stark Bank API. The ‘create’ function sends the objects to the Stark Bank API and returns the list of created objects.
DynamicBrcodes are conciliated BR Codes that can be used to receive Pix transactions in a convenient way. When a DynamicBrcode is paid, a Deposit is created with the tags parameter containing the character “dynamic-brcode/” followed by the DynamicBrcode’s uuid “dynamic-brcode/#uuid” for conciliation. Additionally, all tags passed on the DynamicBrcode will be transferred to the respective Deposit resource.
## Parameters (required):
-
amount [integer]: DynamicBrcode value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34)
## Parameters (optional):
-
expiration [integer, default 3600 (1 hour)]: time interval in seconds between due date and expiration date. ex 123456789
-
tags [list of strings, default []]: list of strings for tagging, these will be passed to the respective DynamicBrcode resource when paid
## Attributes (return-only):
-
id [string]: id returned on creation, this is the BR code. ex: “00020126360014br.gov.bcb.pix0114+552840092118152040000530398654040.095802BR5915Jamie Lannister6009Sao Paulo620705038566304FC6C”
-
uuid [string]: unique uuid returned when the DynamicBrcode is created. ex: “4e2eab725ddd495f9c98ffd97440702d”
-
picture_url [string]: public QR Code (png image) URL. “
” -
updated [DateTime]: latest update datetime for the DynamicBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
-
created [DateTime]: creation datetime for the DynamicBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#picture_url ⇒ Object
readonly
Returns the value of attribute picture_url.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
-
.create(brcodes, user: nil) ⇒ Object
# Create DynamicBrcode.
-
.get(uuid, user: nil) ⇒ Object
# Retrieve a specific DynamicBrcode.
-
.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, uuids: nil, user: nil) ⇒ Object
# Retrieve paged DynamicBrcodes.
-
.query(limit: nil, after: nil, before: nil, tags: nil, uuids: nil, user: nil) ⇒ Object
# Retrieve DynamicBrcodes.
- .resource ⇒ Object
Instance Method Summary collapse
-
#initialize(amount:, expiration: nil, tags: nil, id: nil, uuid: nil, picture_url: nil, updated: nil, created: nil) ⇒ DynamicBrcode
constructor
A new instance of DynamicBrcode.
Constructor Details
#initialize(amount:, expiration: nil, tags: nil, id: nil, uuid: nil, picture_url: nil, updated: nil, created: nil) ⇒ DynamicBrcode
Returns a new instance of DynamicBrcode.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 33 def initialize( amount:, expiration: nil, tags: nil, id: nil, uuid: nil, picture_url: nil, updated: nil, created: nil ) super(id) @amount = amount @expiration = expiration = @uuid = uuid @picture_url = picture_url @created = StarkCore::Utils::Checks.check_datetime(created) @updated = StarkCore::Utils::Checks.check_datetime(updated) end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
32 33 34 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 32 def amount @amount end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
32 33 34 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 32 def created @created end |
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration.
32 33 34 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 32 def expiration @expiration end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
32 33 34 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 32 def id @id end |
#picture_url ⇒ Object (readonly)
Returns the value of attribute picture_url.
32 33 34 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 32 def picture_url @picture_url end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
32 33 34 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 32 def end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
32 33 34 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 32 def updated @updated end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
32 33 34 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 32 def uuid @uuid end |
Class Method Details
.create(brcodes, user: nil) ⇒ Object
# Create DynamicBrcode
Send a list of DynamicBrcode objects for creation in the Stark Bank API
## Parameters (required):
-
brcodes [list of DynamicBrcode objects]: list of DynamicBrcode 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 DynamicBrcode objects with updated attributes
58 59 60 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 58 def self.create(brcodes, user: nil) StarkBank::Utils::Rest.post(entities: brcodes, user: user, **resource) end |
.get(uuid, user: nil) ⇒ Object
# Retrieve a specific DynamicBrcode
Receive a single DynamicBrcode object previously created in the Stark Bank API by its uuid
## Parameters (required):
-
uuid [string]: object unique uuid. ex: “901e71f2447c43c886f58366a5432c4b”
## Parameters (optional):
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
DynamicBrcode object with updated attributes
74 75 76 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 74 def self.get(uuid, user: nil) StarkBank::Utils::Rest.get_id(id: uuid, user: user, **resource) end |
.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, uuids: nil, user: nil) ⇒ Object
# Retrieve paged DynamicBrcodes
Receive a list of up to 100 DynamicBrcode 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’]
-
uuids [list of strings, default nil]: list of uuids to filter retrieved objects. ex: [“901e71f2447c43c886f58366a5432c4b”, “4e2eab725ddd495f9c98ffd97440702d”]
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
list of DynamicBrcode objects with updated attributes and cursor to retrieve the next page of DynamicBrcode objects
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 122 def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, uuids: 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: , uuids: uuids, user: user, **resource ) end |
.query(limit: nil, after: nil, before: nil, tags: nil, uuids: nil, user: nil) ⇒ Object
# Retrieve DynamicBrcodes
Receive a generator of DynamicBrcode 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’]
-
uuids [list of strings, default nil]: list of uuids to filter retrieved objects. ex: [“901e71f2447c43c886f58366a5432c4b”, “4e2eab725ddd495f9c98ffd97440702d”]
-
user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
generator of DynamicBrcode objects with updated attributes
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 92 def self.query(limit: nil, after: nil, before: nil, tags: nil, uuids: 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: , uuids: uuids, user: user, **resource ) end |
.resource ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/dynamic_brcode/dynamic_brcode.rb', line 137 def self.resource { resource_name: 'DynamicBrcode', resource_maker: proc { |json| DynamicBrcode.new( id: json['id'], amount: json['amount'], expiration: json['expiration'], tags: json['tags'], uuid: json['uuid'], picture_url: json['picture_url'], created: json['created'], updated: json['updated'] ) } } end |