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
@@ -17,10 +17,10 @@ module StarkInfra
17
17
  # ## Parameters (required):
18
18
  # - amount [integer]: amount in cents to be reversed. ex: 11234 (= R$ 112.34)
19
19
  # - reference_id [string]: end_to_end_id or return_id of the transaction to be reversed. ex: 'E20018183202201201450u34sDGd19lz'
20
- # - reason [string]: reason why the reversal was requested. Options: 'fraud', 'flaw', 'reversalChargeback'
20
+ # - reason [string]: reason why the reversal was requested. Options: 'flaw', 'fraud', 'subscriptionFlaw' (the API also assigns 'reversalChargeback' automatically when a chargeback stems from a closed Pix Infraction, but it cannot be passed on creation).
21
21
  #
22
22
  # ## Parameters (optional):
23
- # - description [string, default nil]: description for the PixChargeback. ex: 'Payment for service #1234'
23
+ # - description [string, default nil]: description for the PixChargeback. Required when reason is 'flaw'. ex: 'Payment for service #1234'
24
24
  # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
25
25
  #
26
26
  # ## Attributes (return-only):
@@ -33,15 +33,26 @@ module StarkInfra
33
33
  # - result [string]: result after the analysis of the PixChargeback by the receiving party. Options: 'rejected', 'accepted', 'partiallyAccepted'
34
34
  # - flow [string]: direction of the Pix Chargeback. Options: 'in' for received chargebacks, 'out' for chargebacks you requested
35
35
  # - status [string]: current PixChargeback status. Options: 'created', 'failed', 'delivered', 'closed', 'canceled'.
36
+ # - dispute_id [string]: id of the dispute associated with the PixChargeback. ex: '5656565656565656'
37
+ # - is_monitoring_required [bool]: indicates if monitoring is required for this chargeback. ex: true
38
+ # - reversal_account_number [string]: account number for the reversal transaction. ex: '876543-2'
39
+ # - reversal_account_type [string]: account type for the reversal transaction. ex: 'checking'
40
+ # - reversal_bank_code [string]: bank code for the reversal transaction. ex: '20018183'
41
+ # - reversal_branch_code [string]: branch code for the reversal transaction. ex: '1357-9'
42
+ # - reversal_tax_id [string]: tax ID for the reversal transaction. ex: '01234567890'
36
43
  # - created [DateTime]: creation datetime for the PixChargeback. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
37
44
  # - updated [DateTime]: latest update datetime for the PixChargeback. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
45
+ # - bacen_id [string]: unique transaction id returned from Central Bank. ex: 'ccf9bd9c-e99d-999e-bab9-b999ca999f99'
38
46
  class PixChargeback < StarkCore::Utils::Resource
39
47
  attr_reader :amount, :reference_id, :reason, :description, :tags, :id, :analysis, :sender_bank_code,
40
- :receiver_bank_code, :rejection_reason, :reversal_reference_id, :result, :flow, :status, :created, :updated
48
+ :receiver_bank_code, :rejection_reason, :reversal_reference_id, :result, :flow, :status,
49
+ :dispute_id, :is_monitoring_required, :reversal_account_number, :reversal_account_type,
50
+ :reversal_bank_code, :reversal_branch_code, :reversal_tax_id, :created, :updated, :bacen_id
41
51
  def initialize(
42
52
  amount:, reference_id:, reason:, description: nil, tags: nil, id: nil, analysis: nil, sender_bank_code: nil,
43
53
  receiver_bank_code: nil, rejection_reason: nil, reversal_reference_id: nil, result: nil, flow: nil, status: nil,
44
- created: nil, updated: nil
54
+ dispute_id: nil, is_monitoring_required: nil, reversal_account_number: nil, reversal_account_type: nil,
55
+ reversal_bank_code: nil, reversal_branch_code: nil, reversal_tax_id: nil, created: nil, updated: nil, bacen_id: nil
45
56
  )
46
57
  super(id)
47
58
  @amount = amount
@@ -57,8 +68,16 @@ module StarkInfra
57
68
  @result = result
58
69
  @flow = flow
59
70
  @status = status
71
+ @dispute_id = dispute_id
72
+ @is_monitoring_required = is_monitoring_required
73
+ @reversal_account_number = reversal_account_number
74
+ @reversal_account_type = reversal_account_type
75
+ @reversal_bank_code = reversal_bank_code
76
+ @reversal_branch_code = reversal_branch_code
77
+ @reversal_tax_id = reversal_tax_id
60
78
  @created = StarkCore::Utils::Checks.check_datetime(created)
61
79
  @updated = StarkCore::Utils::Checks.check_datetime(updated)
80
+ @bacen_id = bacen_id
62
81
  end
63
82
 
64
83
  # # Create PixChargebacks
@@ -167,10 +186,10 @@ module StarkInfra
167
186
  #
168
187
  # ## Parameters (required):
169
188
  # - id [string]: PixChargeback unique id. ex: '5656565656565656'
170
- # - result [string]: result after the analysis of the PixChargeback. Options: 'rejected', 'accepted', 'partiallyAccepted'.
189
+ # - result [string]: result of the chargeback analysis to submit. Options: 'agreed', 'disagreed', 'partiallyAgreed'.
171
190
  #
172
191
  # ## Parameters (conditionally required):
173
- # - rejection_reason [string, default nil]: if the PixChargeback is rejected a reason is required. Options: 'noBalance', 'accountClosed', 'unableToReverse',
192
+ # - rejection_reason [string, default nil]: if the PixChargeback's result is 'rejected', a reason is required. Options: 'other', 'noBalance', 'accountClosed', 'invalidRequest' ('unableToReverse' is not a valid value).
174
193
  # - reversal_reference_id [string, default nil]: return_id of the reversal transaction. ex: 'D20018183202201201450u34sDGd19lz'
175
194
  #
176
195
  # ## Parameters (optional):
@@ -226,8 +245,16 @@ module StarkInfra
226
245
  result: json['result'],
227
246
  flow: json['flow'],
228
247
  status: json['status'],
248
+ dispute_id: json['dispute_id'],
249
+ is_monitoring_required: json['is_monitoring_required'],
250
+ reversal_account_number: json['reversal_account_number'],
251
+ reversal_account_type: json['reversal_account_type'],
252
+ reversal_bank_code: json['reversal_bank_code'],
253
+ reversal_branch_code: json['reversal_branch_code'],
254
+ reversal_tax_id: json['reversal_tax_id'],
229
255
  created: json['created'],
230
- updated: json['updated']
256
+ updated: json['updated'],
257
+ bacen_id: json['bacen_id']
231
258
  )
232
259
  }
233
260
  }
@@ -8,6 +8,8 @@ module StarkInfra
8
8
  #
9
9
  # A Pix Claim is a request to transfer a Pix Key from an account hosted at another
10
10
  # Pix participant to an account under your bank code. Pix Claims must always be requested by the claimer.
11
+ # An 'ownership' claim changes the holder of a Pix Key and only applies to phone-type keys; a 'portability'
12
+ # claim changes the linked account without changing the holder, and applies to phone, email or taxId keys.
11
13
  #
12
14
  # When you initialize a PixClaim, the entity will not be automatically
13
15
  # created in the Stark Infra API. The 'create' function sends the objects
@@ -27,9 +29,10 @@ module StarkInfra
27
29
  #
28
30
  # ## Attributes (return-only):
29
31
  # - id [string]: unique id returned when the PixClaim is created. ex: '5656565656565656'
32
+ # - bacen_id [string]: unique transaction id returned from Central Bank. ex: 'ccf9bd9c-e99d-999e-bab9-b999ca999f99'
30
33
  # - status [string]: current PixClaim status. Options: 'created', 'failed', 'delivered', 'confirmed', 'success', 'canceled'
31
34
  # - type [string]: type of Pix Claim. Options: 'ownership', 'portability'.
32
- # - key_type [string]: keyType of the claimed Pix Key. Options: 'CPF', 'CNPJ', 'phone' or 'email'
35
+ # - key_type [string]: keyType of the claimed Pix Key. Options: 'cpf', 'cnpj', 'phone', 'email', 'evp'.
33
36
  # - flow [string]: direction of the Pix Claim. Options: 'in' if you received the PixClaim or 'out' if you created the PixClaim.
34
37
  # - claimer_bank_code [string]: bank_code of the Pix participant that created the PixClaim. ex: '20018183'.
35
38
  # - claimed_bank_code [string]: bank_code of the account donating the PixClaim. ex: '20018183'.
@@ -37,11 +40,12 @@ module StarkInfra
37
40
  # - updated [DateTime]: update datetime for the PixClaim. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
38
41
  class PixClaim < StarkCore::Utils::Resource
39
42
  attr_reader :account_created, :account_number, :account_type, :branch_code, :name, :tax_id, :key_id,
40
- :tags, :id, :status, :type, :key_type, :flow, :claimer_bank_code, :claimed_bank_code, :created, :updated
43
+ :tags, :id, :status, :type, :key_type, :flow, :claimer_bank_code, :claimed_bank_code, :created, :updated,
44
+ :bacen_id
41
45
  def initialize(
42
46
  account_created:, account_number:, account_type:, branch_code:, name:,
43
47
  tax_id:, key_id:, tags: nil, id: nil, status: nil, type: nil, key_type: nil, flow: nil,
44
- claimer_bank_code: nil, claimed_bank_code: nil, created: nil, updated: nil
48
+ claimer_bank_code: nil, claimed_bank_code: nil, created: nil, updated: nil, bacen_id: nil
45
49
  )
46
50
  super(id)
47
51
  @account_created = account_created
@@ -60,6 +64,7 @@ module StarkInfra
60
64
  @claimed_bank_code = claimed_bank_code
61
65
  @created = StarkCore::Utils::Checks.check_datetime(created)
62
66
  @updated = StarkCore::Utils::Checks.check_datetime(updated)
67
+ @bacen_id = bacen_id
63
68
  end
64
69
 
65
70
  # # Create a PixClaim object
@@ -183,11 +188,13 @@ module StarkInfra
183
188
 
184
189
  # # Update a PixClaim entity
185
190
  #
186
- # Update a PixClaim parameters by passing id.
191
+ # Update a PixClaim by passing id. You must answer an inbound PixClaim within 7 days of its status
192
+ # changing to 'delivered' — if unanswered, a 'portability' claim is rejected by default and an
193
+ # 'ownership' claim is accepted by default, both with reason 'defaultBehavior'.
187
194
  #
188
195
  # ## Parameters (required):
189
196
  # - id [string]: PixClaim unique id. ex: '5656565656565656'
190
- # - status [string]: patched status for Pix Claim. Options: 'confirmed' and 'canceled'
197
+ # - status [string]: patched status for the PixClaim. Options: 'confirmed' (only allowed from 'delivered' status; deletes the referenced PixKey from Stark Infra and the Central Bank) and 'canceled' (only allowed from 'delivered' or 'confirmed' status).
191
198
  #
192
199
  # ## Parameters (optional):
193
200
  # - reason [string, default 'userRequested']: reason why the PixClaim is being patched. Options: 'fraud', 'userRequested', 'accountClosure'.
@@ -226,7 +233,8 @@ module StarkInfra
226
233
  claimer_bank_code: json['claimer_bank_code'],
227
234
  claimed_bank_code: json['claimed_bank_code'],
228
235
  created: json['created'],
229
- updated: json['updated']
236
+ updated: json['updated'],
237
+ bacen_id: json['bacen_id']
230
238
  )
231
239
  }
232
240
  }
@@ -23,7 +23,7 @@ module StarkInfra
23
23
  # - team_phones [list of strings]: list of phones of the team. ex: ['+5511988889999', '+5511988889998']
24
24
  #
25
25
  # ## Attributes (return-only):
26
- # - status [string]: current PixDirector status. ex: 'success'
26
+ # - status [string]: current PixDirector status. Options: 'success', 'processing', 'failed'.
27
27
  class PixDirector < StarkCore::Utils::SubResource
28
28
  attr_reader :name, :tax_id, :phone, :email, :password, :team_email, :team_phones, :status
29
29
  def initialize(name:, tax_id:, phone:, email:, password:, team_email:, team_phones:, status: nil)
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('pix_dispute')
5
+ require_relative('../utils/rest')
6
+
7
+ module StarkInfra
8
+ class PixDispute
9
+ # # PixDispute::Log object
10
+ #
11
+ # Every time a PixDispute entity is modified, a corresponding PixDispute::Log
12
+ # is generated for the entity. This log is never generated by the user.
13
+ #
14
+ # ## Attributes (return-only):
15
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
16
+ # - dispute [PixDispute]: PixDispute entity to which the log refers to.
17
+ # - type [string]: type of the PixDispute event which triggered the log creation. ex: 'created', 'delivered', 'analysed'
18
+ # - errors [list of strings]: list of errors linked to this PixDispute event.
19
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
20
+ class Log < StarkCore::Utils::Resource
21
+ attr_reader :id, :dispute, :type, :errors, :created
22
+ def initialize(id:, dispute:, type:, errors:, created:)
23
+ super(id)
24
+ @dispute = dispute
25
+ @type = type
26
+ @errors = errors
27
+ @created = StarkCore::Utils::Checks.check_datetime(created)
28
+ end
29
+
30
+ # # Retrieve a specific PixDispute::Log
31
+ #
32
+ # Receive a single PixDispute::Log object previously created by the Stark Infra API by passing its id
33
+ #
34
+ # ## Parameters (required):
35
+ # - id [string]: object unique id. ex: '5656565656565656'
36
+ #
37
+ # ## Parameters (optional):
38
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
39
+ #
40
+ # ## Return:
41
+ # - PixDispute::Log object with updated attributes
42
+ def self.get(id, user: nil)
43
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
44
+ end
45
+
46
+ # # Retrieve PixDispute::Logs
47
+ #
48
+ # Receive a generator of PixDispute::Log objects previously created in the Stark Infra API
49
+ #
50
+ # ## Parameters (optional):
51
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
52
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
53
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
54
+ # - types [list of strings, default nil]: filter retrieved objects by types. ex: ['analysed', 'delivered']
55
+ # - dispute_ids [list of strings, default nil]: list of PixDispute ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
56
+ # - ids [list of strings, default nil]: Log ids to filter PixDispute Logs. ex: ['5656565656565656']
57
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
58
+ #
59
+ # ## Return:
60
+ # - generator of PixDispute::Log objects with updated attributes
61
+ def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil, dispute_ids: nil, user: nil)
62
+ after = StarkCore::Utils::Checks.check_date(after)
63
+ before = StarkCore::Utils::Checks.check_date(before)
64
+ StarkInfra::Utils::Rest.get_stream(
65
+ ids: ids,
66
+ limit: limit,
67
+ after: after,
68
+ before: before,
69
+ types: types,
70
+ dispute_ids: dispute_ids,
71
+ user: user,
72
+ **resource
73
+ )
74
+ end
75
+
76
+ # # Retrieve paged PixDispute::Logs
77
+ #
78
+ # Receive a list of up to 100 PixDispute::Log objects previously created in the Stark Infra API and the cursor to the next page.
79
+ # Use this function instead of query if you want to manually page your logs.
80
+ #
81
+ # ## Parameters (optional):
82
+ # - cursor [string, default nil]: cursor returned on the previous page function call
83
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
84
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
85
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
86
+ # - types [list of strings, default nil]: filter retrieved objects by types. ex: ['analysed', 'delivered']
87
+ # - dispute_ids [list of strings, default nil]: list of PixDispute ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
88
+ # - ids [list of strings, default nil]: Log ids to filter PixDispute Logs. ex: ['5656565656565656']
89
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
90
+ #
91
+ # ## Return:
92
+ # - list of PixDispute::Log objects with updated attributes
93
+ # - cursor to retrieve the next page of Log objects
94
+ def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil, dispute_ids: nil, user: nil)
95
+ after = StarkCore::Utils::Checks.check_date(after)
96
+ before = StarkCore::Utils::Checks.check_date(before)
97
+ StarkInfra::Utils::Rest.get_page(
98
+ cursor: cursor,
99
+ ids: ids,
100
+ limit: limit,
101
+ after: after,
102
+ before: before,
103
+ types: types,
104
+ dispute_ids: dispute_ids,
105
+ user: user,
106
+ **resource
107
+ )
108
+ end
109
+
110
+ def self.resource
111
+ dispute_maker = StarkInfra::PixDispute.resource[:resource_maker]
112
+ {
113
+ resource_name: 'PixDisputeLog',
114
+ resource_maker: proc { |json|
115
+ Log.new(
116
+ id: json['id'],
117
+ dispute: StarkCore::Utils::API.from_api_json(dispute_maker, json['dispute']),
118
+ type: json['type'],
119
+ errors: json['errors'],
120
+ created: json['created']
121
+ )
122
+ }
123
+ }
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+
6
+ module StarkInfra
7
+ # # PixDispute object
8
+ #
9
+ # A PixDispute is a request to investigate a Pix transaction that is suspected of
10
+ # fraud or that resulted from a system malfunction. It maps the network of
11
+ # transactions linked to the reported one for analysis.
12
+ #
13
+ # When you initialize a PixDispute, the entity will not be automatically
14
+ # created in the Stark Infra API. The 'create' function sends a list of objects
15
+ # to the Stark Infra API and returns the list of created objects.
16
+ #
17
+ # ## Parameters (required):
18
+ # - reference_id [string]: end_to_end_id of the transaction being reported. ex: 'E20018183202201201450u34sDGd19lz'
19
+ # - method [string]: method of the dispute. Options: 'scam', 'unauthorized', 'coercion', 'invasion', 'other', 'unknown'.
20
+ # - operator_email [string]: contact email of the operator responsible for the PixDispute. ex: 'ruby-sdk@starkinfra.com'
21
+ # - operator_phone [string]: contact phone number of the operator responsible for the PixDispute. ex: '+5511999999999'
22
+ #
23
+ # ## Parameters (conditionally required):
24
+ # - description [string, default nil]: details for the investigation. Required when method == 'other'; optional otherwise.
25
+ #
26
+ # ## Parameters (optional):
27
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
28
+ # - min_transaction_amount [integer, default nil]: minimum transaction amount considered for the graph creation. ex: 100
29
+ # - max_transaction_count [integer, default nil]: maximum number of transactions considered for the graph creation. ex: 10
30
+ # - max_hop_interval [integer, default nil]: mean time between transactions considered for the graph creation. ex: 3600
31
+ # - max_hop_count [integer, default nil]: depth considered for the graph creation. ex: 5
32
+ #
33
+ # ## Attributes (return-only):
34
+ # - id [string]: unique id returned when the PixDispute is created. ex: '5656565656565656'
35
+ # - bacen_id [string]: central bank's unique PixDispute id. ex: '817fc523-9e9d-40ab-9e53-dacb71454a05'
36
+ # - flow [string]: direction of the PixDispute. Options: 'in' for received disputes, 'out' for disputes you created.
37
+ # - status [string]: current PixDispute status. Options: 'created', 'delivered', 'analysed', 'processing', 'closed', 'failed', 'canceled'
38
+ # - transactions [list of PixDispute::Transaction objects]: list of Transaction objects linked to the PixDispute.
39
+ # - created [DateTime]: creation datetime for the PixDispute. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
40
+ # - updated [DateTime]: latest update datetime for the PixDispute. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
41
+ class PixDispute < StarkCore::Utils::Resource
42
+ attr_reader :reference_id, :method, :operator_email, :operator_phone, :description, :tags, :min_transaction_amount,
43
+ :max_transaction_count, :max_hop_interval, :max_hop_count, :id, :bacen_id, :flow, :status,
44
+ :transactions, :created, :updated
45
+ def initialize(
46
+ reference_id:, method:, operator_email:, operator_phone:, description: nil, tags: nil,
47
+ min_transaction_amount: nil, max_transaction_count: nil, max_hop_interval: nil, max_hop_count: nil,
48
+ id: nil, bacen_id: nil, flow: nil, status: nil, transactions: nil, created: nil, updated: nil
49
+ )
50
+ super(id)
51
+ @reference_id = reference_id
52
+ @method = method
53
+ @operator_email = operator_email
54
+ @operator_phone = operator_phone
55
+ @description = description
56
+ @tags = tags
57
+ @min_transaction_amount = min_transaction_amount
58
+ @max_transaction_count = max_transaction_count
59
+ @max_hop_interval = max_hop_interval
60
+ @max_hop_count = max_hop_count
61
+ @bacen_id = bacen_id
62
+ @flow = flow
63
+ @status = status
64
+ @transactions = PixDispute::Transaction.parse_transactions(transactions)
65
+ @created = StarkCore::Utils::Checks.check_datetime(created)
66
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
67
+ end
68
+
69
+ # # Create PixDisputes
70
+ #
71
+ # Send a list of PixDispute objects for creation in the Stark Infra API
72
+ #
73
+ # ## Parameters (required):
74
+ # - disputes [list of PixDispute objects]: list of PixDispute objects to be created in the API.
75
+ #
76
+ # ## Parameters (optional):
77
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
78
+ #
79
+ # ## Return:
80
+ # - list of PixDispute objects with updated attributes
81
+ def self.create(disputes, user: nil)
82
+ StarkInfra::Utils::Rest.post(entities: disputes, user: user, **resource)
83
+ end
84
+
85
+ # # Retrieve a specific PixDispute
86
+ #
87
+ # Receive a single PixDispute object previously created in the Stark Infra API by passing its id
88
+ #
89
+ # ## Parameters (required):
90
+ # - id [string]: object unique id. ex: '5656565656565656'
91
+ #
92
+ # ## Parameters (optional):
93
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
94
+ #
95
+ # ## Return:
96
+ # - PixDispute object with updated attributes
97
+ def self.get(id, user: nil)
98
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
99
+ end
100
+
101
+ # # Retrieve PixDisputes
102
+ #
103
+ # Receive a generator of PixDispute objects previously created in the Stark Infra API
104
+ #
105
+ # ## Parameters (optional):
106
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
107
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
108
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
109
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['created', 'delivered']
110
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
111
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
112
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
113
+ #
114
+ # ## Return:
115
+ # - generator of PixDispute objects with updated attributes
116
+ def self.query(limit: nil, after: nil, before: nil, status: nil, ids: nil, tags: nil, user: nil)
117
+ after = StarkCore::Utils::Checks.check_date(after)
118
+ before = StarkCore::Utils::Checks.check_date(before)
119
+ StarkInfra::Utils::Rest.get_stream(
120
+ limit: limit,
121
+ after: after,
122
+ before: before,
123
+ status: status,
124
+ ids: ids,
125
+ tags: tags,
126
+ user: user,
127
+ **resource
128
+ )
129
+ end
130
+
131
+ # # Retrieve paged PixDisputes
132
+ #
133
+ # Receive a list of up to 100 PixDispute 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 disputes.
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 only after specified date. ex: Date.new(2020, 3, 10)
140
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
141
+ # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['created', 'delivered']
142
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
143
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
144
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
145
+ #
146
+ # ## Return:
147
+ # - list of PixDispute objects with updated attributes
148
+ # - cursor to retrieve the next page of PixDispute objects
149
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, ids: nil, tags: nil, user: nil)
150
+ after = StarkCore::Utils::Checks.check_date(after)
151
+ before = StarkCore::Utils::Checks.check_date(before)
152
+ StarkInfra::Utils::Rest.get_page(
153
+ cursor: cursor,
154
+ limit: limit,
155
+ after: after,
156
+ before: before,
157
+ status: status,
158
+ ids: ids,
159
+ tags: tags,
160
+ user: user,
161
+ **resource
162
+ )
163
+ end
164
+
165
+ # # Cancel a PixDispute entity
166
+ #
167
+ # Cancel a PixDispute entity previously created in the Stark Infra API
168
+ #
169
+ # ## Parameters (required):
170
+ # - id [string]: PixDispute unique id. ex: '5656565656565656'
171
+ #
172
+ # ## Parameters (optional):
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
+ # - canceled PixDispute object
177
+ def self.cancel(id, user: nil)
178
+ StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
179
+ end
180
+
181
+ def self.resource
182
+ {
183
+ resource_name: 'PixDispute',
184
+ resource_maker: proc { |json|
185
+ PixDispute.new(
186
+ id: json['id'],
187
+ reference_id: json['reference_id'],
188
+ method: json['method'],
189
+ operator_email: json['operator_email'],
190
+ operator_phone: json['operator_phone'],
191
+ description: json['description'],
192
+ tags: json['tags'],
193
+ min_transaction_amount: json['min_transaction_amount'],
194
+ max_transaction_count: json['max_transaction_count'],
195
+ max_hop_interval: json['max_hop_interval'],
196
+ max_hop_count: json['max_hop_count'],
197
+ bacen_id: json['bacen_id'],
198
+ flow: json['flow'],
199
+ status: json['status'],
200
+ transactions: json['transactions'],
201
+ created: json['created'],
202
+ updated: json['updated']
203
+ )
204
+ }
205
+ }
206
+ end
207
+ end
208
+ end
209
+
210
+ require_relative('transaction')
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+
5
+ module StarkInfra
6
+ class PixDispute
7
+ # # PixDispute::Transaction object
8
+ #
9
+ # Transactions linked to a PixDispute as part of the graph analysis. This object
10
+ # is return-only; it is never created by the user.
11
+ #
12
+ # ## Attributes (return-only):
13
+ # - end_to_end_id [string]: central bank's unique transaction id. ex: 'E20018183202201201450u34sDGd19lz'
14
+ # - amount [integer]: transaction amount in cents. ex: 11234 (= R$ 112.34)
15
+ # - nominal_amount [integer]: refundable amount in cents of the transaction. ex: 11234 (= R$ 112.34)
16
+ # - receiver_type [string]: receiver's type. Options: 'individual', 'business'
17
+ # - receiver_tax_id_created [string]: receiver's taxId creation date (business type only).
18
+ # - receiver_account_created [string]: receiver's account creation date.
19
+ # - receiver_bank_code [string]: receiver's bank code. ex: '20018183'
20
+ # - receiver_id [string]: Bacen-generated pseudo ID for the receiver, used only for transaction-tracking context (not a real account identifier).
21
+ # - sender_type [string]: sender's type. Options: 'individual', 'business'
22
+ # - sender_tax_id_created [string]: sender's taxId creation date (business type only).
23
+ # - sender_account_created [string]: sender's account creation date.
24
+ # - sender_bank_code [string]: sender's bank code. ex: '20018183'
25
+ # - sender_id [string]: Bacen-generated pseudo ID for the sender, used only for transaction-tracking context (not a real account identifier).
26
+ # - settled [DateTime]: settled datetime of the transaction. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
27
+ class Transaction < StarkCore::Utils::SubResource
28
+ attr_reader :end_to_end_id, :amount, :nominal_amount, :receiver_type, :receiver_tax_id_created,
29
+ :receiver_account_created, :receiver_bank_code, :receiver_id, :sender_type, :sender_tax_id_created,
30
+ :sender_account_created, :sender_bank_code, :sender_id, :settled
31
+ def initialize(
32
+ end_to_end_id: nil, amount: nil, nominal_amount: nil, receiver_type: nil, receiver_tax_id_created: nil,
33
+ receiver_account_created: nil, receiver_bank_code: nil, receiver_id: nil, sender_type: nil,
34
+ sender_tax_id_created: nil, sender_account_created: nil, sender_bank_code: nil, sender_id: nil, settled: nil
35
+ )
36
+ @end_to_end_id = end_to_end_id
37
+ @amount = amount
38
+ @nominal_amount = nominal_amount
39
+ @receiver_type = receiver_type
40
+ @receiver_tax_id_created = receiver_tax_id_created
41
+ @receiver_account_created = receiver_account_created
42
+ @receiver_bank_code = receiver_bank_code
43
+ @receiver_id = receiver_id
44
+ @sender_type = sender_type
45
+ @sender_tax_id_created = sender_tax_id_created
46
+ @sender_account_created = sender_account_created
47
+ @sender_bank_code = sender_bank_code
48
+ @sender_id = sender_id
49
+ @settled = StarkCore::Utils::Checks.check_datetime(settled)
50
+ end
51
+
52
+ def self.parse_transactions(transactions)
53
+ resource_maker = StarkInfra::PixDispute::Transaction.resource[:resource_maker]
54
+ return transactions if transactions.nil?
55
+
56
+ parsed_transactions = []
57
+ transactions.each do |transaction|
58
+ unless transaction.is_a? Transaction
59
+ transaction = StarkCore::Utils::API.from_api_json(resource_maker, transaction)
60
+ end
61
+ parsed_transactions << transaction
62
+ end
63
+ parsed_transactions
64
+ end
65
+
66
+ def self.resource
67
+ {
68
+ resource_name: 'PixDisputeTransaction',
69
+ resource_maker: proc { |json|
70
+ Transaction.new(
71
+ end_to_end_id: json['end_to_end_id'],
72
+ amount: json['amount'],
73
+ nominal_amount: json['nominal_amount'],
74
+ receiver_type: json['receiver_type'],
75
+ receiver_tax_id_created: json['receiver_tax_id_created'],
76
+ receiver_account_created: json['receiver_account_created'],
77
+ receiver_bank_code: json['receiver_bank_code'],
78
+ receiver_id: json['receiver_id'],
79
+ sender_type: json['sender_type'],
80
+ sender_tax_id_created: json['sender_tax_id_created'],
81
+ sender_account_created: json['sender_account_created'],
82
+ sender_bank_code: json['sender_bank_code'],
83
+ sender_id: json['sender_id'],
84
+ settled: json['settled']
85
+ )
86
+ }
87
+ }
88
+ end
89
+ end
90
+ end
91
+ end