Class: StarkBank::UtilityPayment
- Inherits:
-
StarkBank::Utils::Resource
- Object
- StarkBank::Utils::Resource
- StarkBank::UtilityPayment
- Defined in:
- lib/utility_payment/utility_payment.rb,
lib/utility_payment/log.rb
Overview
# UtilityPayment object
When you initialize a UtilityPayment, 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 (conditionally required):
-
line [string, default nil]: Number sequence that describes the payment. Either ‘line’ or ‘bar_code’ parameters are required. If both are sent, they must match. ex: “34191.09008 63571.277308 71444.640008 5 81960000000062”
-
bar_code [string, default nil]: Bar code number that describes the payment. Either ‘line’ or ‘barCode’ parameters are required. If both are sent, they must match. ex: “34195819600000000621090063571277307144464000”
## Parameters (required):
-
description [string]: Text to be displayed in your statement (min. 10 characters). ex: “payment ABC”
## Parameters (optional):
-
scheduled [Date, DateTime, Time or string, default today]: payment scheduled date. ex: Date.new(2020, 3, 10)
-
tags [list of strings]: list of strings for tagging
## Attributes (return-only):
-
id [string, default nil]: unique id returned when payment is created. ex: “5656565656565656”
-
status [string, default nil]: current payment status. ex: “registered” or “paid”
-
amount [int, default nil]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)
-
fee [integer, default nil]: fee charged when utility payment is created. ex: 200 (= R$ 2.00)
-
created [DateTime, default nil]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
Defined Under Namespace
Classes: Log
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#bar_code ⇒ Object
readonly
Returns the value of attribute bar_code.
-
#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.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#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.
Class Method Summary collapse
-
.create(payments, user: nil) ⇒ Object
# Create UtilityPayments.
-
.delete(id, user: nil) ⇒ Object
# Delete a UtilityPayment entity.
-
.get(id, user: nil) ⇒ Object
# Retrieve a specific UtilityPayment.
-
.pdf(id, user: nil) ⇒ Object
# Retrieve a specific UtilityPayment pdf file.
-
.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil) ⇒ Object
# Retrieve UtilityPayments.
- .resource ⇒ Object
Instance Method Summary collapse
-
#initialize(description:, line: nil, bar_code: nil, tags: nil, scheduled: nil, id: nil, amount: nil, fee: nil, status: nil, created: nil) ⇒ UtilityPayment
constructor
A new instance of UtilityPayment.
Methods inherited from StarkBank::Utils::Resource
Constructor Details
#initialize(description:, line: nil, bar_code: nil, tags: nil, scheduled: nil, id: nil, amount: nil, fee: nil, status: nil, created: nil) ⇒ UtilityPayment
Returns a new instance of UtilityPayment.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/utility_payment/utility_payment.rb', line 33 def initialize(description:, line: nil, bar_code: nil, tags: nil, scheduled: nil, id: nil, amount: nil, fee: nil, status: nil, created: nil) super(id) @description = description @line = line = = @scheduled = StarkBank::Utils::Checks.check_datetime(scheduled) @amount = amount @fee = fee @status = status @created = StarkBank::Utils::Checks.check_datetime(created) end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def amount @amount end |
#bar_code ⇒ Object (readonly)
Returns the value of attribute bar_code.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def created @created end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def description @description end |
#fee ⇒ Object (readonly)
Returns the value of attribute fee.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def fee @fee end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def id @id end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def line @line end |
#scheduled ⇒ Object (readonly)
Returns the value of attribute scheduled.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def scheduled @scheduled end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def status @status end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
32 33 34 |
# File 'lib/utility_payment/utility_payment.rb', line 32 def end |
Class Method Details
.create(payments, user: nil) ⇒ Object
# Create UtilityPayments
Send a list of UtilityPayment objects for creation in the Stark Bank API
## Parameters (required):
-
payments [list of UtilityPayment objects]: list of UtilityPayment objects to be created in the API
## Parameters (optional):
-
user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
list of UtilityPayment objects with updated attributes
58 59 60 |
# File 'lib/utility_payment/utility_payment.rb', line 58 def self.create(payments, user: nil) StarkBank::Utils::Rest.post(entities: payments, user: user, **resource) end |
.delete(id, user: nil) ⇒ Object
# Delete a UtilityPayment entity
Delete a UtilityPayment entity previously created in the Stark Bank API
## Parameters (required):
-
id [string]: UtilityPayment unique id. ex: “5656565656565656”
## Parameters (optional):
-
user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
deleted UtilityPayment with updated attributes
137 138 139 |
# File 'lib/utility_payment/utility_payment.rb', line 137 def self.delete(id, user: nil) StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource) end |
.get(id, user: nil) ⇒ Object
# Retrieve a specific UtilityPayment
Receive a single UtilityPayment object previously created by the Stark Bank API by passing its id
## Parameters (required):
-
id [string]: object unique id. ex: “5656565656565656”
## Parameters (optional):
-
user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
UtilityPayment object with updated attributes
74 75 76 |
# File 'lib/utility_payment/utility_payment.rb', line 74 def self.get(id, user: nil) StarkBank::Utils::Rest.get_id(id: id, user: user, **resource) end |
.pdf(id, user: nil) ⇒ Object
# Retrieve a specific UtilityPayment pdf file
Receive a single UtilityPayment pdf file generated in the Stark Bank API by passing its id. Only valid for utility payments with “success” status.
## Parameters (required):
-
id [string]: object unique id. ex: “5656565656565656”
## Parameters (optional):
-
user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
UtilityPayment pdf file
91 92 93 |
# File 'lib/utility_payment/utility_payment.rb', line 91 def self.pdf(id, user: nil) StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource) end |
.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil) ⇒ Object
# Retrieve UtilityPayments
Receive a generator of UtilityPayment 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 ids to filter retrieved objects. ex: [‘5656565656565656’, ‘4545454545454545’]
-
status [string, default nil]: filter for status of retrieved objects. ex: ‘paid’
-
user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
generator of UtilityPayment objects with updated attributes
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/utility_payment/utility_payment.rb', line 110 def self.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil) after = StarkBank::Utils::Checks.check_date(after) before = StarkBank::Utils::Checks.check_date(before) StarkBank::Utils::Rest.get_list( user: user, limit: limit, after: after, before: before, tags: , ids: ids, status: status, **resource ) end |
.resource ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/utility_payment/utility_payment.rb', line 141 def self.resource { resource_name: 'UtilityPayment', resource_maker: proc { |json| UtilityPayment.new( id: json['id'], description: json['description'], line: json['line'], bar_code: json['bar_code'], tags: json['tags'], scheduled: json['scheduled'], amount: json['amount'], fee: json['fee'], status: json['status'], created: json['created'] ) } } end |