starkinfra 0.5.2 → 0.7.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/brcode_preview/brcode_preview.rb +25 -4
- data/lib/brcode_preview/subscription.rb +102 -0
- data/lib/business_account_request/business_account_request.rb +276 -0
- data/lib/business_account_request/log.rb +124 -0
- data/lib/business_attachment/business_attachment.rb +189 -0
- data/lib/{individual_document → business_attachment}/log.rb +35 -32
- data/lib/business_identity/business_identity.rb +228 -0
- data/lib/business_identity/log.rb +127 -0
- data/lib/credit_holmes/credit_holmes.rb +2 -1
- data/lib/credit_holmes/log.rb +125 -0
- data/lib/credit_note/credit_note.rb +51 -8
- data/lib/credit_note/rule.rb +55 -0
- data/lib/credit_note/transfer.rb +1 -1
- data/lib/credit_preview/credit_note_preview.rb +10 -2
- data/lib/credit_preview/credit_preview.rb +2 -1
- data/lib/credit_signer/credit_signer.rb +27 -2
- data/lib/dynamic_brcode/dynamic_brcode.rb +5 -2
- data/lib/event/event.rb +10 -2
- data/lib/individual_account_attachment/individual_account_attachment.rb +178 -0
- data/lib/individual_account_attachment/log.rb +124 -0
- data/lib/individual_account_request/individual_account_request.rb +271 -0
- data/lib/individual_account_request/log.rb +124 -0
- data/lib/individual_identity/individual_identity.rb +4 -7
- data/lib/issuing_balance/issuing_balance.rb +8 -2
- data/lib/issuing_billing_invoice/issuing_billing_invoice.rb +155 -0
- data/lib/issuing_billing_transaction/issuing_billing_transaction.rb +142 -0
- data/lib/issuing_card/issuing_card.rb +10 -6
- data/lib/issuing_design/issuing_design.rb +9 -0
- data/lib/issuing_embossing_request/issuing_embossing_request.rb +3 -2
- data/lib/issuing_holder/issuing_holder.rb +6 -5
- data/lib/issuing_product/issuing_product.rb +6 -3
- data/lib/issuing_purchase/issuing_purchase.rb +41 -8
- data/lib/issuing_restock/issuing_restock.rb +3 -2
- data/lib/issuing_rule/issuing_rule.rb +45 -3
- data/lib/issuing_stock/issuing_stock.rb +5 -2
- data/lib/issuing_stock_rule/issuing_stock_rule.rb +214 -0
- data/lib/issuing_token/issuing_token.rb +309 -0
- data/lib/issuing_token/log.rb +127 -0
- data/lib/issuing_token_activation/issuing_token_activation.rb +62 -0
- data/lib/issuing_token_design/issuing_token_design.rb +118 -0
- data/lib/issuing_token_request/issuing_token_request.rb +63 -0
- data/lib/issuing_withdrawal/issuing_withdrawal.rb +2 -2
- data/lib/ledger/ledger.rb +175 -0
- data/lib/ledger/log.rb +122 -0
- data/lib/ledger/rule.rb +55 -0
- data/lib/ledger_transaction/ledger_transaction.rb +179 -0
- data/lib/merchant_category/merchant_category.rb +6 -3
- data/lib/pix_balance/pix_balance.rb +1 -1
- data/lib/pix_chargeback/pix_chargeback.rb +34 -7
- data/lib/pix_claim/pix_claim.rb +14 -6
- data/lib/pix_director/pix_director.rb +1 -1
- data/lib/pix_dispute/log.rb +127 -0
- data/lib/pix_dispute/pix_dispute.rb +210 -0
- data/lib/pix_dispute/transaction.rb +91 -0
- data/lib/pix_fraud/log.rb +128 -0
- data/lib/pix_fraud/pix_fraud.rb +180 -0
- data/lib/pix_infraction/pix_infraction.rb +37 -7
- data/lib/pix_internal_transaction_report/log.rb +129 -0
- data/lib/pix_internal_transaction_report/pix_internal_transaction_report.rb +200 -0
- data/lib/pix_key/pix_key.rb +1 -1
- data/lib/pix_key_holmes/log.rb +129 -0
- data/lib/{individual_document/individual_document.rb → pix_key_holmes/pix_key_holmes.rb} +48 -56
- data/lib/pix_pull_request/log.rb +127 -0
- data/lib/pix_pull_request/pix_pull_request.rb +268 -0
- data/lib/pix_pull_subscription/log.rb +127 -0
- data/lib/pix_pull_subscription/pix_pull_subscription.rb +307 -0
- data/lib/pix_request/pix_request.rb +19 -6
- data/lib/pix_reversal/pix_reversal.rb +14 -8
- data/lib/pix_statement/pix_statement.rb +11 -5
- data/lib/pix_user/pix_user.rb +52 -0
- data/lib/pix_user/statistics.rb +64 -0
- data/lib/starkinfra.rb +45 -4
- data/lib/static_brcode/static_brcode.rb +8 -4
- data/lib/utils/bacen_id.rb +27 -0
- data/lib/utils/end_to_end_id.rb +20 -0
- data/lib/utils/pix_subscription_bacen_id.rb +21 -0
- data/lib/utils/return_id.rb +21 -0
- data/lib/webhook/webhook.rb +3 -3
- metadata +48 -11
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require('starkcore')
|
|
4
|
+
require_relative('../utils/rest')
|
|
5
|
+
require_relative('../utils/parse')
|
|
6
|
+
|
|
7
|
+
module StarkInfra
|
|
8
|
+
# # BusinessAttachment object
|
|
9
|
+
#
|
|
10
|
+
# Business attachments are files containing documents of a company that must be attached to a business
|
|
11
|
+
# identity to be used for its validation.
|
|
12
|
+
#
|
|
13
|
+
# When you initialize a BusinessAttachment, the entity will not be automatically
|
|
14
|
+
# created in the Stark Infra API. The 'create' function sends the objects
|
|
15
|
+
# to the Stark Infra API and returns the list of created objects.
|
|
16
|
+
#
|
|
17
|
+
# ## Parameters (required):
|
|
18
|
+
# - name [string]: name of the BusinessAttachment. ex: "articles-of-incorporation.pdf"
|
|
19
|
+
# - content [string]: Base64 data url of the file or its raw bytes on creation; when retrieved via get, populated only when expand: ['content'] is passed, nil otherwise. ex: data:application/pdf;base64,JVBERi0xLjQ...
|
|
20
|
+
# - business_identity_id [string]: Unique id of BusinessIdentity. ex: "5656565656565656"
|
|
21
|
+
#
|
|
22
|
+
# ## Parameters (optional):
|
|
23
|
+
# - content_type [string, default nil]: content MIME type. This parameter is required as input only. ex: "image/png" or "application/pdf"
|
|
24
|
+
# - tags [list of strings, default nil]: list of strings for reference when searching for BusinessAttachments. ex: ["employees", "monthly"]
|
|
25
|
+
#
|
|
26
|
+
# ## Attributes (return-only):
|
|
27
|
+
# - id [string]: unique id returned when the BusinessAttachment is created. ex: "5656565656565656"
|
|
28
|
+
# - attachment_id [string]: Unique id of the attached file. ex: "5656565656565656"
|
|
29
|
+
# - status [string]: current status of the BusinessAttachment. Options: "created", "canceled", "approved", "denied"
|
|
30
|
+
# - created [DateTime]: creation datetime for the BusinessAttachment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
|
31
|
+
# - updated [DateTime]: latest update datetime for the BusinessAttachment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
|
32
|
+
class BusinessAttachment < StarkCore::Utils::Resource
|
|
33
|
+
attr_reader :name, :content, :content_type, :business_identity_id, :tags, :id, :attachment_id, :status, :created, :updated
|
|
34
|
+
def initialize(name:, content:, business_identity_id:, content_type: nil, tags: nil, id: nil, attachment_id: nil,
|
|
35
|
+
status: nil, created: nil, updated: nil)
|
|
36
|
+
super(id)
|
|
37
|
+
@name = name
|
|
38
|
+
@business_identity_id = business_identity_id
|
|
39
|
+
@tags = tags
|
|
40
|
+
@attachment_id = attachment_id
|
|
41
|
+
@status = status
|
|
42
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
|
43
|
+
@updated = StarkCore::Utils::Checks.check_datetime(updated)
|
|
44
|
+
@content = content
|
|
45
|
+
@content_type = content_type
|
|
46
|
+
|
|
47
|
+
if @content_type
|
|
48
|
+
@content = "data:#{content_type};base64,#{Base64.encode64(content)}"
|
|
49
|
+
@content_type = nil
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# # Create BusinessAttachments
|
|
54
|
+
#
|
|
55
|
+
# Send a list of BusinessAttachment objects for creation at the Stark Infra API. Limit of 1 attachment per
|
|
56
|
+
# request and 2 attachments per identity. Only PDF, JPG and PNG files are accepted, up to 8 MB each; name
|
|
57
|
+
# must be unique among the identity's other 'created' attachments; the identity must be in 'created'/'pending'
|
|
58
|
+
# status with fewer than 2 attachments already.
|
|
59
|
+
#
|
|
60
|
+
# ## Parameters (required):
|
|
61
|
+
# - attachments [list of BusinessAttachment objects]: list of BusinessAttachment objects to be created in the API.
|
|
62
|
+
#
|
|
63
|
+
# ## Parameters (optional):
|
|
64
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
|
65
|
+
#
|
|
66
|
+
# ## Return:
|
|
67
|
+
# - list of BusinessAttachment objects with updated attributes
|
|
68
|
+
def self.create(attachments, user: nil)
|
|
69
|
+
StarkInfra::Utils::Rest.post(entities: attachments, user: user, **resource)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# # Retrieve a specific BusinessAttachment
|
|
73
|
+
#
|
|
74
|
+
# Receive a single BusinessAttachment object previously created in the Stark Infra API by its id
|
|
75
|
+
#
|
|
76
|
+
# ## Parameters (required):
|
|
77
|
+
# - id [string]: object unique id. ex: "5656565656565656"
|
|
78
|
+
#
|
|
79
|
+
# ## Parameters (optional):
|
|
80
|
+
# - expand [list of strings, default nil]: fields to expand information. ex: ["content"]
|
|
81
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
|
82
|
+
#
|
|
83
|
+
# ## Return:
|
|
84
|
+
# - BusinessAttachment object with updated attributes
|
|
85
|
+
def self.get(id, expand: nil, user: nil)
|
|
86
|
+
StarkInfra::Utils::Rest.get_id(id: id, expand: expand, user: user, **resource)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# # Retrieve BusinessAttachments
|
|
90
|
+
#
|
|
91
|
+
# Receive a generator of BusinessAttachment objects previously created in the Stark Infra API
|
|
92
|
+
#
|
|
93
|
+
# ## Parameters (optional):
|
|
94
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
|
95
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
|
96
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
|
97
|
+
# - status [list of strings, default nil]: filter for status of retrieved objects. Options: ["created", "canceled", "approved", "denied"]
|
|
98
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
|
99
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
|
|
100
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
|
101
|
+
#
|
|
102
|
+
# ## Return:
|
|
103
|
+
# - generator of BusinessAttachment objects with updated attributes
|
|
104
|
+
def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
|
105
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
|
106
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
|
107
|
+
StarkInfra::Utils::Rest.get_stream(
|
|
108
|
+
limit: limit,
|
|
109
|
+
after: after,
|
|
110
|
+
before: before,
|
|
111
|
+
status: status,
|
|
112
|
+
tags: tags,
|
|
113
|
+
ids: ids,
|
|
114
|
+
user: user,
|
|
115
|
+
**resource
|
|
116
|
+
)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# # Retrieve paged BusinessAttachments
|
|
120
|
+
#
|
|
121
|
+
# Receive a list of up to 100 BusinessAttachment objects previously created in the Stark Infra API and the cursor to the next page.
|
|
122
|
+
# Use this function instead of query if you want to manually page your requests.
|
|
123
|
+
#
|
|
124
|
+
# ## Parameters (optional):
|
|
125
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
|
126
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex 35
|
|
127
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
|
128
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
|
129
|
+
# - status [list of strings, default nil]: filter for status of retrieved objects. Options: ["created", "canceled", "approved", "denied"]
|
|
130
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
|
131
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
|
|
132
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
|
133
|
+
#
|
|
134
|
+
# ## Return:
|
|
135
|
+
# - list of BusinessAttachment objects with updated attributes
|
|
136
|
+
# - cursor to retrieve the next page of BusinessAttachment objects
|
|
137
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
|
138
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
|
139
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
|
140
|
+
StarkInfra::Utils::Rest.get_page(
|
|
141
|
+
cursor: cursor,
|
|
142
|
+
limit: limit,
|
|
143
|
+
after: after,
|
|
144
|
+
before: before,
|
|
145
|
+
status: status,
|
|
146
|
+
tags: tags,
|
|
147
|
+
ids: ids,
|
|
148
|
+
user: user,
|
|
149
|
+
**resource
|
|
150
|
+
)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# # Cancel a BusinessAttachment entity
|
|
154
|
+
#
|
|
155
|
+
# Cancel a BusinessAttachment entity previously created in the Stark Infra API. Only attachments in 'created' status can be canceled.
|
|
156
|
+
#
|
|
157
|
+
# ## Parameters (required):
|
|
158
|
+
# - id [string]: BusinessAttachment unique id. ex: '5656565656565656'
|
|
159
|
+
#
|
|
160
|
+
# ## Parameters (optional):
|
|
161
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
|
162
|
+
#
|
|
163
|
+
# ## Return:
|
|
164
|
+
# - canceled BusinessAttachment object
|
|
165
|
+
def self.cancel(id, user: nil)
|
|
166
|
+
StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def self.resource
|
|
170
|
+
{
|
|
171
|
+
resource_name: 'BusinessAttachment',
|
|
172
|
+
resource_maker: proc { |json|
|
|
173
|
+
BusinessAttachment.new(
|
|
174
|
+
name: json['name'],
|
|
175
|
+
content: json['content'],
|
|
176
|
+
content_type: json['content_type'],
|
|
177
|
+
business_identity_id: json['business_identity_id'],
|
|
178
|
+
tags: json['tags'],
|
|
179
|
+
id: json['id'],
|
|
180
|
+
attachment_id: json['attachment_id'],
|
|
181
|
+
status: json['status'],
|
|
182
|
+
created: json['created'],
|
|
183
|
+
updated: json['updated']
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -2,34 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
require('starkcore')
|
|
4
4
|
require_relative('../utils/rest')
|
|
5
|
-
require_relative('
|
|
5
|
+
require_relative('business_attachment')
|
|
6
6
|
|
|
7
7
|
module StarkInfra
|
|
8
|
-
class
|
|
9
|
-
# #
|
|
8
|
+
class BusinessAttachment
|
|
9
|
+
# # BusinessAttachment::Log object
|
|
10
10
|
#
|
|
11
|
-
# Every time
|
|
12
|
-
# This Log is never generated by the user, but it can be retrieved to check additional information on the
|
|
11
|
+
# Every time a BusinessAttachment entity is updated, a corresponding BusinessAttachment::Log is generated for the entity.
|
|
12
|
+
# This Log is never generated by the user, but it can be retrieved to check additional information on the BusinessAttachment.
|
|
13
13
|
#
|
|
14
14
|
# ## Attributes (return-only):
|
|
15
15
|
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
|
16
|
-
# -
|
|
17
|
-
# - errors [list of strings]: list of errors linked to this
|
|
18
|
-
# - type [string]: type of the
|
|
16
|
+
# - attachment [BusinessAttachment]: BusinessAttachment entity to which the log refers to.
|
|
17
|
+
# - errors [list of strings]: list of errors linked to this BusinessAttachment event
|
|
18
|
+
# - type [string]: type of the BusinessAttachment event which triggered the log creation. ex: 'created', 'canceled', 'approved', 'denied'.
|
|
19
19
|
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
|
20
20
|
class Log < StarkCore::Utils::Resource
|
|
21
|
-
attr_reader :id, :
|
|
22
|
-
def initialize(id: nil,
|
|
21
|
+
attr_reader :id, :attachment, :errors, :type, :created
|
|
22
|
+
def initialize(id: nil, attachment: nil, errors: nil, type: nil, created: nil)
|
|
23
23
|
super(id)
|
|
24
|
-
@
|
|
24
|
+
@attachment = attachment
|
|
25
25
|
@errors = errors
|
|
26
26
|
@type = type
|
|
27
27
|
@created = StarkCore::Utils::Checks.check_datetime(created)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
# # Retrieve a specific
|
|
30
|
+
# # Retrieve a specific BusinessAttachment::Log
|
|
31
31
|
#
|
|
32
|
-
# Receive a single
|
|
32
|
+
# Receive a single BusinessAttachment::Log object previously created by the Stark Infra API by passing its id
|
|
33
33
|
#
|
|
34
34
|
# ## Parameters (required):
|
|
35
35
|
# - id [string]: object unique id. ex: '5656565656565656'
|
|
@@ -38,26 +38,27 @@ module StarkInfra
|
|
|
38
38
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
|
39
39
|
#
|
|
40
40
|
# ## Return:
|
|
41
|
-
# -
|
|
41
|
+
# - BusinessAttachment::Log object with updated attributes
|
|
42
42
|
def self.get(id, user: nil)
|
|
43
43
|
StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
# # Retrieve
|
|
46
|
+
# # Retrieve BusinessAttachment::Logs
|
|
47
47
|
#
|
|
48
|
-
# Receive a generator of
|
|
48
|
+
# Receive a generator of BusinessAttachment::Log objects previously created in the Stark Infra API
|
|
49
49
|
#
|
|
50
50
|
# ## Parameters (optional):
|
|
51
51
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
|
52
52
|
# - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
|
53
53
|
# - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
|
54
|
-
# - types [list of strings, default nil]: filter for log event types. ex: ['created', 'canceled', '
|
|
55
|
-
# -
|
|
54
|
+
# - types [list of strings, default nil]: filter for log event types. ex: ['created', 'canceled', 'approved', 'denied']
|
|
55
|
+
# - attachment_ids [list of strings, default nil]: list of BusinessAttachment ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
|
56
|
+
# - ids [list of strings, default nil]: Log ids to filter BusinessAttachment Logs. ex: ['5656565656565656']
|
|
56
57
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
|
57
58
|
#
|
|
58
59
|
# ## Return:
|
|
59
|
-
# - generator of
|
|
60
|
-
def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil,
|
|
60
|
+
# - generator of BusinessAttachment::Log objects with updated attributes
|
|
61
|
+
def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil, attachment_ids: nil, user: nil)
|
|
61
62
|
after = StarkCore::Utils::Checks.check_date(after)
|
|
62
63
|
before = StarkCore::Utils::Checks.check_date(before)
|
|
63
64
|
StarkInfra::Utils::Rest.get_stream(
|
|
@@ -66,52 +67,54 @@ module StarkInfra
|
|
|
66
67
|
after: after,
|
|
67
68
|
before: before,
|
|
68
69
|
types: types,
|
|
69
|
-
|
|
70
|
+
attachment_ids: attachment_ids,
|
|
70
71
|
user: user,
|
|
71
72
|
**resource
|
|
72
73
|
)
|
|
73
74
|
end
|
|
74
75
|
|
|
75
|
-
# # Retrieve paged
|
|
76
|
+
# # Retrieve paged BusinessAttachment::Logs
|
|
76
77
|
#
|
|
77
|
-
# Receive a list of up to 100
|
|
78
|
-
# Use this function instead of query if you want to manually page your
|
|
78
|
+
# Receive a list of up to 100 BusinessAttachment::Log objects previously created in the Stark Infra API and the cursor to the next page.
|
|
79
|
+
# Use this function instead of query if you want to manually page your attachments.
|
|
79
80
|
#
|
|
80
81
|
# ## Parameters (optional):
|
|
81
82
|
# - cursor [string, default nil]: cursor returned on the previous page function call
|
|
82
83
|
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
|
83
84
|
# - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
|
84
85
|
# - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
|
85
|
-
# - types [list of strings, default nil]: filter for log event types. ex: ['created', 'canceled', '
|
|
86
|
-
# -
|
|
86
|
+
# - types [list of strings, default nil]: filter for log event types. ex: ['created', 'canceled', 'approved', 'denied']
|
|
87
|
+
# - attachment_ids [list of strings, default nil]: list of attachment ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
|
88
|
+
# - ids [list of strings, default nil]: Log ids to filter BusinessAttachment Logs. ex: ['5656565656565656']
|
|
87
89
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
|
88
90
|
#
|
|
89
91
|
# ## Return:
|
|
90
|
-
# - list of
|
|
92
|
+
# - list of BusinessAttachment::Log objects with updated attributes
|
|
91
93
|
# - cursor to retrieve the next page of Log objects
|
|
92
|
-
def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil,
|
|
94
|
+
def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil, attachment_ids: nil, user: nil)
|
|
93
95
|
after = StarkCore::Utils::Checks.check_date(after)
|
|
94
96
|
before = StarkCore::Utils::Checks.check_date(before)
|
|
95
97
|
StarkInfra::Utils::Rest.get_page(
|
|
96
98
|
cursor: cursor,
|
|
99
|
+
ids: ids,
|
|
97
100
|
limit: limit,
|
|
98
101
|
after: after,
|
|
99
102
|
before: before,
|
|
100
103
|
types: types,
|
|
101
|
-
|
|
104
|
+
attachment_ids: attachment_ids,
|
|
102
105
|
user: user,
|
|
103
106
|
**resource
|
|
104
107
|
)
|
|
105
108
|
end
|
|
106
109
|
|
|
107
110
|
def self.resource
|
|
108
|
-
request_maker = StarkInfra::
|
|
111
|
+
request_maker = StarkInfra::BusinessAttachment.resource[:resource_maker]
|
|
109
112
|
{
|
|
110
|
-
resource_name: '
|
|
113
|
+
resource_name: 'BusinessAttachmentLog',
|
|
111
114
|
resource_maker: proc { |json|
|
|
112
115
|
Log.new(
|
|
113
116
|
id: json['id'],
|
|
114
|
-
|
|
117
|
+
attachment: StarkCore::Utils::API.from_api_json(request_maker, json['attachment']),
|
|
115
118
|
errors: json['errors'],
|
|
116
119
|
type: json['type'],
|
|
117
120
|
created: json['created']
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require('starkcore')
|
|
4
|
+
require_relative('../utils/rest')
|
|
5
|
+
require_relative('../utils/parse')
|
|
6
|
+
|
|
7
|
+
module StarkInfra
|
|
8
|
+
# # BusinessIdentity object
|
|
9
|
+
#
|
|
10
|
+
# A BusinessIdentity represents a company to be validated. It can have several business attachments
|
|
11
|
+
# attached to it, which are used to validate the identity of the company. Once a business identity is created,
|
|
12
|
+
# business attachments must be attached to it using the created method of the business attachment resource. When all
|
|
13
|
+
# the required business attachments are attached to a business identity it can be sent to validation by patching its
|
|
14
|
+
# status to processing.
|
|
15
|
+
#
|
|
16
|
+
# When you initialize a BusinessIdentity, the entity will not be automatically
|
|
17
|
+
# created in the Stark Infra API. The 'create' function sends the objects
|
|
18
|
+
# to the Stark Infra API and returns the list of created objects.
|
|
19
|
+
#
|
|
20
|
+
# ## Parameters (required):
|
|
21
|
+
# - tax_id [string]: company's tax ID (CNPJ). ex: "20.018.183/0001-80"
|
|
22
|
+
#
|
|
23
|
+
# ## Parameters (optional):
|
|
24
|
+
# - tags [list of strings, default nil]: list of strings for reference when searching for BusinessIdentities. ex: ["employees", "monthly"]
|
|
25
|
+
#
|
|
26
|
+
# ## Attributes (return-only):
|
|
27
|
+
# - id [string]: unique id returned when the BusinessIdentity is created. ex: "5656565656565656"
|
|
28
|
+
# - name [string]: company's full name. ex: "Stark Bank S.A."
|
|
29
|
+
# - tax_id_status [string]: bureau status of the CNPJ, normalized from the Receita Federal value. Options: 'active' (ATIVA), 'blocked' (SUSPENSA), 'pending' (INAPTA), 'canceled' (BAIXADA), 'voided' (NULA).
|
|
30
|
+
# - insight_tax_id [string]: tax ID returned by the validation insight. ex: "20018183000180"
|
|
31
|
+
# - insight_document_type [string]: document type returned by the validation insight. ex: "cnpj"
|
|
32
|
+
# - num_pages [integer]: number of pages of the attached documents. ex: 3
|
|
33
|
+
# - representatives [string]: JSON string with the company's representatives.
|
|
34
|
+
# - attachments [list of strings]: list of BusinessAttachment ids attached to the BusinessIdentity. ex: ["5656565656565656", "4545454545454545"]
|
|
35
|
+
# - rules [string]: JSON string with the validation rules.
|
|
36
|
+
# - status [string]: current status of the BusinessIdentity. Options: "created", "pending", "canceled", "processing", "success", "failed"
|
|
37
|
+
# - created [DateTime]: creation datetime for the BusinessIdentity. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
|
38
|
+
# - updated [DateTime]: latest update datetime for the BusinessIdentity. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
|
39
|
+
class BusinessIdentity < StarkCore::Utils::Resource
|
|
40
|
+
attr_reader :tax_id, :tags, :id, :name, :tax_id_status, :insight_tax_id, :insight_document_type, :num_pages,
|
|
41
|
+
:representatives, :attachments, :rules, :status, :created, :updated
|
|
42
|
+
def initialize(tax_id:, tags: nil, id: nil, name: nil, tax_id_status: nil, insight_tax_id: nil,
|
|
43
|
+
insight_document_type: nil, num_pages: nil, representatives: nil, attachments: nil, rules: nil,
|
|
44
|
+
status: nil, created: nil, updated: nil)
|
|
45
|
+
super(id)
|
|
46
|
+
@tax_id = tax_id
|
|
47
|
+
@tags = tags
|
|
48
|
+
@name = name
|
|
49
|
+
@tax_id_status = tax_id_status
|
|
50
|
+
@insight_tax_id = insight_tax_id
|
|
51
|
+
@insight_document_type = insight_document_type
|
|
52
|
+
@num_pages = num_pages
|
|
53
|
+
@representatives = representatives
|
|
54
|
+
@attachments = attachments
|
|
55
|
+
@rules = rules
|
|
56
|
+
@status = status
|
|
57
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
|
58
|
+
@updated = StarkCore::Utils::Checks.check_datetime(updated)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# # Create BusinessIdentities
|
|
62
|
+
#
|
|
63
|
+
# Send a list of BusinessIdentity objects for creation at the Stark Infra API. Each entry is created in
|
|
64
|
+
# 'pending' status. The CNPJ must be valid, active in the official bureau, and return non-empty
|
|
65
|
+
# representatives (sócios), or the request fails.
|
|
66
|
+
#
|
|
67
|
+
# ## Parameters (required):
|
|
68
|
+
# - identities [list of BusinessIdentity objects]: list of BusinessIdentity objects to be created in the API.
|
|
69
|
+
#
|
|
70
|
+
# ## Parameters (optional):
|
|
71
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
|
72
|
+
#
|
|
73
|
+
# ## Return:
|
|
74
|
+
# - list of BusinessIdentity objects with updated attributes
|
|
75
|
+
def self.create(identities, user: nil)
|
|
76
|
+
StarkInfra::Utils::Rest.post(entities: identities, user: user, **resource)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# # Retrieve a specific BusinessIdentity
|
|
80
|
+
#
|
|
81
|
+
# Receive a single BusinessIdentity object previously created in the Stark Infra API by its id
|
|
82
|
+
#
|
|
83
|
+
# ## Parameters (required):
|
|
84
|
+
# - id [string]: object unique id. ex: "5656565656565656"
|
|
85
|
+
#
|
|
86
|
+
# ## Parameters (optional):
|
|
87
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
|
88
|
+
#
|
|
89
|
+
# ## Return:
|
|
90
|
+
# - BusinessIdentity object with updated attributes
|
|
91
|
+
def self.get(uuid, user: nil)
|
|
92
|
+
StarkInfra::Utils::Rest.get_id(id: uuid, user: user, **resource)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# # Retrieve BusinessIdentities
|
|
96
|
+
#
|
|
97
|
+
# Receive a generator of BusinessIdentity objects previously created in the Stark Infra API
|
|
98
|
+
#
|
|
99
|
+
# ## Parameters (optional):
|
|
100
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
|
101
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
|
102
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
|
103
|
+
# - status [list of strings, default nil]: filter for status of retrieved objects. ex: ["created", "pending", "canceled", "processing", "success", "failed"]
|
|
104
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
|
105
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
|
|
106
|
+
# - tax_ids [list of strings, default nil]: list of tax ids to filter retrieved objects. ex: ["20.018.183/0001-80"]
|
|
107
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
|
108
|
+
#
|
|
109
|
+
# ## Return:
|
|
110
|
+
# - generator of BusinessIdentity objects with updated attributes
|
|
111
|
+
def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, tax_ids: nil, user: nil)
|
|
112
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
|
113
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
|
114
|
+
StarkInfra::Utils::Rest.get_stream(
|
|
115
|
+
limit: limit,
|
|
116
|
+
after: after,
|
|
117
|
+
before: before,
|
|
118
|
+
status: status,
|
|
119
|
+
tags: tags,
|
|
120
|
+
ids: ids,
|
|
121
|
+
tax_ids: tax_ids,
|
|
122
|
+
user: user,
|
|
123
|
+
**resource
|
|
124
|
+
)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# # Retrieve paged BusinessIdentities
|
|
128
|
+
#
|
|
129
|
+
# Receive a list of up to 100 BusinessIdentity objects previously created in the Stark Infra API and the cursor to the next page.
|
|
130
|
+
# Use this function instead of query if you want to manually page your requests.
|
|
131
|
+
#
|
|
132
|
+
# ## Parameters (optional):
|
|
133
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
|
134
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex 35
|
|
135
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
|
136
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
|
137
|
+
# - status [list of strings, default nil]: filter for status of retrieved objects. ex: ["created", "pending", "canceled", "processing", "success", "failed"]
|
|
138
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
|
139
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
|
|
140
|
+
# - tax_ids [list of strings, default nil]: list of tax ids to filter retrieved objects. ex: ["20.018.183/0001-80"]
|
|
141
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
|
142
|
+
#
|
|
143
|
+
# ## Return:
|
|
144
|
+
# - list of BusinessIdentity objects with updated attributes
|
|
145
|
+
# - cursor to retrieve the next page of BusinessIdentity objects
|
|
146
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, tax_ids: nil, user: nil)
|
|
147
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
|
148
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
|
149
|
+
StarkInfra::Utils::Rest.get_page(
|
|
150
|
+
cursor: cursor,
|
|
151
|
+
limit: limit,
|
|
152
|
+
after: after,
|
|
153
|
+
before: before,
|
|
154
|
+
status: status,
|
|
155
|
+
tags: tags,
|
|
156
|
+
ids: ids,
|
|
157
|
+
tax_ids: tax_ids,
|
|
158
|
+
user: user,
|
|
159
|
+
**resource
|
|
160
|
+
)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# # Update BusinessIdentity entity
|
|
164
|
+
#
|
|
165
|
+
# Update a BusinessIdentity by passing id.
|
|
166
|
+
#
|
|
167
|
+
# ## Parameters (required):
|
|
168
|
+
# - id [string]: BusinessIdentity unique id. ex: '5656565656565656'
|
|
169
|
+
#
|
|
170
|
+
# ## Parameters (optional):
|
|
171
|
+
# - status [string, default nil]: only 'processing' is accepted, triggering the AI Model analysis. The identity must be in 'created'/'pending' status and already have at least one BusinessAttachment associated with it.
|
|
172
|
+
# - tags [list of strings, default nil]: list of strings for reference when searching for BusinessIdentities. ex: ["employees", "monthly"]
|
|
173
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
|
174
|
+
#
|
|
175
|
+
# ## Return:
|
|
176
|
+
# - target BusinessIdentity with updated attributes
|
|
177
|
+
def self.update(id, status: nil, tags: nil, user: nil)
|
|
178
|
+
StarkInfra::Utils::Rest.patch_id(
|
|
179
|
+
id: id,
|
|
180
|
+
status: status,
|
|
181
|
+
tags: tags,
|
|
182
|
+
user: user,
|
|
183
|
+
**resource
|
|
184
|
+
)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# # Cancel a BusinessIdentity entity
|
|
188
|
+
#
|
|
189
|
+
# Cancel a BusinessIdentity entity previously created in the Stark Infra API. Only identities in 'created'
|
|
190
|
+
# or 'pending' status can be canceled.
|
|
191
|
+
#
|
|
192
|
+
# ## Parameters (required):
|
|
193
|
+
# - id [string]: BusinessIdentity unique id. ex: '5656565656565656'
|
|
194
|
+
#
|
|
195
|
+
# ## Parameters (optional):
|
|
196
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
|
197
|
+
#
|
|
198
|
+
# ## Return:
|
|
199
|
+
# - canceled BusinessIdentity object
|
|
200
|
+
def self.cancel(id, user: nil)
|
|
201
|
+
StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def self.resource
|
|
205
|
+
{
|
|
206
|
+
resource_name: 'BusinessIdentity',
|
|
207
|
+
resource_maker: proc { |json|
|
|
208
|
+
BusinessIdentity.new(
|
|
209
|
+
tax_id: json['tax_id'],
|
|
210
|
+
tags: json['tags'],
|
|
211
|
+
id: json['id'],
|
|
212
|
+
name: json['name'],
|
|
213
|
+
tax_id_status: json['tax_id_status'],
|
|
214
|
+
insight_tax_id: json['insight_tax_id'],
|
|
215
|
+
insight_document_type: json['insight_document_type'],
|
|
216
|
+
num_pages: json['num_pages'],
|
|
217
|
+
representatives: json['representatives'],
|
|
218
|
+
attachments: json['attachments'],
|
|
219
|
+
rules: json['rules'],
|
|
220
|
+
status: json['status'],
|
|
221
|
+
created: json['created'],
|
|
222
|
+
updated: json['updated']
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|