starkinfra 0.1.0 → 0.3.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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcodepreview/brcodepreview.rb +125 -0
  3. data/lib/cardmethod/cardmethod.rb +56 -0
  4. data/lib/creditholmes/creditholmes.rb +160 -0
  5. data/lib/creditnote/creditnote.rb +51 -355
  6. data/lib/creditnote/invoice/description.rb +51 -0
  7. data/lib/creditnote/invoice/discount.rb +49 -0
  8. data/lib/creditnote/invoice/invoice.rb +124 -0
  9. data/lib/creditnote/log.rb +18 -19
  10. data/lib/creditnote/transfer.rb +90 -0
  11. data/lib/creditpreview/creditnotepreview.rb +85 -0
  12. data/lib/creditpreview/creditpreview.rb +77 -0
  13. data/lib/creditsigner/creditsigner.rb +57 -0
  14. data/lib/dynamicbrcode/dynamicbrcode.rb +350 -0
  15. data/lib/event/attempt.rb +5 -4
  16. data/lib/event/event.rb +11 -11
  17. data/lib/individualdocument/individualdocument.rb +165 -0
  18. data/lib/individualdocument/log.rb +125 -0
  19. data/lib/individualidentity/individualidentity.rb +193 -0
  20. data/lib/individualidentity/log.rb +124 -0
  21. data/lib/issuingbalance/issuingbalance.rb +4 -4
  22. data/lib/issuingcard/issuingcard.rb +35 -33
  23. data/lib/issuingcard/log.rb +21 -21
  24. data/lib/issuingdesign/issuingdesign.rb +138 -0
  25. data/lib/issuingembossingkit/issuingembossingkit.rb +121 -0
  26. data/lib/issuingembossingrequest/issuingembossingrequest.rb +210 -0
  27. data/lib/issuingembossingrequest/log.rb +128 -0
  28. data/lib/issuingholder/issuingholder.rb +21 -15
  29. data/lib/issuingholder/log.rb +19 -19
  30. data/lib/issuinginvoice/issuinginvoice.rb +29 -14
  31. data/lib/issuinginvoice/log.rb +18 -18
  32. data/lib/{issuingbin/issuingbin.rb → issuingproduct/issuingproduct.rb} +27 -30
  33. data/lib/issuingpurchase/issuingpurchase.rb +111 -31
  34. data/lib/issuingpurchase/log.rb +16 -16
  35. data/lib/issuingrestock/issuingrestock.rb +162 -0
  36. data/lib/issuingrestock/log.rb +127 -0
  37. data/lib/issuingrule/issuingrule.rb +64 -18
  38. data/lib/issuingstock/issuingstock.rb +138 -0
  39. data/lib/issuingstock/log.rb +130 -0
  40. data/lib/issuingtransaction/issuingtransaction.rb +12 -13
  41. data/lib/issuingwithdrawal/issuingwithdrawal.rb +12 -11
  42. data/lib/merchantcategory/merchantcategory.rb +63 -0
  43. data/lib/merchantcountry/merchantcountry.rb +59 -0
  44. data/lib/pixbalance/pixbalance.rb +5 -5
  45. data/lib/pixchargeback/log.rb +15 -15
  46. data/lib/pixchargeback/pixchargeback.rb +32 -20
  47. data/lib/pixclaim/log.rb +21 -24
  48. data/lib/pixclaim/pixclaim.rb +44 -34
  49. data/lib/pixdirector/pixdirector.rb +9 -11
  50. data/lib/pixdomain/certificate.rb +1 -1
  51. data/lib/pixdomain/pixdomain.rb +5 -5
  52. data/lib/pixinfraction/log.rb +20 -20
  53. data/lib/pixinfraction/pixinfraction.rb +23 -15
  54. data/lib/pixkey/log.rb +23 -23
  55. data/lib/pixkey/pixkey.rb +14 -12
  56. data/lib/pixrequest/log.rb +24 -20
  57. data/lib/pixrequest/pixrequest.rb +54 -21
  58. data/lib/pixreversal/log.rb +3 -3
  59. data/lib/pixreversal/pixreversal.rb +48 -21
  60. data/lib/pixstatement/pixstatement.rb +13 -8
  61. data/lib/starkinfra.rb +40 -15
  62. data/lib/staticbrcode/staticbrcode.rb +170 -0
  63. data/lib/user/project.rb +1 -1
  64. data/lib/utils/api.rb +1 -0
  65. data/lib/utils/bacenid.rb +1 -1
  66. data/lib/utils/parse.rb +7 -3
  67. data/lib/utils/request.rb +1 -1
  68. data/lib/utils/resource.rb +1 -1
  69. data/lib/utils/sub_resource.rb +21 -22
  70. data/lib/webhook/webhook.rb +11 -11
  71. metadata +29 -4
  72. data/lib/issuingauthorization/issuingauthorization.rb +0 -141
@@ -0,0 +1,350 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+ require_relative('../utils/parse')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ # # DynamicBrcode object
10
+ #
11
+ # BR Codes store information represented by Pix QR Codes, which are used to
12
+ # send or receive Pix transactions in a convenient way.
13
+ # DynamicBrcodes represent charges with information that can change at any time,
14
+ # since all data needed for the payment is requested dynamically to an URL stored
15
+ # in the BR Code. Stark Infra will receive the GET request and forward it to your
16
+ # registered endpoint with a GET request containing the UUID of the BR Code for
17
+ # identification.
18
+ #
19
+ # When you initialize a DynamicBrcode, the entity will not be automatically
20
+ # created in the Stark Infra API. The 'create' function sends the objects
21
+ # to the Stark Infra API and returns the created object.
22
+ #
23
+ # ## Parameters (required):
24
+ # - name [string]: receiver's name. ex: 'Tony Stark'
25
+ # - city [string]: receiver's city name. ex: 'Rio de Janeiro'
26
+ # - external_id [string]: string that must be unique among all your DynamicBrcodes. Duplicated external ids will cause failures. ex: 'my-internal-id-123456'
27
+ #
28
+ # ## Parameters (optional):
29
+ # - type [string, default 'instant']: type of the DynamicBrcode. Options: 'instant', 'due'
30
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
31
+ #
32
+ # ## Attributes (return-only):
33
+ # - id [string]: id returned on creation, this is the BR Code. ex: '00020126360014br.gov.bcb.pix0114+552840092118152040000530398654040.095802BR5915Jamie Lannister6009Sao Paulo620705038566304FC6C'
34
+ # - uuid [string]: unique uuid returned when the DynamicBrcode is created. ex: '4e2eab725ddd495f9c98ffd97440702d'
35
+ # - url [string]: url link to the BR Code image. ex: 'https://brcode-h.development.starkinfra.com/dynamic-qrcode/901e71f2447c43c886f58366a5432c4b.png'
36
+ # - created [DateTime]: creation datetime for the DynamicBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
37
+ # - updated [DateTime]: latest update datetime for the DynamicBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
38
+ class DynamicBrcode < StarkInfra::Utils::Resource
39
+ attr_reader :name, :city, :external_id, :type, :tags, :id, :uuid, :url, :updated, :created
40
+ def initialize(name:, city:, external_id:, type: nil, tags: nil, id: nil, uuid: nil, url: nil, updated: nil, created: nil)
41
+ super(id)
42
+ @name = name
43
+ @city = city
44
+ @external_id = external_id
45
+ @type = type
46
+ @tags = tags
47
+ @uuid = uuid
48
+ @url = url
49
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
50
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
51
+ end
52
+
53
+ # # Create DynamicBrcodes
54
+ #
55
+ # Send a list of DynamicBrcode objects for creation at the Stark Infra API
56
+ #
57
+ # ## Parameters (required):
58
+ # - brcodes [list of DynamicBrcode objects]: list of DynamicBrcode objects to be created in the API.
59
+ #
60
+ # ## Parameters (optional):
61
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
62
+ #
63
+ # ## Return:
64
+ # - list of DynamicBrcode objects with updated attributes
65
+ def self.create(brcodes, user: nil)
66
+ StarkInfra::Utils::Rest.post(entities: brcodes, user: user, **resource)
67
+ end
68
+
69
+ # # Retrieve a specific DynamicBrcode
70
+ #
71
+ # Receive a single DynamicBrcode object previously created in the Stark Infra API by its uuid
72
+ #
73
+ # ## Parameters (required):
74
+ # - uuid [string]: object's unique uuid. ex: '901e71f2447c43c886f58366a5432c4b'
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
+ # - DynamicBrcode object with updated attributes
81
+ def self.get(uuid, user: nil)
82
+ StarkInfra::Utils::Rest.get_id(id: uuid, user: user, **resource)
83
+ end
84
+
85
+ # # Retrieve DynamicBrcodes
86
+ #
87
+ # Receive a generator of DynamicBrcode objects previously created in the Stark Infra API
88
+ #
89
+ # ## Parameters (optional):
90
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. 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
+ # - external_ids [list of strings, default nil]: list of external_ids to filter retrieved objects. ex: ['my_external_id1', 'my_external_id2']
94
+ # - uuids [list of strings, default nil]: list of uuids to filter retrieved objects. ex: ['901e71f2447c43c886f58366a5432c4b', '4e2eab725ddd495f9c98ffd97440702d']
95
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
96
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
97
+ #
98
+ # ## Return:
99
+ # - generator of DynamicBrcode objects with updated attributes
100
+ def self.query(limit: nil, after: nil, before: nil, external_ids: nil, uuids: nil, tags: nil, user: nil)
101
+ after = StarkInfra::Utils::Checks.check_date(after)
102
+ before = StarkInfra::Utils::Checks.check_date(before)
103
+ StarkInfra::Utils::Rest.get_stream(
104
+ limit: limit,
105
+ after: after,
106
+ before: before,
107
+ external_ids: external_ids,
108
+ uuids: uuids,
109
+ tags: tags,
110
+ user: user,
111
+ **resource
112
+ )
113
+ end
114
+
115
+ # # Retrieve DynamicBrcodes
116
+ #
117
+ # Receive a list of DynamicBrcode objects previously created in the Stark Infra API and the cursor to the next page.
118
+ #
119
+ # ## Parameters (optional):
120
+ # - cursor [string, default nil]: cursor returned on the previous page function call
121
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex 35
122
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
123
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
124
+ # - external_ids [list of strings, default nil]: list of external_ids to filter retrieved objects. ex: ['my_external_id1', 'my_external_id2']
125
+ # - uuids [list of strings, default nil]: list of uuids to filter retrieved objects. ex: ['901e71f2447c43c886f58366a5432c4b', '4e2eab725ddd495f9c98ffd97440702d']
126
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
127
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
128
+ #
129
+ # ## Return:
130
+ # - list of DynamicBrcode objects with updated attributes
131
+ # - cursor to retrieve the next page of DynamicBrcode objects
132
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, uuids: nil, external_ids: nil, user: nil)
133
+ after = StarkInfra::Utils::Checks.check_date(after)
134
+ before = StarkInfra::Utils::Checks.check_date(before)
135
+ StarkInfra::Utils::Rest.get_page(
136
+ cursor: cursor,
137
+ limit: limit,
138
+ after: after,
139
+ before: before,
140
+ external_ids: external_ids,
141
+ uuids: uuids,
142
+ tags: tags,
143
+ user: user,
144
+ **resource
145
+ )
146
+ end
147
+
148
+ # # Helps you respond to a due DynamicBrcode Read
149
+ #
150
+ # When a Due DynamicBrcode is read by your user, a GET request containing the Brcode's
151
+ # UUID will be made to your registered URL to retrieve additional information needed
152
+ # to complete the transaction.
153
+ # The get request must be answered in the following format, within 5 seconds, and with
154
+ # an HTTP status code 200.
155
+ #
156
+ # ## Parameters (required):
157
+ # - version [integer]: integer that represents how many times the BR Code was updated.
158
+ # - created [DateTime or string]: creation datetime in ISO format of the DynamicBrcode. ex: "2020-03-10T10:30:00.000000+00:00" or DateTime.new(2020, 3, 10, 10, 30, 0, 0).
159
+ # - due [Date or string]: requested payment due datetime in ISO format. ex: "2020-03-10T10:30:00.000000+00:00" or DateTime.new(2020, 3, 10, 10, 30, 0, 0)
160
+ # - key_id [string]: receiver's PixKey id. Can be a taxId (CPF/CNPJ), a phone number, an email or an alphanumeric sequence (EVP). ex: '+5511989898989'
161
+ # - status [string]: BR Code status. Options: "created", "overdue", "paid", "canceled" or "expired"
162
+ # - reconciliation_id [string]: id to be used for conciliation of the resulting Pix transaction. This id must have from to 26 to 35 alphanumeric characters' ex: "cd65c78aeb6543eaaa0170f68bd741ee"
163
+ # - nominal_amount [integer]: positive integer that represents the amount in cents of the resulting Pix transaction. ex: 1234 (= R$ 12.34)
164
+ # - sender_name [string]: sender's full name. ex: "Anthony Edward Stark"
165
+ # - receiver_name [string]: receiver's full name. ex: "Jamie Lannister"
166
+ # - receiver_street_line [string]: receiver's main address. ex: "Av. Paulista, 200"
167
+ # - receiver_city [string]: receiver's address city name. ex: "Sao Paulo"
168
+ # - receiver_state_code [string]: receiver's address state code. ex: "SP"
169
+ # - receiver_zip_code [string]: receiver's address zip code. ex: "01234-567"
170
+ #
171
+ # ## Parameters (optional):
172
+ # - expiration [integer]: time in seconds counted from the creation datetime until the DynamicBrcode expires. After expiration, the BR Code cannot be paid anymore.
173
+ # - sender_tax_id [string, default nil]: sender's CPF (11 digits formatted or unformatted) or CNPJ (14 digits formatted or unformatted). ex: '01.001.001/0001-01'
174
+ # - receiver_tax_id [string, default nil]: receiver's CPF (11 digits formatted or unformatted) or CNPJ (14 digits formatted or unformatted). ex: '012.345.678-90'
175
+ # - fine [float, default 2.0]: Percentage charged if the sender pays after the due datetime. ex. 2.0
176
+ # - interest [float, default 1.0]: Interest percentage charged if the sender pays after the due datetime. ex: 1.5
177
+ # - discounts [list of dictionaries, default nil]: discount amount applied if the sender pays at a specific datetime before the due datetime.
178
+ # - description [string, default nil]: additional information to be shown to the sender at the moment of payment. ex: 'Response Due DynamicBrocde'
179
+ #
180
+ # ## Return:
181
+ # - Dumped JSON string that must be returned to us
182
+ def self.response_due(
183
+ version: , created: , due: , key_id: , status: , reconciliation_id: , nominal_amount: ,
184
+ sender_name: , receiver_name: , receiver_street_line: , receiver_city: , receiver_state_code: ,
185
+ receiver_zip_code: , expiration: , sender_tax_id: , receiver_tax_id: , fine: , interest: ,
186
+ discounts: , description:
187
+ )
188
+
189
+ params = {
190
+ 'version': version,
191
+ 'created': created,
192
+ 'due': due,
193
+ 'keyId': key_id,
194
+ 'status': status,
195
+ 'reconciliationId': reconciliation_id,
196
+ 'nominalAmount': nominal_amount,
197
+ 'senderName': sender_name,
198
+ 'receiverName': receiver_name,
199
+ 'receiverStreetLine': receiver_street_line,
200
+ 'receiverCity': receiver_city,
201
+ 'receiverStateCode': receiver_state_code,
202
+ 'receiverZipCode': receiver_zip_code,
203
+ 'expiration': expiration,
204
+ 'senderTaxId': sender_tax_id,
205
+ 'receiverTaxId': receiver_tax_id,
206
+ 'fine': fine,
207
+ 'interest': interest,
208
+ 'discounts': Discount.parse_discounts(discounts),
209
+ 'description': description
210
+ }
211
+
212
+ params.to_json
213
+ end
214
+
215
+ # # Helps you respond to an instant DynamicBrcode Read
216
+ #
217
+ # When an instant DynamicBrcode is read by your user, a GET request containing the BR Code's UUID will be made
218
+ # to your registered URL to retrieve additional information needed to complete the transaction.
219
+ # The get request must be answered in the following format within 5 seconds and with an HTTP status code 200.
220
+ #
221
+ # ## Parameters (required):
222
+ # - version [integer]: integer that represents how many times the BR Code was updated.
223
+ # - created [DateTime or string]: creation datetime of the DynamicBrcode. ex: "2020-03-10T10:30:00.000000+00:00" or DateTime.new(2020, 3, 10, 10, 30, 0, 0).
224
+ # - key_id [string]: receiver's PixKey id. Can be a tax_id (CPF/CNPJ), a phone number, an email or an alphanumeric sequence (EVP). ex: '+5511989898989'
225
+ # - status [string]: BR Code status. Options: 'created', 'overdue', 'paid', 'canceled' or 'expired'
226
+ # - reconciliation_id [string]: id to be used for conciliation of the resulting Pix transaction. This id must have from to 26 to 35 alphanumeric characters' ex: "cd65c78aeb6543eaaa0170f68bd741ee"
227
+ # - amount [integer]: positive integer that represents the amount in cents of the resulting Pix transaction. ex: 1234 (= R$ 12.34)
228
+ #
229
+ # ## Parameters (required):
230
+ # - cashier_type [string, default nil]: cashier's type. Required if the cashAmount is different from 0. Options: 'merchant', 'participant' and 'other'
231
+ # - cashier_bank_code [string, default nil]: cashier's bank code. Required if the cash_amount is different from 0. ex: '20018183'
232
+ #
233
+ # ## Parameters (optional):
234
+ # - expiration [integer, default nil]: time in seconds counted from the creation datetime until the DynamicBrcode expires. After expiration, the BR Code cannot be paid anymore. ex: 123456789
235
+ # - cash_amount [integer, default nil]: amount to be withdrawn from the cashier in cents. ex: 1000 (= R$ 10.00)
236
+ # - sender_name [string, default nil]: sender's full name. ex: 'Anthony Edward Stark'
237
+ # - sender_tax_id [string, default nil]: sender's CPF (11 digits formatted or unformatted) or CNPJ (14 digits formatted or unformatted). ex: '01.001.001/0001-01'
238
+ # - amount_type [string, default 'fixed']: amount type of the BR Code. If the amount type is 'custom' the Brcode's amount can be changed by the sender at the moment of payment. Options: 'fixed' or 'custom'
239
+ # - description [string, default nil]: additional information to be shown to the sender at the moment of payment. ex: 'Response Instant DynamicBrocde'
240
+ #
241
+ # ## Return:
242
+ # # - Dumped JSON string that must be returned to us
243
+ def self.response_instant(
244
+ version:, created:, key_id:, status:, reconciliation_id:, amount:, cashier_type:,
245
+ cashier_bank_code:, cash_amount:, expiration:, sender_name:, sender_tax_id:,
246
+ amount_type:, description:
247
+ )
248
+ params = {
249
+ 'version': version,
250
+ 'created': created,
251
+ 'keyId': key_id,
252
+ 'status': status,
253
+ 'reconciliationId': reconciliation_id,
254
+ 'amount': amount,
255
+ 'cashierType': cashier_type,
256
+ 'cashierBankCode': cashier_bank_code,
257
+ 'cashAmount': cash_amount,
258
+ 'expiration': expiration,
259
+ 'senderName': sender_name,
260
+ 'senderTaxId': sender_tax_id,
261
+ 'amountType': amount_type,
262
+ 'description': description
263
+ }
264
+
265
+ params.to_json
266
+ end
267
+
268
+ # # Verify a DynamicBrcode Read
269
+ #
270
+ # When a DynamicBrcode is read by your user, a GET request will be made to your registered URL to
271
+ # retrieve additional information needed to complete the transaction.
272
+ # Use this method to verify the authenticity of a GET request received at your registered endpoint.
273
+ # If the provided digital signature does not check out with the StarkInfra public key,
274
+ # a stark.exception.InvalidSignatureException will be raised.
275
+ #
276
+ # ## Parameters (required):
277
+ # - uuid [string]: unique uuid of the DynamicBrcode, passed as a path variable in the DynamicBrcode Read request. ex: "4e2eab725ddd495f9c98ffd97440702d"
278
+ # - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
279
+ #
280
+ # ## Parameters (optional):
281
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
282
+ #
283
+ # ## Return:
284
+ # - verified Brcode's uuid.
285
+ def self.verify(uuid:, signature:, user: nil)
286
+ StarkInfra::Utils::Parse.verify(content: uuid, signature: signature, user: user)
287
+ end
288
+
289
+ def self.resource
290
+ {
291
+ resource_name: 'DynamicBrcode',
292
+ resource_maker: proc { |json|
293
+ DynamicBrcode.new(
294
+ id: json['id'],
295
+ name: json['name'],
296
+ city: json['city'],
297
+ external_id: json['external_id'],
298
+ type: json['type'],
299
+ tags: json['tags'],
300
+ uuid: json['uuid'],
301
+ url: json['url'],
302
+ updated: json['updated'],
303
+ created: json['created']
304
+ )
305
+ }
306
+ }
307
+ end
308
+
309
+ # # DynamicBrcode.Discount object
310
+ #
311
+ # Used to define a Discount in the BR Code
312
+ #
313
+ # ## Parameters (required):
314
+ # - percentage [integer]: discount percentage that will be applied. ex: 2.5
315
+ # - due [DateTime or string, default now + 2 days]: Date after when the discount will be overdue in UTC ISO format. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0) or "2020-03-10T10:30:00.000000+00:00"
316
+ class Discount < StarkInfra::Utils::SubResource
317
+ attr_reader :percentage, :due
318
+ def initialize(percentage:, due:)
319
+ @percentage = percentage
320
+ @due = due
321
+ end
322
+
323
+ def self.parse_discounts(discounts)
324
+ return discounts if discounts.nil?
325
+
326
+ parsed_discounts = []
327
+ discounts.each do |discount|
328
+
329
+ if discount.is_a? DynamicBrcode::Discount
330
+ discount = StarkInfra::Utils::API.api_json(discount)
331
+ end
332
+ parsed_discounts << discount
333
+ end
334
+ parsed_discounts
335
+ end
336
+
337
+ def self.resource
338
+ {
339
+ resource_name: 'Discount',
340
+ resource_maker: proc { |json|
341
+ Discount.new(
342
+ percentage: json['percentage'],
343
+ due: json['due']
344
+ )
345
+ }
346
+ }
347
+ end
348
+ end
349
+ end
350
+ end
data/lib/event/attempt.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require_relative('event')
4
4
  require_relative('../utils/rest')
5
5
  require_relative('../utils/checks')
6
- require_relative('event')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  class Event
@@ -12,7 +12,7 @@ module StarkInfra
12
12
  # When an Event delivery fails, an event attempt will be registered.
13
13
  # It carries information meant to help you debug event reception issues.
14
14
  #
15
- # ## Attributes:
15
+ # ## Attributes (return-only):
16
16
  # - id [string]: unique id that identifies the delivery attempt. ex: '5656565656565656'
17
17
  # - code [string]: delivery error code. ex: badHttpStatus, badConnection, timeout
18
18
  # - message [string]: delivery error full description. ex: 'HTTP POST request returned status 404'
@@ -94,7 +94,8 @@ module StarkInfra
94
94
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
95
95
  after = StarkInfra::Utils::Checks.check_date(after)
96
96
  before = StarkInfra::Utils::Checks.check_date(before)
97
- return StarkInfra::Utils::Rest.get_page(
97
+
98
+ StarkInfra::Utils::Rest.get_page(
98
99
  cursor: cursor,
99
100
  limit: limit,
100
101
  after: after,
data/lib/event/event.rb CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  require('json')
4
4
  require('starkbank-ecdsa')
5
- require_relative('../utils/resource')
5
+ require_relative('../error')
6
6
  require_relative('../utils/rest')
7
- require_relative('../utils/checks')
7
+ require_relative('../utils/parse')
8
8
  require_relative('../utils/cache')
9
- require_relative('../error')
9
+ require_relative('../utils/checks')
10
+ require_relative('../utils/resource')
10
11
  require_relative('../pixrequest/log')
11
12
  require_relative('../pixreversal/log')
12
- require_relative('../utils/parse')
13
13
 
14
14
  module StarkInfra
15
15
  # # Webhook Event object
@@ -18,7 +18,7 @@ module StarkInfra
18
18
  # Events cannot be created, but may be retrieved from the Stark Infra API to
19
19
  # list all generated updates on entities.
20
20
  #
21
- # ## Attributes:
21
+ # ## Attributes (return-only):
22
22
  # - id [string]: unique id returned when the event is created. ex: '5656565656565656'
23
23
  # - log [Log]: a Log object from one the subscription services (PixRequestLog, PixReversalLog)
24
24
  # - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
@@ -35,18 +35,18 @@ module StarkInfra
35
35
  @subscription = subscription
36
36
 
37
37
  resource = {
38
- 'credit-note': StarkInfra::CreditNote::Log.resource,
38
+ 'pix-key': StarkInfra::PixKey::Log.resource,
39
+ 'pix-claim': StarkInfra::PixClaim::Log.resource,
40
+ 'pix-chargeback': StarkInfra::PixChargeback::Log.resource,
41
+ 'pix-infraction': StarkInfra::PixInfraction::Log.resource,
39
42
  'pix-request.in': StarkInfra::PixRequest::Log.resource,
40
43
  'pix-request.out': StarkInfra::PixRequest::Log.resource,
41
44
  'pix-reversal.in': StarkInfra::PixReversal::Log.resource,
42
45
  'pix-reversal.out': StarkInfra::PixReversal::Log.resource,
43
- 'pix-key': StarkInfra::PixKey::Log.resource,
44
- 'pix-claim': StarkInfra::PixClaim::Log.resource,
45
- 'pix-infraction': StarkInfra::PixInfraction::Log.resource,
46
- 'pix-chargeback': StarkInfra::PixChargeback::Log.resource,
47
46
  'issuing-card': StarkInfra::IssuingCard::Log.resource,
48
47
  'issuing-invoice': StarkInfra::IssuingInvoice::Log.resource,
49
- 'issuing-purchase': StarkInfra::IssuingPurchase::Log.resource
48
+ 'issuing-purchase': StarkInfra::IssuingPurchase::Log.resource,
49
+ 'credit-note': StarkInfra::CreditNote::Log.resource,
50
50
  }[subscription.to_sym]
51
51
 
52
52
  @log = log
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+ require_relative('../utils/parse')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ # # IndividualDocument object
10
+ #
11
+ # Individual documents are images containing either side of a document or a selfie
12
+ # to be used in a matching validation. When created, they must be attached to an individual
13
+ # identity to be used for its validation.
14
+ #
15
+ # When you initialize a IndividualDocument, the entity will not be automatically
16
+ # created in the Stark Infra API. The 'create' function sends the objects
17
+ # to the Stark Infra API and returns the list of created objects.
18
+ #
19
+ # ## Parameters (required):
20
+ # - type [string]: type of the IndividualDocument. Options: "drivers-license-front", "drivers-license-back", "identity-front", "identity-back" or "selfie"
21
+ # - content [string]: Base64 data url of the picture. ex: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...
22
+ # - content_type [string]: content MIME type. This parameter is required as input only. ex: "image/png" or "image/jpeg"
23
+ # - identity_id [string]: Unique id of IndividualIdentity. ex: "5656565656565656"
24
+ #
25
+ # ## Parameters (optional):
26
+ # - tags [list of strings, default nil]: list of strings for reference when searching for IndividualDocuments. ex: ["employees", "monthly"]
27
+ #
28
+ # ## Attributes (return-only):
29
+ # - id [string]: unique id returned when the IndividualDocument is created. ex: "5656565656565656"
30
+ # - status [string]: current status of the IndividualDocument. Options: "created", "canceled", "processing", "failed", "success"
31
+ # - created [DateTime]: creation datetime for the IndividualDocument. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
+ class IndividualDocument < StarkInfra::Utils::Resource
33
+ attr_reader :type, :content, :content_type, :identity_id, :tags, :id, :status, :created
34
+ def initialize(type:, content:, content_type:, identity_id:, tags: nil, id: nil, status: nil, created: nil)
35
+ super(id)
36
+ @type = type
37
+ @identity_id = identity_id
38
+ @tags = tags
39
+ @status = status
40
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
41
+ @content = content
42
+ @content_type = content_type
43
+
44
+ if @content_type
45
+ @content = "data:#{content_type};base64,#{Base64.encode64(content)}"
46
+ @content_type = nil
47
+ end
48
+ end
49
+
50
+ # # Create IndividualDocuments
51
+ #
52
+ # Send a list of IndividualDocument objects for creation at the Stark Infra API
53
+ #
54
+ # ## Parameters (required):
55
+ # - documents [list of IndividualDocument objects]: list of IndividualDocument objects to be created in the API.
56
+ #
57
+ # ## Parameters (optional):
58
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
59
+ #
60
+ # ## Return:
61
+ # - list of IndividualDocument object with updated attributes
62
+ def self.create(documents, user: nil)
63
+ StarkInfra::Utils::Rest.post(entities: documents, user: user, **resource)
64
+ end
65
+
66
+ # # Retrieve a specific IndividualDocument
67
+ #
68
+ # Receive a single IndividualDocument object previously created in the Stark Infra API by its id
69
+ #
70
+ # ## Parameters (required):
71
+ # - id [string]: object unique id. ex: "5656565656565656"
72
+ #
73
+ # ## Parameters (optional):
74
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
75
+ #
76
+ # ## Return:
77
+ # - IndividualDocument object with updated attributes
78
+ def self.get(id, user: nil)
79
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
80
+ end
81
+
82
+ # # Retrieve IndividualDocuments
83
+ #
84
+ # Receive a generator of IndividualDocument objects previously created in the Stark Infra API
85
+ #
86
+ # ## Parameters (optional):
87
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
88
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
89
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
90
+ # - status [list of strings, default nil]: filter for status of retrieved objects. Options: ["created", "canceled", "processing", "failed", "success"]
91
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
92
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
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
+ # - generator of IndividualDocument objects with updated attributes
97
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
98
+ after = StarkInfra::Utils::Checks.check_date(after)
99
+ before = StarkInfra::Utils::Checks.check_date(before)
100
+ StarkInfra::Utils::Rest.get_stream(
101
+ limit: limit,
102
+ after: after,
103
+ before: before,
104
+ status: status,
105
+ tags: tags,
106
+ ids: ids,
107
+ user: user,
108
+ **resource
109
+ )
110
+ end
111
+
112
+ # # Retrieve paged IndividualDocuments
113
+ #
114
+ # Receive a list of up to 100 IndividualDocument objects previously created in the Stark Infra API and the cursor to the next page.
115
+ # Use this function instead of query if you want to manually page your requests.
116
+ #
117
+ # ## Parameters (optional):
118
+ # - cursor [string, default nil]: cursor returned on the previous page function call
119
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex 35
120
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
121
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
122
+ # - status [list of strings, default nil]: filter for status of retrieved objects. Options: ["created", "canceled", "processing", "failed", "success"]
123
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
124
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
125
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
126
+ #
127
+ # ## Return:
128
+ # - list of IndividualDocument objects with updated attributes
129
+ # - cursor to retrieve the next page of IndividualDocument objects
130
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
131
+ after = StarkInfra::Utils::Checks.check_date(after)
132
+ before = StarkInfra::Utils::Checks.check_date(before)
133
+ StarkInfra::Utils::Rest.get_page(
134
+ cursor: cursor,
135
+ limit: limit,
136
+ after: after,
137
+ before: before,
138
+ status: status,
139
+ tags: tags,
140
+ ids: ids,
141
+ user: user,
142
+ **resource
143
+ )
144
+ end
145
+
146
+
147
+ def self.resource
148
+ {
149
+ resource_name: 'IndividualDocument',
150
+ resource_maker: proc { |json|
151
+ IndividualDocument.new(
152
+ type: json['type'],
153
+ content: json['content'],
154
+ content_type: json['content_type'],
155
+ identity_id: json['identity_id'],
156
+ tags: json['tags'],
157
+ id: json['id'],
158
+ status: json['status'],
159
+ created: json['created']
160
+ )
161
+ }
162
+ }
163
+ end
164
+ end
165
+ end