starkinfra 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/creditnote/creditnote.rb +561 -0
  3. data/lib/creditnote/log.rb +126 -0
  4. data/lib/event/attempt.rb +126 -0
  5. data/lib/event/event.rb +125 -7
  6. data/lib/issuingauthorization/issuingauthorization.rb +141 -0
  7. data/lib/issuingbalance/issuingbalance.rb +55 -0
  8. data/lib/issuingbin/issuingbin.rb +89 -0
  9. data/lib/issuingcard/issuingcard.rb +260 -0
  10. data/lib/issuingcard/log.rb +123 -0
  11. data/lib/issuingholder/issuingholder.rb +206 -0
  12. data/lib/issuingholder/log.rb +123 -0
  13. data/lib/issuinginvoice/issuinginvoice.rb +152 -0
  14. data/lib/issuinginvoice/log.rb +120 -0
  15. data/lib/issuingpurchase/issuingpurchase.rb +209 -0
  16. data/lib/issuingpurchase/log.rb +131 -0
  17. data/lib/issuingrule/issuingrule.rb +81 -0
  18. data/lib/issuingtransaction/issuingtransaction.rb +136 -0
  19. data/lib/issuingwithdrawal/issuingwithdrawal.rb +153 -0
  20. data/lib/pixbalance/pixbalance.rb +13 -13
  21. data/lib/pixchargeback/log.rb +129 -0
  22. data/lib/pixchargeback/pixchargeback.rb +225 -0
  23. data/lib/pixclaim/log.rb +135 -0
  24. data/lib/pixclaim/pixclaim.rb +225 -0
  25. data/lib/pixdirector/pixdirector.rb +76 -0
  26. data/lib/pixdomain/certificate.rb +30 -0
  27. data/lib/pixdomain/pixdomain.rb +58 -0
  28. data/lib/pixinfraction/log.rb +129 -0
  29. data/lib/pixinfraction/pixinfraction.rb +212 -0
  30. data/lib/pixkey/log.rb +128 -0
  31. data/lib/pixkey/pixkey.rb +239 -0
  32. data/lib/pixrequest/log.rb +16 -16
  33. data/lib/pixrequest/pixrequest.rb +66 -67
  34. data/lib/pixreversal/log.rb +13 -12
  35. data/lib/pixreversal/pixreversal.rb +72 -71
  36. data/lib/pixstatement/pixstatement.rb +22 -23
  37. data/lib/starkinfra.rb +32 -2
  38. data/lib/user/organization.rb +54 -0
  39. data/lib/user/project.rb +37 -0
  40. data/lib/user/user.rb +20 -0
  41. data/lib/utils/api.rb +10 -2
  42. data/lib/utils/bacenid.rb +19 -0
  43. data/lib/utils/checks.rb +2 -3
  44. data/lib/utils/endtoendid.rb +11 -0
  45. data/lib/utils/parse.rb +13 -13
  46. data/lib/utils/request.rb +1 -1
  47. data/lib/utils/rest.rb +7 -5
  48. data/lib/utils/returnid.rb +11 -0
  49. data/lib/webhook/webhook.rb +124 -0
  50. metadata +45 -24
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkInfra
8
+ # # PixChargeback object
9
+ #
10
+ # A Pix chargeback can be created when fraud is detected on a transaction or a system malfunction
11
+ # results in an erroneous transaction.
12
+ # It notifies another participant of your request to reverse the payment they have received.
13
+ # When you initialize a PixChargeback, the entity will not be automatically
14
+ # created in the Stark Infra API. The 'create' function sends the objects
15
+ #
16
+ # ## Parameters (required):
17
+ # - amount [integer]: amount in cents to be reversed. ex: 11234 (= R$ 112.34)
18
+ # - reference_id [string]: end_to_end_id or return_id of the transaction to be reversed. ex: 'E20018183202201201450u34sDGd19lz'
19
+ # - reason [string]: reason why the reversal was requested. Options: 'fraud', 'flaw', 'reversalChargeback'
20
+ #
21
+ # ## Parameters (optional):
22
+ # - description [string, default nil]: description for the PixChargeback. ex: 'Payment for service #1234'
23
+ #
24
+ # ## Attributes (return-only):
25
+ # - id [string]: unique id returned when PixChargeback is created. ex: '5656565656565656'
26
+ # - analysis [string]: analysis that led to the result.
27
+ # - bacen_id [string]: central bank's unique UUID that identifies the PixChargeback.
28
+ # - sender_bank_code [string]: bank_code of the Pix participant that created the PixChargeback. ex: '20018183'
29
+ # - receiver_bank_code [string]: bank_code of the Pix participant that received the PixChargeback. ex: '20018183'
30
+ # - rejection_reason [string]: reason for the rejection of the Pix chargeback. Options: 'noBalance', 'accountClosed', 'unableToReverse'
31
+ # - reversal_reference_id [string]: return id of the reversal transaction. ex: 'D20018183202202030109X3OoBHG74wo'.
32
+ # - id [string]: unique id returned when the PixChargeback is created. ex: '5656565656565656'
33
+ # - result [string]: result after the analysis of the PixChargeback by the receiving party. Options: 'rejected', 'accepted', 'partiallyAccepted'
34
+ # - status [string]: current PixChargeback status. Options: 'created', 'failed', 'delivered', 'closed', 'canceled'.
35
+ # - created [DateTime]: creation datetime for the PixChargeback. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
36
+ # - updated [DateTime]: latest update datetime for the PixChargeback. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
37
+ class PixChargeback < StarkInfra::Utils::Resource
38
+ attr_reader :amount, :reference_id, :reason, :description, :id, :analysis, :bacen_id, :sender_bank_code,
39
+ :receiver_bank_code, :rejection_reason, :reversal_reference_id, :result, :status, :created, :updated
40
+ def initialize(
41
+ amount:, reference_id:, reason:, description: nil, id: nil, analysis: nil, bacen_id: nil,
42
+ sender_bank_code: nil, receiver_bank_code: nil, rejection_reason: nil, reversal_reference_id: nil,
43
+ result: nil, status: nil, created: nil, updated: nil
44
+ )
45
+ super(id)
46
+ @amount = amount
47
+ @reference_id = reference_id
48
+ @reason = reason
49
+ @description = description
50
+ @analysis = analysis
51
+ @bacen_id = bacen_id
52
+ @sender_bank_code = sender_bank_code
53
+ @receiver_bank_code = receiver_bank_code
54
+ @rejection_reason = rejection_reason
55
+ @reversal_reference_id = reversal_reference_id
56
+ @result = result
57
+ @status = status
58
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
59
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
60
+ end
61
+
62
+ # # Create PixChargebacks
63
+ #
64
+ # Send a list of PixChargeback objects for creation in the Stark Infra API
65
+ #
66
+ # ## Parameters (required):
67
+ # - chargebacks [list of PixChargeback objects]: list of PixChargeback objects to be created in the API. ex: [PixChargeback.new()]
68
+ #
69
+ # ## Parameters (optional):
70
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
71
+ #
72
+ # ## Return:
73
+ # - list of PixChargeback objects with updated attributes
74
+ def self.create(chargebacks, user: nil)
75
+ StarkInfra::Utils::Rest.post(entities: chargebacks, user: user, **resource)
76
+ end
77
+
78
+ # # Retrieve a specific PixChargeback
79
+ #
80
+ # Receive a single PixChargeback object previously created in the Stark Infra API by passing its id
81
+ #
82
+ # ## Parameters (required):
83
+ # - id [string]: object unique id. ex: '5656565656565656'
84
+ #
85
+ # ## Parameters (optional):
86
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
87
+ #
88
+ # ## Return:
89
+ # - PixChargeback object with updated attributes
90
+ def self.get(id, user: nil)
91
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
92
+ end
93
+
94
+ # # Retrieve PixChargebacks
95
+ #
96
+ # Receive a generator of PixChargeback objects previously created in the Stark Infra API
97
+ #
98
+ # ## Parameters (optional):
99
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
100
+ # - after [Date or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
101
+ # - before [Date or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
102
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
103
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
104
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
105
+ #
106
+ # ## Return:
107
+ # - generator of PixChargeback objects with updated attributes
108
+ def self.query(limit: nil, after: nil, before: nil, status: nil, ids: nil, user: nil)
109
+ after = StarkInfra::Utils::Checks.check_date(after)
110
+ before = StarkInfra::Utils::Checks.check_date(before)
111
+ StarkInfra::Utils::Rest.get_stream(
112
+ limit: limit,
113
+ after: after,
114
+ before: before,
115
+ status: status,
116
+ ids: ids,
117
+ user: user,
118
+ **resource
119
+ )
120
+ end
121
+
122
+ # # Retrieve paged PixChargebacks
123
+ #
124
+ # Receive a list of up to 100 PixChargeback objects previously created in the Stark infra API and the cursor to the next page.
125
+ # Use this function instead of query if you want to manually page your chargebacks.
126
+ #
127
+ # ## Parameters (optional):
128
+ # - cursor [string, default nil]: cursor returned on the previous page function call
129
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
130
+ # - after [Date or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
131
+ # - before [Date or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
132
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
133
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
134
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
135
+ #
136
+ # ## Return:
137
+ # - list of PixChargeback objects with updated attributes
138
+ # - cursor to retrieve the next page of PixChargeback objects
139
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, ids: nil, user: nil)
140
+ after = StarkInfra::Utils::Checks.check_date(after)
141
+ before = StarkInfra::Utils::Checks.check_date(before)
142
+ StarkInfra::Utils::Rest.get_page(
143
+ cursor: cursor,
144
+ limit: limit,
145
+ after: after,
146
+ before: before,
147
+ status: status,
148
+ ids: ids,
149
+ user: user,
150
+ **resource
151
+ )
152
+ end
153
+
154
+ # # Update a PixChargeback entity
155
+ #
156
+ # Respond to a received PixChargeback.
157
+ #
158
+ # ## Parameters (required):
159
+ # - id [string]: PixChargeback unique id. ex: '5656565656565656'
160
+ # - result [string]: result of the PixChargeback. Options: 'rejected', 'accepted', 'partiallyAccepted'.
161
+ #
162
+ # ## Parameters (conditionally required):
163
+ # - rejection_reason [string, default nil]: if the PixChargeback is rejected a reason is required. Options: 'noBalance', 'accountClosed', 'unableToReverse',
164
+ # - reversal_reference_id [string, default nil]: return_id of the reversal transaction. ex: 'D20018183202201201450u34sDGd19lz'
165
+ #
166
+ # ## Parameters (optional):
167
+ # - analysis [string, default nil]: description of the analysis that led to the result.
168
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
169
+ #
170
+ # ## Return:
171
+ # - updated PixChargeback object
172
+ def self.update(id, result:, rejection_reason: nil, reversal_reference_id: nil, analysis: nil, user: nil)
173
+ StarkInfra::Utils::Rest.patch_id(
174
+ id: id,
175
+ result: result,
176
+ rejection_reason: rejection_reason,
177
+ analysis: analysis,
178
+ reversal_reference_id: reversal_reference_id,
179
+ user: user,
180
+ **resource
181
+ )
182
+ end
183
+
184
+ # # Cancel a PixChargeback entity
185
+ #
186
+ # Cancel a PixChargeback entity previously created in the Stark Infra API
187
+ #
188
+ # ## Parameters (required):
189
+ # - id [string]: PixChargeback unique id. ex: '5656565656565656'
190
+ #
191
+ # ## Parameters (optional):
192
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
193
+ #
194
+ # ## Return:
195
+ # - canceled PixChargeback object
196
+ def self.cancel(id, user: nil)
197
+ StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
198
+ end
199
+
200
+ def self.resource
201
+ {
202
+ resource_name: 'PixChargeback',
203
+ resource_maker: proc { |json|
204
+ PixChargeback.new(
205
+ amount: json['amount'],
206
+ reference_id: json['reference_id'],
207
+ reason: json['reason'],
208
+ description: json['description'],
209
+ id: json['id'],
210
+ analysis: json['analysis'],
211
+ bacen_id: json['bacen_id'],
212
+ sender_bank_code: json['sender_bank_code'],
213
+ receiver_bank_code: json['receiver_bank_code'],
214
+ rejection_reason: json['rejection_reason'],
215
+ reversal_reference_id: json['reversal_reference_id'],
216
+ result: json['result'],
217
+ status: json['status'],
218
+ created: json['created'],
219
+ updated: json['updated']
220
+ )
221
+ }
222
+ }
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('pixclaim')
7
+
8
+ module StarkInfra
9
+ class PixClaim
10
+ # # PixClaim::Log object
11
+ #
12
+ # Every time a PixClaim entity is modified, a corresponding PixClaim::Log
13
+ # is generated for the entity. This log is never generated by the
14
+ # user.
15
+ #
16
+ # ## Attributes:
17
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
+ # - type [string]: type of the PixClaim event which triggered the log creation. Options: 'created', 'failed', 'delivering', 'delivered', 'confirming', 'confirmed', 'success', 'canceling', 'canceled'.
20
+ # - errors [list of strings]: list of errors linked to this PixClaim event.
21
+ # - agent [string]: agent that modified the PixClaim resulting in the Log. Options: 'claimer', 'claimed'.
22
+ # - reason [string]: reason why the PixClaim was modified, resulting in the Log. Options: 'fraud', 'userRequested', 'accountClosure', 'defaultOperation', 'reconciliation'
23
+ # - claim [PixClaim]: PixClaim entity to which the log refers to.
24
+ class Log < StarkInfra::Utils::Resource
25
+ attr_reader :id, :created, :type, :errors, :agent, :reason, :claim
26
+ def initialize(id:, created:, type:, errors:, agent:, reason:, claim:)
27
+ super(id)
28
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
29
+ @type = type
30
+ @errors = errors
31
+ @agent = agent
32
+ @reason = reason
33
+ @claim = claim
34
+ end
35
+
36
+ # # Retrieve a specific Log
37
+ #
38
+ # Receive a single Log object previously created by the Stark Infra API by passing its id
39
+ #
40
+ # ## Parameters (required):
41
+ # - id [string]: object unique id. ex: '5656565656565656'
42
+ #
43
+ # ## Parameters (optional):
44
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
45
+ #
46
+ # ## Return:
47
+ # - Log object with updated attributes
48
+ def self.get(id, user: nil)
49
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
50
+ end
51
+
52
+ # # Retrieve Logs
53
+ #
54
+ # Receive a generator of Log objects previously created in the Stark Infra API
55
+ #
56
+ # ## Parameters (optional):
57
+ # - ids [list of strings, default nil]: Log ids to filter PixClaim Logs. ex: ['5656565656565656']
58
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
59
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
60
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
61
+ # - types [list of strings]: filter PixClaim Logs by their types. Options: 'created', 'failed', 'delivering', 'delivered', 'confirming', 'confirmed', 'success', 'canceling', 'canceled'.
62
+ # - claim_ids [list of strings, default nil]: list of PixClaim ids to filter retrieved objects. ex: %w[5656565656565656 4545454545454545]
63
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
64
+ #
65
+ # ## Return:
66
+ # - generator of Log objects with updated attributes
67
+ def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil, claim_ids: nil, user: nil)
68
+ after = StarkInfra::Utils::Checks.check_date(after)
69
+ before = StarkInfra::Utils::Checks.check_date(before)
70
+ StarkInfra::Utils::Rest.get_stream(
71
+ ids: ids,
72
+ limit: limit,
73
+ after: after,
74
+ before: before,
75
+ types: types,
76
+ claim_ids: claim_ids,
77
+ user: user,
78
+ **resource
79
+ )
80
+ end
81
+
82
+ # # Retrieve paged Logs
83
+ #
84
+ # Receive a list of up to 100 Log objects previously created in the Stark Infra API and the cursor to the next page.
85
+ # Use this function instead of query if you want to manually page your claims.
86
+ #
87
+ # ## Parameters (optional):
88
+ # - ids [list of strings, default nil]: Log ids to filter PixClaim Logs. ex: ['5656565656565656']
89
+ # - cursor [string, default nil]: cursor returned on the previous page function call
90
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
91
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
92
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
93
+ # - types [list of strings]: filter PixClaim Logs by their types. Options: 'created', 'failed', 'delivering', 'delivered', 'confirming', 'confirmed', 'success', 'canceling', 'canceled'.
94
+ # - claim_ids [list of strings, default nil]: list of PixClaim ids to filter retrieved objects. ex: %w[5656565656565656 4545454545454545]
95
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
96
+ #
97
+ # ## Return:
98
+ # - list of Log objects with updated attributes
99
+ # - cursor to retrieve the next page of Log objects
100
+ def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil, claim_ids: nil, user: nil)
101
+ after = StarkInfra::Utils::Checks.check_date(after)
102
+ before = StarkInfra::Utils::Checks.check_date(before)
103
+ StarkInfra::Utils::Rest.get_page(
104
+ cursor: cursor,
105
+ ids: ids,
106
+ limit: limit,
107
+ after: after,
108
+ before: before,
109
+ types: types,
110
+ claim_ids: claim_ids,
111
+ user: user,
112
+ **resource
113
+ )
114
+ end
115
+
116
+ def self.resource
117
+ claim_maker = StarkInfra::PixClaim.resource[:resource_maker]
118
+ {
119
+ resource_name: 'PixClaimLog',
120
+ resource_maker: proc { |json|
121
+ Log.new(
122
+ id: json['id'],
123
+ created: json['created'],
124
+ type: json['type'],
125
+ errors: json['errors'],
126
+ agent: json['agent'],
127
+ reason: json['reason'],
128
+ claim: StarkInfra::Utils::API.from_api_json(claim_maker, json['claim'])
129
+ )
130
+ }
131
+ }
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+
7
+ module StarkInfra
8
+ # # PixClaim object
9
+ #
10
+ # PixClaims intend to transfer a PixClaim from one account to another.
11
+ # When you initialize a PixClaim, the entity will not be automatically
12
+ # created in the Stark Infra API. The 'create' function sends the objects
13
+ # to the Stark Infra API and returns the created object.
14
+ #
15
+ # ## Parameters (required):
16
+ # - account_created [Date, DateTime or string]: opening Date or DateTime for the account claiming the PixClaim. ex: '2022-01-01'.
17
+ # - account_number [string]: number of the account claiming the PixClaim. ex: '76543'.
18
+ # - account_type [string]: type of the account claiming the PixClaim. Options: 'checking', 'savings', 'salary' or 'payment'.
19
+ # - branch_code [string]: branch code of the account claiming the PixClaim. ex: 1234'.
20
+ # - name [string]: holder's name of the account claiming the PixClaim. ex: 'Jamie Lannister'.
21
+ # - tax_id [string]: holder's taxId of the account claiming the PixClaim (CPF/CNPJ). ex: '012.345.678-90'.
22
+ # - key_id [string]: id of the registered Pix Key to be claimed. Allowed keyTypes are CPF, CNPJ, phone number or email. ex: '+5511989898989'.
23
+ #
24
+ # ## Attributes (return-only):
25
+ # - id [string]: unique id returned when the PixClaim is created. ex: '5656565656565656'
26
+ # - status [string]: current PixClaim status. Options: 'created', 'failed', 'delivered', 'confirmed', 'success', 'canceled'
27
+ # - type [string]: type of Pix Claim. Options: 'ownership', 'portability'.
28
+ # - key_type [string]: keyType of the claimed Pix Key. Options: 'CPF', 'CNPJ', 'phone' or 'email'
29
+ # - agent [string]: Options: 'claimer' if you requested the PixClaim or 'claimed' if you received a PixClaim request.
30
+ # - bank_code [string]: bank_code of the account linked to the PixClaim being claimed. ex: '20018183'.
31
+ # - claimed_bank_code [string]: bank_code of the account donating the PixClaim. ex: '20018183'.
32
+ # - created [DateTime]: creation datetime for the PixClaim. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
+ # - updated [DateTime]: update datetime for the PixClaim. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ class PixClaim < StarkInfra::Utils::Resource
35
+ attr_reader :account_created, :account_number, :account_type, :branch_code, :name, :tax_id, :key_id, :id, :status, :type, :key_type, :agent, :bank_code, :claimed_bank_code, :created, :updated
36
+ def initialize(
37
+ account_created:, account_number:, account_type:, branch_code:, name:,
38
+ tax_id:, key_id:, id: nil, status: nil, type: nil, key_type: nil, agent: nil,
39
+ bank_code: nil, claimed_bank_code: nil, created: nil, updated: nil
40
+ )
41
+ super(id)
42
+ @account_created = account_created
43
+ @account_number = account_number
44
+ @account_type = account_type
45
+ @branch_code = branch_code
46
+ @name = name
47
+ @tax_id = tax_id
48
+ @key_id = key_id
49
+ @status = status
50
+ @type = type
51
+ @key_type = key_type
52
+ @agent = agent
53
+ @bank_code = bank_code
54
+ @claimed_bank_code = claimed_bank_code
55
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
56
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
57
+ end
58
+
59
+ # # Create a PixClaim
60
+ #
61
+ # Send a PixClaim object for creation in the Stark Infra API
62
+ #
63
+ # ## Parameters (required):
64
+ # - claim [PixClaim object]: PixClaim object to be created in the API. ex: PixClaim.new()
65
+ #
66
+ # ## Parameters (optional):
67
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
68
+ #
69
+ # ## Return:
70
+ # - PixClaim object with updated attributes
71
+ def self.create(claim, user: nil)
72
+ StarkInfra::Utils::Rest.post_single(entity: claim, user: user, **resource)
73
+ end
74
+
75
+ # # Retrieve a specific PixClaim
76
+ #
77
+ # Receive a single PixClaim object previously created in the Stark Infra API by passing its id
78
+ #
79
+ # ## Parameters (required):
80
+ # - id [string]: object unique id. ex: '5656565656565656'
81
+ #
82
+ # ## Parameters (optional):
83
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
84
+ #
85
+ # ## Return:
86
+ # - PixClaim object with updated attributes
87
+ def self.get(id, user: nil)
88
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
89
+ end
90
+
91
+ # # Retrieve PixClaims
92
+ #
93
+ # Receive a generator of PixClaim objects previously created in the Stark Infra API
94
+ #
95
+ # ## Parameters (optional):
96
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
97
+ # - after [Date or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
98
+ # - before [Date or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
99
+ # - status [string, default nil]: filter for status of retrieved objects. Options: 'created', 'failed', 'delivered', 'confirmed', 'success', 'canceled'
100
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
101
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
102
+ # - type [string, default nil]: filter for the type of retrieved PixClaims. Options: 'ownership' or 'portability'
103
+ # - agent [string, default nil]: filter for the agent of retrieved PixClaims. Options: 'claimer' or 'claimed'.
104
+ # - key_type [string, default nil]: filter for the PixKey type of retrieved PixClaims. Options: 'cpf', 'cnpj', 'phone', 'email' and 'evp',
105
+ # - key_id [string, default nil]: filter PixClaims linked to a specific PixKey id. Example: '+5511989898989'.
106
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
107
+ #
108
+ # ## Return:
109
+ # - generator of PixClaim objects with updated attributes
110
+ def self.query(
111
+ limit: nil, after: nil, before: nil, status: nil, ids: nil,
112
+ type: nil, agent: nil, key_type: nil, key_id: nil, user: nil
113
+ )
114
+ after = StarkInfra::Utils::Checks.check_date(after)
115
+ before = StarkInfra::Utils::Checks.check_date(before)
116
+ StarkInfra::Utils::Rest.get_stream(
117
+ limit: limit,
118
+ after: after,
119
+ before: before,
120
+ status: status,
121
+ ids: ids,
122
+ type: type,
123
+ agent: agent,
124
+ key_type: key_type,
125
+ key_id: key_id,
126
+ user: user,
127
+ **resource
128
+ )
129
+ end
130
+
131
+ # # Retrieve paged PixClaims
132
+ #
133
+ # Receive a list of up to 100 PixClaim objects previously created in the Stark infra API and the cursor to the next page.
134
+ # Use this function instead of query if you want to manually page your claims.
135
+ #
136
+ # ## Parameters (optional):
137
+ # - cursor [string, default nil]: cursor returned on the previous page function call
138
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
139
+ # - after [Date or string, default nil]: date filter for objects created or updated only after specified date. ex: Date.new(2020, 3, 10)
140
+ # - before [Date or string, default nil]: date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
141
+ # - status [string, default nil]: filter for status of retrieved objects. Options: 'created', 'failed', 'delivered', 'confirmed', 'success', 'canceled'
142
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
143
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
144
+ # - type [string, default nil]: filter for the type of retrieved PixClaims. Options: 'ownership' or 'portability'
145
+ # - agent [string, default nil]: filter for the agent of retrieved PixClaims. Options: 'claimer' or 'claimed'.
146
+ # - key_type [string, default nil]: filter for the PixKey type of retrieved PixClaims. Options: 'cpf', 'cnpj', 'phone', 'email' and 'evp',
147
+ # - key_id [string, default nil]: filter PixClaims linked to a specific PixKey id. Example: '+5511989898989'.
148
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
149
+ #
150
+ # ## Return:
151
+ # - list of PixClaim objects with updated attributes
152
+ # - cursor to retrieve the next page of PixClaim objects
153
+ def self.page(
154
+ cursor: nil, limit: nil, after: nil, before: nil, status: nil, ids: nil,
155
+ type: nil, agent: nil, key_type: nil, key_id: nil, user: nil
156
+ )
157
+ after = StarkInfra::Utils::Checks.check_date(after)
158
+ before = StarkInfra::Utils::Checks.check_date(before)
159
+ StarkInfra::Utils::Rest.get_page(
160
+ cursor: cursor,
161
+ limit: limit,
162
+ after: after,
163
+ before: before,
164
+ status: status,
165
+ ids: ids,
166
+ type: type,
167
+ agent: agent,
168
+ key_type: key_type,
169
+ key_id: key_id,
170
+ user: user,
171
+ **resource
172
+ )
173
+ end
174
+
175
+ # # Update a PixClaim entity
176
+ #
177
+ # Respond to a received PixClaim.
178
+ #
179
+ # ## Parameters (required):
180
+ # - id [string]: PixClaim unique id. ex: '5656565656565656'
181
+ # - status [string]: patched status for Pix Claim. Options: 'confirmed' and 'canceled'
182
+ #
183
+ # ## Parameters (optional):
184
+ # - reason [string, default 'userRequested']: reason why the PixClaim is being patched. Options: 'fraud', 'userRequested', 'accountClosure'.
185
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
186
+ #
187
+ # ## Return:
188
+ # - updated PixClaim object
189
+ def self.update(id, status:, reason: nil, user: nil)
190
+ StarkInfra::Utils::Rest.patch_id(
191
+ id: id,
192
+ status: status,
193
+ reason: reason,
194
+ user: user,
195
+ **resource
196
+ )
197
+ end
198
+
199
+ def self.resource
200
+ {
201
+ resource_name: 'PixClaim',
202
+ resource_maker: proc { |json|
203
+ PixClaim.new(
204
+ account_created: json['account_created'],
205
+ account_number: json['account_number'],
206
+ account_type: json['account_type'],
207
+ branch_code: json['branch_code'],
208
+ name: json['name'],
209
+ tax_id: json['tax_id'],
210
+ key_id: json['key_id'],
211
+ id: json['id'],
212
+ status: json['status'],
213
+ type: json['type'],
214
+ key_type: json['key_type'],
215
+ agent: json['agent'],
216
+ bank_code: json['bank_code'],
217
+ claimed_bank_code: json['claimed_bank_code'],
218
+ created: json['created'],
219
+ updated: json['updated']
220
+ )
221
+ }
222
+ }
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/resource')
4
+ require_relative('../utils/rest')
5
+
6
+ module StarkInfra
7
+ # # PixDirector object
8
+ #
9
+ # Mandatory data that must be registered within the Central Bank for
10
+ # emergency contact purposes. When you initialize a PixDirector,
11
+ # the entity will not be automatically created in the Stark Infra API.
12
+ # The 'create' function sends the objects to the Stark Infra API and
13
+ # returns the list of created objects.
14
+ #
15
+ # ## Parameters (required):
16
+ # - name [string]: name of the PixDirector. ex: 'Edward Stark'.
17
+ # - tax_id [string]: tax ID (CPF) of the PixDirector. ex: '012.345.678-90'
18
+ # - phone [string]: phone of the PixDirector. ex: '+551198989898'
19
+ # - email [string]: email of the PixDirector. ex: 'ned.stark@starkbank.com'
20
+ # - password [string]: password of the PixDirector. ex: '12345678'
21
+ # - team_email [string]: team email. ex: 'pix.team@company.com'
22
+ # - team_phones [list of strings]: list of phones of the team. ex: ['+5511988889999', '+5511988889998']
23
+ #
24
+ # ## Attributes (return-only):
25
+ # - id [string]: unique id returned when the PixDirector is created. ex: '5656565656565656'
26
+ # - status [string]: current PixDirector status. ex: 'success'
27
+ class PixDirector < StarkInfra::Utils::Resource
28
+ attr_reader :name, :tax_id, :phone, :email, :password, :team_email, :team_phones, :id, :status
29
+ def initialize(name:, tax_id:, phone:, email:, password:, team_email:, team_phones:, id: nil, status: nil)
30
+ super(id)
31
+ @name = name
32
+ @tax_id = tax_id
33
+ @phone = phone
34
+ @email = email
35
+ @password = password
36
+ @team_email = team_email
37
+ @team_phones = team_phones
38
+ @status = status
39
+ end
40
+
41
+ # # Create a PixDirector
42
+ #
43
+ # Send a PixDirector object for creation in the Stark Infra API
44
+ #
45
+ # ## Parameters (required):
46
+ # - director [PixDirector object]: PixDirector object to be created in the API. ex: PixDirector.new()
47
+ #
48
+ # ## Parameters (optional):
49
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
50
+ #
51
+ # ## Return:
52
+ # - PixDirector object with updated attributes.
53
+ def self.create(director, user: nil)
54
+ StarkInfra::Utils::Rest.post_single(entity: director, user: user, **resource)
55
+ end
56
+
57
+ def self.resource
58
+ {
59
+ resource_name: 'PixDirector',
60
+ resource_maker: proc { |json|
61
+ PixDirector.new(
62
+ id: json['id'],
63
+ name: json['name'],
64
+ tax_id: json['tax_id'],
65
+ phone: json['phone'],
66
+ email: json['email'],
67
+ password: json['password'],
68
+ team_email: json['team_email'],
69
+ team_phones: json['team_phones'],
70
+ status: json['status']
71
+ )
72
+ }
73
+ }
74
+ end
75
+ end
76
+ end