starkinfra 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/creditnote/creditnote.rb +583 -0
- data/lib/creditnote/log.rb +126 -0
- data/lib/event/attempt.rb +126 -0
- data/lib/event/event.rb +125 -7
- data/lib/issuingauthorization/issuingauthorization.rb +141 -0
- data/lib/issuingbalance/issuingbalance.rb +55 -0
- data/lib/issuingbin/issuingbin.rb +89 -0
- data/lib/issuingcard/issuingcard.rb +261 -0
- data/lib/issuingcard/log.rb +123 -0
- data/lib/issuingholder/issuingholder.rb +206 -0
- data/lib/issuingholder/log.rb +123 -0
- data/lib/issuinginvoice/issuinginvoice.rb +152 -0
- data/lib/issuinginvoice/log.rb +120 -0
- data/lib/issuingpurchase/issuingpurchase.rb +209 -0
- data/lib/issuingpurchase/log.rb +131 -0
- data/lib/issuingrule/issuingrule.rb +79 -0
- data/lib/issuingtransaction/issuingtransaction.rb +136 -0
- data/lib/issuingwithdrawal/issuingwithdrawal.rb +153 -0
- data/lib/pixbalance/pixbalance.rb +15 -15
- data/lib/pixchargeback/log.rb +129 -0
- data/lib/pixchargeback/pixchargeback.rb +225 -0
- data/lib/pixclaim/log.rb +135 -0
- data/lib/pixclaim/pixclaim.rb +226 -0
- data/lib/pixdirector/pixdirector.rb +76 -0
- data/lib/pixdomain/certificate.rb +30 -0
- data/lib/pixdomain/pixdomain.rb +58 -0
- data/lib/pixinfraction/log.rb +129 -0
- data/lib/pixinfraction/pixinfraction.rb +212 -0
- data/lib/pixkey/log.rb +128 -0
- data/lib/pixkey/pixkey.rb +240 -0
- data/lib/pixrequest/log.rb +16 -16
- data/lib/pixrequest/pixrequest.rb +66 -67
- data/lib/pixreversal/log.rb +13 -12
- data/lib/pixreversal/pixreversal.rb +74 -72
- data/lib/pixstatement/pixstatement.rb +24 -25
- data/lib/starkinfra.rb +32 -3
- data/lib/user/organization.rb +54 -0
- data/lib/user/project.rb +37 -0
- data/lib/user/user.rb +20 -0
- data/lib/utils/api.rb +10 -2
- data/lib/utils/bacenid.rb +19 -0
- data/lib/utils/checks.rb +2 -3
- data/lib/utils/endtoendid.rb +11 -0
- data/lib/utils/parse.rb +13 -13
- data/lib/utils/request.rb +2 -2
- data/lib/utils/rest.rb +6 -5
- data/lib/utils/returnid.rb +11 -0
- data/lib/webhook/webhook.rb +124 -0
- metadata +45 -24
@@ -12,17 +12,16 @@ module StarkInfra
|
|
12
12
|
# accessed by the user. This feature is only available for direct participants.
|
13
13
|
#
|
14
14
|
# ## Parameters (required):
|
15
|
-
# - after [Date
|
16
|
-
# - before [Date
|
17
|
-
# - type [string]:
|
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)
|
17
|
+
# - type [string]: type of entities to include in statement. Options: 'interchange', 'interchangeTotal', 'transaction'
|
18
18
|
#
|
19
19
|
# ## Attributes (return-only):
|
20
|
-
# - id [string
|
21
|
-
# - status [string
|
22
|
-
# - transaction_count [integer]: number of transactions that happened during the day that the PixStatement was requested. ex 11
|
23
|
-
# - created [
|
24
|
-
# - updated [
|
25
|
-
|
20
|
+
# - id [string]: unique id returned when the PixStatement is created. ex: '5656565656565656'
|
21
|
+
# - status [string]: current PixStatement status. ex: 'success' or 'failed'
|
22
|
+
# - transaction_count [integer]: number of transactions that happened during the day that the PixStatement was requested. ex: 11
|
23
|
+
# - created [DateTime]: creation datetime for the PixStatement. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
24
|
+
# - updated [DateTime]: latest update datetime for the PixStatement. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
26
25
|
class PixStatement < StarkInfra::Utils::Resource
|
27
26
|
attr_reader :after, :before, :type, :id, :status, :transaction_count, :created, :updated
|
28
27
|
def initialize(after:, before:, type:, id: nil, status: nil, transaction_count: nil, created: nil, updated: nil)
|
@@ -40,11 +39,11 @@ module StarkInfra
|
|
40
39
|
#
|
41
40
|
# Create a PixStatements linked to your workspace in the Stark Infra API
|
42
41
|
#
|
43
|
-
# ## Parameters (
|
42
|
+
# ## Parameters (required):
|
44
43
|
# - statement [PixStatement object]: PixStatement object to be created in the API.
|
45
44
|
#
|
46
45
|
# ## Parameters (optional):
|
47
|
-
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if
|
46
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
48
47
|
#
|
49
48
|
# ## Return:
|
50
49
|
# - PixStatement object with updated attributes.
|
@@ -52,18 +51,18 @@ module StarkInfra
|
|
52
51
|
StarkInfra::Utils::Rest.post_single(entity: statement, user: user, **resource)
|
53
52
|
end
|
54
53
|
|
55
|
-
# # Retrieve a specific
|
54
|
+
# # Retrieve a specific PixStatement object
|
56
55
|
#
|
57
|
-
# Receive a single
|
56
|
+
# Receive a single PixStatement object previously created in the Stark Infra API by passing its id
|
58
57
|
#
|
59
58
|
# ## Parameters (required):
|
60
59
|
# - id [string]: object unique id. ex: '5656565656565656'
|
61
60
|
#
|
62
61
|
# ## Parameters (optional):
|
63
|
-
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
62
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
64
63
|
#
|
65
64
|
# ## Return:
|
66
|
-
# -
|
65
|
+
# - PixStatement object with updated attributes
|
67
66
|
def self.get(id, user: nil)
|
68
67
|
StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
|
69
68
|
end
|
@@ -75,7 +74,7 @@ module StarkInfra
|
|
75
74
|
# ## Parameters (optional):
|
76
75
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
77
76
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
78
|
-
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
77
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
79
78
|
#
|
80
79
|
# ## Return:
|
81
80
|
# - generator of PixStatement objects with updated attributes
|
@@ -91,19 +90,19 @@ module StarkInfra
|
|
91
90
|
# # Retrieve paged PixStatements
|
92
91
|
#
|
93
92
|
# Receive a list of up to 100 PixStatements objects previously created in the Stark infra API and the cursor to the next page.
|
94
|
-
# Use this function instead of query if you want to manually page your
|
93
|
+
# Use this function instead of query if you want to manually page your statements.
|
95
94
|
#
|
96
95
|
# ## Parameters (optional):
|
97
96
|
# - cursor [string, default nil]: cursor returned on the previous page function call
|
98
|
-
# - limit [integer, default
|
97
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
99
98
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
100
|
-
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
99
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
101
100
|
#
|
102
101
|
# ## Return:
|
103
102
|
# - list of PixStatement objects with updated attributes
|
104
|
-
# -
|
103
|
+
# - cursor to retrieve the next page of PixStatement objects
|
105
104
|
def self.page(cursor: nil, limit: nil, ids: nil, user: nil)
|
106
|
-
|
105
|
+
StarkInfra::Utils::Rest.get_page(
|
107
106
|
cursor: cursor,
|
108
107
|
limit: limit,
|
109
108
|
ids: ids,
|
@@ -117,15 +116,15 @@ module StarkInfra
|
|
117
116
|
# Retrieve a specific PixStatement by its ID in a .csv file.
|
118
117
|
#
|
119
118
|
# ## Parameters (required):
|
120
|
-
# - id [string]: object unique id. ex:
|
119
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
121
120
|
#
|
122
121
|
# ## Parameters (optional):
|
123
|
-
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if
|
122
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
124
123
|
#
|
125
124
|
# ## Return:
|
126
125
|
# - PixStatement .csv file
|
127
126
|
def self.csv(id, user: nil)
|
128
|
-
|
127
|
+
StarkInfra::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'csv', **resource)
|
129
128
|
end
|
130
129
|
|
131
130
|
def self.resource
|
@@ -140,7 +139,7 @@ module StarkInfra
|
|
140
139
|
status: json['status'],
|
141
140
|
transaction_count: json['transaction_count'],
|
142
141
|
created: json['created'],
|
143
|
-
updated: json['updated']
|
142
|
+
updated: json['updated']
|
144
143
|
)
|
145
144
|
}
|
146
145
|
}
|
data/lib/starkinfra.rb
CHANGED
@@ -1,19 +1,48 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require('starkbank')
|
4
3
|
require_relative('key')
|
5
|
-
require_relative('
|
4
|
+
require_relative('user/project')
|
5
|
+
require_relative('user/organization')
|
6
|
+
require_relative('issuingauthorization/issuingauthorization')
|
7
|
+
require_relative('issuingbalance/issuingbalance')
|
8
|
+
require_relative('issuingbin/issuingbin')
|
9
|
+
require_relative('issuingcard/issuingcard')
|
10
|
+
require_relative('issuingcard/log')
|
11
|
+
require_relative('issuingholder/issuingholder')
|
12
|
+
require_relative('issuingholder/log')
|
13
|
+
require_relative('issuinginvoice/issuinginvoice')
|
14
|
+
require_relative('issuinginvoice/log')
|
15
|
+
require_relative('issuingpurchase/issuingpurchase')
|
16
|
+
require_relative('issuingpurchase/log')
|
17
|
+
require_relative('issuingtransaction/issuingtransaction')
|
18
|
+
require_relative('issuingwithdrawal/issuingwithdrawal')
|
19
|
+
require_relative('issuingrule/issuingrule')
|
6
20
|
require_relative('pixrequest/pixrequest')
|
7
21
|
require_relative('pixrequest/log')
|
8
22
|
require_relative('pixreversal/pixreversal')
|
9
23
|
require_relative('pixreversal/log')
|
10
24
|
require_relative('pixbalance/pixbalance')
|
11
25
|
require_relative('pixstatement/pixstatement')
|
26
|
+
require_relative('pixinfraction/pixinfraction')
|
27
|
+
require_relative('pixinfraction/log')
|
28
|
+
require_relative('pixchargeback/pixchargeback')
|
29
|
+
require_relative('pixchargeback/log')
|
30
|
+
require_relative('pixkey/pixkey')
|
31
|
+
require_relative('pixkey/log')
|
32
|
+
require_relative('pixclaim/pixclaim')
|
33
|
+
require_relative('pixclaim/log')
|
34
|
+
require_relative('pixdomain/pixdomain')
|
35
|
+
require_relative('pixdirector/pixdirector')
|
36
|
+
require_relative('webhook/webhook')
|
12
37
|
require_relative('event/event')
|
38
|
+
require_relative('event/attempt')
|
39
|
+
require_relative('utils/endtoendid')
|
40
|
+
require_relative('utils/returnid')
|
41
|
+
require_relative('creditnote/creditnote')
|
42
|
+
require_relative('creditnote/log')
|
13
43
|
|
14
44
|
# SDK to facilitate Ruby integrations with Stark Infra
|
15
45
|
module StarkInfra
|
16
|
-
include StarkBank
|
17
46
|
@user = nil
|
18
47
|
@language = 'en-US'
|
19
48
|
class << self; attr_accessor :user, :language; end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('user')
|
4
|
+
|
5
|
+
module StarkInfra
|
6
|
+
# # Organization object
|
7
|
+
# The Organization object is an authentication entity for the SDK that
|
8
|
+
# represents your entire Organization, being able to access any Workspace
|
9
|
+
# underneath it and even create new Workspaces. Only a legal representative
|
10
|
+
# of your organization can register or change the Organization credentials.
|
11
|
+
# All requests to the Stark Infra API must be authenticated via an SDK user,
|
12
|
+
# which must have been previously created at the Stark Infra website
|
13
|
+
# [https://web.sandbox.starkinfra.com] or [https://web.starkinfra.com]
|
14
|
+
# before you can use it in this SDK. Organizations may be passed as the user parameter on
|
15
|
+
# each request or may be defined as the default user at the start (See README).
|
16
|
+
# If you are accessing a specific Workspace using Organization credentials, you should
|
17
|
+
# specify the workspace ID when building the Organization object or by request, using
|
18
|
+
# the Organization.replace(organization, workspace_id) method, which creates a copy of the organization
|
19
|
+
# object with the altered workspace ID. If you are listing or creating new Workspaces, the
|
20
|
+
# workspace_id should be nil.
|
21
|
+
#
|
22
|
+
# ## Parameters (required):
|
23
|
+
# - environment [string]: environment where the organization is being used. ex: 'sandbox' or 'production'
|
24
|
+
# - id [string]: unique id required to identify organization. ex: '5656565656565656'
|
25
|
+
# - private_key [string]: PEM string of the private key linked to the organization. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
26
|
+
# - workspace_id [string]: unique id of the accessed Workspace, if any. ex: nil or '4848484848484848'
|
27
|
+
#
|
28
|
+
# ## Attributes (return-only):
|
29
|
+
# - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
30
|
+
class Organization < StarkInfra::User
|
31
|
+
attr_reader :workspace_id
|
32
|
+
def initialize(id:, environment:, private_key:, workspace_id: nil)
|
33
|
+
super(environment, id, private_key)
|
34
|
+
@workspace_id = workspace_id
|
35
|
+
end
|
36
|
+
|
37
|
+
def access_id
|
38
|
+
if @workspace_id
|
39
|
+
"organization/#{@id}/workspace/#{@workspace_id}"
|
40
|
+
else
|
41
|
+
"organization/#{@id}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.replace(organization, workspace_id)
|
46
|
+
Organization.new(
|
47
|
+
environment: organization.environment,
|
48
|
+
id: organization.id,
|
49
|
+
private_key: organization.pem,
|
50
|
+
workspace_id: workspace_id
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/user/project.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('user')
|
4
|
+
|
5
|
+
module StarkInfra
|
6
|
+
# # Project object
|
7
|
+
#
|
8
|
+
# The Project object is an authentication entity for the SDK that is permanently
|
9
|
+
# linked to a specific Workspace.
|
10
|
+
# All requests to the Stark Infra API must be authenticated via an SDK user,
|
11
|
+
# which must have been previously created at the Stark Infra website
|
12
|
+
# [https://web.sandbox.starkinfra.com] or [https://web.starkinfra.com]
|
13
|
+
# before you can use it in this SDK. Projects may be passed as the user parameter on
|
14
|
+
# each request or may be defined as the default user at the start (See README).
|
15
|
+
#
|
16
|
+
# ## Parameters (required):
|
17
|
+
# - id [string]: unique id required to identify project. ex: '5656565656565656'
|
18
|
+
# - private_key [string]: PEM string of the private key linked to the project. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
19
|
+
# - environment [string]: environment where the project is being used. ex: 'sandbox' or 'production'
|
20
|
+
#
|
21
|
+
# ## Attributes (return-only):
|
22
|
+
# - name [string, default '']: project name. ex: 'MyProject'
|
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
|
+
# - pem [string]: private key in pem format. ex: '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEyTIHK6jYuik6ktM9FIF3yCEYzpLjO5X/\ntqDioGM+R2RyW0QEo+1DG8BrUf4UXHSvCjtQ0yLppygz23z0yPZYfw==\n-----END PUBLIC KEY-----'
|
25
|
+
class Project < StarkInfra::User
|
26
|
+
attr_reader :name, :allowed_ips
|
27
|
+
def initialize(environment:, id:, private_key:, name: '', allowed_ips: nil)
|
28
|
+
super(environment, id, private_key)
|
29
|
+
@name = name
|
30
|
+
@allowed_ips = allowed_ips
|
31
|
+
end
|
32
|
+
|
33
|
+
def access_id
|
34
|
+
"project/#{@id}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/user/user.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkbank-ecdsa')
|
4
|
+
require_relative('../utils/resource')
|
5
|
+
|
6
|
+
module StarkInfra
|
7
|
+
class User < StarkInfra::Utils::Resource
|
8
|
+
attr_reader :pem, :environment
|
9
|
+
def initialize(environment, id, private_key)
|
10
|
+
require_relative('../utils/checks')
|
11
|
+
super(id)
|
12
|
+
@pem = StarkInfra::Utils::Checks.check_private_key(private_key)
|
13
|
+
@environment = StarkInfra::Utils::Checks.check_environment(environment)
|
14
|
+
end
|
15
|
+
|
16
|
+
def private_key
|
17
|
+
EllipticCurve::PrivateKey.fromPem(@pem)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/utils/api.rb
CHANGED
@@ -41,7 +41,15 @@ module StarkInfra
|
|
41
41
|
|
42
42
|
list = []
|
43
43
|
value.each do |v|
|
44
|
-
|
44
|
+
if v.is_a?(Hash)
|
45
|
+
list << cast_json_to_api_format(v)
|
46
|
+
next
|
47
|
+
end
|
48
|
+
if v.is_a?(SubResource)
|
49
|
+
list << api_json(v)
|
50
|
+
next
|
51
|
+
end
|
52
|
+
list << v
|
45
53
|
end
|
46
54
|
list
|
47
55
|
end
|
@@ -51,7 +59,7 @@ module StarkInfra
|
|
51
59
|
json.each do |key, value|
|
52
60
|
snakes[StarkInfra::Utils::Case.camel_to_snake(key)] = value
|
53
61
|
end
|
54
|
-
|
62
|
+
|
55
63
|
resource_maker.call(snakes)
|
56
64
|
end
|
57
65
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require('date')
|
4
|
+
|
5
|
+
module StarkInfra
|
6
|
+
module Utils
|
7
|
+
module BacenId
|
8
|
+
def self._create(bank_code)
|
9
|
+
random_source = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'.split('')
|
10
|
+
random_string = ''
|
11
|
+
|
12
|
+
11.times do
|
13
|
+
random_string << random_source[rand(random_source.length)]
|
14
|
+
end
|
15
|
+
bank_code + DateTime.now.strftime('%Y%m%d%H%M') << random_string
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/utils/checks.rb
CHANGED
@@ -2,14 +2,13 @@
|
|
2
2
|
|
3
3
|
require('date')
|
4
4
|
require('starkbank-ecdsa')
|
5
|
-
require('starkbank')
|
6
5
|
require_relative('environment')
|
7
6
|
|
8
7
|
module StarkInfra
|
9
8
|
module Utils
|
10
9
|
class Checks
|
11
10
|
def self.check_user(user)
|
12
|
-
return user if user.is_a?(
|
11
|
+
return user if user.is_a?(StarkInfra::User)
|
13
12
|
|
14
13
|
user = user.nil? ? StarkInfra.user : user
|
15
14
|
raise(ArgumentError, 'A user is required to access our API. Check our README: https://github.com/starkinfra/sdk-ruby/') if user.nil?
|
@@ -90,7 +89,7 @@ module StarkInfra
|
|
90
89
|
end
|
91
90
|
|
92
91
|
begin
|
93
|
-
|
92
|
+
[DateTime.strptime(data, '%Y-%m-%d'), 'date']
|
94
93
|
rescue ArgumentError
|
95
94
|
raise(ArgumentError, 'invalid datetime string ' + data)
|
96
95
|
end
|
data/lib/utils/parse.rb
CHANGED
@@ -5,28 +5,30 @@ require('starkbank-ecdsa')
|
|
5
5
|
require_relative('api')
|
6
6
|
require_relative('cache')
|
7
7
|
require_relative('request')
|
8
|
-
require_relative('../error')
|
9
|
-
|
8
|
+
require_relative('../error')
|
10
9
|
|
11
10
|
module StarkInfra
|
12
11
|
module Utils
|
13
12
|
module Parse
|
14
13
|
def self.parse_and_verify(content:, signature:, user: nil, resource:, key: nil)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
json = JSON.parse(content)
|
15
|
+
json = JSON.parse(content)[key] unless key.nil?
|
16
|
+
event = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], json)
|
19
17
|
|
20
18
|
begin
|
21
19
|
signature = EllipticCurve::Signature.fromBase64(signature)
|
22
20
|
rescue
|
23
21
|
raise(StarkInfra::Error::InvalidSignatureError, 'The provided signature is not valid')
|
24
22
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
|
24
|
+
if verify_signature(content: content, signature: signature, user: user)
|
25
|
+
return event
|
26
|
+
end
|
27
|
+
|
28
|
+
if verify_signature(content: content, signature: signature, user: user, refresh: true)
|
29
|
+
return event
|
30
|
+
end
|
31
|
+
|
30
32
|
raise(StarkInfra::Error::InvalidSignatureError, 'The provided signature and content do not match the Stark Infra public key')
|
31
33
|
end
|
32
34
|
|
@@ -46,5 +48,3 @@ module StarkInfra
|
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
49
|
-
|
50
|
-
|
data/lib/utils/request.rb
CHANGED
@@ -28,7 +28,7 @@ module StarkInfra
|
|
28
28
|
|
29
29
|
base_url = {
|
30
30
|
Environment::PRODUCTION => 'https://api.starkinfra.com/',
|
31
|
-
Environment::SANDBOX => 'https://sandbox.api.starkinfra.com/'
|
31
|
+
Environment::SANDBOX => 'https://sandbox.api.starkinfra.com/'
|
32
32
|
}[user.environment] + 'v2'
|
33
33
|
|
34
34
|
url = "#{base_url}/#{path}#{StarkInfra::Utils::URL.urlencode(query)}"
|
@@ -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-
|
64
|
+
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-Infra-0.1.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/rest.rb
CHANGED
@@ -50,26 +50,26 @@ module StarkInfra
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def self.get_id(resource_name:, resource_maker:, id:, user: nil)
|
53
|
+
def self.get_id(resource_name:, resource_maker:, id:, user: nil, **query)
|
54
54
|
json = StarkInfra::Utils::Request.fetch(
|
55
55
|
method: 'GET',
|
56
56
|
path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}",
|
57
|
+
query: query,
|
57
58
|
user: user
|
58
59
|
).json
|
59
60
|
entity = json[StarkInfra::Utils::API.last_name(resource_name)]
|
60
61
|
StarkInfra::Utils::API.from_api_json(resource_maker, entity)
|
61
62
|
end
|
62
63
|
|
63
|
-
def self.get_content(resource_name:,
|
64
|
+
def self.get_content(resource_name:, sub_resource_name:, id:, user: nil)
|
64
65
|
StarkInfra::Utils::Request.fetch(
|
65
66
|
method: 'GET',
|
66
67
|
path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}/#{sub_resource_name}",
|
67
|
-
query: StarkInfra::Utils::API.cast_json_to_api_format(query),
|
68
68
|
user: user
|
69
69
|
).content
|
70
70
|
end
|
71
71
|
|
72
|
-
def self.post(resource_name:, resource_maker:, entities:, user: nil)
|
72
|
+
def self.post(resource_name:, resource_maker:, entities:, user: nil, **query)
|
73
73
|
jsons = []
|
74
74
|
entities.each do |entity|
|
75
75
|
jsons << StarkInfra::Utils::API.api_json(entity)
|
@@ -79,6 +79,7 @@ module StarkInfra
|
|
79
79
|
method: 'POST',
|
80
80
|
path: StarkInfra::Utils::API.endpoint(resource_name),
|
81
81
|
payload: payload,
|
82
|
+
query: query,
|
82
83
|
user: user
|
83
84
|
).json
|
84
85
|
returned_jsons = json[StarkInfra::Utils::API.last_name_plural(resource_name)]
|
@@ -126,7 +127,7 @@ module StarkInfra
|
|
126
127
|
method: 'GET',
|
127
128
|
path: "#{StarkInfra::Utils::API.endpoint(resource_name)}/#{id}/#{StarkInfra::Utils::API.endpoint(sub_resource_name)}",
|
128
129
|
user: user,
|
129
|
-
query:
|
130
|
+
query: query
|
130
131
|
).json
|
131
132
|
entity = json[StarkInfra::Utils::API.last_name(sub_resource_name)]
|
132
133
|
StarkInfra::Utils::API.from_api_json(sub_resource_maker, entity)
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
|
7
|
+
module StarkInfra
|
8
|
+
# # Webhook subscription object
|
9
|
+
#
|
10
|
+
# A Webhook is used to subscribe to notification events on a user-selected endpoint.
|
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.
|
12
|
+
#
|
13
|
+
# ## Parameters (required):
|
14
|
+
# - url [string]: URL that will be notified when an event occurs.
|
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
|
+
#
|
17
|
+
# ## Attributes:
|
18
|
+
# - id [string]: unique id returned when the webhook is created. ex: '5656565656565656'
|
19
|
+
class Webhook < StarkInfra::Utils::Resource
|
20
|
+
attr_reader :url, :subscriptions, :id
|
21
|
+
def initialize(url:, subscriptions:, id: nil)
|
22
|
+
super(id)
|
23
|
+
@url = url
|
24
|
+
@subscriptions = subscriptions
|
25
|
+
end
|
26
|
+
|
27
|
+
# # Create Webhook subscription
|
28
|
+
#
|
29
|
+
# Send a single Webhook subscription for creation in the Stark Infra API
|
30
|
+
#
|
31
|
+
# ## Parameters (required):
|
32
|
+
# - webhook [Webhook object or hash]: Webhook subscription to be created to receive Events. ex: Webhook.new()
|
33
|
+
#
|
34
|
+
# ## Parameters (optional):
|
35
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
36
|
+
#
|
37
|
+
# ## Return:
|
38
|
+
# - Webhook object with updated attributes
|
39
|
+
def self.create(webhook, user: nil)
|
40
|
+
StarkInfra::Utils::Rest.post_single(entity: webhook, user: user, **resource)
|
41
|
+
end
|
42
|
+
|
43
|
+
# # Retrieve a specific Webhook subscription
|
44
|
+
#
|
45
|
+
# Receive a single Webhook subscription object previously created in the Stark Infra API by passing its id
|
46
|
+
#
|
47
|
+
# ## Parameters (required):
|
48
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
49
|
+
#
|
50
|
+
# ## Parameters (optional):
|
51
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
52
|
+
#
|
53
|
+
# ## Return:
|
54
|
+
# - Webhook object with updated attributes
|
55
|
+
def self.get(id, user: nil)
|
56
|
+
StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
|
57
|
+
end
|
58
|
+
|
59
|
+
# # Retrieve Webhook subscriptions
|
60
|
+
#
|
61
|
+
# Receive a generator of Webhook subscription objects previously created in the Stark Infra API
|
62
|
+
#
|
63
|
+
# ## Parameters (optional):
|
64
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
65
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
66
|
+
#
|
67
|
+
# ## Return:
|
68
|
+
# - generator of Webhook objects with updated attributes
|
69
|
+
def self.query(limit: nil, user: nil)
|
70
|
+
StarkInfra::Utils::Rest.get_stream(user: user, limit: limit, **resource)
|
71
|
+
end
|
72
|
+
|
73
|
+
# # Retrieve paged Webhooks
|
74
|
+
#
|
75
|
+
# Receive a list of up to 100 Webhook objects previously created in the Stark Infra API and the cursor to the next page.
|
76
|
+
# Use this function instead of query if you want to manually page your requests.
|
77
|
+
#
|
78
|
+
# ## Parameters (optional):
|
79
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
80
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
81
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
82
|
+
#
|
83
|
+
# ## Return:
|
84
|
+
# - list of Webhook objects with updated attributes
|
85
|
+
# - cursor to retrieve the next page of Webhook objects
|
86
|
+
def self.page(cursor: nil, limit: nil, user: nil)
|
87
|
+
return StarkInfra::Utils::Rest.get_page(
|
88
|
+
cursor: cursor,
|
89
|
+
limit: limit,
|
90
|
+
user: user,
|
91
|
+
**resource
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
# # Delete a Webhook entity
|
96
|
+
#
|
97
|
+
# Delete a Webhook entity previously created in the Stark Infra API
|
98
|
+
#
|
99
|
+
# ## Parameters (required):
|
100
|
+
# - id [string]: Webhook unique id. ex: '5656565656565656'
|
101
|
+
#
|
102
|
+
# ## Parameters (optional):
|
103
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
104
|
+
#
|
105
|
+
# ## Return:
|
106
|
+
# - deleted Webhook object
|
107
|
+
def self.delete(id, user: nil)
|
108
|
+
StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.resource
|
112
|
+
{
|
113
|
+
resource_name: 'Webhook',
|
114
|
+
resource_maker: proc { |json|
|
115
|
+
Webhook.new(
|
116
|
+
id: json['id'],
|
117
|
+
url: json['url'],
|
118
|
+
subscriptions: json['subscriptions']
|
119
|
+
)
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|