starkinfra 0.0.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcodepreview/brcodepreview.rb +121 -0
  3. data/lib/cardmethod/cardmethod.rb +56 -0
  4. data/lib/creditnote/creditnote.rb +58 -341
  5. data/lib/creditnote/invoice/description.rb +51 -0
  6. data/lib/creditnote/invoice/discount.rb +49 -0
  7. data/lib/creditnote/invoice/invoice.rb +123 -0
  8. data/lib/creditnote/log.rb +2 -2
  9. data/lib/creditnote/transfer.rb +90 -0
  10. data/lib/creditpreview/creditnotepreview.rb +85 -0
  11. data/lib/creditpreview/creditpreview.rb +83 -0
  12. data/lib/creditsigner/creditsigner.rb +57 -0
  13. data/lib/dynamicbrcode/dynamicbrcode.rb +350 -0
  14. data/lib/event/attempt.rb +4 -3
  15. data/lib/event/event.rb +10 -10
  16. data/lib/issuingbalance/issuingbalance.rb +4 -4
  17. data/lib/issuingcard/issuingcard.rb +40 -36
  18. data/lib/issuingcard/log.rb +3 -3
  19. data/lib/issuingholder/issuingholder.rb +14 -9
  20. data/lib/issuingholder/log.rb +3 -3
  21. data/lib/issuinginvoice/issuinginvoice.rb +24 -10
  22. data/lib/issuinginvoice/log.rb +3 -3
  23. data/lib/issuingproduct/issuingproduct.rb +86 -0
  24. data/lib/issuingpurchase/issuingpurchase.rb +100 -24
  25. data/lib/issuingpurchase/log.rb +2 -2
  26. data/lib/issuingrule/issuingrule.rb +74 -30
  27. data/lib/issuingtransaction/issuingtransaction.rb +6 -8
  28. data/lib/issuingwithdrawal/issuingwithdrawal.rb +11 -7
  29. data/lib/merchantcategory/merchantcategory.rb +63 -0
  30. data/lib/merchantcountry/merchantcountry.rb +59 -0
  31. data/lib/pixbalance/pixbalance.rb +5 -5
  32. data/lib/pixchargeback/log.rb +3 -3
  33. data/lib/pixchargeback/pixchargeback.rb +32 -20
  34. data/lib/pixclaim/log.rb +8 -11
  35. data/lib/pixclaim/pixclaim.rb +43 -32
  36. data/lib/pixdirector/pixdirector.rb +9 -11
  37. data/lib/pixdomain/certificate.rb +1 -1
  38. data/lib/pixdomain/pixdomain.rb +4 -4
  39. data/lib/pixinfraction/log.rb +2 -2
  40. data/lib/pixinfraction/pixinfraction.rb +21 -13
  41. data/lib/pixkey/log.rb +5 -5
  42. data/lib/pixkey/pixkey.rb +12 -10
  43. data/lib/pixrequest/log.rb +2 -2
  44. data/lib/pixrequest/pixrequest.rb +51 -21
  45. data/lib/pixreversal/log.rb +2 -2
  46. data/lib/pixreversal/pixreversal.rb +48 -20
  47. data/lib/pixstatement/pixstatement.rb +12 -7
  48. data/lib/starkinfra.rb +27 -15
  49. data/lib/staticbrcode/staticbrcode.rb +164 -0
  50. data/lib/user/project.rb +1 -1
  51. data/lib/utils/api.rb +1 -0
  52. data/lib/utils/parse.rb +7 -3
  53. data/lib/utils/request.rb +1 -1
  54. data/lib/utils/resource.rb +1 -1
  55. data/lib/utils/rest.rb +1 -2
  56. data/lib/utils/sub_resource.rb +21 -22
  57. data/lib/webhook/webhook.rb +3 -3
  58. metadata +16 -4
  59. data/lib/issuingauthorization/issuingauthorization.rb +0 -141
  60. data/lib/issuingbin/issuingbin.rb +0 -89
@@ -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
+ # - DynamicBrcode object 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
+ # - expiration [integer]: time in seconds counted from the creation datetime until the DynamicBrcode expires. After expiration, the BR Code cannot be paid anymore.
171
+ #
172
+ # ## Parameters (optional):
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
+ # - expiration [integer]: time in seconds counted from the creation datetime until the DynamicBrcode expires. After expiration, the BR Code cannot be paid anymore. ex: 123456789
229
+ #
230
+ # ## Parameters (required):
231
+ # - cashier_type [string, default nil]: cashier's type. Required if the cashAmount is different from 0. Options: 'merchant', 'participant' and 'other'
232
+ # - cashier_bank_code [string, default nil]: cashier's bank code. Required if the cash_amount is different from 0. ex: '20018183'
233
+ #
234
+ # ## Parameters (optional):
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
@@ -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
@@ -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
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingBalance object
@@ -13,7 +13,7 @@ module StarkInfra
13
13
  #
14
14
  # ## Attributes (return-only):
15
15
  # - id [string]: unique id returned when IssuingBalance is created. ex: '5656565656565656'
16
- # - amount [integer]: current balance amount of the Workspace in cents. ex: 200 (= R$ 2.00)
16
+ # - amount [integer]: current issuing balance amount of the Workspace in cents. ex: 200 (= R$ 2.00)
17
17
  # - currency [string]: currency of the current Workspace. Expect others to be added eventually. ex: 'BRL'
18
18
  # - updated [DateTime]: latest update datetime for the IssuingBalance. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
19
  class IssuingBalance < StarkInfra::Utils::Resource
@@ -43,10 +43,10 @@ module StarkInfra
43
43
  resource_name: 'IssuingBalance',
44
44
  resource_maker: proc { |json|
45
45
  IssuingBalance.new(
46
+ id: json['id'],
46
47
  amount: json['amount'],
47
48
  currency: json['currency'],
48
- updated: json['updated'],
49
- id: json['id']
49
+ updated: json['updated']
50
50
  )
51
51
  }
52
52
  }
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingCard object
@@ -10,6 +10,10 @@ module StarkInfra
10
10
  # The IssuingCard object displays the information of the cards created in your Workspace.
11
11
  # Sensitive information will only be returned when the 'expand' parameter is used, to avoid security concerns.
12
12
  #
13
+ # When you initialize a IssuingCard, the entity will not be automatically
14
+ # created in the Stark Infra API. The 'create' function sends the objects
15
+ # to the Stark Infra API and returns the created object.
16
+ #
13
17
  # ## Parameters (required):
14
18
  # - holder_name [string]: card holder name. ex: 'Tony Stark'
15
19
  # - holder_tax_id [string]: card holder tax ID. ex: '012.345.678-90'
@@ -18,14 +22,14 @@ module StarkInfra
18
22
  # ## Parameters (optional):
19
23
  # - display_name [string, default nil]: card displayed name. ex: 'ANTHONY STARK'
20
24
  # - rules [list of IssuingRule objects, default nil]: [EXPANDABLE] list of card spending rules.
21
- # - bin_id [string, default nil]: BIN ID to which the card is bound. ex: '53810200'
25
+ # - product_id [string, default nil]: card product ID to which the card is bound. ex: '53810200'
22
26
  # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
23
- # - street_line_1 [string, default nil]: card holder main address. ex: 'Av. Paulista, 200'
24
- # - street_line_2 [string, default nil]: card holder address complement. ex: 'Apto. 123'
25
- # - district [string, default nil]: card holder address district / neighbourhood. ex: 'Bela Vista'
26
- # - city [string, default nil]: card holder address city. ex: 'Rio de Janeiro'
27
- # - state_code [string, default nil]: card holder address state. ex: 'GO'
28
- # - zip_code [string, default nil]: card holder address zip code. ex: '01311-200'
27
+ # - street_line_1 [string, default sub-issuer street line 1]: card holder main address. ex: 'Av. Paulista, 200'
28
+ # - street_line_2 [string, default sub-issuer street line 2]: card holder address complement. ex: 'Apto. 123'
29
+ # - district [string, default sub-issuer district]: card holder address district / neighbourhood. ex: 'Bela Vista'
30
+ # - city [string, default sub-issuer city]: card holder address city. ex: 'Rio de Janeiro'
31
+ # - state_code [string, default sub-issuer state code]: card holder address state. ex: 'GO'
32
+ # - zip_code [string, default sub-issuer zip code]: card holder address zip code. ex: '01311-200'
29
33
  #
30
34
  # ## Attributes (return-only):
31
35
  # - id [string]: unique id returned when IssuingCard is created. ex: '5656565656565656'
@@ -34,39 +38,39 @@ module StarkInfra
34
38
  # - status [string]: current IssuingCard status. ex: 'active', 'blocked', 'canceled', 'expired'.
35
39
  # - number [string]: [EXPANDABLE] masked card number. Expand to unmask the value. ex: '123'.
36
40
  # - security_code [string]: [EXPANDABLE] masked card verification value (cvv). Expand to unmask the value. ex: '123'.
37
- # - expiration [string]: [EXPANDABLE] masked card expiration datetime. Expand to unmask the value. ex: '2032-02-29T23:59:59.999999+00:00'.
41
+ # - expiration [DateTime]: [EXPANDABLE] masked card expiration datetime. Expand to unmask the value. ex: DateTime.new(2032, 3, 10, 10, 30, 0, 0)
38
42
  # - created [DateTime]: creation datetime for the IssuingCard. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
39
43
  # - updated [DateTime]: latest update datetime for the IssuingCard. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
40
44
  class IssuingCard < StarkInfra::Utils::Resource
41
- attr_reader :id, :holder_id, :holder_name, :holder_tax_id, :holder_external_id, :type, :display_name, :status,
42
- :rules, :bin_id, :street_line_1, :street_line_2, :district, :city, :state_code, :zip_code, :tags, :number,
43
- :security_code, :expiration, :created, :updated
45
+ attr_reader :id, :holder_name, :holder_tax_id, :holder_external_id, :display_name, :rules, :product_id, :tags,
46
+ :street_line_1, :street_line_2, :district, :city, :state_code, :zip_code, :holder_id,
47
+ :type, :status, :number, :security_code, :expiration, :created, :updated
44
48
  def initialize(
45
- holder_name:, holder_tax_id:, holder_external_id:, id: nil, holder_id: nil, type: nil,
46
- display_name: nil, status: nil, rules: nil, bin_id: nil, street_line_1: nil, street_line_2: nil, district: nil,
47
- city: nil, state_code: nil, zip_code: nil, tags: nil, number: nil, security_code: nil, expiration: nil,
48
- created: nil, updated: nil
49
+ holder_name: , holder_tax_id: , holder_external_id: , display_name: nil, rules: nil, product_id: nil, tags: nil,
50
+ street_line_1: nil, street_line_2: nil, district: nil, city: nil, state_code: nil, zip_code: nil, id: nil,
51
+ holder_id: nil, type: nil, status: nil, number: nil, security_code: nil, expiration: nil, created: nil, updated: nil
49
52
  )
50
53
  super(id)
51
54
  @holder_name = holder_name
52
55
  @holder_tax_id = holder_tax_id
53
56
  @holder_external_id = holder_external_id
54
- @holder_id = holder_id
55
- @type = type
56
57
  @display_name = display_name
57
- @status = status
58
58
  @rules = StarkInfra::IssuingRule.parse_rules(rules)
59
- @bin_id = bin_id
59
+ @product_id = product_id
60
+ @tags = tags
60
61
  @street_line_1 = street_line_1
61
62
  @street_line_2 = street_line_2
62
63
  @district = district
63
64
  @city = city
64
65
  @state_code = state_code
65
66
  @zip_code = zip_code
66
- @tags = tags
67
+ @holder_id = holder_id
68
+ @type = type
69
+ @status = status
67
70
  @number = number
68
71
  @security_code = security_code
69
- @expiration = expiration
72
+ expiration = nil if !expiration.nil? && expiration.include?('*')
73
+ @expiration = StarkInfra::Utils::Checks.check_datetime(expiration)
70
74
  @created = StarkInfra::Utils::Checks.check_datetime(created)
71
75
  @updated = StarkInfra::Utils::Checks.check_datetime(updated)
72
76
  end
@@ -111,13 +115,13 @@ module StarkInfra
111
115
  # ## Parameters (optional):
112
116
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
113
117
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
114
- # - after [DateTime or string, default nil] date filter for objects created only after specified date. ex: DateTime.new(2020, 3, 10)
115
- # - before [DateTime or string, default nil] date filter for objects created only before specified date. ex: DateTime.new(2020, 3, 10)
118
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
119
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
116
120
  # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled', 'expired']
117
121
  # - types [list of strings, default nil]: card type. ex: ['virtual']
118
- # - holder_ids [list of strings]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
122
+ # - holder_ids [list of strings, default nil]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
119
123
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
120
- # - expand [list of strings, default []]: fields to expand information. ex: ['rules', 'security_code', 'number', 'expiration']
124
+ # - expand [list of strings, default nil]: fields to expand information. ex: ['rules', 'security_code', 'number', 'expiration']
121
125
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
122
126
  #
123
127
  # ## Return:
@@ -147,15 +151,15 @@ module StarkInfra
147
151
  #
148
152
  # ## Parameters (optional):
149
153
  # - cursor [string, default nil]: cursor returned on the previous page function call.
150
- # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
154
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
151
155
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
152
- # - after [DateTime or string, default nil] date filter for objects created only after specified date. ex: DateTime.new(2020, 3, 10)
153
- # - before [DateTime or string, default nil] date filter for objects created only before specified date. ex: DateTime.new(2020, 3, 10)
156
+ # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
157
+ # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
154
158
  # - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled', 'expired']
155
159
  # - types [list of strings, default nil]: card type. ex: ['virtual']
156
- # - holder_ids [list of strings]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
160
+ # - holder_ids [list of strings, default nil]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
157
161
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
158
- # - expand [list of strings, default []]: fields to expand information. ex: ['rules', 'security_code', 'number', 'expiration']
162
+ # - expand [list of strings, default nil]: fields to expand information. ex: ['rules', 'security_code', 'number', 'expiration']
159
163
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
160
164
  #
161
165
  # ## Return:
@@ -231,22 +235,22 @@ module StarkInfra
231
235
  resource_maker: proc { |json|
232
236
  IssuingCard.new(
233
237
  id: json['id'],
234
- holder_id: json['holder_id'],
235
238
  holder_name: json['holder_name'],
236
239
  holder_tax_id: json['holder_tax_id'],
237
240
  holder_external_id: json['holder_external_id'],
238
- type: json['type'],
239
241
  display_name: json['display_name'],
240
- status: json['status'],
241
242
  rules: json['rules'],
242
- bin_id: json['bin_id'],
243
+ product_id: json['product_id'],
244
+ tags: json['tags'],
243
245
  street_line_1: json['street_line_1'],
244
246
  street_line_2: json['street_line_2'],
245
247
  district: json['district'],
246
248
  city: json['city'],
247
249
  state_code: json['state_code'],
248
250
  zip_code: json['zip_code'],
249
- tags: json['tags'],
251
+ holder_id: json['holder_id'],
252
+ type: json['type'],
253
+ status: json['status'],
250
254
  number: json['number'],
251
255
  security_code: json['security_code'],
252
256
  expiration: json['expiration'],
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require_relative('issuingcard')
4
4
  require_relative('../utils/rest')
5
5
  require_relative('../utils/checks')
6
- require_relative('issuingcard')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  class IssuingCard
@@ -79,7 +79,7 @@ module StarkInfra
79
79
  # ## Parameters (optional):
80
80
  # - cursor [string, default nil]: cursor returned on the previous page function call
81
81
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
82
- # - limit [integer, default nil]: maximum number of objects to be retrieved. Max = 100. ex: 35
82
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
83
83
  # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
84
84
  # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
85
85
  # - types [list of strings, default nil]: filter for log event types. ex: ['blocked', 'canceled', 'created', 'expired', 'unblocked', 'updated']