starkbank 2.2.1 → 2.6.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 +2 -2
- data/lib/boleto/boleto.rb +53 -14
- data/lib/boleto/log.rb +36 -5
- data/lib/boleto_holmes/boleto_holmes.rb +41 -6
- data/lib/boleto_holmes/log.rb +36 -5
- data/lib/boleto_payment/boleto_payment.rb +42 -9
- data/lib/boleto_payment/log.rb +36 -5
- data/lib/brcode_payment/brcode_payment.rb +56 -17
- data/lib/brcode_payment/log.rb +36 -5
- data/lib/brcode_preview/brcode_preview.rb +5 -3
- data/lib/darf_payment/darf_payment.rb +218 -0
- data/lib/darf_payment/log.rb +125 -0
- data/lib/deposit/deposit.rb +46 -8
- data/lib/deposit/log.rb +36 -5
- data/lib/dict_key/dict_key.rb +45 -9
- data/lib/error.rb +13 -5
- data/lib/event/attempt.rb +125 -0
- data/lib/event/event.rb +44 -8
- data/lib/institution/institution.rb +67 -0
- data/lib/invoice/invoice.rb +81 -15
- data/lib/invoice/log.rb +52 -5
- data/lib/invoice/payment.rb +57 -0
- data/lib/payment_preview/boleto_preview.rb +75 -0
- data/lib/payment_preview/brcode_preview.rb +75 -0
- data/lib/payment_preview/payment_preview.rb +67 -0
- data/lib/payment_preview/tax_preview.rb +45 -0
- data/lib/payment_preview/utility_preview.rb +45 -0
- data/lib/payment_request/payment_request.rb +53 -11
- data/lib/starkbank.rb +14 -0
- data/lib/tax_payment/log.rb +125 -0
- data/lib/tax_payment/tax_payment.rb +203 -0
- data/lib/transaction/transaction.rb +39 -6
- data/lib/transfer/log.rb +36 -5
- data/lib/transfer/transfer.rb +59 -14
- data/lib/user/organization.rb +54 -0
- data/lib/user/project.rb +11 -6
- data/lib/user/user.rb +0 -4
- data/lib/utility_payment/log.rb +36 -5
- data/lib/utility_payment/utility_payment.rb +42 -9
- data/lib/utils/api.rb +1 -0
- data/lib/utils/request.rb +1 -1
- data/lib/utils/resource.rb +2 -21
- data/lib/utils/rest.rb +29 -14
- data/lib/utils/sub_resource.rb +28 -0
- data/lib/utils/url.rb +3 -1
- data/lib/webhook/webhook.rb +30 -9
- data/lib/workspace/workspace.rb +141 -0
- metadata +22 -7
data/lib/event/event.rb
CHANGED
@@ -15,6 +15,8 @@ require_relative('../brcode_payment/log')
|
|
15
15
|
require_relative('../transfer/log')
|
16
16
|
require_relative('../boleto_payment/log')
|
17
17
|
require_relative('../utility_payment/log')
|
18
|
+
require_relative('../tax_payment/log')
|
19
|
+
require_relative('../darf_payment/log')
|
18
20
|
|
19
21
|
module StarkBank
|
20
22
|
# # Webhook Event object
|
@@ -28,13 +30,15 @@ module StarkBank
|
|
28
30
|
# - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
|
29
31
|
# - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
30
32
|
# - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
|
33
|
+
# - 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'
|
31
34
|
# - subscription [string]: service that triggered this event. ex: 'transfer', 'utility-payment'
|
32
35
|
class Event < StarkBank::Utils::Resource
|
33
|
-
attr_reader :id, :log, :created, :is_delivered, :subscription
|
34
|
-
def initialize(id:, log:, created:, is_delivered:, subscription:)
|
36
|
+
attr_reader :id, :log, :created, :is_delivered, :workspace_id, :subscription
|
37
|
+
def initialize(id:, log:, created:, is_delivered:, workspace_id:, subscription:)
|
35
38
|
super(id)
|
36
39
|
@created = StarkBank::Utils::Checks.check_datetime(created)
|
37
40
|
@is_delivered = is_delivered
|
41
|
+
@workspace_id = workspace_id
|
38
42
|
@subscription = subscription
|
39
43
|
|
40
44
|
resource = {
|
@@ -45,6 +49,8 @@ module StarkBank
|
|
45
49
|
'boleto': StarkBank::Boleto::Log.resource,
|
46
50
|
'boleto-payment': StarkBank::BoletoPayment::Log.resource,
|
47
51
|
'utility-payment': StarkBank::UtilityPayment::Log.resource,
|
52
|
+
'tax-payment': StarkBank::TaxPayment::Log.resource,
|
53
|
+
'darf-payment': StarkBank::DarfPayment::Log.resource,
|
48
54
|
'boleto-holmes': StarkBank::BoletoHolmes::Log.resource
|
49
55
|
}[subscription.to_sym]
|
50
56
|
|
@@ -60,7 +66,7 @@ module StarkBank
|
|
60
66
|
# - id [string]: object unique id. ex: '5656565656565656'
|
61
67
|
#
|
62
68
|
# ## Parameters (optional):
|
63
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
69
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
64
70
|
#
|
65
71
|
# ## Return:
|
66
72
|
# - Event object with updated attributes
|
@@ -77,14 +83,14 @@ module StarkBank
|
|
77
83
|
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
78
84
|
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
79
85
|
# - is_delivered [bool, default nil]: bool to filter successfully delivered events. ex: True or False
|
80
|
-
# - user [Project object
|
86
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
81
87
|
#
|
82
88
|
# ## Return:
|
83
89
|
# - generator of Event objects with updated attributes
|
84
90
|
def self.query(limit: nil, after: nil, before: nil, is_delivered: nil, user: nil)
|
85
91
|
after = StarkBank::Utils::Checks.check_date(after)
|
86
92
|
before = StarkBank::Utils::Checks.check_date(before)
|
87
|
-
StarkBank::Utils::Rest.
|
93
|
+
StarkBank::Utils::Rest.get_stream(
|
88
94
|
user: user,
|
89
95
|
limit: limit,
|
90
96
|
after: after,
|
@@ -94,6 +100,35 @@ module StarkBank
|
|
94
100
|
)
|
95
101
|
end
|
96
102
|
|
103
|
+
# # Retrieve paged Events
|
104
|
+
#
|
105
|
+
# Receive a list of up to 100 Event objects previously created in the Stark Bank API and the cursor to the next page.
|
106
|
+
# Use this function instead of query if you want to manually page your requests.
|
107
|
+
#
|
108
|
+
# ## Parameters (optional):
|
109
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
110
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
111
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
112
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
113
|
+
# - is_delivered [bool, default nil]: bool to filter successfully delivered events. ex: True or False
|
114
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
115
|
+
#
|
116
|
+
# ## Return:
|
117
|
+
# - list of Event objects with updated attributes and cursor to retrieve the next page of Event objects
|
118
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, is_delivered: nil, user: nil)
|
119
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
120
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
121
|
+
return StarkBank::Utils::Rest.get_page(
|
122
|
+
cursor: cursor,
|
123
|
+
limit: limit,
|
124
|
+
after: after,
|
125
|
+
before: before,
|
126
|
+
is_delivered: is_delivered,
|
127
|
+
user: user,
|
128
|
+
**resource
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
97
132
|
# # Delete a notification Event
|
98
133
|
#
|
99
134
|
# Delete a of notification Event entity previously created in the Stark Bank API by its ID
|
@@ -102,7 +137,7 @@ module StarkBank
|
|
102
137
|
# - id [string]: Event unique id. ex: '5656565656565656'
|
103
138
|
#
|
104
139
|
# ## Parameters (optional):
|
105
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
140
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
106
141
|
#
|
107
142
|
# ## Return:
|
108
143
|
# - deleted Event object
|
@@ -120,7 +155,7 @@ module StarkBank
|
|
120
155
|
# - is_delivered [bool]: If True and event hasn't been delivered already, event will be set as delivered. ex: True
|
121
156
|
#
|
122
157
|
# ## Parameters (optional):
|
123
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
158
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
124
159
|
#
|
125
160
|
# ## Return:
|
126
161
|
# - target Event with updated attributes
|
@@ -139,7 +174,7 @@ module StarkBank
|
|
139
174
|
# - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
|
140
175
|
#
|
141
176
|
# ## Parameters (optional):
|
142
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
177
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
143
178
|
#
|
144
179
|
# ## Return:
|
145
180
|
# - Parsed Event object
|
@@ -185,6 +220,7 @@ module StarkBank
|
|
185
220
|
log: json['log'],
|
186
221
|
created: json['created'],
|
187
222
|
is_delivered: json['is_delivered'],
|
223
|
+
workspace_id: json['workspace_id'],
|
188
224
|
subscription: json['subscription']
|
189
225
|
)
|
190
226
|
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/sub_resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
|
7
|
+
module StarkBank
|
8
|
+
# # Institution object
|
9
|
+
#
|
10
|
+
# This resource is used to get information on the institutions that are recognized by the Brazilian Central Bank.
|
11
|
+
# Besides the display name and full name, they also include the STR code (used for TEDs) and the SPI Code
|
12
|
+
# (used for Pix) for the institutions. Either of these codes may be empty if the institution is not registered on
|
13
|
+
# that Central Bank service.
|
14
|
+
#
|
15
|
+
# ## Attributes (return-only):
|
16
|
+
# - display_name [string]: short version of the institution name that should be displayed to end users. ex: 'Stark Bank'
|
17
|
+
# - name [string]: full version of the institution name. ex: 'Stark Bank S.A.'
|
18
|
+
# - spi_code [string]: SPI code used to identify the institution on Pix transactions. ex: '20018183'
|
19
|
+
# - str_code [string]: STR code used to identify the institution on TED transactions. ex: '123'
|
20
|
+
class Institution < StarkBank::Utils::SubResource
|
21
|
+
attr_reader :display_name, :name, :spi_code, :str_code
|
22
|
+
def initialize(display_name: nil, name: nil, spi_code: nil, str_code: nil)
|
23
|
+
@display_name = display_name
|
24
|
+
@name = name
|
25
|
+
@spi_code = spi_code
|
26
|
+
@str_code = str_code
|
27
|
+
end
|
28
|
+
|
29
|
+
# # Retrieve Bacen Institutions
|
30
|
+
#
|
31
|
+
# Receive a list of Institution objects that are recognized by the Brazilian Central bank for Pix and TED transactions
|
32
|
+
#
|
33
|
+
# ## Parameters (optional):
|
34
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
35
|
+
# - search [string, default nil]: part of the institution name to be searched. ex: 'stark'
|
36
|
+
# - spi_codes [list of strings, default nil]: list of SPI (Pix) codes to be searched. ex: ['20018183']
|
37
|
+
# - str_codes [list of strings, default nil]: list of STR (TED) codes to be searched. ex: ['260']
|
38
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
39
|
+
#
|
40
|
+
# ## Return:
|
41
|
+
# - list of Institution objects with updated attributes
|
42
|
+
def self.query(limit: nil, search: nil, spi_codes: nil, str_codes: nil, user: nil)
|
43
|
+
StarkBank::Utils::Rest.get_page(
|
44
|
+
limit: limit,
|
45
|
+
search: search,
|
46
|
+
spi_codes: spi_codes,
|
47
|
+
str_codes: str_codes,
|
48
|
+
user: user,
|
49
|
+
**resource
|
50
|
+
).first
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.resource
|
54
|
+
{
|
55
|
+
resource_name: 'Institution',
|
56
|
+
resource_maker: proc { |json|
|
57
|
+
Institution.new(
|
58
|
+
display_name: json['display_name'],
|
59
|
+
name: json['name'],
|
60
|
+
spi_code: json['spi_code'],
|
61
|
+
str_code: json['str_code']
|
62
|
+
)
|
63
|
+
}
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/invoice/invoice.rb
CHANGED
@@ -10,6 +10,8 @@ module StarkBank
|
|
10
10
|
# When you initialize an Invoice, the entity will not be automatically
|
11
11
|
# sent to the Stark Bank API. The 'create' function sends the objects
|
12
12
|
# to the Stark Bank API and returns the list of created objects.
|
13
|
+
# To create scheduled Invoices, which will display the discount, interest, etc. on the final users banking interface,
|
14
|
+
# use dates instead of datetimes on the "due" and "discounts" fields.
|
13
15
|
#
|
14
16
|
# ## Parameters (required):
|
15
17
|
# - amount [integer]: Invoice value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34)
|
@@ -26,6 +28,8 @@ module StarkBank
|
|
26
28
|
# - tags [list of strings, default nil]: list of strings for tagging
|
27
29
|
#
|
28
30
|
# ## Attributes (return-only):
|
31
|
+
# - pdf [string, default nil]: public Invoice PDF URL. ex: 'https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8'
|
32
|
+
# - link [string, default nil]: public Invoice webpage URL. ex: 'https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8'
|
29
33
|
# - id [string, default nil]: unique id returned when Invoice is created. ex: '5656565656565656'
|
30
34
|
# - nominal_amount [integer, default nil]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
|
31
35
|
# - fine_amount [integer, default nil]: Invoice fine value calculated over nominal_amount. ex: 20000
|
@@ -37,22 +41,23 @@ module StarkBank
|
|
37
41
|
# - created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
38
42
|
# - updated [DateTime, default nil]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
39
43
|
class Invoice < StarkBank::Utils::Resource
|
40
|
-
attr_reader :amount, :tax_id, :name, :due, :expiration, :fine, :interest, :discounts, :tags, :descriptions, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :id, :brcode, :fee, :status, :created, :updated
|
44
|
+
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
|
41
45
|
def initialize(
|
42
46
|
amount:, tax_id:, name:, due: nil, expiration: nil, fine: nil, interest: nil, discounts: nil,
|
43
|
-
tags: nil, descriptions: nil, nominal_amount: nil, fine_amount: nil, interest_amount: nil,
|
44
|
-
discount_amount: nil, id: nil, brcode: nil, fee: nil, status: nil, created: nil, updated: nil
|
47
|
+
tags: nil, pdf: nil, link: nil, descriptions: nil, nominal_amount: nil, fine_amount: nil, interest_amount: nil,
|
48
|
+
discount_amount: nil, id: nil, brcode: nil, fee: nil, status: nil, transaction_ids: nil, created: nil, updated: nil
|
45
49
|
)
|
46
50
|
super(id)
|
47
51
|
@amount = amount
|
48
|
-
@due = StarkBank::Utils::Checks.
|
52
|
+
@due = StarkBank::Utils::Checks.check_date_or_datetime(due)
|
49
53
|
@tax_id = tax_id
|
50
54
|
@name = name
|
51
55
|
@expiration = expiration
|
52
56
|
@fine = fine
|
53
57
|
@interest = interest
|
54
|
-
@discounts = discounts
|
55
58
|
@tags = tags
|
59
|
+
@pdf = pdf
|
60
|
+
@link = link
|
56
61
|
@descriptions = descriptions
|
57
62
|
@nominal_amount = nominal_amount
|
58
63
|
@fine_amount = fine_amount
|
@@ -61,8 +66,17 @@ module StarkBank
|
|
61
66
|
@brcode = brcode
|
62
67
|
@fee = fee
|
63
68
|
@status = status
|
69
|
+
@transaction_ids = transaction_ids
|
64
70
|
@updated = StarkBank::Utils::Checks.check_datetime(updated)
|
65
71
|
@created = StarkBank::Utils::Checks.check_datetime(created)
|
72
|
+
if !discounts.nil?
|
73
|
+
checked_discounts = []
|
74
|
+
discounts.each do |discount|
|
75
|
+
discount["due"] = StarkBank::Utils::Checks.check_date_or_datetime(discount["due"])
|
76
|
+
checked_discounts.push(discount)
|
77
|
+
end
|
78
|
+
@discounts = checked_discounts
|
79
|
+
end
|
66
80
|
end
|
67
81
|
|
68
82
|
# # Create Invoices
|
@@ -73,7 +87,7 @@ module StarkBank
|
|
73
87
|
# - invoices [list of Invoice objects]: list of Invoice objects to be created in the API
|
74
88
|
#
|
75
89
|
# ## Parameters (optional):
|
76
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
90
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
77
91
|
#
|
78
92
|
# ## Return:
|
79
93
|
# - list of Invoice objects with updated attributes
|
@@ -89,7 +103,7 @@ module StarkBank
|
|
89
103
|
# - id [string]: object unique id. ex: '5656565656565656'
|
90
104
|
#
|
91
105
|
# ## Parameters (optional):
|
92
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
106
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
93
107
|
#
|
94
108
|
# ## Return:
|
95
109
|
# - Invoice object with updated attributes
|
@@ -105,12 +119,12 @@ module StarkBank
|
|
105
119
|
# - id [string]: object unique id. ex: '5656565656565656'
|
106
120
|
#
|
107
121
|
# ## Parameters (optional):
|
108
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
122
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
109
123
|
#
|
110
124
|
# ## Return:
|
111
125
|
# - Invoice pdf file
|
112
126
|
def self.pdf(id, user: nil)
|
113
|
-
StarkBank::Utils::Rest.
|
127
|
+
StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
|
114
128
|
end
|
115
129
|
|
116
130
|
# # Retrieve a specific Invoice QR Code file
|
@@ -121,12 +135,12 @@ module StarkBank
|
|
121
135
|
# - id [string]: object unique id. ex: '5656565656565656'
|
122
136
|
#
|
123
137
|
# ## Parameters (optional):
|
124
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
138
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
125
139
|
#
|
126
140
|
# ## Return:
|
127
141
|
# - Invoice QR Code png blob
|
128
142
|
def self.qrcode(id, user: nil)
|
129
|
-
StarkBank::Utils::Rest.
|
143
|
+
StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'qrcode', **resource)
|
130
144
|
end
|
131
145
|
|
132
146
|
# # Retrieve Invoices
|
@@ -135,19 +149,52 @@ module StarkBank
|
|
135
149
|
#
|
136
150
|
# ## Parameters (optional):
|
137
151
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
138
|
-
# - after [Date
|
139
|
-
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
152
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
153
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
140
154
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
141
155
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
142
156
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
143
|
-
# - user [Project object
|
157
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
144
158
|
#
|
145
159
|
# ## Return:
|
146
160
|
# - generator of Invoice objects with updated attributes
|
147
161
|
def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
148
162
|
after = StarkBank::Utils::Checks.check_date(after)
|
149
163
|
before = StarkBank::Utils::Checks.check_date(before)
|
150
|
-
StarkBank::Utils::Rest.
|
164
|
+
StarkBank::Utils::Rest.get_stream(
|
165
|
+
limit: limit,
|
166
|
+
after: after,
|
167
|
+
before: before,
|
168
|
+
status: status,
|
169
|
+
tags: tags,
|
170
|
+
ids: ids,
|
171
|
+
user: user,
|
172
|
+
**resource
|
173
|
+
)
|
174
|
+
end
|
175
|
+
|
176
|
+
# # Retrieve paged Invoices
|
177
|
+
#
|
178
|
+
# Receive a list of up to 100 Invoice objects previously created in the Stark Bank API and the cursor to the next page.
|
179
|
+
# Use this function instead of query if you want to manually page your requests.
|
180
|
+
#
|
181
|
+
# ## Parameters (optional):
|
182
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
183
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
184
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
185
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
186
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
187
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
188
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
189
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
190
|
+
#
|
191
|
+
# ## Return:
|
192
|
+
# - list of Invoice objects with updated attributes and cursor to retrieve the next page of Invoice objects
|
193
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
194
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
195
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
196
|
+
return StarkBank::Utils::Rest.get_page(
|
197
|
+
cursor: cursor,
|
151
198
|
limit: limit,
|
152
199
|
after: after,
|
153
200
|
before: before,
|
@@ -178,6 +225,22 @@ module StarkBank
|
|
178
225
|
StarkBank::Utils::Rest.patch_id(id: id, status: status, amount: amount, due: due, expiration: expiration, user: user, **resource)
|
179
226
|
end
|
180
227
|
|
228
|
+
# # Retrieve a specific Invoice payment information
|
229
|
+
#
|
230
|
+
# Receive the Invoice::Payment sub-resource associated with a paid Invoice.
|
231
|
+
#
|
232
|
+
# ## Parameters (required):
|
233
|
+
# - id [string]: Invoice unique id. ex: '5656565656565656'
|
234
|
+
#
|
235
|
+
# ## Parameters (optional):
|
236
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
237
|
+
#
|
238
|
+
# ## Return:
|
239
|
+
# - Invoice::Payment sub-resource
|
240
|
+
def self.payment(id, user: nil)
|
241
|
+
StarkBank::Utils::Rest.get_sub_resource(id: id, user: user, **resource, **StarkBank::Invoice::Payment.resource)
|
242
|
+
end
|
243
|
+
|
181
244
|
def self.resource
|
182
245
|
{
|
183
246
|
resource_name: 'Invoice',
|
@@ -193,6 +256,8 @@ module StarkBank
|
|
193
256
|
interest: json['interest'],
|
194
257
|
discounts: json['discounts'],
|
195
258
|
tags: json['tags'],
|
259
|
+
pdf: json['pdf'],
|
260
|
+
link: json['link'],
|
196
261
|
descriptions: json['descriptions'],
|
197
262
|
nominal_amount: json['nominal_amount'],
|
198
263
|
fine_amount: json['fine_amount'],
|
@@ -201,6 +266,7 @@ module StarkBank
|
|
201
266
|
brcode: json['brcode'],
|
202
267
|
fee: json['fee'],
|
203
268
|
status: json['status'],
|
269
|
+
transaction_ids: json['transaction_ids'],
|
204
270
|
updated: json['updated'],
|
205
271
|
created: json['created'],
|
206
272
|
)
|
data/lib/invoice/log.rb
CHANGED
@@ -38,7 +38,7 @@ module StarkBank
|
|
38
38
|
# - id [string]: object unique id. ex: '5656565656565656'
|
39
39
|
#
|
40
40
|
# ## Parameters (optional):
|
41
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
41
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
42
42
|
#
|
43
43
|
# ## Return:
|
44
44
|
# - Log object with updated attributes
|
@@ -52,18 +52,18 @@ module StarkBank
|
|
52
52
|
#
|
53
53
|
# ## Parameters (optional):
|
54
54
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
55
|
-
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
56
|
-
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
55
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
56
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
57
57
|
# - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
|
58
58
|
# - invoice_ids [list of strings, default nil]: list of Invoice ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
59
|
-
# - user [Project object
|
59
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
60
60
|
#
|
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
64
|
after = StarkBank::Utils::Checks.check_date(after)
|
65
65
|
before = StarkBank::Utils::Checks.check_date(before)
|
66
|
-
StarkBank::Utils::Rest.
|
66
|
+
StarkBank::Utils::Rest.get_stream(
|
67
67
|
limit: limit,
|
68
68
|
after: after,
|
69
69
|
before: before,
|
@@ -74,6 +74,53 @@ module StarkBank
|
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
77
|
+
# # Retrieve paged Logs
|
78
|
+
#
|
79
|
+
# Receive a list of up to 100 Log objects previously created in the Stark Bank API and the cursor to the next page.
|
80
|
+
# Use this function instead of query if you want to manually page your requests.
|
81
|
+
#
|
82
|
+
# ## Parameters (optional):
|
83
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
84
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
85
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
86
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
87
|
+
# - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'registered'
|
88
|
+
# - boleto_ids [list of strings, default nil]: list of Boleto ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
89
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
90
|
+
#
|
91
|
+
# ## Return:
|
92
|
+
# - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
|
93
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, invoice_ids: nil, user: nil)
|
94
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
95
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
96
|
+
return StarkBank::Utils::Rest.get_page(
|
97
|
+
cursor: cursor,
|
98
|
+
limit: limit,
|
99
|
+
after: after,
|
100
|
+
before: before,
|
101
|
+
types: types,
|
102
|
+
invoice_ids: invoice_ids,
|
103
|
+
user: user,
|
104
|
+
**resource
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
# # Retrieve a specific Invoice::Log pdf file
|
109
|
+
#
|
110
|
+
# Receive a single Invoice::Log pdf file generated in the Stark Bank API by passing its id.
|
111
|
+
#
|
112
|
+
# ## Parameters (required):
|
113
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
114
|
+
#
|
115
|
+
# ## Parameters (optional):
|
116
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
117
|
+
#
|
118
|
+
# ## Return:
|
119
|
+
# - Invoice::Log pdf file
|
120
|
+
def self.pdf(id, user: nil)
|
121
|
+
StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
|
122
|
+
end
|
123
|
+
|
77
124
|
def self.resource
|
78
125
|
invoice_maker = StarkBank::Invoice.resource[:resource_maker]
|
79
126
|
{
|