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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcode_preview/brcode_preview.rb +25 -4
  3. data/lib/brcode_preview/subscription.rb +102 -0
  4. data/lib/business_account_request/business_account_request.rb +276 -0
  5. data/lib/business_account_request/log.rb +124 -0
  6. data/lib/business_attachment/business_attachment.rb +189 -0
  7. data/lib/{individual_document → business_attachment}/log.rb +35 -32
  8. data/lib/business_identity/business_identity.rb +228 -0
  9. data/lib/business_identity/log.rb +127 -0
  10. data/lib/credit_holmes/credit_holmes.rb +2 -1
  11. data/lib/credit_holmes/log.rb +125 -0
  12. data/lib/credit_note/credit_note.rb +51 -8
  13. data/lib/credit_note/rule.rb +55 -0
  14. data/lib/credit_note/transfer.rb +1 -1
  15. data/lib/credit_preview/credit_note_preview.rb +10 -2
  16. data/lib/credit_preview/credit_preview.rb +2 -1
  17. data/lib/credit_signer/credit_signer.rb +27 -2
  18. data/lib/dynamic_brcode/dynamic_brcode.rb +5 -2
  19. data/lib/event/event.rb +10 -2
  20. data/lib/individual_account_attachment/individual_account_attachment.rb +178 -0
  21. data/lib/individual_account_attachment/log.rb +124 -0
  22. data/lib/individual_account_request/individual_account_request.rb +271 -0
  23. data/lib/individual_account_request/log.rb +124 -0
  24. data/lib/individual_identity/individual_identity.rb +4 -7
  25. data/lib/issuing_balance/issuing_balance.rb +8 -2
  26. data/lib/issuing_billing_invoice/issuing_billing_invoice.rb +155 -0
  27. data/lib/issuing_billing_transaction/issuing_billing_transaction.rb +142 -0
  28. data/lib/issuing_card/issuing_card.rb +10 -6
  29. data/lib/issuing_design/issuing_design.rb +9 -0
  30. data/lib/issuing_embossing_request/issuing_embossing_request.rb +3 -2
  31. data/lib/issuing_holder/issuing_holder.rb +6 -5
  32. data/lib/issuing_product/issuing_product.rb +6 -3
  33. data/lib/issuing_purchase/issuing_purchase.rb +41 -8
  34. data/lib/issuing_restock/issuing_restock.rb +3 -2
  35. data/lib/issuing_rule/issuing_rule.rb +45 -3
  36. data/lib/issuing_stock/issuing_stock.rb +5 -2
  37. data/lib/issuing_stock_rule/issuing_stock_rule.rb +214 -0
  38. data/lib/issuing_token/issuing_token.rb +309 -0
  39. data/lib/issuing_token/log.rb +127 -0
  40. data/lib/issuing_token_activation/issuing_token_activation.rb +62 -0
  41. data/lib/issuing_token_design/issuing_token_design.rb +118 -0
  42. data/lib/issuing_token_request/issuing_token_request.rb +63 -0
  43. data/lib/issuing_withdrawal/issuing_withdrawal.rb +2 -2
  44. data/lib/ledger/ledger.rb +175 -0
  45. data/lib/ledger/log.rb +122 -0
  46. data/lib/ledger/rule.rb +55 -0
  47. data/lib/ledger_transaction/ledger_transaction.rb +179 -0
  48. data/lib/merchant_category/merchant_category.rb +6 -3
  49. data/lib/pix_balance/pix_balance.rb +1 -1
  50. data/lib/pix_chargeback/pix_chargeback.rb +34 -7
  51. data/lib/pix_claim/pix_claim.rb +14 -6
  52. data/lib/pix_director/pix_director.rb +1 -1
  53. data/lib/pix_dispute/log.rb +127 -0
  54. data/lib/pix_dispute/pix_dispute.rb +210 -0
  55. data/lib/pix_dispute/transaction.rb +91 -0
  56. data/lib/pix_fraud/log.rb +128 -0
  57. data/lib/pix_fraud/pix_fraud.rb +180 -0
  58. data/lib/pix_infraction/pix_infraction.rb +37 -7
  59. data/lib/pix_internal_transaction_report/log.rb +129 -0
  60. data/lib/pix_internal_transaction_report/pix_internal_transaction_report.rb +200 -0
  61. data/lib/pix_key/pix_key.rb +1 -1
  62. data/lib/pix_key_holmes/log.rb +129 -0
  63. data/lib/{individual_document/individual_document.rb → pix_key_holmes/pix_key_holmes.rb} +48 -56
  64. data/lib/pix_pull_request/log.rb +127 -0
  65. data/lib/pix_pull_request/pix_pull_request.rb +268 -0
  66. data/lib/pix_pull_subscription/log.rb +127 -0
  67. data/lib/pix_pull_subscription/pix_pull_subscription.rb +307 -0
  68. data/lib/pix_request/pix_request.rb +19 -6
  69. data/lib/pix_reversal/pix_reversal.rb +14 -8
  70. data/lib/pix_statement/pix_statement.rb +11 -5
  71. data/lib/pix_user/pix_user.rb +52 -0
  72. data/lib/pix_user/statistics.rb +64 -0
  73. data/lib/starkinfra.rb +45 -4
  74. data/lib/static_brcode/static_brcode.rb +8 -4
  75. data/lib/utils/bacen_id.rb +27 -0
  76. data/lib/utils/end_to_end_id.rb +20 -0
  77. data/lib/utils/pix_subscription_bacen_id.rb +21 -0
  78. data/lib/utils/return_id.rb +21 -0
  79. data/lib/webhook/webhook.rb +3 -3
  80. metadata +48 -11
@@ -0,0 +1,307 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/parse')
6
+
7
+ module StarkInfra
8
+ # # PixPullSubscription object
9
+ #
10
+ # A PixPullSubscription is a recurring Pix debit authorization. It defines the frequency, amount,
11
+ # and required payer authorizations for a series of Pix debits to be pulled from the sender by
12
+ # the receiver. Each cycle of an active subscription is triggered by a PixPullRequest whose
13
+ # subscription_id references the subscription's id.
14
+ #
15
+ # When you initialize a PixPullSubscription, the entity will not be automatically
16
+ # created in the Stark Infra API. The 'create' function sends the objects
17
+ # to the Stark Infra API and returns the list of created objects.
18
+ #
19
+ # ## Parameters (required):
20
+ # - bacen_id [string]: Central Bank's unique recurrency id. Identifies the subscription in the Pix infrastructure.
21
+ # - external_id [string]: url safe string that must be unique among all your Pix Pull Subscriptions. Used for idempotency. ex: 'my-internal-id-123456'
22
+ # - installment_start [DateTime or string]: start datetime of settlements allowed for this subscription. ex: '2020-10-28T17:59:26.249976+00:00'
23
+ # - interval [string]: cycle definition. Options: 'week', 'month', 'quarter', 'semester', 'year'
24
+ # - receiver_name [string]: receiver's full name. ex: 'Edward Stark'
25
+ # - receiver_tax_id [string]: receiver's tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
26
+ # - sender_account_number [string]: sender's bank account number. Use '-' before the verifier digit. ex: '876543-2'
27
+ # - sender_bank_code [string]: sender's bank institution code in Brazil. ex: '20018183'
28
+ # - sender_branch_code [string]: sender's bank account branch code. Use '-' in case there is a verifier digit. ex: '1357-9'
29
+ # - sender_tax_id [string]: sender's tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
30
+ # - type [string]: subscription journey type. Options: 'push', 'qrcode', 'qrcodeAndPayment', 'paymentAndOrQrcode'
31
+ #
32
+ # ## Parameters (conditionally-required):
33
+ # - amount [integer, default nil]: amount in cents charged every cycle. Required if the subscription has a fixed amount. ex: 1234 (= R$ 12.34)
34
+ # - amount_min_limit [integer, default nil]: floor value for the maximum amount the sender can set when approving. Required if the subscription has a variable amount. ex: 1234 (= R$ 12.34)
35
+ #
36
+ # ## Parameters (optional):
37
+ # - description [string, default nil]: additional information delivered to the sender. ex: 'Payment for service #1234'
38
+ # - due [DateTime or string, default nil]: due date for the sender's answer (approval or denial). ex: '2020-10-28T17:59:26.249976+00:00'
39
+ # - installment_end [DateTime or string, default nil]: end datetime of settlements allowed for this subscription. ex: '2020-10-28T17:59:26.249976+00:00'
40
+ # - receiver_bank_code [string, default nil]: receiver's bank institution code. Defaults to the workspace's primary institution when omitted. ex: '20018183'
41
+ # - reference_code [string, default nil]: commercial-relation identifier. May be a contract number, order id, or client code. ex: 'contract-123'
42
+ # - pull_retry_limit [integer, default nil]: max number of retries the receiver may issue for a single failed pull cycle. ex: 3
43
+ # - sender_city_code [string, default nil]: IBGE code of the payer's city. ex: '3550308'
44
+ # - sender_final_name [string, default nil]: final sender name when the sender differs from the originating institution. ex: 'Edward Stark'
45
+ # - sender_final_tax_id [string, default nil]: final sender tax ID. Same format rules as sender_tax_id. ex: '01234567890' or '20.018.183/0001-80'
46
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['employees', 'monthly']
47
+ #
48
+ # ## Attributes (return-only):
49
+ # - id [string]: unique id returned when the PixPullSubscription is created. ex: '5656565656565656'
50
+ # - status [string]: current PixPullSubscription status. Options: 'created', 'pending', 'failed', 'denied', 'approved', 'active', 'expired', 'canceled'
51
+ # - flow [string]: direction of money flow. Options: 'in', 'out'
52
+ # - created [DateTime]: creation datetime for the PixPullSubscription. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
53
+ # - updated [DateTime]: latest update datetime for the PixPullSubscription. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
54
+ class PixPullSubscription < StarkCore::Utils::Resource
55
+ attr_reader :bacen_id, :external_id, :installment_start, :interval, :receiver_name, :receiver_tax_id,
56
+ :sender_account_number, :sender_bank_code, :sender_branch_code, :sender_tax_id, :type,
57
+ :amount, :amount_min_limit, :description, :due, :installment_end, :receiver_bank_code,
58
+ :reference_code, :pull_retry_limit, :sender_city_code, :sender_final_name, :sender_final_tax_id,
59
+ :tags, :id, :status, :flow, :created, :updated
60
+ def initialize(
61
+ bacen_id:, external_id:, installment_start:, interval:, receiver_name:, receiver_tax_id:,
62
+ sender_account_number:, sender_bank_code:, sender_branch_code:, sender_tax_id:, type:,
63
+ amount: nil, amount_min_limit: nil, description: nil, due: nil, installment_end: nil,
64
+ receiver_bank_code: nil, reference_code: nil, pull_retry_limit: nil, sender_city_code: nil,
65
+ sender_final_name: nil, sender_final_tax_id: nil, tags: nil, id: nil, status: nil, flow: nil,
66
+ created: nil, updated: nil
67
+ )
68
+ super(id)
69
+ @bacen_id = bacen_id
70
+ @external_id = external_id
71
+ @installment_start = StarkCore::Utils::Checks.check_datetime(installment_start)
72
+ @interval = interval
73
+ @receiver_name = receiver_name
74
+ @receiver_tax_id = receiver_tax_id
75
+ @sender_account_number = sender_account_number
76
+ @sender_bank_code = sender_bank_code
77
+ @sender_branch_code = sender_branch_code
78
+ @sender_tax_id = sender_tax_id
79
+ @type = type
80
+ @amount = amount
81
+ @amount_min_limit = amount_min_limit
82
+ @description = description
83
+ @due = StarkCore::Utils::Checks.check_datetime(due == '' ? nil : due)
84
+ @installment_end = StarkCore::Utils::Checks.check_datetime(installment_end == '' ? nil : installment_end)
85
+ @receiver_bank_code = receiver_bank_code
86
+ @reference_code = reference_code
87
+ @pull_retry_limit = pull_retry_limit
88
+ @sender_city_code = sender_city_code
89
+ @sender_final_name = sender_final_name
90
+ @sender_final_tax_id = sender_final_tax_id
91
+ @tags = tags
92
+ @status = status
93
+ @flow = flow
94
+ @created = StarkCore::Utils::Checks.check_datetime(created)
95
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
96
+ end
97
+
98
+ # # Create PixPullSubscriptions
99
+ #
100
+ # Send a list of PixPullSubscription objects for creation in the Stark Infra API
101
+ #
102
+ # ## Parameters (required):
103
+ # - subscriptions [list of PixPullSubscription objects]: list of PixPullSubscription objects to be created in the API
104
+ #
105
+ # ## Parameters (optional):
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
+ # - list of PixPullSubscription objects with updated attributes
110
+ def self.create(subscriptions, user: nil)
111
+ StarkInfra::Utils::Rest.post(entities: subscriptions, user: user, **resource)
112
+ end
113
+
114
+ # # Retrieve a specific PixPullSubscription
115
+ #
116
+ # Receive a single PixPullSubscription object previously created in the Stark Infra API by passing its id
117
+ #
118
+ # ## Parameters (required):
119
+ # - id [string]: object unique id. ex: '5656565656565656'
120
+ #
121
+ # ## Parameters (optional):
122
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
123
+ #
124
+ # ## Return:
125
+ # - PixPullSubscription object with updated attributes
126
+ def self.get(id, user: nil)
127
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
128
+ end
129
+
130
+ # # Retrieve PixPullSubscriptions
131
+ #
132
+ # Receive a generator of PixPullSubscription objects previously created in the Stark Infra API
133
+ #
134
+ # ## Parameters (optional):
135
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
136
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
137
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
138
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'canceled']
139
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['employees', 'monthly']
140
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
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
+ # - generator of PixPullSubscription objects with updated attributes
145
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
146
+ after = StarkCore::Utils::Checks.check_date(after)
147
+ before = StarkCore::Utils::Checks.check_date(before)
148
+ StarkInfra::Utils::Rest.get_stream(
149
+ limit: limit,
150
+ after: after,
151
+ before: before,
152
+ status: status,
153
+ tags: tags,
154
+ ids: ids,
155
+ user: user,
156
+ **resource
157
+ )
158
+ end
159
+
160
+ # # Retrieve paged PixPullSubscriptions
161
+ #
162
+ # Receive a list of up to 100 PixPullSubscription objects previously created in the Stark Infra API and the cursor to the next page.
163
+ # Use this function instead of query if you want to manually page your subscriptions.
164
+ #
165
+ # ## Parameters (optional):
166
+ # - cursor [string, default nil]: cursor returned on the previous page function call
167
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
168
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
169
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
170
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'canceled']
171
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['employees', 'monthly']
172
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
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
+ # - list of PixPullSubscription objects with updated attributes
177
+ # - cursor to retrieve the next page of PixPullSubscription objects
178
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
179
+ after = StarkCore::Utils::Checks.check_date(after)
180
+ before = StarkCore::Utils::Checks.check_date(before)
181
+ StarkInfra::Utils::Rest.get_page(
182
+ cursor: cursor,
183
+ limit: limit,
184
+ after: after,
185
+ before: before,
186
+ status: status,
187
+ tags: tags,
188
+ ids: ids,
189
+ user: user,
190
+ **resource
191
+ )
192
+ end
193
+
194
+ # # Update PixPullSubscriptions
195
+ #
196
+ # A PixPullSubscription can be patched to approve, deny or activate it. As the payer (sender), you may set
197
+ # status to 'approved' or 'denied'. As the receiver, you may set status to 'active' once approved. When
198
+ # confirming (approving), include sender_city_code.
199
+ #
200
+ # ## Parameters (required):
201
+ # - id [string]: PixPullSubscription unique id. ex: '5656565656565656'
202
+ # - patch_data [hash]: hash containing the attributes to be updated. ex: { status: 'approved', sender_city_code: '3550308' }
203
+ # ## Parameters (required):
204
+ # - status [string]: new status of the Pix Subscription.
205
+ # ## Parameters (conditionally-required):
206
+ # - sender_city_code [string]: IBGE code of the payer's city. Required if you are confirming the subscription.
207
+ # - reason [string]: reason why the PixPullSubscription is being patched. Options: 'invalidSenderAccountNumber', 'accountClosed', 'accountBlocked', 'invalidBranchCode', 'notRecognizedBySender', 'userRejected', 'notOffered'.
208
+ #
209
+ # ## Parameters (optional):
210
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
211
+ #
212
+ # ## Return:
213
+ # - updated PixPullSubscription object
214
+ def self.update(id, patch_data: nil, user: nil)
215
+ patch_data ||= {}
216
+ StarkInfra::Utils::Rest.patch_id(id: id, user: user, **patch_data, **resource)
217
+ end
218
+
219
+ # # Cancel a PixPullSubscription entity
220
+ #
221
+ # Cancel a PixPullSubscription entity previously created in the Stark Infra API.
222
+ # The reason is sent as a query parameter, not in the request body.
223
+ #
224
+ # ## Parameters (required):
225
+ # - id [string]: PixPullSubscription unique id. ex: '5656565656565656'
226
+ # - reason [string, default nil]: reason for the cancellation. Options: 'accountClosed', 'receiverOrganizationClosed', 'receiverInternalError', 'senderDeceased', 'fraud', 'senderUserRequested', 'receiverUserRequested', 'paymentNotFound'.
227
+ #
228
+ # ## Parameters (optional):
229
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
230
+ #
231
+ # ## Return:
232
+ # - canceled PixPullSubscription object
233
+ def self.cancel(id, reason:, user: nil)
234
+ response = StarkInfra::Utils::Rest.delete_raw(
235
+ path: "/pix-pull-subscription/#{id}",
236
+ query: { reason: reason },
237
+ user: user,
238
+ raiseException: true
239
+ )
240
+ maker = resource[:resource_maker]
241
+ StarkCore::Utils::API.from_api_json(maker, response.json['subscription'])
242
+ end
243
+
244
+ # # Create a single verified PixPullSubscription object from a content string
245
+ #
246
+ # Create a single PixPullSubscription object from a content string received from a handler listening at the subscription url.
247
+ # If the provided digital signature does not check out with the StarkInfra public key, a
248
+ # StarkInfra::Error::InvalidSignatureError will be raised.
249
+ #
250
+ # ## Parameters (required):
251
+ # - content [string]: response content from request received at user endpoint (not parsed)
252
+ # - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
253
+ #
254
+ # ## Parameters (optional):
255
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
256
+ #
257
+ # ## Return:
258
+ # - Parsed PixPullSubscription object
259
+ def self.parse(content:, signature:, user: nil)
260
+ StarkInfra::Utils::Parse.parse_and_verify(
261
+ content: content,
262
+ signature: signature,
263
+ user: user,
264
+ key: nil,
265
+ resource: resource
266
+ )
267
+ end
268
+
269
+ def self.resource
270
+ {
271
+ resource_name: 'PixPullSubscription',
272
+ resource_maker: proc { |json|
273
+ PixPullSubscription.new(
274
+ id: json['id'],
275
+ bacen_id: json['bacen_id'],
276
+ external_id: json['external_id'],
277
+ installment_start: json['installment_start'],
278
+ interval: json['interval'],
279
+ receiver_name: json['receiver_name'],
280
+ receiver_tax_id: json['receiver_tax_id'],
281
+ sender_account_number: json['sender_account_number'],
282
+ sender_bank_code: json['sender_bank_code'],
283
+ sender_branch_code: json['sender_branch_code'],
284
+ sender_tax_id: json['sender_tax_id'],
285
+ type: json['type'],
286
+ amount: json['amount'],
287
+ amount_min_limit: json['amount_min_limit'],
288
+ description: json['description'],
289
+ due: json['due'],
290
+ installment_end: json['installment_end'],
291
+ receiver_bank_code: json['receiver_bank_code'],
292
+ reference_code: json['reference_code'],
293
+ pull_retry_limit: json['pull_retry_limit'],
294
+ sender_city_code: json['sender_city_code'],
295
+ sender_final_name: json['sender_final_name'],
296
+ sender_final_tax_id: json['sender_final_tax_id'],
297
+ tags: json['tags'],
298
+ status: json['status'],
299
+ flow: json['flow'],
300
+ created: json['created'],
301
+ updated: json['updated']
302
+ )
303
+ }
304
+ }
305
+ end
306
+ end
307
+ end
@@ -35,18 +35,23 @@ module StarkInfra
35
35
  # - cashier_bank_code [string]: Cashier's bank code. Required if the cash_amount is different from 0. ex: '20018183'
36
36
  #
37
37
  # ## Parameters (optional):
38
- # - cash_amount [integer, default nil]: Amount to be withdrawal from the cashier in cents. ex: 1000 (= R$ 10.00)
38
+ # - cash_amount [integer, default nil]: amount to be withdrawn from the cashier in cents for Pix Saque/Troco; must be less than or equal to amount. ex: 1000 (= R$ 10.00)
39
39
  # - receiver_key_id [string, default nil]: Receiver's dict key. Example: tax id (CPF/CNPJ).
40
40
  # - description [string, default nil]: optional description to override default description to be shown in the bank statement. ex: 'Payment for service #1234'
41
41
  # - reconciliation_id [string, default nil]: Reconciliation ID linked to this payment. ex: 'b77f5236-7ab9-4487-9f95-66ee6eaf1781'
42
42
  # - initiator_tax_id [string, default nil]: Payment initiator's tax id (CPF/CNPJ). ex: '01234567890' or '20.018.183/0001-80'
43
43
  # - tags [list of strings, default nil]: list of strings for reference when searching for PixRequests. ex: ['employees', 'monthly']
44
44
  # - method [string, default nil]: execution method of creation of the Pix. ex: 'manual', 'payerQrcode', 'dynamicQrcode'.
45
+ # - priority priority [string, default 'high']: Specifies the message channel used to send the Pix Request. If set to 'high', the request is sent through the primary channel; if set to 'low', it uses the secondary channel. Options: 'high' or 'low'
46
+ # - reason [string, default 'customerRequest']: underlying reason for the payment transaction. Options: 'customerRequest', 'subscriptionFlaw', 'fraud'. When reason is 'fraud' (returning funds from a PixDispute), dispute_id is required and sender_tax_id must be your institution's organization tax ID (CNPJ).
47
+ #
48
+ # ## Parameters (conditionally-required):
49
+ # - dispute_id [string, default nil]: Id of the Pix Dispute being refunded. Required when reason is 'fraud' and not allowed with any other reason. The dispute must be one you received and must be awaiting the refund, otherwise the request is refused with invalidDisputeId.
45
50
  #
46
51
  # ## Attributes (return-only):
47
52
  # - id [string]: unique id returned when the PixRequest is created. ex: '5656565656565656'
48
53
  # - fee [integer]: fee charged when PixRequest is paid. ex: 200 (= R$ 2.00)
49
- # - status [string]: current PixRequest status. ex: 'registered' or 'paid'
54
+ # - status [string]: current PixRequest status. Options: 'created', 'processing', 'success', 'failed'.
50
55
  # - flow [string]: direction of money flow. ex: 'in' or 'out'
51
56
  # - sender_bank_code [string]: code of the sender bank institution in Brazil. ex: '20018183'
52
57
  # - created [DateTime]: creation datetime for the PixRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
@@ -56,13 +61,14 @@ module StarkInfra
56
61
  :sender_account_type, :receiver_name, :receiver_tax_id, :receiver_bank_code, :receiver_account_number,
57
62
  :receiver_branch_code, :receiver_account_type, :end_to_end_id, :cashier_type,
58
63
  :cashier_bank_code, :cash_amount, :receiver_key_id, :description, :reconciliation_id, :initiator_tax_id,
59
- :tags, :method, :id, :fee, :status, :flow, :sender_bank_code, :created, :updated
64
+ :tags, :method, :priority, :reason, :dispute_id, :id, :fee, :status, :flow, :sender_bank_code, :created, :updated
60
65
  def initialize(
61
66
  amount:, external_id:, sender_name:, sender_tax_id:, sender_branch_code:, sender_account_number:,
62
67
  sender_account_type:, receiver_name:, receiver_tax_id:, receiver_bank_code:, receiver_account_number:,
63
68
  receiver_branch_code:, receiver_account_type:, end_to_end_id:, cashier_type: nil, cashier_bank_code: nil,
64
69
  cash_amount: nil, receiver_key_id: nil, description: nil, reconciliation_id: nil, initiator_tax_id: nil,
65
- tags: nil, method: nil, id: nil, fee: nil, status:nil, flow: nil, sender_bank_code: nil, created: nil, updated: nil
70
+ tags: nil, method: nil, priority: nil, reason: nil, dispute_id: nil, id: nil, fee: nil, status:nil, flow: nil, sender_bank_code: nil,
71
+ created: nil, updated: nil
66
72
  )
67
73
  super(id)
68
74
  @amount = amount
@@ -88,6 +94,9 @@ module StarkInfra
88
94
  @initiator_tax_id = initiator_tax_id
89
95
  @tags = tags
90
96
  @method = method
97
+ @priority = priority
98
+ @reason = reason
99
+ @dispute_id = dispute_id
91
100
  @fee = fee
92
101
  @status = status
93
102
  @flow = flow
@@ -216,7 +225,7 @@ module StarkInfra
216
225
  # ## Return:
217
226
  # - Parsed PixRequest object
218
227
  def self.parse(content:, signature:, user: nil)
219
- request = StarkCore::Utils::Parse.parse_and_verify(content: content, signature: signature, user: user, resource: resource)
228
+ request = StarkInfra::Utils::Parse.parse_and_verify(content: content, signature: signature, user: user, resource: resource)
220
229
 
221
230
  !request.fee.nil? ? request.fee : 0
222
231
  !request.tags.nil? ? request.tags : []
@@ -226,7 +235,8 @@ module StarkInfra
226
235
  request
227
236
  end
228
237
 
229
- # Helps you respond to a PixRequest authorization
238
+ # Helps you respond to a PixRequest authorization. You must answer within 1 second with HTTP status 200,
239
+ # or the request is denied by default.
230
240
  #
231
241
  ## Parameters (required):
232
242
  # - status [string]: response to the authorization. ex: 'approved' or 'denied'
@@ -276,6 +286,9 @@ module StarkInfra
276
286
  initiator_tax_id: json['initiator_tax_id'],
277
287
  tags: json['tags'],
278
288
  method: json['method'],
289
+ priority: json['priority'],
290
+ reason: json['reason'],
291
+ dispute_id: json['dispute_id'],
279
292
  fee: json['fee'],
280
293
  status: json['status'],
281
294
  flow: json['flow'],
@@ -18,7 +18,7 @@ module StarkInfra
18
18
  # - amount [integer]: amount in cents to be reversed from PixRequest. ex: 1234 (= R$ 12.34)
19
19
  # - external_id [string]: string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: 'my-internal-id-123456'
20
20
  # - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
21
- # - reason [string]: reason why the PixRequest is being reversed. Options are 'bankError', 'fraud', 'pixWithdrawError', 'refund3ByEndCustomer'
21
+ # - reason [string]: reason why the PixReversal is being reversed. Options are 'bankError', 'fraud', 'cashierError', 'customerRequest'.
22
22
  #
23
23
  # ## Parameters (optional):
24
24
  # - tags [list of strings, default nil]: list of strings for reference when searching for PixReversals. ex: ['employees', 'monthly']
@@ -27,16 +27,17 @@ module StarkInfra
27
27
  # - id [string]: unique id returned when the PixReversal is created. ex: '5656565656565656'.
28
28
  # - return_id [string]: central bank's unique reversal transaction ID. ex: 'D20018183202202030109X3OoBHG74wo'.
29
29
  # - fee [string]: fee charged by this PixReversal. ex: 200 (= R$ 2.00)
30
- # - status [string]: current PixReversal status. ex: 'registered' or 'paid'
30
+ # - status [string]: current PixReversal status. Options are 'created', 'processing', 'success' or 'failed'.
31
31
  # - flow [string]: direction of money flow. ex: 'in' or 'out'
32
32
  # - created [DateTime]: creation datetime for the PixReversal. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
33
  # - updated [DateTime]: latest update datetime for the PixReversal. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ # - description [string]: description of the reversal.
34
35
  class PixReversal < StarkCore::Utils::Resource
35
36
  attr_reader :amount, :external_id, :end_to_end_id, :reason, :tags, :id, :return_id,
36
- :fee, :status, :flow, :created, :updated
37
+ :fee, :status, :flow, :created, :updated, :description
37
38
  def initialize(
38
39
  amount:, external_id:, end_to_end_id:, reason:, tags: nil, id: nil, return_id: nil, fee: nil,
39
- status: nil, flow: nil, created: nil, updated: nil
40
+ status: nil, flow: nil, created: nil, updated: nil, description: nil
40
41
  )
41
42
  super(id)
42
43
  @amount = amount
@@ -50,11 +51,13 @@ module StarkInfra
50
51
  @flow = flow
51
52
  @created = StarkCore::Utils::Checks.check_datetime(created)
52
53
  @updated = StarkCore::Utils::Checks.check_datetime(updated)
54
+ @description = description
53
55
  end
54
56
 
55
57
  # # Create PixReversals
56
58
  #
57
- # Send a list of PixReversal objects for creation in the Stark Infra API
59
+ # Send a list of PixReversal objects for creation in the Stark Infra API. Reversals can only be created
60
+ # for inbound PixRequests with status 'success'; reference the original request by its end_to_end_id.
58
61
  #
59
62
  # ## Parameters (required):
60
63
  # - reversals [list of PixReversal objects]: list of PixReversal objects to be created in the API
@@ -170,7 +173,7 @@ module StarkInfra
170
173
  # ## Return:
171
174
  # - Parsed PixReversal object
172
175
  def self.parse(content:, signature:, user: nil)
173
- reversal = StarkCore::Utils::Parse.parse_and_verify(
176
+ reversal = StarkInfra::Utils::Parse.parse_and_verify(
174
177
  content: content,
175
178
  signature: signature,
176
179
  user: user,
@@ -185,7 +188,9 @@ module StarkInfra
185
188
  reversal
186
189
  end
187
190
 
188
- # Helps you respond to a PixReversal authorization
191
+ # Helps you respond to a PixReversal authorization sent to your pixReversalUrl (must differ from your
192
+ # pixRequestUrl). Answer within 1 second with HTTP 200, or it is denied by default; if no pixReversalUrl
193
+ # is registered, inbound reversals are accepted by default.
189
194
  #
190
195
  ## Parameters (required):
191
196
  # - status [string]: response to the authorization. ex: 'approved' or 'denied'
@@ -222,7 +227,8 @@ module StarkInfra
222
227
  status: json['status'],
223
228
  flow: json['flow'],
224
229
  created: json['created'],
225
- updated: json['updated']
230
+ updated: json['updated'],
231
+ description: json['description']
226
232
  )
227
233
  }
228
234
  }
@@ -22,13 +22,17 @@ module StarkInfra
22
22
  #
23
23
  # ## Attributes (return-only):
24
24
  # - id [string]: unique id returned when the PixStatement is created. ex: '5656565656565656'
25
- # - status [string]: current PixStatement status. ex: 'success' or 'failed'
25
+ # - status [string]: current PixStatement status. Options: 'created', 'looking', 'success', 'failed'.
26
26
  # - transaction_count [integer]: number of transactions that happened during the day that the PixStatement was requested. ex: 11
27
27
  # - created [DateTime]: creation datetime for the PixStatement. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
28
28
  # - updated [DateTime]: latest update datetime for the PixStatement. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
29
+ # - chunk_count [integer]: number of chunks the statement file is split into. ex: 2
29
30
  class PixStatement < StarkCore::Utils::Resource
30
- attr_reader :after, :before, :type, :id, :status, :transaction_count, :created, :updated
31
- def initialize(after:, before:, type:, id: nil, status: nil, transaction_count: nil, created: nil, updated: nil)
31
+ attr_reader :after, :before, :type, :id, :status, :transaction_count, :created, :updated, :chunk_count
32
+ def initialize(
33
+ after:, before:, type:, id: nil, status: nil, transaction_count: nil, created: nil, updated: nil,
34
+ chunk_count: nil
35
+ )
32
36
  super(id)
33
37
  @after = StarkCore::Utils::Checks.check_date(after)
34
38
  @before = StarkCore::Utils::Checks.check_date(before)
@@ -37,6 +41,7 @@ module StarkInfra
37
41
  @transaction_count = transaction_count
38
42
  @created = StarkCore::Utils::Checks.check_datetime(created)
39
43
  @updated = StarkCore::Utils::Checks.check_datetime(updated)
44
+ @chunk_count = chunk_count
40
45
  end
41
46
 
42
47
  # # Create a PixStatement object
@@ -117,7 +122,7 @@ module StarkInfra
117
122
 
118
123
  # # # Retrieve a .cvs PixStatement
119
124
  #
120
- # Retrieve a specific PixStatement by its ID in a .csv file.
125
+ # Retrieve a specific PixStatement's CSV file by its ID. The file is returned compressed in gzip format.
121
126
  #
122
127
  # ## Parameters (required):
123
128
  # - id [string]: object unique id. ex: '5656565656565656'
@@ -143,7 +148,8 @@ module StarkInfra
143
148
  status: json['status'],
144
149
  transaction_count: json['transaction_count'],
145
150
  created: json['created'],
146
- updated: json['updated']
151
+ updated: json['updated'],
152
+ chunk_count: json['chunk_count']
147
153
  )
148
154
  }
149
155
  }
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+
6
+ module StarkInfra
7
+ # # PixUser object
8
+ #
9
+ # Pix Users are used to get fraud statistics of a user.
10
+ #
11
+ # ## Parameters (required):
12
+ # - id [string]: user tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
13
+ #
14
+ # ## Attributes (return-only):
15
+ # - statistics [list of PixUser::Statistics, default []]: list of PixUser::Statistics objects. ex: [PixUser::Statistics.new(after: '2023-11-06T18:57:08.325090+00:00', source: 'pix-key')]
16
+ class PixUser < StarkCore::Utils::Resource
17
+ attr_reader :id, :statistics
18
+ def initialize(id:, statistics: nil)
19
+ super(id)
20
+ @statistics = StarkInfra::PixUser::Statistics.parse_statistics(statistics)
21
+ end
22
+
23
+ # # Retrieve a PixUser object
24
+ #
25
+ # Receive a single PixUser object information by passing its taxId
26
+ #
27
+ # ## Parameters (required):
28
+ # - id [string]: user tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
29
+ #
30
+ # ## Parameters (optional):
31
+ # - key_id [string, default nil]: marked PixKey id. ex: '+5511989898989'
32
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
33
+ #
34
+ # ## Return:
35
+ # - PixUser object that corresponds to the given id.
36
+ def self.get(id, key_id: nil, user: nil)
37
+ StarkInfra::Utils::Rest.get_id(id: id, key_id: key_id, user: user, **resource)
38
+ end
39
+
40
+ def self.resource
41
+ {
42
+ resource_name: 'PixUser',
43
+ resource_maker: proc { |json|
44
+ PixUser.new(
45
+ id: json['id'],
46
+ statistics: json['statistics']
47
+ )
48
+ }
49
+ }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,64 @@
1
+ require_relative('../utils/rest')
2
+
3
+ module StarkInfra
4
+ class PixUser
5
+ # # PixUser::Statistics object
6
+ #
7
+ # The PixUser::Statistics object stores fraud statistics data of a Pix user.
8
+ #
9
+ # ## Attributes (return-only):
10
+ # - value [integer]: aggregated value of the statistic. ex: 3
11
+ # - type [string]: type of the statistic. ex: 'infractions'
12
+ # - source [string]: source of the statistic. ex: 'keyManagement'
13
+ # - after [DateTime]: start datetime considered for the statistic aggregation. ex: DateTime.new(2020, 4, 23, 23, 0, 0)
14
+ # - updated [DateTime]: latest update datetime for the statistic. ex: DateTime.new(2020, 4, 23, 23, 0, 0)
15
+ class Statistics < StarkCore::Utils::SubResource
16
+ attr_reader :value, :type, :source, :after, :updated
17
+ def initialize(value: nil, type: nil, source: nil, after: nil, updated: nil)
18
+ @value = value
19
+ @type = type
20
+ @source = source
21
+ @after = StarkCore::Utils::Checks.check_datetime(after)
22
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
23
+ end
24
+
25
+ # # Parse PixUser::Statistics
26
+ #
27
+ # Converts a list of hashes (or Statistics objects) received from the API into a list of PixUser::Statistics objects.
28
+ #
29
+ # ## Parameters (required):
30
+ # - statistics [list of hashes or PixUser::Statistics objects]: list to be parsed.
31
+ #
32
+ # ## Return:
33
+ # - list of parsed PixUser::Statistics objects
34
+ def self.parse_statistics(statistics)
35
+ resource_maker = StarkInfra::PixUser::Statistics.resource[:resource_maker]
36
+ return statistics if statistics.nil?
37
+
38
+ parsed_statistics = []
39
+ statistics.each do |statistic|
40
+ unless statistic.is_a? Statistics
41
+ statistic = StarkCore::Utils::API.from_api_json(resource_maker, statistic)
42
+ end
43
+ parsed_statistics << statistic
44
+ end
45
+ return parsed_statistics
46
+ end
47
+
48
+ def self.resource
49
+ {
50
+ resource_name: 'Statistics',
51
+ resource_maker: proc { |json|
52
+ Statistics.new(
53
+ value: json['value'],
54
+ type: json['type'],
55
+ source: json['source'],
56
+ after: json['after'],
57
+ updated: json['updated']
58
+ )
59
+ }
60
+ }
61
+ end
62
+ end
63
+ end
64
+ end