starkbank 2.6.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/balance/balance.rb +8 -8
- data/lib/boleto/boleto.rb +22 -19
- data/lib/boleto/log.rb +10 -10
- data/lib/boleto_holmes/boleto_holmes.rb +14 -14
- data/lib/boleto_holmes/log.rb +16 -13
- data/lib/boleto_payment/boleto_payment.rb +21 -18
- data/lib/boleto_payment/log.rb +10 -10
- data/lib/brcode_payment/brcode_payment.rb +23 -20
- data/lib/brcode_payment/log.rb +10 -10
- data/lib/brcode_payment/rule.rb +49 -0
- data/lib/darf_payment/darf_payment.rb +23 -21
- data/lib/darf_payment/log.rb +10 -10
- data/lib/deposit/deposit.rb +9 -9
- data/lib/deposit/log.rb +10 -10
- data/lib/dict_key/dict_key.rb +26 -27
- data/lib/dynamic_brcode/dynamic_brcode.rb +155 -0
- data/lib/error.rb +7 -40
- data/lib/event/attempt.rb +9 -9
- data/lib/event/event.rb +30 -56
- data/lib/institution/institution.rb +2 -3
- data/lib/invoice/invoice.rb +24 -23
- data/lib/invoice/log.rb +10 -10
- data/lib/invoice/payment.rb +1 -2
- data/lib/payment_preview/boleto_preview.rb +4 -5
- data/lib/payment_preview/brcode_preview.rb +2 -3
- data/lib/payment_preview/payment_preview.rb +10 -6
- data/lib/payment_preview/tax_preview.rb +2 -3
- data/lib/payment_preview/utility_preview.rb +2 -3
- data/lib/payment_request/payment_request.rb +22 -16
- data/lib/starkbank.rb +16 -5
- data/lib/tax_payment/log.rb +10 -10
- data/lib/tax_payment/tax_payment.rb +22 -19
- data/lib/transaction/transaction.rb +13 -13
- data/lib/transfer/log.rb +10 -10
- data/lib/transfer/rule.rb +49 -0
- data/lib/transfer/transfer.rb +30 -24
- data/lib/utility_payment/log.rb +10 -10
- data/lib/utility_payment/utility_payment.rb +26 -17
- data/lib/utils/parse.rb +35 -0
- data/lib/utils/rest.rb +132 -109
- data/lib/webhook/webhook.rb +5 -5
- data/lib/workspace/workspace.rb +38 -10
- metadata +15 -25
- data/lib/brcode_preview/brcode_preview.rb +0 -79
- data/lib/key.rb +0 -33
- data/lib/user/organization.rb +0 -54
- data/lib/user/project.rb +0 -37
- data/lib/user/user.rb +0 -20
- data/lib/utils/api.rb +0 -79
- data/lib/utils/cache.rb +0 -10
- data/lib/utils/case.rb +0 -21
- data/lib/utils/checks.rb +0 -101
- data/lib/utils/environment.rb +0 -13
- data/lib/utils/request.rb +0 -79
- data/lib/utils/resource.rb +0 -13
- data/lib/utils/sub_resource.rb +0 -28
- data/lib/utils/url.rb +0 -28
data/lib/error.rb
CHANGED
@@ -1,52 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require('
|
3
|
+
require('starkcore')
|
4
4
|
|
5
5
|
module StarkBank
|
6
6
|
module Error
|
7
|
-
|
8
|
-
attr_reader :message
|
9
|
-
def initialize(message)
|
10
|
-
@message = message
|
11
|
-
super(message)
|
12
|
-
end
|
13
|
-
end
|
7
|
+
StarkBankError = StarkCore::Error::StarkCoreError
|
14
8
|
|
15
|
-
|
16
|
-
attr_reader :code, :message
|
17
|
-
def initialize(code, message)
|
18
|
-
@code = code
|
19
|
-
@message = message
|
20
|
-
super("#{code}: #{message}")
|
21
|
-
end
|
22
|
-
end
|
9
|
+
Error = StarkCore::Error::Error
|
23
10
|
|
24
|
-
|
25
|
-
attr_reader :errors
|
26
|
-
def initialize(content)
|
27
|
-
errors = []
|
28
|
-
content.each do |error|
|
29
|
-
errors << Error.new(error['code'], error['message'])
|
30
|
-
end
|
31
|
-
@errors = errors
|
11
|
+
InputErrors = StarkCore::Error::InputErrors
|
32
12
|
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
13
|
+
InternalServerError = StarkCore::Error::InternalServerError
|
36
14
|
|
37
|
-
|
38
|
-
def initialize(message = 'Houston, we have a problem.')
|
39
|
-
super(message)
|
40
|
-
end
|
41
|
-
end
|
15
|
+
UnknownError = StarkCore::Error::UnknownError
|
42
16
|
|
43
|
-
|
44
|
-
def initialize(message)
|
45
|
-
super("Unknown exception encountered: #{message}")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class InvalidSignatureError < StarkBankError
|
50
|
-
end
|
17
|
+
InvalidSignatureError = StarkCore::Error::InvalidSignatureError
|
51
18
|
end
|
52
19
|
end
|
data/lib/event/attempt.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
require_relative('../utils/checks')
|
6
5
|
require_relative('event')
|
7
6
|
|
7
|
+
|
8
8
|
module StarkBank
|
9
9
|
class Event
|
10
10
|
# # Event::Attempt object
|
@@ -12,14 +12,14 @@ module StarkBank
|
|
12
12
|
# When an Event delivery fails, an event attempt will be registered.
|
13
13
|
# It carries information meant to help you debug event reception issues.
|
14
14
|
#
|
15
|
-
# ## Attributes:
|
15
|
+
# ## Attributes (return-only):
|
16
16
|
# - id [string]: unique id that identifies the delivery attempt. ex: "5656565656565656"
|
17
17
|
# - code [string]: delivery error code. ex: badHttpStatus, badConnection, timeout
|
18
18
|
# - message [string]: delivery error full description. ex: "HTTP POST request returned status 404"
|
19
19
|
# - event_id [string]: ID of the Event whose delivery failed. ex: "4848484848484848"
|
20
20
|
# - webhook_id [string]: ID of the Webhook that triggered this event. ex: "5656565656565656"
|
21
21
|
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
22
|
-
class Attempt <
|
22
|
+
class Attempt < StarkCore::Utils::Resource
|
23
23
|
attr_reader :id, :code, :message, :event_id, :webhook_id, :created
|
24
24
|
def initialize(id:, code:, message:, event_id:, webhook_id:, created:)
|
25
25
|
super(id)
|
@@ -27,7 +27,7 @@ module StarkBank
|
|
27
27
|
@message = message
|
28
28
|
@event_id = event_id
|
29
29
|
@webhook_id = webhook_id
|
30
|
-
@created =
|
30
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
31
31
|
end
|
32
32
|
|
33
33
|
# # Retrieve a specific Event::Attempt
|
@@ -61,8 +61,8 @@ module StarkBank
|
|
61
61
|
# ## Return:
|
62
62
|
# - generator of Event::Attempt objects with updated attributes
|
63
63
|
def self.query(limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
|
64
|
-
after =
|
65
|
-
before =
|
64
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
65
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
66
66
|
StarkBank::Utils::Rest.get_stream(
|
67
67
|
limit: limit,
|
68
68
|
after: after,
|
@@ -91,8 +91,8 @@ module StarkBank
|
|
91
91
|
# ## Return:
|
92
92
|
# - list of Attempt objects with updated attributes and cursor to retrieve the next page of Attempt objects
|
93
93
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
|
94
|
-
after =
|
95
|
-
before =
|
94
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
95
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
96
96
|
return StarkBank::Utils::Rest.get_page(
|
97
97
|
cursor: cursor,
|
98
98
|
limit: limit,
|
data/lib/event/event.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require('json')
|
4
|
-
require('
|
5
|
-
require_relative('../utils/resource')
|
4
|
+
require('starkcore')
|
6
5
|
require_relative('../utils/rest')
|
7
|
-
require_relative('../utils/
|
8
|
-
require_relative('../utils/cache')
|
6
|
+
require_relative('../utils/parse')
|
9
7
|
require_relative('../error')
|
10
8
|
require_relative('../boleto/log')
|
11
9
|
require_relative('../boleto_holmes/log')
|
@@ -25,18 +23,18 @@ module StarkBank
|
|
25
23
|
# Events cannot be created, but may be retrieved from the Stark Bank API to
|
26
24
|
# list all generated updates on entities.
|
27
25
|
#
|
28
|
-
# ## Attributes:
|
26
|
+
# ## Attributes (return-only):
|
29
27
|
# - id [string]: unique id returned when the event is created. ex: '5656565656565656'
|
30
28
|
# - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
|
31
29
|
# - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
32
30
|
# - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
|
33
31
|
# - workspace_id [string]: ID of the Workspace that generated this event. Mostly used when multiple Workspaces have Webhooks registered to the same endpoint. ex: '4545454545454545'
|
34
32
|
# - subscription [string]: service that triggered this event. ex: 'transfer', 'utility-payment'
|
35
|
-
class Event <
|
33
|
+
class Event < StarkCore::Utils::Resource
|
36
34
|
attr_reader :id, :log, :created, :is_delivered, :workspace_id, :subscription
|
37
35
|
def initialize(id:, log:, created:, is_delivered:, workspace_id:, subscription:)
|
38
36
|
super(id)
|
39
|
-
@created =
|
37
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
40
38
|
@is_delivered = is_delivered
|
41
39
|
@workspace_id = workspace_id
|
42
40
|
@subscription = subscription
|
@@ -55,7 +53,7 @@ module StarkBank
|
|
55
53
|
}[subscription.to_sym]
|
56
54
|
|
57
55
|
@log = log
|
58
|
-
@log =
|
56
|
+
@log = StarkCore::Utils::API.from_api_json(resource[:resource_maker], log) unless resource.nil?
|
59
57
|
end
|
60
58
|
|
61
59
|
# # Retrieve a specific notification Event
|
@@ -88,8 +86,8 @@ module StarkBank
|
|
88
86
|
# ## Return:
|
89
87
|
# - generator of Event objects with updated attributes
|
90
88
|
def self.query(limit: nil, after: nil, before: nil, is_delivered: nil, user: nil)
|
91
|
-
after =
|
92
|
-
before =
|
89
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
90
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
93
91
|
StarkBank::Utils::Rest.get_stream(
|
94
92
|
user: user,
|
95
93
|
limit: limit,
|
@@ -116,8 +114,8 @@ module StarkBank
|
|
116
114
|
# ## Return:
|
117
115
|
# - list of Event objects with updated attributes and cursor to retrieve the next page of Event objects
|
118
116
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, is_delivered: nil, user: nil)
|
119
|
-
after =
|
120
|
-
before =
|
117
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
118
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
121
119
|
return StarkBank::Utils::Rest.get_page(
|
122
120
|
cursor: cursor,
|
123
121
|
limit: limit,
|
@@ -179,53 +177,29 @@ module StarkBank
|
|
179
177
|
# ## Return:
|
180
178
|
# - Parsed Event object
|
181
179
|
def self.parse(content:, signature:, user: nil)
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
return event if verify_signature(content: content, signature: signature, user: user)
|
191
|
-
|
192
|
-
return event if verify_signature(content: content, signature: signature, user: user, refresh: true)
|
193
|
-
|
194
|
-
raise(StarkBank::Error::InvalidSignatureError, 'The provided signature and content do not match the Stark Bank public key')
|
180
|
+
StarkBank::Utils::Parse.parse_and_verify(
|
181
|
+
content: content,
|
182
|
+
signature: signature,
|
183
|
+
user: user,
|
184
|
+
resource: resource,
|
185
|
+
key: 'event'
|
186
|
+
)
|
195
187
|
end
|
196
188
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
def get_public_key_pem(user)
|
211
|
-
StarkBank::Utils::Request.fetch(method: 'GET', path: 'public-key', query: { limit: 1 }, user: user).json['publicKeys'][0]['content']
|
212
|
-
end
|
213
|
-
|
214
|
-
def resource
|
215
|
-
{
|
216
|
-
resource_name: 'Event',
|
217
|
-
resource_maker: proc { |json|
|
218
|
-
Event.new(
|
219
|
-
id: json['id'],
|
220
|
-
log: json['log'],
|
221
|
-
created: json['created'],
|
222
|
-
is_delivered: json['is_delivered'],
|
223
|
-
workspace_id: json['workspace_id'],
|
224
|
-
subscription: json['subscription']
|
225
|
-
)
|
226
|
-
}
|
189
|
+
def self.resource
|
190
|
+
{
|
191
|
+
resource_name: 'Event',
|
192
|
+
resource_maker: proc { |json|
|
193
|
+
Event.new(
|
194
|
+
id: json['id'],
|
195
|
+
log: json['log'],
|
196
|
+
created: json['created'],
|
197
|
+
is_delivered: json['is_delivered'],
|
198
|
+
workspace_id: json['workspace_id'],
|
199
|
+
subscription: json['subscription']
|
200
|
+
)
|
227
201
|
}
|
228
|
-
|
202
|
+
}
|
229
203
|
end
|
230
204
|
end
|
231
205
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('../utils/sub_resource')
|
4
3
|
require_relative('../utils/rest')
|
5
|
-
|
4
|
+
|
6
5
|
|
7
6
|
module StarkBank
|
8
7
|
# # Institution object
|
@@ -17,7 +16,7 @@ module StarkBank
|
|
17
16
|
# - name [string]: full version of the institution name. ex: 'Stark Bank S.A.'
|
18
17
|
# - spi_code [string]: SPI code used to identify the institution on Pix transactions. ex: '20018183'
|
19
18
|
# - str_code [string]: STR code used to identify the institution on TED transactions. ex: '123'
|
20
|
-
class Institution <
|
19
|
+
class Institution < StarkCore::Utils::SubResource
|
21
20
|
attr_reader :display_name, :name, :spi_code, :str_code
|
22
21
|
def initialize(display_name: nil, name: nil, spi_code: nil, str_code: nil)
|
23
22
|
@display_name = display_name
|
data/lib/invoice/invoice.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
module StarkBank
|
8
8
|
# # Invoice object
|
@@ -28,19 +28,20 @@ module StarkBank
|
|
28
28
|
# - tags [list of strings, default nil]: list of strings for tagging
|
29
29
|
#
|
30
30
|
# ## Attributes (return-only):
|
31
|
-
# - pdf [string
|
32
|
-
# - link [string
|
33
|
-
# - id [string
|
34
|
-
# - nominal_amount [integer
|
35
|
-
# - fine_amount [integer
|
36
|
-
# - interest_amount [integer
|
37
|
-
# - discount_amount [integer
|
38
|
-
# - brcode [string
|
39
|
-
# - fee [integer
|
40
|
-
# -
|
41
|
-
# -
|
42
|
-
# -
|
43
|
-
|
31
|
+
# - pdf [string]: public Invoice PDF URL. ex: 'https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8'
|
32
|
+
# - link [string]: public Invoice webpage URL. ex: 'https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8'
|
33
|
+
# - id [string]: unique id returned when Invoice is created. ex: '5656565656565656'
|
34
|
+
# - nominal_amount [integer]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
|
35
|
+
# - fine_amount [integer]: Invoice fine value calculated over nominal_amount. ex: 20000
|
36
|
+
# - interest_amount [integer]: Invoice interest value calculated over nominal_amount. ex: 10000
|
37
|
+
# - discount_amount [integer]: Invoice discount value calculated over nominal_amount. ex: 3000
|
38
|
+
# - brcode [string]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
|
39
|
+
# - fee [integer]: fee charged by the Invoice. ex: 65 (= R$ 0.65)
|
40
|
+
# - 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"]
|
41
|
+
# - status [string]: current Invoice status. ex: 'registered' or 'paid'
|
42
|
+
# - created [DateTime]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
43
|
+
# - updated [DateTime]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
44
|
+
class Invoice < StarkCore::Utils::Resource
|
44
45
|
attr_reader :amount, :tax_id, :name, :due, :expiration, :fine, :interest, :discounts, :tags, :pdf, :link, :descriptions, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :id, :brcode, :fee, :status, :transaction_ids, :created, :updated
|
45
46
|
def initialize(
|
46
47
|
amount:, tax_id:, name:, due: nil, expiration: nil, fine: nil, interest: nil, discounts: nil,
|
@@ -49,7 +50,7 @@ module StarkBank
|
|
49
50
|
)
|
50
51
|
super(id)
|
51
52
|
@amount = amount
|
52
|
-
@due =
|
53
|
+
@due = StarkCore::Utils::Checks.check_date_or_datetime(due)
|
53
54
|
@tax_id = tax_id
|
54
55
|
@name = name
|
55
56
|
@expiration = expiration
|
@@ -67,12 +68,12 @@ module StarkBank
|
|
67
68
|
@fee = fee
|
68
69
|
@status = status
|
69
70
|
@transaction_ids = transaction_ids
|
70
|
-
@updated =
|
71
|
-
@created =
|
71
|
+
@updated = StarkCore::Utils::Checks.check_datetime(updated)
|
72
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
72
73
|
if !discounts.nil?
|
73
74
|
checked_discounts = []
|
74
75
|
discounts.each do |discount|
|
75
|
-
discount["due"] =
|
76
|
+
discount["due"] = StarkCore::Utils::Checks.check_date_or_datetime(discount["due"])
|
76
77
|
checked_discounts.push(discount)
|
77
78
|
end
|
78
79
|
@discounts = checked_discounts
|
@@ -159,8 +160,8 @@ module StarkBank
|
|
159
160
|
# ## Return:
|
160
161
|
# - generator of Invoice objects with updated attributes
|
161
162
|
def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
162
|
-
after =
|
163
|
-
before =
|
163
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
164
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
164
165
|
StarkBank::Utils::Rest.get_stream(
|
165
166
|
limit: limit,
|
166
167
|
after: after,
|
@@ -191,8 +192,8 @@ module StarkBank
|
|
191
192
|
# ## Return:
|
192
193
|
# - list of Invoice objects with updated attributes and cursor to retrieve the next page of Invoice objects
|
193
194
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
194
|
-
after =
|
195
|
-
before =
|
195
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
196
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
196
197
|
return StarkBank::Utils::Rest.get_page(
|
197
198
|
cursor: cursor,
|
198
199
|
limit: limit,
|
data/lib/invoice/log.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
require_relative('../utils/checks')
|
6
5
|
require_relative('invoice')
|
7
6
|
|
7
|
+
|
8
8
|
module StarkBank
|
9
9
|
class Invoice
|
10
10
|
# # Invoice::Log object
|
@@ -14,20 +14,20 @@ module StarkBank
|
|
14
14
|
# user, but it can be retrieved to check additional information
|
15
15
|
# on the Invoice.
|
16
16
|
#
|
17
|
-
# ## Attributes:
|
17
|
+
# ## Attributes (return-only):
|
18
18
|
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
19
19
|
# - invoice [Invoice]: Invoice entity to which the log refers to.
|
20
20
|
# - errors [list of strings]: list of errors linked to this Invoice event
|
21
21
|
# - type [string]: type of the Invoice event which triggered the log creation. ex: 'canceled' or 'paid'
|
22
22
|
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
23
|
-
class Log <
|
23
|
+
class Log < StarkCore::Utils::Resource
|
24
24
|
attr_reader :id, :created, :type, :errors, :invoice
|
25
25
|
def initialize(id:, created:, type:, errors:, invoice:)
|
26
26
|
super(id)
|
27
27
|
@type = type
|
28
28
|
@errors = errors
|
29
29
|
@invoice = invoice
|
30
|
-
@created =
|
30
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
31
31
|
end
|
32
32
|
|
33
33
|
# # Retrieve a specific Log
|
@@ -61,8 +61,8 @@ module StarkBank
|
|
61
61
|
# ## Return:
|
62
62
|
# - list of Log objects with updated attributes
|
63
63
|
def self.query(limit: nil, after: nil, before: nil, types: nil, invoice_ids: nil, user: nil)
|
64
|
-
after =
|
65
|
-
before =
|
64
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
65
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
66
66
|
StarkBank::Utils::Rest.get_stream(
|
67
67
|
limit: limit,
|
68
68
|
after: after,
|
@@ -91,8 +91,8 @@ module StarkBank
|
|
91
91
|
# ## Return:
|
92
92
|
# - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
|
93
93
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, invoice_ids: nil, user: nil)
|
94
|
-
after =
|
95
|
-
before =
|
94
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
95
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
96
96
|
return StarkBank::Utils::Rest.get_page(
|
97
97
|
cursor: cursor,
|
98
98
|
limit: limit,
|
@@ -131,7 +131,7 @@ module StarkBank
|
|
131
131
|
created: json['created'],
|
132
132
|
type: json['type'],
|
133
133
|
errors: json['errors'],
|
134
|
-
invoice:
|
134
|
+
invoice: StarkCore::Utils::API.from_api_json(invoice_maker, json['invoice'])
|
135
135
|
)
|
136
136
|
}
|
137
137
|
}
|
data/lib/invoice/payment.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('../utils/sub_resource')
|
4
3
|
require_relative('invoice')
|
5
4
|
|
6
5
|
module StarkBank
|
@@ -20,7 +19,7 @@ module StarkBank
|
|
20
19
|
# - account_type [string]: payer bank account type. ex: 'checking', 'savings', 'salary' or 'payment'
|
21
20
|
# - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
|
22
21
|
# - method [string]: payment method that was used. ex: 'pix'
|
23
|
-
class Payment <
|
22
|
+
class Payment < StarkCore::Utils::SubResource
|
24
23
|
attr_reader :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :amount, :end_to_end_id, :method
|
25
24
|
def initialize(name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, amount:, end_to_end_id:, method:)
|
26
25
|
@name = name
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('../utils/sub_resource')
|
4
3
|
require_relative('../utils/rest')
|
5
|
-
|
4
|
+
|
6
5
|
|
7
6
|
module StarkBank
|
8
7
|
class PaymentPreview
|
@@ -26,7 +25,7 @@ module StarkBank
|
|
26
25
|
# - payer_tax_id [string]: payer tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
|
27
26
|
# - line [string]: Number sequence that identifies the payment. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062'
|
28
27
|
# - bar_code [string]: Bar code number that identifies the payment. ex: '34195819600000000621090063571277307144464000'
|
29
|
-
class BoletoPreview <
|
28
|
+
class BoletoPreview < StarkCore::Utils::SubResource
|
30
29
|
attr_reader :status, :amount, :discount_amount, :fine_amount, :interest_amount, :due, :expiration, :name, :tax_id, :receiver_name, :receiver_tax_id, :payer_name, :payer_tax_id, :line, :bar_code
|
31
30
|
def initialize(status:, amount:, discount_amount:, fine_amount:, interest_amount:, due:, expiration:, name:, tax_id:, receiver_name:, receiver_tax_id:, payer_name:, payer_tax_id:, line:, bar_code:)
|
32
31
|
@status = status
|
@@ -34,8 +33,8 @@ module StarkBank
|
|
34
33
|
@discount_amount = discount_amount
|
35
34
|
@fine_amount = fine_amount
|
36
35
|
@interest_amount = interest_amount
|
37
|
-
@due =
|
38
|
-
@expiration =
|
36
|
+
@due = StarkCore::Utils::Checks.check_datetime(due)
|
37
|
+
@expiration = StarkCore::Utils::Checks.check_datetime(expiration)
|
39
38
|
@name = name
|
40
39
|
@tax_id = tax_id
|
41
40
|
@receiver_name = receiver_name
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('../utils/sub_resource')
|
4
3
|
require_relative('../utils/rest')
|
5
|
-
|
4
|
+
|
6
5
|
|
7
6
|
module StarkBank
|
8
7
|
class PaymentPreview
|
@@ -26,7 +25,7 @@ module StarkBank
|
|
26
25
|
# - reduction_amount [integer]: Current value reduction value in cents that this payment is expecting. ex: 123 (= R$1,23)
|
27
26
|
# - discount_amount [integer]: Current discount value in cents that this payment is expecting. ex: 123 (= R$1,23)
|
28
27
|
# - reconciliation_id [string]: Reconciliation ID linked to this payment. ex: 'txId', 'payment-123'
|
29
|
-
class BrcodePreview <
|
28
|
+
class BrcodePreview < StarkCore::Utils::SubResource
|
30
29
|
attr_reader :status, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :allow_change, :amount, :nominal_amount, :interest_amount, :fine_amount, :reduction_amount, :discount_amount, :reconciliation_id
|
31
30
|
def initialize(status:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, allow_change:, amount:, nominal_amount:, interest_amount:, fine_amount:, reduction_amount:, discount_amount:, reconciliation_id:)
|
32
31
|
@status = status
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
module StarkBank
|
8
8
|
# # PaymentPreview object
|
@@ -10,16 +10,20 @@ module StarkBank
|
|
10
10
|
# A PaymentPreview is used to get information from a payment code before confirming the payment.
|
11
11
|
# This resource can be used to preview BR Codes and bar codes of boleto, tax and utility payments
|
12
12
|
#
|
13
|
-
# ##
|
13
|
+
# ## Parameters (required):
|
14
14
|
# - id [string]: Main identification of the payment. This should be the BR Code for Pix payments and lines or bar codes for payment slips. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062', '00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A'
|
15
|
+
#
|
16
|
+
# ## Parameters (optional):
|
15
17
|
# - scheduled [DateTime or string]: intended payment date. Right now, this parameter only has effect on BrcodePreviews. ex: '2020-04-30'
|
18
|
+
#
|
19
|
+
# ## Attributes (return-only):
|
16
20
|
# - type [string]: Payment type. ex: 'brcode-payment', 'boleto-payment', 'utility-payment' or 'tax-payment'
|
17
21
|
# - payment [BrcodePreview, BoletoPreview, UtilityPreview or TaxPreview]: Information preview of the informed payment.
|
18
|
-
class PaymentPreview <
|
22
|
+
class PaymentPreview < StarkCore::Utils::Resource
|
19
23
|
attr_reader :id, :scheduled, :type, :payment
|
20
24
|
def initialize(id: nil, scheduled: nil, type: nil, payment: nil)
|
21
25
|
super(id)
|
22
|
-
@scheduled =
|
26
|
+
@scheduled = StarkCore::Utils::Checks.check_date(scheduled)
|
23
27
|
@type = type
|
24
28
|
@payment = payment
|
25
29
|
return if type.nil?
|
@@ -31,7 +35,7 @@ module StarkBank
|
|
31
35
|
'utility-payment': StarkBank::PaymentPreview::UtilityPreview.resource
|
32
36
|
}[type.to_sym]
|
33
37
|
|
34
|
-
@payment =
|
38
|
+
@payment = StarkCore::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
|
35
39
|
end
|
36
40
|
|
37
41
|
# # Create PaymentPreviews
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('../utils/sub_resource')
|
4
3
|
require_relative('../utils/rest')
|
5
|
-
|
4
|
+
|
6
5
|
|
7
6
|
module StarkBank
|
8
7
|
class PaymentPreview
|
@@ -16,7 +15,7 @@ module StarkBank
|
|
16
15
|
# - description [string]: tax payment description. ex: "ISS Payment - Iron Throne"
|
17
16
|
# - line [string]: Number sequence that identifies the payment. ex: "85660000006 6 67940064007 5 41190025511 7 00010601813 8"
|
18
17
|
# - bar_code [string]: Bar code number that identifies the payment. ex: "85660000006679400640074119002551100010601813"
|
19
|
-
class TaxPreview <
|
18
|
+
class TaxPreview < StarkCore::Utils::SubResource
|
20
19
|
attr_reader :amount, :name, :description, :line, :bar_code
|
21
20
|
def initialize(amount:, name:, description:, line:, bar_code:)
|
22
21
|
@amount = amount
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('../utils/sub_resource')
|
4
3
|
require_relative('../utils/rest')
|
5
|
-
|
4
|
+
|
6
5
|
|
7
6
|
module StarkBank
|
8
7
|
class PaymentPreview
|
@@ -16,7 +15,7 @@ module StarkBank
|
|
16
15
|
# - description [string]: utility payment description. ex: "Utility Payment - Light Company"
|
17
16
|
# - line [string]: Number sequence that identifies the payment. ex: "82660000002 8 44361143007 7 41190025511 7 00010601813 8"
|
18
17
|
# - bar_code [string]: Bar code number that identifies the payment. ex: "82660000002443611430074119002551100010601813"
|
19
|
-
class UtilityPreview <
|
18
|
+
class UtilityPreview < StarkCore::Utils::SubResource
|
20
19
|
attr_reader :amount, :name, :description, :line, :bar_code
|
21
20
|
def initialize(amount:, name:, description:, line:, bar_code:)
|
22
21
|
@amount = amount
|