starkinfra 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brcodepreview/brcodepreview.rb +125 -0
- data/lib/cardmethod/cardmethod.rb +56 -0
- data/lib/creditholmes/creditholmes.rb +160 -0
- data/lib/creditnote/creditnote.rb +51 -355
- data/lib/creditnote/invoice/description.rb +51 -0
- data/lib/creditnote/invoice/discount.rb +49 -0
- data/lib/creditnote/invoice/invoice.rb +124 -0
- data/lib/creditnote/log.rb +18 -19
- data/lib/creditnote/transfer.rb +90 -0
- data/lib/creditpreview/creditnotepreview.rb +85 -0
- data/lib/creditpreview/creditpreview.rb +77 -0
- data/lib/creditsigner/creditsigner.rb +57 -0
- data/lib/dynamicbrcode/dynamicbrcode.rb +350 -0
- data/lib/event/attempt.rb +5 -4
- data/lib/event/event.rb +11 -11
- data/lib/individualdocument/individualdocument.rb +165 -0
- data/lib/individualdocument/log.rb +125 -0
- data/lib/individualidentity/individualidentity.rb +193 -0
- data/lib/individualidentity/log.rb +124 -0
- data/lib/issuingbalance/issuingbalance.rb +4 -4
- data/lib/issuingcard/issuingcard.rb +35 -33
- data/lib/issuingcard/log.rb +21 -21
- data/lib/issuingdesign/issuingdesign.rb +138 -0
- data/lib/issuingembossingkit/issuingembossingkit.rb +121 -0
- data/lib/issuingembossingrequest/issuingembossingrequest.rb +210 -0
- data/lib/issuingembossingrequest/log.rb +128 -0
- data/lib/issuingholder/issuingholder.rb +21 -15
- data/lib/issuingholder/log.rb +19 -19
- data/lib/issuinginvoice/issuinginvoice.rb +29 -14
- data/lib/issuinginvoice/log.rb +18 -18
- data/lib/{issuingbin/issuingbin.rb → issuingproduct/issuingproduct.rb} +27 -30
- data/lib/issuingpurchase/issuingpurchase.rb +111 -31
- data/lib/issuingpurchase/log.rb +16 -16
- data/lib/issuingrestock/issuingrestock.rb +162 -0
- data/lib/issuingrestock/log.rb +127 -0
- data/lib/issuingrule/issuingrule.rb +64 -18
- data/lib/issuingstock/issuingstock.rb +138 -0
- data/lib/issuingstock/log.rb +130 -0
- data/lib/issuingtransaction/issuingtransaction.rb +12 -13
- data/lib/issuingwithdrawal/issuingwithdrawal.rb +12 -11
- data/lib/merchantcategory/merchantcategory.rb +63 -0
- data/lib/merchantcountry/merchantcountry.rb +59 -0
- data/lib/pixbalance/pixbalance.rb +5 -5
- data/lib/pixchargeback/log.rb +15 -15
- data/lib/pixchargeback/pixchargeback.rb +32 -20
- data/lib/pixclaim/log.rb +21 -24
- data/lib/pixclaim/pixclaim.rb +44 -34
- data/lib/pixdirector/pixdirector.rb +9 -11
- data/lib/pixdomain/certificate.rb +1 -1
- data/lib/pixdomain/pixdomain.rb +5 -5
- data/lib/pixinfraction/log.rb +20 -20
- data/lib/pixinfraction/pixinfraction.rb +23 -15
- data/lib/pixkey/log.rb +23 -23
- data/lib/pixkey/pixkey.rb +14 -12
- data/lib/pixrequest/log.rb +24 -20
- data/lib/pixrequest/pixrequest.rb +54 -21
- data/lib/pixreversal/log.rb +3 -3
- data/lib/pixreversal/pixreversal.rb +48 -21
- data/lib/pixstatement/pixstatement.rb +13 -8
- data/lib/starkinfra.rb +40 -15
- data/lib/staticbrcode/staticbrcode.rb +170 -0
- data/lib/user/project.rb +1 -1
- data/lib/utils/api.rb +1 -0
- data/lib/utils/bacenid.rb +1 -1
- data/lib/utils/parse.rb +7 -3
- data/lib/utils/request.rb +1 -1
- data/lib/utils/resource.rb +1 -1
- data/lib/utils/sub_resource.rb +21 -22
- data/lib/webhook/webhook.rb +11 -11
- metadata +29 -4
- data/lib/issuingauthorization/issuingauthorization.rb +0 -141
@@ -1,43 +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
|
-
#
|
12
|
-
#
|
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]:
|
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 [
|
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,
|
34
|
-
: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
|
35
38
|
def initialize(
|
36
|
-
amount:, external_id:, end_to_end_id:, reason:, tags: nil, id: nil, return_id: nil,
|
39
|
+
amount:, external_id:, end_to_end_id:, reason:, tags: nil, id: nil, return_id: nil, fee: nil,
|
37
40
|
status: nil, flow: nil, created: nil, updated: nil
|
38
41
|
)
|
39
|
-
created = StarkInfra::Utils::Checks.check_datetime(created)
|
40
|
-
updated = StarkInfra::Utils::Checks.check_datetime(updated)
|
41
42
|
super(id)
|
42
43
|
@amount = amount
|
43
44
|
@external_id = external_id
|
@@ -45,12 +46,11 @@ module StarkInfra
|
|
45
46
|
@reason = reason
|
46
47
|
@tags = tags
|
47
48
|
@return_id = return_id
|
48
|
-
@bank_code = bank_code
|
49
49
|
@fee = fee
|
50
50
|
@status = status
|
51
51
|
@flow = flow
|
52
|
-
@created = created
|
53
|
-
@updated = updated
|
52
|
+
@created = StarkInfra::Utils::Checks.check_datetime(created)
|
53
|
+
@updated = StarkInfra::Utils::Checks.check_datetime(updated)
|
54
54
|
end
|
55
55
|
|
56
56
|
# # Create PixReversals
|
@@ -94,10 +94,10 @@ module StarkInfra
|
|
94
94
|
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
95
95
|
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
96
96
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
|
97
|
-
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
98
97
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
99
98
|
# - return_ids [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ['D20018183202202030109X3OoBHG74wo', 'D20018183202202030109X3OoBHG72rd'].
|
100
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']
|
101
101
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
102
102
|
#
|
103
103
|
# ## Return:
|
@@ -130,10 +130,10 @@ module StarkInfra
|
|
130
130
|
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
131
131
|
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
132
132
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
133
|
-
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
134
133
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
135
134
|
# - return_ids [list of strings, default nil]: central bank's unique reversal transaction ID. ex: ['D20018183202202030109X3OoBHG74wo', 'D20018183202202030109X3OoBHG72rd'].
|
136
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']
|
137
137
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
138
138
|
#
|
139
139
|
# ## Return:
|
@@ -171,12 +171,40 @@ module StarkInfra
|
|
171
171
|
# ## Return:
|
172
172
|
# - Parsed PixReversal object
|
173
173
|
def self.parse(content:, signature:, user: nil)
|
174
|
-
StarkInfra::Utils::Parse.parse_and_verify(
|
174
|
+
reversal = StarkInfra::Utils::Parse.parse_and_verify(
|
175
175
|
content: content,
|
176
176
|
signature: signature,
|
177
177
|
user: user,
|
178
178
|
resource: resource
|
179
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
|
180
208
|
end
|
181
209
|
|
182
210
|
def self.resource
|
@@ -184,14 +212,13 @@ module StarkInfra
|
|
184
212
|
resource_name: 'PixReversal',
|
185
213
|
resource_maker: proc { |json|
|
186
214
|
PixReversal.new(
|
215
|
+
id: json['id'],
|
187
216
|
amount: json['amount'],
|
188
217
|
external_id: json['external_id'],
|
189
218
|
end_to_end_id: json['end_to_end_id'],
|
190
219
|
reason: json['reason'],
|
191
220
|
tags: json['tags'],
|
192
|
-
id: json['id'],
|
193
221
|
return_id: json['return_id'],
|
194
|
-
bank_code: json['bank_code'],
|
195
222
|
fee: json['fee'],
|
196
223
|
status: json['status'],
|
197
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
|
11
|
-
# a specific day at
|
12
|
-
#
|
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:
|
16
|
-
# - before [Date or string]: transactions that happened at this date are stored in the PixStatement, must be the same as after. ex:
|
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):
|
@@ -38,7 +43,7 @@ module StarkInfra
|
|
38
43
|
# # Create a PixStatement object
|
39
44
|
#
|
40
45
|
# Create a PixStatements linked to your workspace in the Stark Infra API
|
41
|
-
#
|
46
|
+
#
|
42
47
|
# ## Parameters (required):
|
43
48
|
# - statement [PixStatement object]: PixStatement object to be created in the API.
|
44
49
|
#
|
@@ -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,68 @@
|
|
3
3
|
require_relative('key')
|
4
4
|
require_relative('user/project')
|
5
5
|
require_relative('user/organization')
|
6
|
-
require_relative('
|
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('creditholmes/creditholmes')
|
15
|
+
require_relative('creditpreview/creditpreview')
|
16
|
+
require_relative('creditpreview/creditnotepreview')
|
17
|
+
require_relative('creditsigner/creditsigner')
|
18
|
+
require_relative('dynamicbrcode/dynamicbrcode')
|
19
|
+
require_relative('individualdocument/individualdocument')
|
20
|
+
require_relative('individualdocument/log')
|
21
|
+
require_relative('individualidentity/individualidentity')
|
22
|
+
require_relative('individualidentity/log')
|
7
23
|
require_relative('issuingbalance/issuingbalance')
|
8
|
-
require_relative('
|
24
|
+
require_relative('issuingdesign/issuingdesign')
|
25
|
+
require_relative('issuingembossingkit/issuingembossingkit')
|
26
|
+
require_relative('issuingembossingrequest/issuingembossingrequest')
|
27
|
+
require_relative('issuingembossingrequest/log')
|
28
|
+
require_relative('issuingstock/issuingstock')
|
29
|
+
require_relative('issuingstock/log')
|
30
|
+
require_relative('issuingrestock/issuingrestock')
|
31
|
+
require_relative('issuingrestock/log')
|
9
32
|
require_relative('issuingcard/issuingcard')
|
10
33
|
require_relative('issuingcard/log')
|
11
34
|
require_relative('issuingholder/issuingholder')
|
12
35
|
require_relative('issuingholder/log')
|
13
36
|
require_relative('issuinginvoice/issuinginvoice')
|
14
37
|
require_relative('issuinginvoice/log')
|
38
|
+
require_relative('issuingproduct/issuingproduct')
|
15
39
|
require_relative('issuingpurchase/issuingpurchase')
|
16
40
|
require_relative('issuingpurchase/log')
|
41
|
+
require_relative('issuingrule/issuingrule')
|
17
42
|
require_relative('issuingtransaction/issuingtransaction')
|
18
43
|
require_relative('issuingwithdrawal/issuingwithdrawal')
|
19
|
-
require_relative('
|
20
|
-
require_relative('
|
21
|
-
require_relative('pixrequest/log')
|
22
|
-
require_relative('pixreversal/pixreversal')
|
23
|
-
require_relative('pixreversal/log')
|
44
|
+
require_relative('merchantcategory/merchantcategory')
|
45
|
+
require_relative('merchantcountry/merchantcountry')
|
24
46
|
require_relative('pixbalance/pixbalance')
|
25
|
-
require_relative('pixstatement/pixstatement')
|
26
|
-
require_relative('pixinfraction/pixinfraction')
|
27
|
-
require_relative('pixinfraction/log')
|
28
47
|
require_relative('pixchargeback/pixchargeback')
|
29
48
|
require_relative('pixchargeback/log')
|
30
|
-
require_relative('pixkey/pixkey')
|
31
|
-
require_relative('pixkey/log')
|
32
49
|
require_relative('pixclaim/pixclaim')
|
33
50
|
require_relative('pixclaim/log')
|
34
|
-
require_relative('pixdomain/pixdomain')
|
35
51
|
require_relative('pixdirector/pixdirector')
|
52
|
+
require_relative('pixdomain/pixdomain')
|
53
|
+
require_relative('pixinfraction/pixinfraction')
|
54
|
+
require_relative('pixinfraction/log')
|
55
|
+
require_relative('pixkey/pixkey')
|
56
|
+
require_relative('pixkey/log')
|
57
|
+
require_relative('pixrequest/pixrequest')
|
58
|
+
require_relative('pixrequest/log')
|
59
|
+
require_relative('pixreversal/pixreversal')
|
60
|
+
require_relative('pixreversal/log')
|
61
|
+
require_relative('pixstatement/pixstatement')
|
62
|
+
require_relative('staticbrcode/staticbrcode')
|
36
63
|
require_relative('webhook/webhook')
|
37
64
|
require_relative('event/event')
|
38
65
|
require_relative('event/attempt')
|
39
66
|
require_relative('utils/endtoendid')
|
40
67
|
require_relative('utils/returnid')
|
41
|
-
require_relative('creditnote/creditnote')
|
42
|
-
require_relative('creditnote/log')
|
43
68
|
|
44
69
|
# SDK to facilitate Ruby integrations with Stark Infra
|
45
70
|
module StarkInfra
|
@@ -0,0 +1,170 @@
|
|
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
|
+
# - cashier_bank_code [string, default None]: Cashier's bank code. ex: "20018183".
|
26
|
+
# - 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'
|
27
|
+
# - description [string, default None]: optional description to override default description to be shown in the bank statement. ex: "Payment for service #1234"
|
28
|
+
# - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
|
29
|
+
#
|
30
|
+
# ## Attributes (return-only):
|
31
|
+
# - id [string]: id returned on creation, this is the BR Code. ex: '00020126360014br.gov.bcb.pix0114+552840092118152040000530398654040.095802BR5915Jamie Lannister6009Sao Paulo620705038566304FC6C'
|
32
|
+
# - uuid [string]: unique uuid returned when a StaticBrcode is created. ex: '97756273400d42ce9086404fe10ea0d6'
|
33
|
+
# - url [string]: url link to the BR Code image. ex: 'https://brcode-h.development.starkinfra.com/static-qrcode/97756273400d42ce9086404fe10ea0d6.png'
|
34
|
+
# - created [DateTime]: creation datetime for the StaticBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
35
|
+
# - updated [DateTime]: latest update datetime for the StaticBrcode. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
36
|
+
class StaticBrcode < StarkInfra::Utils::Resource
|
37
|
+
attr_reader :name, :key_id, :city, :amount, :cashier_bank_code, :description, :reconciliation_id, :id, :tags, :uuid, :url, :created, :updated
|
38
|
+
def initialize(
|
39
|
+
name:, key_id:, city:, amount:, cashier_bank_code: nil, description: nil, reconciliation_id: nil, id: nil, tags:nil, uuid: nil, url: nil, created: nil, updated: nil
|
40
|
+
)
|
41
|
+
super(id)
|
42
|
+
@name = name
|
43
|
+
@key_id = key_id
|
44
|
+
@city = city
|
45
|
+
@amount = amount
|
46
|
+
@reconciliation_id = reconciliation_id
|
47
|
+
@cashier_bank_code = cashier_bank_code
|
48
|
+
@description = description
|
49
|
+
@tags = tags
|
50
|
+
@uuid = uuid
|
51
|
+
@url = url
|
52
|
+
@created = StarkInfra::Utils::Checks.check_datetime(created)
|
53
|
+
@updated = StarkInfra::Utils::Checks.check_datetime(updated)
|
54
|
+
end
|
55
|
+
|
56
|
+
# # Create StaticBrcodes
|
57
|
+
#
|
58
|
+
# Send a list of StaticBrcode objects for creation at the Stark Infra API
|
59
|
+
#
|
60
|
+
# ## Parameters (required):
|
61
|
+
# - brcodes [list of StaticBrcode objects]: list of StaticBrcode objects to be created in the API.
|
62
|
+
#
|
63
|
+
# ## Parameters (optional):
|
64
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
65
|
+
#
|
66
|
+
# ## Return:
|
67
|
+
# - list of StaticBrcode objects with updated attributes
|
68
|
+
def self.create(brcodes, user: nil)
|
69
|
+
StarkInfra::Utils::Rest.post(entities: brcodes, user: user, **resource)
|
70
|
+
end
|
71
|
+
|
72
|
+
# # Retrieve a specific StaticBrcode
|
73
|
+
#
|
74
|
+
# Receive a single StaticBrcode object previously created in the Stark Infra API by its uuid
|
75
|
+
#
|
76
|
+
# ## Parameters (required):
|
77
|
+
# - uuid [string]: object's unique uuid. ex: '97756273400d42ce9086404fe10ea0d6'
|
78
|
+
#
|
79
|
+
# ## Parameters (optional):
|
80
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
81
|
+
#
|
82
|
+
# ## Return:
|
83
|
+
# - StaticBrcode object with updated attributes
|
84
|
+
def self.get(uuid, user: nil)
|
85
|
+
StarkInfra::Utils::Rest.get_id(id: uuid, user: user, **resource)
|
86
|
+
end
|
87
|
+
|
88
|
+
# # Retrieve StaticBrcodes
|
89
|
+
#
|
90
|
+
# Receive a generator of StaticBrcode objects previously created in the Stark Infra API
|
91
|
+
#
|
92
|
+
# ## Parameters (optional):
|
93
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
94
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
95
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
96
|
+
# - uuids [list of strings, default nil]: list of uuids to filter retrieved objects. ex: ['901e71f2447c43c886f58366a5432c4b', '4e2eab725ddd495f9c98ffd97440702d']
|
97
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
98
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
99
|
+
#
|
100
|
+
# ## Return:
|
101
|
+
# - generator of StaticBrcode objects with updated attributes
|
102
|
+
def self.query(limit: nil, after: nil, before: nil, uuids: nil, tags: nil, user: nil)
|
103
|
+
after = StarkInfra::Utils::Checks.check_date(after)
|
104
|
+
before = StarkInfra::Utils::Checks.check_date(before)
|
105
|
+
StarkInfra::Utils::Rest.get_stream(
|
106
|
+
limit: limit,
|
107
|
+
after: after,
|
108
|
+
before: before,
|
109
|
+
uuids: uuids,
|
110
|
+
tags: tags,
|
111
|
+
user: user,
|
112
|
+
**resource
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
# # Retrieve StaticBrcodes
|
117
|
+
#
|
118
|
+
# Receive a list of StaticBrcode objects previously created in the Stark Infra API and the cursor to the next page.
|
119
|
+
#
|
120
|
+
# ## Parameters (optional):
|
121
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
122
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
123
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
124
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
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 StaticBrcode objects with updated attributes
|
131
|
+
# - cursor to retrieve the next page of StaticBrcode objects
|
132
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, uuids: 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
|
+
uuids: uuids,
|
141
|
+
tags: tags,
|
142
|
+
user: user,
|
143
|
+
**resource
|
144
|
+
)
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.resource
|
148
|
+
{
|
149
|
+
resource_name: 'StaticBrcode',
|
150
|
+
resource_maker: proc { |json|
|
151
|
+
StaticBrcode.new(
|
152
|
+
id: json['id'],
|
153
|
+
name: json['name'],
|
154
|
+
key_id: json['key_id'],
|
155
|
+
city: json['city'],
|
156
|
+
amount: json['amount'],
|
157
|
+
reconciliation_id: json['reconciliation_id'],
|
158
|
+
cashier_bank_code: json['cashier_bank_code'],
|
159
|
+
description: json['description'],
|
160
|
+
tags: json['tags'],
|
161
|
+
uuid: json['uuid'],
|
162
|
+
url: json['url'],
|
163
|
+
created: json['created'],
|
164
|
+
updated: json['updated']
|
165
|
+
)
|
166
|
+
}
|
167
|
+
}
|
168
|
+
end
|
169
|
+
end
|
170
|
+
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
|
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/bacenid.rb
CHANGED
@@ -12,7 +12,7 @@ module StarkInfra
|
|
12
12
|
11.times do
|
13
13
|
random_string << random_source[rand(random_source.length)]
|
14
14
|
end
|
15
|
-
bank_code + DateTime.now.strftime('%Y%m%d%H%M') << random_string
|
15
|
+
bank_code + DateTime.now.strftime('%Y%m%d%H%M').to_s << random_string
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
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
|
29
|
+
return content
|
26
30
|
end
|
27
31
|
|
28
32
|
if verify_signature(content: content, signature: signature, user: user, refresh: true)
|
29
|
-
return
|
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.
|
64
|
+
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-Infra-0.3.0"
|
65
65
|
req['Accept-Language'] = language
|
66
66
|
|
67
67
|
request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
|
data/lib/utils/resource.rb
CHANGED
data/lib/utils/sub_resource.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
module StarkInfra
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
fields = string_vars.join(",\n ")
|
13
|
-
"#{class_name}(\n #{fields}\n)"
|
14
|
-
end
|
15
|
-
|
16
|
-
def inspect
|
17
|
-
"#{class_name}[#{@id}]"
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def class_name
|
23
|
-
self.class.name.split('::').last.downcase
|
24
|
-
end
|
4
|
+
module Utils
|
5
|
+
class SubResource
|
6
|
+
def to_s
|
7
|
+
string_vars = []
|
8
|
+
instance_variables.each do |key|
|
9
|
+
value = instance_variable_get(key).to_s.lines.map(&:chomp).join("\n ")
|
10
|
+
string_vars << "#{key[1..-1]}: #{value}"
|
25
11
|
end
|
12
|
+
fields = string_vars.join(",\n ")
|
13
|
+
"#{class_name}(\n #{fields}\n)"
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
"#{class_name}[#{@id}]"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def class_name
|
23
|
+
self.class.name.split('::').last.downcase
|
24
|
+
end
|
26
25
|
end
|
26
|
+
end
|
27
27
|
end
|
28
|
-
|
data/lib/webhook/webhook.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
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
|
-
# # Webhook
|
8
|
+
# # Webhook object
|
9
9
|
#
|
10
10
|
# A Webhook is used to subscribe to notification events on a user-selected endpoint.
|
11
11
|
# Currently available services for subscription are contract, credit-note, signer, issuing-card, issuing-invoice, issuing-purchase, pix-request.in, pix-request.out, pix-reversal.in, pix-reversal.out, pix-claim, pix-key, pix-chargeback, pix-infraction.
|
@@ -14,7 +14,7 @@ module StarkInfra
|
|
14
14
|
# - url [string]: URL that will be notified when an event occurs.
|
15
15
|
# - subscriptions [list of strings]: list of any non-empty combination of the available services. ex: ['contract', 'credit-note', 'signer', 'issuing-card', 'issuing-invoice', 'issuing-purchase', 'pix-request.in', 'pix-request.out', 'pix-reversal.in', 'pix-reversal.out', 'pix-claim', 'pix-key', 'pix-chargeback', 'pix-infraction']
|
16
16
|
#
|
17
|
-
# ## Attributes:
|
17
|
+
# ## Attributes (return-only):
|
18
18
|
# - id [string]: unique id returned when the webhook is created. ex: '5656565656565656'
|
19
19
|
class Webhook < StarkInfra::Utils::Resource
|
20
20
|
attr_reader :url, :subscriptions, :id
|
@@ -24,12 +24,12 @@ module StarkInfra
|
|
24
24
|
@subscriptions = subscriptions
|
25
25
|
end
|
26
26
|
|
27
|
-
# # Create Webhook
|
27
|
+
# # Create Webhook
|
28
28
|
#
|
29
|
-
# Send a single Webhook
|
29
|
+
# Send a single Webhook for creation in the Stark Infra API
|
30
30
|
#
|
31
31
|
# ## Parameters (required):
|
32
|
-
# - webhook [Webhook object
|
32
|
+
# - webhook [Webhook object]: Webhook to be created to receive Events. ex: Webhook.new()
|
33
33
|
#
|
34
34
|
# ## Parameters (optional):
|
35
35
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
@@ -40,9 +40,9 @@ module StarkInfra
|
|
40
40
|
StarkInfra::Utils::Rest.post_single(entity: webhook, user: user, **resource)
|
41
41
|
end
|
42
42
|
|
43
|
-
# # Retrieve a specific Webhook
|
43
|
+
# # Retrieve a specific Webhook
|
44
44
|
#
|
45
|
-
# Receive a single Webhook
|
45
|
+
# Receive a single Webhook object previously created in the Stark Infra API by passing its id
|
46
46
|
#
|
47
47
|
# ## Parameters (required):
|
48
48
|
# - id [string]: object unique id. ex: '5656565656565656'
|
@@ -56,9 +56,9 @@ module StarkInfra
|
|
56
56
|
StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
|
57
57
|
end
|
58
58
|
|
59
|
-
# # Retrieve
|
59
|
+
# # Retrieve Webhooks
|
60
60
|
#
|
61
|
-
# Receive a generator of Webhook
|
61
|
+
# Receive a generator of Webhook objects previously created in the Stark Infra API
|
62
62
|
#
|
63
63
|
# ## Parameters (optional):
|
64
64
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
@@ -84,7 +84,7 @@ module StarkInfra
|
|
84
84
|
# - list of Webhook objects with updated attributes
|
85
85
|
# - cursor to retrieve the next page of Webhook objects
|
86
86
|
def self.page(cursor: nil, limit: nil, user: nil)
|
87
|
-
|
87
|
+
StarkInfra::Utils::Rest.get_page(
|
88
88
|
cursor: cursor,
|
89
89
|
limit: limit,
|
90
90
|
user: user,
|