starkbank 2.7.0 → 2.9.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.
@@ -0,0 +1,215 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+
6
+ module StarkBank
7
+ # # CorporateHolder object
8
+ #
9
+ # The CorporateHolder describes a card holder that may group several cards.
10
+ #
11
+ # When you initialize a CorporateHolder, the entity will not be automatically
12
+ # created in the Stark Bank API. The 'create' function sends the objects
13
+ # to the Stark Bank API and returns the created object.
14
+ #
15
+ # ## Parameters (required):
16
+ # - name [string]: card holder name. ex: "Tony Stark"
17
+ #
18
+ # ## Parameters (optional):
19
+ # - center_id [string, default nil]: target cost center ID. ex: "5656565656565656"
20
+ # - permissions [list of Permission objects, default nil]: list of Permission object representing access granted to an user for a particular cardholder.
21
+ # - rules [list of CorporateRule objects, default nil]: [EXPANDABLE] list of holder spending rules.
22
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
23
+ #
24
+ # ## Attributes (return-only):
25
+ # - id [string]: unique id returned when CorporateHolder is created. ex: '5656565656565656'
26
+ # - status [string]: current CorporateHolder status. ex: 'active', 'blocked', 'canceled'
27
+ # - updated [DateTime]: latest update datetime for the CorporateHolder. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
28
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
29
+ class CorporateHolder < StarkCore::Utils::Resource
30
+ attr_reader :id, :name, :center_id, :permissions, :rules, :tags, :status, :updated, :created
31
+ def initialize(
32
+ name:, center_id: nil, permissions: nil, rules: nil, tags: nil, id: nil, status: nil, updated: nil, created: nil
33
+ )
34
+ super(id)
35
+ @name = name
36
+ @center_id = center_id
37
+ @permissions = Permission.parse_permissions(permissions)
38
+ @rules = StarkBank::CorporateRule.parse_rules(rules)
39
+ @tags = tags
40
+ @status = status
41
+ @created = StarkCore::Utils::Checks.check_datetime(created)
42
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
43
+ end
44
+
45
+ # # Create CorporateHolders
46
+ #
47
+ # Send a list of CorporateHolder objects for creation in the Stark Bank API
48
+ #
49
+ # ## Parameters (required):
50
+ # - holders [list of CorporateHolder objects]: list of CorporateHolder objects to be created in the API
51
+ #
52
+ # ## Parameters (optional):
53
+ # - expand [list of strings, default nil]: fields to expand information. Options: ['rules']
54
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
55
+ #
56
+ # ## Return:
57
+ # - list of CorporateHolder objects with updated attributes
58
+ def self.create(holders:, expand: nil, user: nil)
59
+ StarkBank::Utils::Rest.post(entities: holders, expand: expand, user: user, **resource)
60
+ end
61
+
62
+ # # Retrieve a specific CorporateHolder
63
+ #
64
+ # Receive a single CorporateHolder object previously created in the Stark Bank API by its id
65
+ #
66
+ # ## Parameters (required):
67
+ # - id [string]: object unique id. ex: '5656565656565656'
68
+ #
69
+ # ## Parameters (optional):
70
+ # - expand [list of strings, default nil]: fields to expand information. ex: ['rules']
71
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
72
+ #
73
+ # ## Return:
74
+ # - CorporateHolder object with updated attributes
75
+ def self.get(id, expand: nil, user: nil)
76
+ StarkBank::Utils::Rest.get_id(id: id, expand: expand, user: user, **resource)
77
+ end
78
+
79
+ # # Retrieve CorporateHolders
80
+ #
81
+ # Receive a generator of CorporateHolder objects previously created in the Stark Bank API
82
+ #
83
+ # ## Parameters (optional):
84
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
85
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
86
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
87
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled']
88
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
89
+ # - expand [string, default nil]: fields to expand information. ex: ['rules']
90
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
91
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
92
+ #
93
+ # ## Return:
94
+ # - generator of CorporateHolders objects with updated attributes
95
+ def self.query(limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil, user: nil)
96
+ after = StarkCore::Utils::Checks.check_date(after)
97
+ before = StarkCore::Utils::Checks.check_date(before)
98
+ StarkBank::Utils::Rest.get_stream(
99
+ limit: limit,
100
+ ids: ids,
101
+ after: after,
102
+ before: before,
103
+ status: status,
104
+ tags: tags,
105
+ expand: expand,
106
+ user: user,
107
+ **resource
108
+ )
109
+ end
110
+
111
+ # # Retrieve paged CorporateHolders
112
+ #
113
+ # Receive a list of up to 100 CorporateHolders objects previously created in the Stark Bank API and the cursor to the next page.
114
+ # Use this function instead of query if you want to manually page your logs.
115
+ #
116
+ # ## Parameters (optional):
117
+ # - cursor [string, default nil]: cursor returned on the previous page function call.
118
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
119
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
120
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
121
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled']
122
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
123
+ # - expand [string, default nil]: fields to expand information. ex: ['rules']
124
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
125
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
126
+ #
127
+ # ## Return:
128
+ # - list of CorporateHolders objects with updated attributes
129
+ # - cursor to retrieve the next page of CorporateHolders objects
130
+ def self.page(cursor: nil, limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil,
131
+ user: nil)
132
+ after = StarkCore::Utils::Checks.check_date(after)
133
+ before = StarkCore::Utils::Checks.check_date(before)
134
+ StarkBank::Utils::Rest.get_page(
135
+ cursor: cursor,
136
+ limit: limit,
137
+ ids: ids,
138
+ after: after,
139
+ before: before,
140
+ status: status,
141
+ tags: tags,
142
+ expand: expand,
143
+ user: user,
144
+ **resource
145
+ )
146
+ end
147
+
148
+ # # Update CorporateHolder entity
149
+ #
150
+ # Update a CorporateHolder by passing id.
151
+ #
152
+ # ## Parameters (required):
153
+ # - id [string]: CorporateHolder id. ex: '5656565656565656'
154
+ #
155
+ # ## Parameters (optional):
156
+ # - center_id [string, default nil]: target cost center ID. ex: "5656565656565656"
157
+ # - permissions [list of Permission object, default nil]: list of Permission object representing access granted to an user for a particular cardholder.
158
+ # - status [string, default nil]: You may block the CorporateHolder by passing 'blocked' in the status
159
+ # - name [string, default nil]: card holder name.
160
+ # - tags [list of strings, default nil]: list of strings for tagging
161
+ # - rules [list of CorporateRule objects, default nil]: list of objects that represent the holder's spending rules.
162
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
163
+ #
164
+ # ## Return:
165
+ # - target CorporateHolder with updated attributes
166
+ def self.update(id, center_id: nil, permissions: nil, status: nil, name: nil, tags: nil, rules: nil, user: nil)
167
+ StarkBank::Utils::Rest.patch_id(
168
+ id: id,
169
+ center_id: center_id,
170
+ permissions: permissions,
171
+ status: status,
172
+ name: name,
173
+ tags: tags,
174
+ rules: rules,
175
+ user: user,
176
+ **resource
177
+ )
178
+ end
179
+
180
+ # # Cancel a CorporateHolder entity
181
+ #
182
+ # Cancel a CorporateHolder entity previously created in the Stark Bank API
183
+ #
184
+ # ## Parameters (required):
185
+ # - id [string]: CorporateHolder unique id. ex: '5656565656565656'
186
+ #
187
+ # ## Parameters (optional):
188
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
189
+ #
190
+ # ## Return:
191
+ # - canceled CorporateHolder object
192
+ def self.cancel(id, user: nil)
193
+ StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
194
+ end
195
+
196
+ def self.resource
197
+ {
198
+ resource_name: 'CorporateHolder',
199
+ resource_maker: proc { |json|
200
+ CorporateHolder.new(
201
+ id: json['id'],
202
+ name: json['name'],
203
+ center_id: json['center_id'],
204
+ permissions: json['permissions'],
205
+ rules: json['rules'],
206
+ tags: json['tags'],
207
+ status: json['status'],
208
+ updated: json['updated'],
209
+ created: json['created']
210
+ )
211
+ }
212
+ }
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('corporateholder')
5
+ require_relative('../utils/rest')
6
+
7
+ module StarkBank
8
+ class CorporateHolder
9
+ # # CorporateHolder::Log object
10
+ #
11
+ # Every time a CorporateHolder entity is updated, a corresponding CorporateHolder::Log is generated for the entity. This
12
+ # log is never generated by the user, but it can be retrieved to check additional information on the CorporateHolder.
13
+ #
14
+ # ## Attributes (return-only):
15
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
16
+ # - holder [CorporateHolder]: CorporateHolder entity to which the log refers to.
17
+ # - type [string]: type of the CorporateHolder event which triggered the log creation. ex: 'blocked', 'canceled', 'created', 'unblocked', 'updated'
18
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
+ class Log < StarkCore::Utils::Resource
20
+ attr_reader :id, :created, :type, :holder
21
+ def initialize(id:, created:, type:, holder:)
22
+ super(id)
23
+ @type = type
24
+ @holder = holder
25
+ @created = StarkCore::Utils::Checks.check_datetime(created)
26
+ end
27
+
28
+ # # Retrieve a specific CorporateHolder::Log
29
+ #
30
+ # Receive a single CorporateHolder::Log object previously created by the Stark Bank API by passing its id
31
+ #
32
+ # ## Parameters (required):
33
+ # - id [string]: object unique id. ex: '5656565656565656'
34
+ #
35
+ # ## Parameters (optional):
36
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
37
+ #
38
+ # ## Return:
39
+ # - CorporateHolder::Log object with updated attributes
40
+ def self.get(id, user: nil)
41
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
42
+ end
43
+
44
+ # # Retrieve CorporateHolder::Logs
45
+ #
46
+ # Receive a generator of CorporateHolder::Log objects previously created in the Stark Bank API
47
+ #
48
+ # ## Parameters (optional):
49
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Max = 100. ex: 35
50
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
51
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
52
+ # - types [list of strings, default nil]: filter for log event types. ex: ['created', 'blocked']
53
+ # - holder_ids [list of strings, default nil]: list of CorporateHolder ids to filter logs. ex: ['5656565656565656', '4545454545454545']
54
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
55
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
56
+ #
57
+ # ## Return:
58
+ # - generator of CorporateHolder::Log objects with updated attributes
59
+ def self.query(limit: nil, after: nil, before: nil, types: nil, holder_ids: nil, user: nil)
60
+ after = StarkCore::Utils::Checks.check_date(after)
61
+ before = StarkCore::Utils::Checks.check_date(before)
62
+ StarkBank::Utils::Rest.get_stream(
63
+ limit: limit,
64
+ after: after,
65
+ before: before,
66
+ types: types,
67
+ holder_ids: holder_ids,
68
+ user: user,
69
+ **resource
70
+ )
71
+ end
72
+
73
+ # # Retrieve paged CorporateHolder::Logs
74
+ #
75
+ # Receive a list of up to 100 CorporateHolder::Log objects previously created in the Stark Bank API and the cursor to the next page.
76
+ # Use this function instead of query if you want to manually page your holders.
77
+ #
78
+ # ## Parameters (optional):
79
+ # - cursor [string, default nil]: cursor returned on the previous page function call
80
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
81
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
82
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
83
+ # - types [list of strings, default nil]: filter for log event types. ex: ['created', 'blocked']
84
+ # - holder_ids [list of strings, default nil]: list of CorporateHolder ids to filter logs. ex: ['5656565656565656', '4545454545454545']
85
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
86
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
87
+ #
88
+ # ## Return:
89
+ # - list of CorporateHolder::Log objects with updated attributes
90
+ # - cursor to retrieve the next page of Log objects
91
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, holder_ids: nil, user: nil)
92
+ after = StarkCore::Utils::Checks.check_date(after)
93
+ before = StarkCore::Utils::Checks.check_date(before)
94
+ StarkBank::Utils::Rest.get_page(
95
+ cursor: cursor,
96
+ limit: limit,
97
+ after: after,
98
+ before: before,
99
+ types: types,
100
+ holder_ids: holder_ids,
101
+ user: user,
102
+ **resource
103
+ )
104
+ end
105
+
106
+ def self.resource
107
+ request_maker = StarkBank::CorporateHolder.resource[:resource_maker]
108
+ {
109
+ resource_name: 'CorporateHolderLog',
110
+ resource_maker: proc { |json|
111
+ Log.new(
112
+ id: json['id'],
113
+ created: json['created'],
114
+ type: json['type'],
115
+ holder: StarkCore::Utils::API.from_api_json(request_maker, json['holder'])
116
+ )
117
+ }
118
+ }
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+
5
+ module StarkBank
6
+ class CorporateHolder
7
+ # # CorporateHolder::Permission object
8
+ #
9
+ # The CorporateHolder::Permission object modifies the behavior of CorporateHolder objects when passed as an argument upon their creation.
10
+ #
11
+ # ## Parameters (optional):
12
+ # - owner_id [string, default nil]: owner unique id. ex: "5656565656565656"
13
+ # - owner_type [string, default nil]: owner type. ex: "project"
14
+ #
15
+ # ## Attributes (return-only):
16
+ # - owner_email [string]: email address of the owner. ex: "tony@starkbank.com
17
+ # - owner_name [string]: name of the owner. ex: "Tony Stark"
18
+ # - owner_picture_url [string]: Profile picture Url of the owner. ex: "https://storage.googleapis.com/api-ms-workspace-sbx.appspot.com/pictures/member/6227829385592832?20230404164942"
19
+ # - owner_status [string]: current owner status. ex: "active", "blocked", "canceled"
20
+ # - created [DateTime]: creation datetime for the Permission. ex: ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
21
+ class Permission < StarkCore::Utils::SubResource
22
+ attr_reader :owner_email, :owner_id, :owner_name, :owner_picture_url, :owner_status, :owner_type, :created
23
+ def initialize(owner_email: nil, owner_id: nil, owner_name: nil, owner_picture_url: nil, owner_status: nil, owner_type: nil, created: nil)
24
+ @owner_email = owner_email
25
+ @owner_id = owner_id
26
+ @owner_name = owner_name
27
+ @owner_picture_url = owner_picture_url
28
+ @owner_status = owner_status
29
+ @owner_type = owner_type
30
+ @created = StarkCore::Utils::Checks.check_datetime(created)
31
+ end
32
+
33
+ def self.parse_permissions(permissions)
34
+ resource_maker = StarkBank::CorporateHolder::Permission.resource[:resource_maker]
35
+ return permissions if permissions.nil?
36
+
37
+ parsed_permissions = []
38
+ permissions.each do |permission|
39
+ unless permission.is_a? Permission
40
+ permission = StarkCore::Utils::API.from_api_json(resource_maker, permission)
41
+ end
42
+ parsed_permissions << permission
43
+ end
44
+ return parsed_permissions
45
+ end
46
+
47
+ def self.resource
48
+ {
49
+ resource_name: 'Permission',
50
+ resource_maker: proc { |json|
51
+ Permission.new(
52
+ owner_email: json['owner_email'],
53
+ owner_id: json['owner_id'],
54
+ owner_name: json['owner_name'],
55
+ owner_picture_url: json['owner_picture_url'],
56
+ owner_status: json['owner_status'],
57
+ owner_type: json['owner_type'],
58
+ created: json['created'],
59
+ )
60
+ }
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+
6
+ module StarkBank
7
+ # # CorporateInvoice object
8
+ #
9
+ # The CorporateInvoice objects created in your Workspace load your Corporate balance when paid.
10
+ #
11
+ # When you initialize a CorporateInvoice, the entity will not be automatically
12
+ # created in the Stark Bank API. The 'create' function sends the objects
13
+ # to the Stark Bank API and returns the created object.
14
+ #
15
+ # ## Parameters (required):
16
+ # - amount [integer]: CorporateInvoice value in cents. ex: 1234 (= R$ 12.34)
17
+ #
18
+ # ## Parameters (optional):
19
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
20
+ #
21
+ # ## Attributes (return-only):
22
+ # - id [string]: unique id returned when CorporateInvoice is created. ex: '5656565656565656'
23
+ # - name [string, default sub-issuer name]: payer name. ex: 'Iron Bank S.A.'
24
+ # - tax_id [string, default sub-issuer tax ID]: payer tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
25
+ # - brcode [string]: BR Code for the Invoice payment. ex: '00020101021226930014br.gov.bcb.pix2571brcode-h.development.starkbank.com/v2/d7f6546e194d4c64a153e8f79f1c41ac5204000053039865802BR5925Stark Bank S.A. - Institu6009Sao Paulo62070503***63042109'
26
+ # - due [DateTime, Date or string]: Invoice due and expiration date in UTC ISO format. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0), Date.new(2020, 3, 10) or '2020-03-10T10:30:00.000000+00:00'
27
+ # - link [string]: public Invoice webpage URL. ex: 'https://starkbank-card-issuer.development.starkbank.com/invoicelink/d7f6546e194d4c64a153e8f79f1c41ac'
28
+ # - status [string]: current CorporateInvoice status. ex: 'created', 'expired', 'overdue', 'paid'
29
+ # - corporate_transaction_id [string]: ledger transaction ids linked to this CorporateInvoice. ex: 'corporate-invoice/5656565656565656'
30
+ # - updated [DateTime]: latest update datetime for the CorporateInvoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
31
+ # - created [DateTime]: creation datetime for the CorporateInvoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
+ class CorporateInvoice < StarkCore::Utils::Resource
33
+ attr_reader :id, :amount, :tax_id, :name, :tags, :brcode, :due, :link, :status, :corporate_transaction_id, :updated, :created
34
+ def initialize(
35
+ amount:, id: nil, tax_id: nil, name: nil, tags: nil, brcode: nil, due: nil, link: nil, status: nil, corporate_transaction_id: nil,
36
+ updated: nil, created: nil
37
+ )
38
+ super(id)
39
+ @amount = amount
40
+ @tax_id = tax_id
41
+ @name = name
42
+ @tags = tags
43
+ @brcode = brcode
44
+ @due = due
45
+ @link = link
46
+ @status = status
47
+ @corporate_transaction_id = corporate_transaction_id
48
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
49
+ @created = StarkCore::Utils::Checks.check_datetime(created)
50
+ end
51
+
52
+ # # Create a CorporateInvoice
53
+ #
54
+ # Send a single CorporateInvoice object for creation in the Stark Bank API
55
+ #
56
+ # ## Parameters (required):
57
+ # - invoice [CorporateInvoice object]: CorporateInvoice object to be created in the API.
58
+ #
59
+ # ## Parameters (optional):
60
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
61
+ #
62
+ # ## Return:
63
+ # - CorporateInvoice object with updated attributes
64
+ def self.create(invoice, user: nil)
65
+ StarkBank::Utils::Rest.post_single(entity: invoice, user: user, **resource)
66
+ end
67
+
68
+ # # Retrieve CorporateInvoices
69
+ #
70
+ # Receive a generator of CorporateInvoices objects previously created in the Stark Bank API
71
+ #
72
+ # ## Parameters (optional):
73
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
74
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
75
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
76
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['created', 'expired', 'overdue', 'paid']
77
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
78
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
79
+ #
80
+ # ## Return:
81
+ # - generator of CorporateInvoices objects with updated attributes
82
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, user: nil)
83
+ after = StarkCore::Utils::Checks.check_date(after)
84
+ before = StarkCore::Utils::Checks.check_date(before)
85
+ StarkBank::Utils::Rest.get_stream(
86
+ limit: limit,
87
+ after: after,
88
+ before: before,
89
+ status: status,
90
+ tags: tags,
91
+ user: user,
92
+ **resource
93
+ )
94
+ end
95
+
96
+ # # Retrieve paged CorporateInvoices
97
+ #
98
+ # Receive a list of up to 100 CorporateInvoices objects previously created in the Stark Bank API and the cursor to the next page.
99
+ # Use this function instead of query if you want to manually page your logs.
100
+ #
101
+ # ## Parameters (optional):
102
+ # - cursor [string, default nil]: cursor returned on the previous page function call.
103
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
104
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
105
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
106
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['created', 'expired', 'overdue', 'paid']
107
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
108
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
109
+ #
110
+ # ## Return:
111
+ # - list of CorporateInvoice objects with updated attributes
112
+ # - cursor to retrieve the next page of CorporateInvoice objects
113
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, user: nil)
114
+ after = StarkCore::Utils::Checks.check_date(after)
115
+ before = StarkCore::Utils::Checks.check_date(before)
116
+ StarkBank::Utils::Rest.get_page(
117
+ cursor: cursor,
118
+ limit: limit,
119
+ after: after,
120
+ before: before,
121
+ status: status,
122
+ tags: tags,
123
+ user: user,
124
+ **resource
125
+ )
126
+ end
127
+
128
+ def self.resource
129
+ {
130
+ resource_name: 'CorporateInvoice',
131
+ resource_maker: proc { |json|
132
+ CorporateInvoice.new(
133
+ id: json['id'],
134
+ amount: json['amount'],
135
+ tax_id: json['tax_id'],
136
+ name: json['name'],
137
+ tags: json['tags'],
138
+ brcode: json['brcode'],
139
+ due: json['due'],
140
+ link: json['link'],
141
+ status: json['status'],
142
+ corporate_transaction_id: json['corporate_transaction_id'],
143
+ updated: json['updated'],
144
+ created: json['created']
145
+ )
146
+ }
147
+ }
148
+ end
149
+ end
150
+ end