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
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
6
4
  require_relative('../utils/parse')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  # # PixRequest object
@@ -28,16 +28,18 @@ module StarkInfra
28
28
  # - receiver_account_type [string]: receiver bank account type. ex: 'checking', 'savings', 'salary' or 'payment'
29
29
  # - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
30
30
  #
31
+ # ## Parameters (conditionally-required):
32
+ # - cashier_type [string]: Cashier's type. Required if the cash_amount is different from 0. Options: 'merchant', 'participant' and 'other'
33
+ # - cashier_bank_code [string]: Cashier's bank code. Required if the cash_amount is different from 0. ex: '20018183'
34
+ #
31
35
  # ## Parameters (optional):
36
+ # - cash_amount [integer, default nil]: Amount to be withdrawal from the cashier in cents. ex: 1000 (= R$ 10.00)
32
37
  # - receiver_key_id [string, default nil]: Receiver's dict key. Example: tax id (CPF/CNPJ).
33
38
  # - description [string, default nil]: optional description to override default description to be shown in the bank statement. ex: 'Payment for service #1234'
34
39
  # - reconciliation_id [string, default nil]: Reconciliation ID linked to this payment. ex: 'b77f5236-7ab9-4487-9f95-66ee6eaf1781'
35
40
  # - initiator_tax_id [string, default nil]: Payment initiator's tax id (CPF/CNPJ). ex: '01234567890' or '20.018.183/0001-80'
36
- # - cash_amount [integer, default nil]: Amount to be withdrawal from the cashier in cents. ex: 1000 (= R$ 10.00)
37
- # - cashier_bank_code [string, default nil]: Cashier's bank code. ex: '00000000'
38
- # - cashier_type [string, default nil]: Cashier's type. ex: [merchant, other, participant]
39
41
  # - tags [list of strings, default nil]: list of strings for reference when searching for PixRequests. ex: ['employees', 'monthly']
40
- # - method [string, default nil]: execution method of creation of the PIX. ex: 'manual', 'payerQrcode', 'dynamicQrcode'.
42
+ # - method [string, default nil]: execution method of creation of the Pix. ex: 'manual', 'payerQrcode', 'dynamicQrcode'.
41
43
  #
42
44
  # ## Attributes (return-only):
43
45
  # - id [string]: unique id returned when the PixRequest is created. ex: '5656565656565656'
@@ -50,15 +52,15 @@ module StarkInfra
50
52
  class PixRequest < StarkInfra::Utils::Resource
51
53
  attr_reader :amount, :external_id, :sender_name, :sender_tax_id, :sender_branch_code, :sender_account_number,
52
54
  :sender_account_type, :receiver_name, :receiver_tax_id, :receiver_bank_code, :receiver_account_number,
53
- :receiver_branch_code, :receiver_account_type, :end_to_end_id, :receiver_key_id, :sender_bank_code,
54
- :status, :reconciliation_id, :description, :flow, :initiator_tax_id, :cash_amount, :cashier_bank_code,
55
- :cashier_type, :tags, :created, :updated, :fee, :id
55
+ :receiver_branch_code, :receiver_account_type, :end_to_end_id, :cashier_type,
56
+ :cashier_bank_code, :cash_amount, :receiver_key_id, :description, :reconciliation_id, :initiator_tax_id,
57
+ :tags, :method, :id, :fee, :status, :flow, :sender_bank_code, :created, :updated
56
58
  def initialize(
57
59
  amount:, external_id:, sender_name:, sender_tax_id:, sender_branch_code:, sender_account_number:,
58
60
  sender_account_type:, receiver_name:, receiver_tax_id:, receiver_bank_code:, receiver_account_number:,
59
- receiver_branch_code:, receiver_account_type:, end_to_end_id:, receiver_key_id: nil, description: nil,
60
- reconciliation_id: nil, initiator_tax_id: nil, cash_amount: nil, cashier_bank_code: nil, cashier_type: nil,
61
- tags: nil, id: nil, fee: nil, status:nil, flow: nil, method: nil, sender_bank_code: nil, created: nil, updated: nil
61
+ receiver_branch_code:, receiver_account_type:, end_to_end_id:, cashier_type: nil, cashier_bank_code: nil,
62
+ cash_amount: nil, receiver_key_id: nil, description: nil, reconciliation_id: nil, initiator_tax_id: nil,
63
+ tags: nil, method: nil, id: nil, fee: nil, status:nil, flow: nil, sender_bank_code: nil, created: nil, updated: nil
62
64
  )
63
65
  super(id)
64
66
  @amount = amount
@@ -75,13 +77,13 @@ module StarkInfra
75
77
  @receiver_branch_code = receiver_branch_code
76
78
  @receiver_account_type = receiver_account_type
77
79
  @end_to_end_id = end_to_end_id
80
+ @cashier_type = cashier_type
81
+ @cashier_bank_code = cashier_bank_code
82
+ @cash_amount = cash_amount
78
83
  @receiver_key_id = receiver_key_id
79
84
  @description = description
80
85
  @reconciliation_id = reconciliation_id
81
86
  @initiator_tax_id = initiator_tax_id
82
- @cash_amount = cash_amount
83
- @cashier_bank_code = cashier_bank_code
84
- @cashier_type = cashier_type
85
87
  @tags = tags
86
88
  @method = method
87
89
  @fee = fee
@@ -169,10 +171,10 @@ module StarkInfra
169
171
  # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
170
172
  # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
171
173
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
172
- # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
173
174
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
174
175
  # - end_to_end_ids [list of strings, default nil]: central bank's unique transaction IDs. ex: ['E79457883202101262140HHX553UPqeq', 'E79457883202101262140HHX553UPxzx']
175
176
  # - external_ids [list of strings, default nil]: url safe strings that must be unique among all your PixRequests. Duplicated external IDs will cause failures. By default, this parameter will block any PixRequests that repeats amount and receiver information on the same date. ex: ['my-internal-id-123456', 'my-internal-id-654321']
177
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
176
178
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
177
179
  #
178
180
  # ## Return:
@@ -212,7 +214,35 @@ module StarkInfra
212
214
  # ## Return:
213
215
  # - Parsed PixRequest object
214
216
  def self.parse(content:, signature:, user: nil)
215
- StarkInfra::Utils::Parse.parse_and_verify(content: content, signature: signature, user: user, resource: resource)
217
+ request = StarkInfra::Utils::Parse.parse_and_verify(content: content, signature: signature, user: user, resource: resource)
218
+
219
+ !request.fee.nil? ? request.fee : 0
220
+ !request.tags.nil? ? request.tags : []
221
+ !request.external_id.nil? ? request.external_id : ''
222
+ !request.description.nil? ? request.description : ''
223
+
224
+ request
225
+ end
226
+
227
+ # Helps you respond to a PixRequest authorization
228
+ #
229
+ ## Parameters (required):
230
+ # - status [string]: response to the authorization. ex: 'approved' or 'denied'
231
+ #
232
+ ## Parameters (conditionally required):
233
+ # - reason [string, default nil]: denial reason. Options: 'invalidAccountNumber', 'blockedAccount', 'accountClosed', 'invalidAccountType', 'invalidTransactionType', 'taxIdMismatch', 'invalidTaxId', 'orderRejected', 'reversalTimeExpired', 'settlementFailed'
234
+ #
235
+ ## Return:
236
+ # - Dumped JSON string that must be returned to us
237
+ def self.response(status:, reason: nil)
238
+ response = {
239
+ authorization: {
240
+ status: status,
241
+ reason: reason
242
+ }
243
+ }.to_json
244
+
245
+ response
216
246
  end
217
247
 
218
248
  def self.resource
@@ -235,18 +265,18 @@ module StarkInfra
235
265
  receiver_branch_code: json['receiver_branch_code'],
236
266
  receiver_account_type: json['receiver_account_type'],
237
267
  end_to_end_id: json['end_to_end_id'],
268
+ cashier_type: json['cashier_type'],
269
+ cashier_bank_code: json['cashier_bank_code'],
270
+ cash_amount: json['cash_amount'],
238
271
  receiver_key_id: json['receiver_key_id'],
239
272
  description: json['description'],
240
273
  reconciliation_id: json['reconciliation_id'],
241
274
  initiator_tax_id: json['initiator_tax_id'],
242
- cash_amount: json['cash_amount'],
243
- cashier_bank_code: json['cashier_bank_code'],
244
- cashier_type: json['cashier_type'],
245
275
  tags: json['tags'],
276
+ method: json['method'],
246
277
  fee: json['fee'],
247
278
  status: json['status'],
248
279
  flow: json['flow'],
249
- method: json['method'],
250
280
  sender_bank_code: json['sender_bank_code'],
251
281
  created: json['created'],
252
282
  updated: json['updated']
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require_relative('pixreversal')
4
4
  require_relative('../utils/rest')
5
5
  require_relative('../utils/checks')
6
- require_relative('pixreversal')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  class PixReversal
@@ -1,42 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
6
4
  require_relative('../utils/parse')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  # # PixReversal object
10
10
  #
11
- # When you initialize a PixReversal, the entity will not be automatically created in the Stark Infra API.
12
- # The 'create' function sends the objects to the Stark Infra API and returns the list of created objects.
11
+ # PixReversals are instant payments used to revert PixRequests. You can
12
+ # only revert inbound PixRequests.
13
+ #
14
+ # When you initialize a PixReversal, the entity will not be automatically
15
+ # created in the Stark Infra API. The 'create' function sends the objects
16
+ # to the Stark Infra API and returns the list of created objects.
13
17
  #
14
18
  # ## Parameters (required):
15
19
  # - amount [integer]: amount in cents to be reversed from PixRequest. ex: 1234 (= R$ 12.34)
16
- # - external_id [string]: url safe string that must be unique among all your PixReversals. Duplicated external ids will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: 'my-internal-id-123456'
20
+ # - external_id [string]: string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: 'my-internal-id-123456'
17
21
  # - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
18
22
  # - reason [string]: reason why the PixRequest is being reversed. Options are 'bankError', 'fraud', 'pixWithdrawError', 'refund3ByEndCustomer'
19
23
  #
20
24
  # ## Parameters (optional):
21
- # - tags [string, default nil]: [list of strings]: list of strings for reference when searching for PixReversals. ex: ['employees', 'monthly']
25
+ # - tags [list of strings, default nil]: list of strings for reference when searching for PixReversals. ex: ['employees', 'monthly']
22
26
  #
23
27
  # ## Attributes (return-only):
24
28
  # - id [string]: unique id returned when the PixReversal is created. ex: '5656565656565656'.
25
29
  # - return_id [string]: central bank's unique reversal transaction ID. ex: 'D20018183202202030109X3OoBHG74wo'.
26
- # - bank_code [string]: code of the bank institution in Brazil. ex: '20018183' or '341'
27
30
  # - fee [string]: fee charged by this PixReversal. ex: 200 (= R$ 2.00)
28
31
  # - status [string]: current PixReversal status. ex: 'registered' or 'paid'
29
32
  # - flow [string]: direction of money flow. ex: 'in' or 'out'
30
33
  # - created [DateTime]: creation datetime for the PixReversal. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
31
34
  # - updated [DateTime]: latest update datetime for the PixReversal. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
- class PixReversal < StarkInfra::Utils::Resource;
33
- attr_reader :amount, :external_id, :end_to_end_id, :reason, :tags, :id, :return_id, :bank_code, :fee, :status, :flow, :created, :updated
35
+ class PixReversal < StarkInfra::Utils::Resource
36
+ attr_reader :amount, :external_id, :end_to_end_id, :reason, :tags, :id, :return_id,
37
+ :fee, :status, :flow, :created, :updated
34
38
  def initialize(
35
- amount:, external_id:, end_to_end_id:, reason:, tags: nil, id: nil, return_id: nil, bank_code: nil, fee: nil,
39
+ amount:, external_id:, end_to_end_id:, reason:, tags: nil, id: nil, return_id: nil, fee: nil,
36
40
  status: nil, flow: nil, created: nil, updated: nil
37
41
  )
38
- created = StarkInfra::Utils::Checks.check_datetime(created)
39
- updated = StarkInfra::Utils::Checks.check_datetime(updated)
40
42
  super(id)
41
43
  @amount = amount
42
44
  @external_id = external_id
@@ -44,12 +46,11 @@ module StarkInfra
44
46
  @reason = reason
45
47
  @tags = tags
46
48
  @return_id = return_id
47
- @bank_code = bank_code
48
49
  @fee = fee
49
50
  @status = status
50
51
  @flow = flow
51
- @created = created
52
- @updated = updated
52
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
53
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
53
54
  end
54
55
 
55
56
  # # Create PixReversals
@@ -93,10 +94,10 @@ module StarkInfra
93
94
  # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
94
95
  # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
95
96
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
96
- # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
97
97
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
98
98
  # - return_ids [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ['D20018183202202030109X3OoBHG74wo', 'D20018183202202030109X3OoBHG72rd'].
99
99
  # - external_ids [list of strings, default nil]: url safe string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ['my-internal-id-123456', 'my-internal-id-654321']
100
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
100
101
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
101
102
  #
102
103
  # ## Return:
@@ -129,10 +130,10 @@ module StarkInfra
129
130
  # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
130
131
  # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
131
132
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
132
- # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
133
133
  # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
134
134
  # - return_ids [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ['D20018183202202030109X3OoBHG74wo', 'D20018183202202030109X3OoBHG72rd'].
135
135
  # - external_ids [list of strings, default nil]: url safe string that must be unique among all your PixReversals. Duplicated external IDs will cause failures. By default, this parameter will block any PixReversal that repeats amount and receiver information on the same date. ex: ['my-internal-id-123456', 'my-internal-id-654321']
136
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
136
137
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
137
138
  #
138
139
  # ## Return:
@@ -170,12 +171,40 @@ module StarkInfra
170
171
  # ## Return:
171
172
  # - Parsed PixReversal object
172
173
  def self.parse(content:, signature:, user: nil)
173
- StarkInfra::Utils::Parse.parse_and_verify(
174
+ reversal = StarkInfra::Utils::Parse.parse_and_verify(
174
175
  content: content,
175
176
  signature: signature,
176
177
  user: user,
177
178
  resource: resource
178
179
  )
180
+
181
+ !reversal.fee.nil? ? reversal.fee : 0
182
+ !reversal.tags.nil? ? reversal.tags : []
183
+ !reversal.external_id.nil? ? reversal.external_id : ''
184
+ !reversal.description.nil? ? reversal.description : ''
185
+
186
+ reversal
187
+ end
188
+
189
+ # Helps you respond to a PixReversal authorization
190
+ #
191
+ ## Parameters (required):
192
+ # - status [string]: response to the authorization. ex: 'approved' or 'denied'
193
+ #
194
+ ## Parameters (conditionally required):
195
+ # - reason [string, default nil]: denial reason. Options: 'invalidAccountNumber', 'blockedAccount', 'accountClosed', 'invalidAccountType', 'invalidTransactionType', 'taxIdMismatch', 'invalidTaxId', 'orderRejected', 'reversalTimeExpired', 'settlementFailed'
196
+ #
197
+ ## Return:
198
+ # - Dumped JSON string that must be returned to us
199
+ def self.response(status:, reason: nil)
200
+ response = {
201
+ authorization: {
202
+ status: status,
203
+ reason: reason
204
+ }
205
+ }.to_json
206
+
207
+ response
179
208
  end
180
209
 
181
210
  def self.resource
@@ -183,14 +212,13 @@ module StarkInfra
183
212
  resource_name: 'PixReversal',
184
213
  resource_maker: proc { |json|
185
214
  PixReversal.new(
215
+ id: json['id'],
186
216
  amount: json['amount'],
187
217
  external_id: json['external_id'],
188
218
  end_to_end_id: json['end_to_end_id'],
189
219
  reason: json['reason'],
190
220
  tags: json['tags'],
191
- id: json['id'],
192
221
  return_id: json['return_id'],
193
- bank_code: json['bank_code'],
194
222
  fee: json['fee'],
195
223
  status: json['status'],
196
224
  flow: json['flow'],
@@ -1,19 +1,24 @@
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
  # # PixStatement object
9
9
  #
10
- # The PixStatement object stores information about all the transactions that happened on
11
- # a specific day at the workspace. It must be created by the user before it can be
12
- # accessed by the user. This feature is only available for direct participants.
10
+ # The PixStatement object stores information about all the transactions that
11
+ # happened on a specific day at your settlment account according to the Central Bank.
12
+ # It must be created by the user before it can be accessed.
13
+ # This feature is only available for direct participants.
14
+ #
15
+ # When you initialize a PixStatement, 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 created object.
13
18
  #
14
19
  # ## Parameters (required):
15
- # - after [Date or string]: transactions that happened at this date are stored in the PixStatement, must be the same as before. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
16
- # - before [Date or string]: transactions that happened at this date are stored in the PixStatement, must be the same as after. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
20
+ # - after [Date or string]: transactions that happened at this date are stored in the PixStatement, must be the same as before. ex: Date.new(2020, 3, 10) or '2020-03-10'
21
+ # - before [Date or string]: transactions that happened at this date are stored in the PixStatement, must be the same as after. ex: Date.new(2020, 3, 10) or '2020-03-10'
17
22
  # - type [string]: type of entities to include in statement. Options: 'interchange', 'interchangeTotal', 'transaction'
18
23
  #
19
24
  # ## Attributes (return-only):
@@ -132,10 +137,10 @@ module StarkInfra
132
137
  resource_name: 'PixStatement',
133
138
  resource_maker: proc { |json|
134
139
  PixStatement.new(
140
+ id: json['id'],
135
141
  after: json['after'],
136
142
  before: json['before'],
137
143
  type: json['type'],
138
- id: json['id'],
139
144
  status: json['status'],
140
145
  transaction_count: json['transaction_count'],
141
146
  created: json['created'],
data/lib/starkinfra.rb CHANGED
@@ -3,43 +3,55 @@
3
3
  require_relative('key')
4
4
  require_relative('user/project')
5
5
  require_relative('user/organization')
6
- require_relative('issuingauthorization/issuingauthorization')
6
+ require_relative('brcodepreview/brcodepreview')
7
+ require_relative('cardmethod/cardmethod')
8
+ require_relative('creditnote/invoice/invoice')
9
+ require_relative('creditnote/invoice/description')
10
+ require_relative('creditnote/invoice/discount')
11
+ require_relative('creditnote/creditnote')
12
+ require_relative('creditnote/log')
13
+ require_relative('creditnote/transfer')
14
+ require_relative('creditpreview/creditpreview')
15
+ require_relative('creditpreview/creditnotepreview')
16
+ require_relative('creditsigner/creditsigner')
17
+ require_relative('dynamicbrcode/dynamicbrcode')
7
18
  require_relative('issuingbalance/issuingbalance')
8
- require_relative('issuingbin/issuingbin')
9
19
  require_relative('issuingcard/issuingcard')
10
20
  require_relative('issuingcard/log')
11
21
  require_relative('issuingholder/issuingholder')
12
22
  require_relative('issuingholder/log')
13
23
  require_relative('issuinginvoice/issuinginvoice')
14
24
  require_relative('issuinginvoice/log')
25
+ require_relative('issuingproduct/issuingproduct')
15
26
  require_relative('issuingpurchase/issuingpurchase')
16
27
  require_relative('issuingpurchase/log')
28
+ require_relative('issuingrule/issuingrule')
17
29
  require_relative('issuingtransaction/issuingtransaction')
18
30
  require_relative('issuingwithdrawal/issuingwithdrawal')
19
- require_relative('issuingrule/issuingrule')
20
- require_relative('pixrequest/pixrequest')
21
- require_relative('pixrequest/log')
22
- require_relative('pixreversal/pixreversal')
23
- require_relative('pixreversal/log')
31
+ require_relative('merchantcategory/merchantcategory')
32
+ require_relative('merchantcountry/merchantcountry')
24
33
  require_relative('pixbalance/pixbalance')
25
- require_relative('pixstatement/pixstatement')
26
- require_relative('pixinfraction/pixinfraction')
27
- require_relative('pixinfraction/log')
28
34
  require_relative('pixchargeback/pixchargeback')
29
35
  require_relative('pixchargeback/log')
30
- require_relative('pixkey/pixkey')
31
- require_relative('pixkey/log')
32
36
  require_relative('pixclaim/pixclaim')
33
37
  require_relative('pixclaim/log')
34
- require_relative('pixdomain/pixdomain')
35
38
  require_relative('pixdirector/pixdirector')
39
+ require_relative('pixdomain/pixdomain')
40
+ require_relative('pixinfraction/pixinfraction')
41
+ require_relative('pixinfraction/log')
42
+ require_relative('pixkey/pixkey')
43
+ require_relative('pixkey/log')
44
+ require_relative('pixrequest/pixrequest')
45
+ require_relative('pixrequest/log')
46
+ require_relative('pixreversal/pixreversal')
47
+ require_relative('pixreversal/log')
48
+ require_relative('pixstatement/pixstatement')
49
+ require_relative('staticbrcode/staticbrcode')
36
50
  require_relative('webhook/webhook')
37
51
  require_relative('event/event')
38
52
  require_relative('event/attempt')
39
53
  require_relative('utils/endtoendid')
40
54
  require_relative('utils/returnid')
41
- require_relative('creditnote/creditnote')
42
- require_relative('creditnote/log')
43
55
 
44
56
  # SDK to facilitate Ruby integrations with Stark Infra
45
57
  module StarkInfra
@@ -0,0 +1,164 @@
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
+ # # StaticBrcode object
10
+ #
11
+ # A StaticBrcode stores account information in the form of a PixKey and can be used to create
12
+ # Pix transactions easily.
13
+ #
14
+ # When you initialize a StaticBrcode, the entity will not be automatically
15
+ # created in the Stark Infra API. The 'create' function sends the objects
16
+ # to the Stark Infra API and returns the created object.
17
+ #
18
+ ## Parameters (required):
19
+ # - name [string]: receiver's name. ex: 'Tony Stark'
20
+ # - key_id [string]: receiver's Pixkey id. ex: '+5541999999999'
21
+ # - city [string, default São Paulo]: receiver's city name. ex: 'Rio de Janeiro'
22
+ #
23
+ # ## Parameters (optional):
24
+ # - amount [integer, default nil]: positive integer that represents the amount in cents of the resulting Pix transaction. If the amount is zero, the sender can choose any amount in the moment of payment. ex: 1234 (= R$ 12.34)
25
+ # - reconciliation_id [string, default nil]: id to be used for conciliation of the resulting Pix transaction. This id must have up to 25 alphanumeric digits ex: 'ah27s53agj6493hjds6836v49'
26
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
27
+ #
28
+ # ## Attributes (return-only):
29
+ # - id [string]: id returned on creation, this is the BR Code. ex: '00020126360014br.gov.bcb.pix0114+552840092118152040000530398654040.095802BR5915Jamie Lannister6009Sao Paulo620705038566304FC6C'
30
+ # - uuid [string]: unique uuid returned when a StaticBrcode is created. ex: '97756273400d42ce9086404fe10ea0d6'
31
+ # - url [string]: url link to the BR Code image. ex: 'https://brcode-h.development.starkinfra.com/static-qrcode/97756273400d42ce9086404fe10ea0d6.png'
32
+ # - created [DateTime]: creation datetime for the StaticBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
+ # - updated [DateTime]: latest update datetime for the StaticBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ class StaticBrcode < StarkInfra::Utils::Resource
35
+ attr_reader :name, :key_id, :city, :amount, :reconciliation_id, :id, :tags, :uuid, :url, :created, :updated
36
+ def initialize(
37
+ name:, key_id:, city:, amount:, reconciliation_id:, id: nil, tags:nil, uuid: nil, url: nil, created: nil, updated: nil
38
+ )
39
+ super(id)
40
+ @name = name
41
+ @key_id = key_id
42
+ @city = city
43
+ @amount = amount
44
+ @reconciliation_id = reconciliation_id
45
+ @tags = tags
46
+ @uuid = uuid
47
+ @url = url
48
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
49
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
50
+ end
51
+
52
+ # # Create StaticBrcodes
53
+ #
54
+ # Send a list of StaticBrcode objects for creation at the Stark Infra API
55
+ #
56
+ # ## Parameters (required):
57
+ # - brcodes [list of StaticBrcode objects]: list of StaticBrcode objects to be created in the API.
58
+ #
59
+ # ## Parameters (optional):
60
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
61
+ #
62
+ # ## Return:
63
+ # - list of StaticBrcode objects with updated attributes
64
+ def self.create(brcodes, user: nil)
65
+ StarkInfra::Utils::Rest.post(entities: brcodes, user: user, **resource)
66
+ end
67
+
68
+ # # Retrieve a specific StaticBrcode
69
+ #
70
+ # Receive a single StaticBrcode object previously created in the Stark Infra API by its uuid
71
+ #
72
+ # ## Parameters (required):
73
+ # - uuid [string]: object's unique uuid. ex: '97756273400d42ce9086404fe10ea0d6'
74
+ #
75
+ # ## Parameters (optional):
76
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
77
+ #
78
+ # ## Return:
79
+ # - StaticBrcode object with updated attributes
80
+ def self.get(uuid, user: nil)
81
+ StarkInfra::Utils::Rest.get_id(id: uuid, user: user, **resource)
82
+ end
83
+
84
+ # # Retrieve StaticBrcodes
85
+ #
86
+ # Receive a generator of StaticBrcode objects previously created in the Stark Infra API
87
+ #
88
+ # ## Parameters (optional):
89
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
90
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
91
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
92
+ # - uuids [list of strings, default nil]: list of uuids to filter retrieved objects. ex: ['901e71f2447c43c886f58366a5432c4b', '4e2eab725ddd495f9c98ffd97440702d']
93
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
94
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
95
+ #
96
+ # ## Return:
97
+ # - generator of StaticBrcode objects with updated attributes
98
+ def self.query(limit: nil, after: nil, before: nil, uuids: nil, tags: nil, user: nil)
99
+ after = StarkInfra::Utils::Checks.check_date(after)
100
+ before = StarkInfra::Utils::Checks.check_date(before)
101
+ StarkInfra::Utils::Rest.get_stream(
102
+ limit: limit,
103
+ after: after,
104
+ before: before,
105
+ uuids: uuids,
106
+ tags: tags,
107
+ user: user,
108
+ **resource
109
+ )
110
+ end
111
+
112
+ # # Retrieve StaticBrcodes
113
+ #
114
+ # Receive a list of StaticBrcode objects previously created in the Stark Infra API and the cursor to the next page.
115
+ #
116
+ # ## Parameters (optional):
117
+ # - cursor [string, default nil]: cursor returned on the previous page function call
118
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
119
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
120
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
121
+ # - uuids [list of strings, default nil]: list of uuids to filter retrieved objects. ex: ['901e71f2447c43c886f58366a5432c4b', '4e2eab725ddd495f9c98ffd97440702d']
122
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
123
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
124
+ #
125
+ # ## Return:
126
+ # - list of StaticBrcode objects with updated attributes
127
+ # - cursor to retrieve the next page of StaticBrcode objects
128
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, uuids: nil, user: nil)
129
+ after = StarkInfra::Utils::Checks.check_date(after)
130
+ before = StarkInfra::Utils::Checks.check_date(before)
131
+ StarkInfra::Utils::Rest.get_page(
132
+ cursor: cursor,
133
+ limit: limit,
134
+ after: after,
135
+ before: before,
136
+ uuids: uuids,
137
+ tags: tags,
138
+ user: user,
139
+ **resource
140
+ )
141
+ end
142
+
143
+ def self.resource
144
+ {
145
+ resource_name: 'StaticBrcode',
146
+ resource_maker: proc { |json|
147
+ StaticBrcode.new(
148
+ id: json['id'],
149
+ name: json['name'],
150
+ key_id: json['key_id'],
151
+ city: json['city'],
152
+ amount: json['amount'],
153
+ reconciliation_id: json['reconciliation_id'],
154
+ tags: json['tags'],
155
+ uuid: json['uuid'],
156
+ url: json['url'],
157
+ created: json['created'],
158
+ updated: json['updated']
159
+ )
160
+ }
161
+ }
162
+ end
163
+ end
164
+ end
data/lib/user/project.rb CHANGED
@@ -19,7 +19,7 @@ module StarkInfra
19
19
  # - environment [string]: environment where the project is being used. ex: 'sandbox' or 'production'
20
20
  #
21
21
  # ## Attributes (return-only):
22
- # - name [string, default '']: project name. ex: 'MyProject'
22
+ # - name [string, default nil]: project name. ex: 'MyProject'
23
23
  # - allowed_ips [list of strings]: list containing the strings of the ips allowed to make requests on behalf of this project. ex: ['190.190.0.50']
24
24
  # - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
25
25
  class Project < StarkInfra::User
data/lib/utils/api.rb CHANGED
@@ -34,6 +34,7 @@ module StarkInfra
34
34
  end
35
35
 
36
36
  def self.parse_value(value)
37
+ return api_json(value) if value.is_a?(SubResource)
37
38
  return value.strftime('%Y-%m-%d') if value.is_a?(Date)
38
39
  return value.strftime('%Y-%m-%dT%H:%M:%S+00:00') if value.is_a?(DateTime) || value.is_a?(Time)
39
40
  return cast_json_to_api_format(value) if value.is_a?(Hash)
data/lib/utils/parse.rb CHANGED
@@ -11,10 +11,14 @@ module StarkInfra
11
11
  module Utils
12
12
  module Parse
13
13
  def self.parse_and_verify(content:, signature:, user: nil, resource:, key: nil)
14
+ content = verify(content:content, signature: signature, user: user)
14
15
  json = JSON.parse(content)
15
16
  json = JSON.parse(content)[key] unless key.nil?
16
- event = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], json)
17
17
 
18
+ StarkInfra::Utils::API.from_api_json(resource[:resource_maker], json)
19
+ end
20
+
21
+ def self.verify(content:, signature:, user: nil)
18
22
  begin
19
23
  signature = EllipticCurve::Signature.fromBase64(signature)
20
24
  rescue
@@ -22,11 +26,11 @@ module StarkInfra
22
26
  end
23
27
 
24
28
  if verify_signature(content: content, signature: signature, user: user)
25
- return event
29
+ return content
26
30
  end
27
31
 
28
32
  if verify_signature(content: content, signature: signature, user: user, refresh: true)
29
- return event
33
+ return content
30
34
  end
31
35
 
32
36
  raise(StarkInfra::Error::InvalidSignatureError, 'The provided signature and content do not match the Stark Infra public key')
data/lib/utils/request.rb CHANGED
@@ -61,7 +61,7 @@ module StarkInfra
61
61
  req['Access-Time'] = access_time
62
62
  req['Access-Signature'] = signature
63
63
  req['Content-Type'] = 'application/json'
64
- req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-Infra-0.0.3"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-Infra-0.2.0"
65
65
  req['Accept-Language'] = language
66
66
 
67
67
  request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }