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