starkinfra 0.6.0 → 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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcode_preview/brcode_preview.rb +22 -4
  3. data/lib/brcode_preview/subscription.rb +2 -2
  4. data/lib/business_account_request/business_account_request.rb +276 -0
  5. data/lib/{individual_document → business_account_request}/log.rb +35 -35
  6. data/lib/business_attachment/business_attachment.rb +6 -3
  7. data/lib/business_identity/business_identity.rb +7 -4
  8. data/lib/credit_holmes/credit_holmes.rb +2 -1
  9. data/lib/credit_holmes/log.rb +125 -0
  10. data/lib/credit_note/credit_note.rb +42 -5
  11. data/lib/credit_note/rule.rb +9 -0
  12. data/lib/credit_note/transfer.rb +1 -1
  13. data/lib/credit_preview/credit_note_preview.rb +10 -2
  14. data/lib/credit_preview/credit_preview.rb +2 -1
  15. data/lib/credit_signer/credit_signer.rb +27 -2
  16. data/lib/dynamic_brcode/dynamic_brcode.rb +5 -2
  17. data/lib/event/event.rb +2 -2
  18. data/lib/individual_account_attachment/individual_account_attachment.rb +178 -0
  19. data/lib/individual_account_attachment/log.rb +124 -0
  20. data/lib/individual_account_request/individual_account_request.rb +271 -0
  21. data/lib/individual_account_request/log.rb +124 -0
  22. data/lib/individual_identity/individual_identity.rb +4 -7
  23. data/lib/issuing_card/issuing_card.rb +5 -4
  24. data/lib/issuing_design/issuing_design.rb +9 -0
  25. data/lib/issuing_embossing_request/issuing_embossing_request.rb +3 -2
  26. data/lib/issuing_holder/issuing_holder.rb +6 -5
  27. data/lib/issuing_product/issuing_product.rb +2 -2
  28. data/lib/issuing_purchase/issuing_purchase.rb +25 -1
  29. data/lib/issuing_restock/issuing_restock.rb +3 -2
  30. data/lib/issuing_rule/issuing_rule.rb +36 -0
  31. data/lib/issuing_stock_rule/issuing_stock_rule.rb +6 -5
  32. data/lib/issuing_token/issuing_token.rb +2 -2
  33. data/lib/issuing_token/log.rb +127 -0
  34. data/lib/issuing_token_activation/issuing_token_activation.rb +62 -0
  35. data/lib/issuing_token_request/issuing_token_request.rb +1 -1
  36. data/lib/issuing_withdrawal/issuing_withdrawal.rb +2 -2
  37. data/lib/ledger/ledger.rb +175 -0
  38. data/lib/ledger/log.rb +122 -0
  39. data/lib/ledger/rule.rb +55 -0
  40. data/lib/ledger_transaction/ledger_transaction.rb +179 -0
  41. data/lib/pix_balance/pix_balance.rb +1 -1
  42. data/lib/pix_chargeback/pix_chargeback.rb +10 -7
  43. data/lib/pix_claim/pix_claim.rb +14 -6
  44. data/lib/pix_director/pix_director.rb +1 -1
  45. data/lib/pix_dispute/pix_dispute.rb +1 -1
  46. data/lib/pix_dispute/transaction.rb +4 -4
  47. data/lib/pix_fraud/pix_fraud.rb +1 -1
  48. data/lib/pix_infraction/pix_infraction.rb +21 -5
  49. data/lib/pix_internal_transaction_report/pix_internal_transaction_report.rb +1 -1
  50. data/lib/pix_key/pix_key.rb +1 -1
  51. data/lib/pix_key_holmes/log.rb +129 -0
  52. data/lib/pix_key_holmes/pix_key_holmes.rb +19 -2
  53. data/lib/pix_pull_request/pix_pull_request.rb +6 -3
  54. data/lib/pix_pull_subscription/pix_pull_subscription.rb +31 -5
  55. data/lib/pix_request/pix_request.rb +13 -7
  56. data/lib/pix_reversal/pix_reversal.rb +14 -8
  57. data/lib/pix_statement/pix_statement.rb +11 -5
  58. data/lib/pix_user/pix_user.rb +52 -0
  59. data/lib/pix_user/statistics.rb +64 -0
  60. data/lib/starkinfra.rb +20 -3
  61. data/lib/static_brcode/static_brcode.rb +8 -4
  62. data/lib/utils/bacen_id.rb +27 -0
  63. data/lib/utils/end_to_end_id.rb +20 -0
  64. data/lib/utils/pix_subscription_bacen_id.rb +21 -0
  65. data/lib/utils/return_id.rb +1 -4
  66. data/lib/webhook/webhook.rb +2 -2
  67. metadata +21 -4
  68. data/lib/individual_document/individual_document.rb +0 -164
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+ require_relative('pix_key_holmes')
6
+
7
+ module StarkInfra
8
+ class PixKeyHolmes
9
+ # # PixKeyHolmes::Log object
10
+ #
11
+ # Every time a PixKeyHolmes entity is updated, a corresponding PixKeyHolmes::Log
12
+ # is generated for the entity. This log is never generated by the
13
+ # user, but it can be retrieved to check additional information
14
+ # on the PixKeyHolmes.
15
+ #
16
+ # ## Attributes (return-only):
17
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
+ # - holmes [PixKeyHolmes]: PixKeyHolmes entity to which the log refers to.
19
+ # - errors [list of strings]: list of errors linked to this PixKeyHolmes event.
20
+ # - type [string]: type of the PixKeyHolmes event which triggered the log creation. ex: 'solving', 'solved'
21
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
+ class Log < StarkCore::Utils::Resource
23
+ attr_reader :id, :created, :type, :errors, :holmes
24
+ def initialize(id:, created:, type:, errors:, holmes:)
25
+ super(id)
26
+ @holmes = holmes
27
+ @errors = errors
28
+ @type = type
29
+ @created = StarkCore::Utils::Checks.check_datetime(created)
30
+ end
31
+
32
+ # # Retrieve a specific PixKeyHolmes::Log
33
+ #
34
+ # Receive a single PixKeyHolmes::Log object previously created by the Stark Infra API by its id
35
+ #
36
+ # ## Parameters (required):
37
+ # - id [string]: object unique id. ex: '5656565656565656'
38
+ #
39
+ # ## Parameters (optional):
40
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
41
+ #
42
+ # ## Return:
43
+ # - PixKeyHolmes::Log object with updated attributes
44
+ def self.get(id, user: nil)
45
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
46
+ end
47
+
48
+ # # Retrieve PixKeyHolmes::Logs
49
+ #
50
+ # Receive a generator of PixKeyHolmes::Log objects previously created in the Stark Infra API
51
+ #
52
+ # ## Parameters (optional):
53
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
54
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
57
+ # - types [list of strings, default nil]: filter for log event types. ex: ['solving', 'solved']
58
+ # - holmes_ids [list of strings, default nil]: list of PixKeyHolmes ids to filter logs. ex: ['5656565656565656', '4545454545454545']
59
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
60
+ #
61
+ # ## Return:
62
+ # - generator of PixKeyHolmes::Log objects with updated attributes
63
+ def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil, holmes_ids: nil, user: nil)
64
+ after = StarkCore::Utils::Checks.check_date(after)
65
+ before = StarkCore::Utils::Checks.check_date(before)
66
+ StarkInfra::Utils::Rest.get_stream(
67
+ ids: ids,
68
+ limit: limit,
69
+ after: after,
70
+ before: before,
71
+ types: types,
72
+ holmes_ids: holmes_ids,
73
+ user: user,
74
+ **resource
75
+ )
76
+ end
77
+
78
+ # # Retrieve paged PixKeyHolmes::Logs
79
+ #
80
+ # Receive a list of up to 100 PixKeyHolmes::Log objects previously created in the Stark Infra API and the cursor to the next page.
81
+ # Use this function instead of query if you want to manually page your requests.
82
+ #
83
+ # ## Parameters (optional):
84
+ # - cursor [string, default nil]: cursor returned on the previous page function call
85
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
86
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
87
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
88
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
89
+ # - types [list of strings, default nil]: filter for log event types. ex: ['solving', 'solved']
90
+ # - holmes_ids [list of strings, default nil]: list of PixKeyHolmes ids to filter logs. ex: ['5656565656565656', '4545454545454545']
91
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
92
+ #
93
+ # ## Return:
94
+ # - list of PixKeyHolmes::Log objects with updated attributes
95
+ # - cursor to retrieve the next page of PixKeyHolmes::Log objects
96
+ def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil, holmes_ids: nil, user: nil)
97
+ after = StarkCore::Utils::Checks.check_date(after)
98
+ before = StarkCore::Utils::Checks.check_date(before)
99
+ StarkInfra::Utils::Rest.get_page(
100
+ cursor: cursor,
101
+ ids: ids,
102
+ limit: limit,
103
+ after: after,
104
+ before: before,
105
+ types: types,
106
+ holmes_ids: holmes_ids,
107
+ user: user,
108
+ **resource
109
+ )
110
+ end
111
+
112
+ def self.resource
113
+ holmes_maker = StarkInfra::PixKeyHolmes.resource[:resource_maker]
114
+ {
115
+ resource_name: 'PixKeyHolmesLog',
116
+ resource_maker: proc { |json|
117
+ Log.new(
118
+ id: json['id'],
119
+ holmes: StarkCore::Utils::API.from_api_json(holmes_maker, json['holmes']),
120
+ errors: json['errors'],
121
+ type: json['type'],
122
+ created: json['created']
123
+ )
124
+ }
125
+ }
126
+ end
127
+ end
128
+ end
129
+ end
@@ -23,7 +23,7 @@ module StarkInfra
23
23
  # ## Attributes (return-only):
24
24
  # - id [string]: unique id returned when the PixKeyHolmes is created. ex: "5656565656565656"
25
25
  # - result [string]: investigation result once the case is solved. ex: "registered", "unregistered"
26
- # - status [string]: current status of the PixKeyHolmes. ex: "created", "solving", "solved", "failed"
26
+ # - status [string]: current status of the PixKeyHolmes. ex: "solving", "solved"
27
27
  # - created [DateTime]: creation datetime for the PixKeyHolmes. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
28
28
  # - updated [DateTime]: latest update datetime for the PixKeyHolmes. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
29
29
  class PixKeyHolmes < StarkCore::Utils::Resource
@@ -41,7 +41,8 @@ module StarkInfra
41
41
 
42
42
  # # Create PixKeyHolmes
43
43
  #
44
- # Send a list of PixKeyHolmes objects for creation at the Stark Infra API
44
+ # Send a list of PixKeyHolmes objects for creation at the Stark Infra API. You can create up to 100
45
+ # PixKeyHolmes in a single call.
45
46
  #
46
47
  # ## Parameters (required):
47
48
  # - holmes [list of PixKeyHolmes objects]: list of PixKeyHolmes objects to be created in the API.
@@ -55,6 +56,22 @@ module StarkInfra
55
56
  StarkInfra::Utils::Rest.post(entities: holmes, user: user, **resource)
56
57
  end
57
58
 
59
+ # # Retrieve a specific PixKeyHolmes
60
+ #
61
+ # Receive a single PixKeyHolmes object previously created in the Stark Infra API by its id
62
+ #
63
+ # ## Parameters (required):
64
+ # - id [string]: object unique id. ex: "5656565656565656"
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
+ # - PixKeyHolmes object with updated attributes
71
+ def self.get(id, user: nil)
72
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
73
+ end
74
+
58
75
  # # Retrieve PixKeyHolmes
59
76
  #
60
77
  # Receive a generator of PixKeyHolmes objects previously created in the Stark Infra API
@@ -34,7 +34,7 @@ module StarkInfra
34
34
  #
35
35
  # ## Attributes (return-only):
36
36
  # - id [string]: unique id returned when the PixPullRequest is created. ex: '5656565656565656'
37
- # - status [string]: current PixPullRequest status. Options: 'created', 'processing', 'scheduled', 'denied', 'success', 'canceled', 'expired'
37
+ # - status [string]: current PixPullRequest status. Options: 'created', 'processing', 'scheduled', 'denied', 'success', 'failed', 'canceled', 'expired'.
38
38
  # - flow [string]: direction of money flow. Options: 'in', 'out'
39
39
  # - receiver_name [string]: receiver's full name (filled in by the Pix infrastructure during settlement). ex: 'Edward Stark'
40
40
  # - receiver_tax_id [string]: receiver's tax ID (CPF or CNPJ). ex: '01234567890' or '20.018.183/0001-80'
@@ -85,7 +85,10 @@ module StarkInfra
85
85
 
86
86
  # # Create PixPullRequests
87
87
  #
88
- # Send a list of PixPullRequest objects for creation in the Stark Infra API
88
+ # Send a list of 1 to 100 PixPullRequest objects for creation in the Stark Infra API. Stark Infra verifies
89
+ # that the parent subscription is approved, the amount is within its authorized limit, the settlement date
90
+ # matches the subscription's charge cycle, payer/receiver details match the contract, the request is made
91
+ # between 10 and 2 days before settlement, and there is no other scheduled request for the same cycle.
89
92
  #
90
93
  # ## Parameters (required):
91
94
  # - requests [list of PixPullRequest objects]: list of PixPullRequest objects to be created in the API
@@ -211,7 +214,7 @@ module StarkInfra
211
214
  #
212
215
  # ## Parameters (required):
213
216
  # - id [string]: PixPullRequest unique id. ex: '5656565656565656'
214
- # - reason [string]: reason for the cancellation. As receiver: 'accountClosed', 'receiverOrganizationClosed', 'receiverInternalError', 'fraud', 'receiverUserRequested'. As sender: 'accountClosed', 'senderDeceased', 'fraud', 'senderUserRequested'.
217
+ # - reason [string]: cancellation reason. As sender: 'accountClosed', 'accountBlocked', 'pixRequestFailed', 'other', 'senderUserRequested'. As receiver: 'accountClosed', 'accountBlocked', 'other', 'receiverUserRequested'.
215
218
  #
216
219
  # ## Parameters (optional):
217
220
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
@@ -2,6 +2,7 @@
2
2
 
3
3
  require('starkcore')
4
4
  require_relative('../utils/rest')
5
+ require_relative('../utils/parse')
5
6
 
6
7
  module StarkInfra
7
8
  # # PixPullSubscription object
@@ -192,9 +193,9 @@ module StarkInfra
192
193
 
193
194
  # # Update PixPullSubscriptions
194
195
  #
195
- # A Pix Subscription can be patched for three distinct purposes - to update, confirm or deny it.
196
- # As the receiver, you can approve or deny the subscription if the subscription type is 'subscriptionAndPayment'.
197
- # As the sender, you can confirm or deny a delivered subscription.
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.
198
199
  #
199
200
  # ## Parameters (required):
200
201
  # - id [string]: PixPullSubscription unique id. ex: '5656565656565656'
@@ -203,7 +204,7 @@ module StarkInfra
203
204
  # - status [string]: new status of the Pix Subscription.
204
205
  # ## Parameters (conditionally-required):
205
206
  # - sender_city_code [string]: IBGE code of the payer's city. Required if you are confirming the subscription.
206
- # - reason [string]: reason why the Pix Subscription is being patched. Options: 'accountClosed', 'accountBlocked', 'invalidBranchCode', 'notRecognizedBySender', 'userRejected', 'notOffered'
207
+ # - reason [string]: reason why the PixPullSubscription is being patched. Options: 'invalidSenderAccountNumber', 'accountClosed', 'accountBlocked', 'invalidBranchCode', 'notRecognizedBySender', 'userRejected', 'notOffered'.
207
208
  #
208
209
  # ## Parameters (optional):
209
210
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
@@ -222,7 +223,7 @@ module StarkInfra
222
223
  #
223
224
  # ## Parameters (required):
224
225
  # - id [string]: PixPullSubscription unique id. ex: '5656565656565656'
225
- # - reason [string]: reason for the cancellation. As receiver: 'accountClosed', 'receiverOrganizationClosed', 'receiverInternalError', 'fraud', 'receiverUserRequested'. As sender: 'accountClosed', 'senderDeceased', 'fraud', 'senderUserRequested'.
226
+ # - reason [string, default nil]: reason for the cancellation. Options: 'accountClosed', 'receiverOrganizationClosed', 'receiverInternalError', 'senderDeceased', 'fraud', 'senderUserRequested', 'receiverUserRequested', 'paymentNotFound'.
226
227
  #
227
228
  # ## Parameters (optional):
228
229
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
@@ -240,6 +241,31 @@ module StarkInfra
240
241
  StarkCore::Utils::API.from_api_json(maker, response.json['subscription'])
241
242
  end
242
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
+
243
269
  def self.resource
244
270
  {
245
271
  resource_name: 'PixPullSubscription',
@@ -35,7 +35,7 @@ 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'
@@ -43,12 +43,15 @@ module StarkInfra
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
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. ex: 'customerRequest', 'fraud', 'subscriptionFlaw'
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.
47
50
  #
48
51
  # ## Attributes (return-only):
49
52
  # - id [string]: unique id returned when the PixRequest is created. ex: '5656565656565656'
50
53
  # - fee [integer]: fee charged when PixRequest is paid. ex: 200 (= R$ 2.00)
51
- # - status [string]: current PixRequest status. ex: 'registered' or 'paid'
54
+ # - status [string]: current PixRequest status. Options: 'created', 'processing', 'success', 'failed'.
52
55
  # - flow [string]: direction of money flow. ex: 'in' or 'out'
53
56
  # - sender_bank_code [string]: code of the sender bank institution in Brazil. ex: '20018183'
54
57
  # - created [DateTime]: creation datetime for the PixRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
@@ -58,13 +61,13 @@ module StarkInfra
58
61
  :sender_account_type, :receiver_name, :receiver_tax_id, :receiver_bank_code, :receiver_account_number,
59
62
  :receiver_branch_code, :receiver_account_type, :end_to_end_id, :cashier_type,
60
63
  :cashier_bank_code, :cash_amount, :receiver_key_id, :description, :reconciliation_id, :initiator_tax_id,
61
- :tags, :method, :priority, :reason, :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
62
65
  def initialize(
63
66
  amount:, external_id:, sender_name:, sender_tax_id:, sender_branch_code:, sender_account_number:,
64
67
  sender_account_type:, receiver_name:, receiver_tax_id:, receiver_bank_code:, receiver_account_number:,
65
68
  receiver_branch_code:, receiver_account_type:, end_to_end_id:, cashier_type: nil, cashier_bank_code: nil,
66
69
  cash_amount: nil, receiver_key_id: nil, description: nil, reconciliation_id: nil, initiator_tax_id: nil,
67
- tags: nil, method: nil, priority: nil, reason: nil, id: nil, fee: nil, status:nil, flow: nil, sender_bank_code: 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,
68
71
  created: nil, updated: nil
69
72
  )
70
73
  super(id)
@@ -93,6 +96,7 @@ module StarkInfra
93
96
  @method = method
94
97
  @priority = priority
95
98
  @reason = reason
99
+ @dispute_id = dispute_id
96
100
  @fee = fee
97
101
  @status = status
98
102
  @flow = flow
@@ -221,7 +225,7 @@ module StarkInfra
221
225
  # ## Return:
222
226
  # - Parsed PixRequest object
223
227
  def self.parse(content:, signature:, user: nil)
224
- 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)
225
229
 
226
230
  !request.fee.nil? ? request.fee : 0
227
231
  !request.tags.nil? ? request.tags : []
@@ -231,7 +235,8 @@ module StarkInfra
231
235
  request
232
236
  end
233
237
 
234
- # 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.
235
240
  #
236
241
  ## Parameters (required):
237
242
  # - status [string]: response to the authorization. ex: 'approved' or 'denied'
@@ -283,6 +288,7 @@ module StarkInfra
283
288
  method: json['method'],
284
289
  priority: json['priority'],
285
290
  reason: json['reason'],
291
+ dispute_id: json['dispute_id'],
286
292
  fee: json['fee'],
287
293
  status: json['status'],
288
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