starkbank 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/balance/balance.rb +1 -1
- data/lib/boleto/boleto.rb +49 -10
- data/lib/boleto/log.rb +35 -4
- data/lib/boleto_holmes/boleto_holmes.rb +39 -4
- data/lib/boleto_holmes/log.rb +35 -4
- data/lib/boleto_payment/boleto_payment.rb +38 -5
- data/lib/boleto_payment/log.rb +35 -4
- data/lib/brcode_payment/brcode_payment.rb +52 -13
- data/lib/brcode_payment/log.rb +35 -4
- data/lib/brcode_preview/brcode_preview.rb +2 -2
- data/lib/darf_payment/darf_payment.rb +218 -0
- data/lib/darf_payment/log.rb +125 -0
- data/lib/deposit/deposit.rb +45 -7
- data/lib/deposit/log.rb +35 -4
- data/lib/dict_key/dict_key.rb +44 -8
- data/lib/error.rb +13 -5
- data/lib/event/attempt.rb +125 -0
- data/lib/event/event.rb +40 -4
- data/lib/institution/institution.rb +67 -0
- data/lib/invoice/invoice.rb +66 -9
- data/lib/invoice/log.rb +51 -4
- data/lib/invoice/payment.rb +57 -0
- data/lib/payment_request/payment_request.rb +47 -7
- data/lib/starkbank.rb +7 -0
- data/lib/tax_payment/log.rb +125 -0
- data/lib/tax_payment/tax_payment.rb +203 -0
- data/lib/transaction/transaction.rb +37 -4
- data/lib/transfer/log.rb +35 -4
- data/lib/transfer/transfer.rb +47 -8
- data/lib/user/organization.rb +1 -1
- data/lib/user/project.rb +1 -1
- data/lib/utility_payment/log.rb +35 -4
- data/lib/utility_payment/utility_payment.rb +38 -5
- data/lib/utils/api.rb +1 -0
- data/lib/utils/request.rb +1 -1
- data/lib/utils/resource.rb +2 -21
- data/lib/utils/rest.rb +28 -12
- data/lib/utils/sub_resource.rb +28 -0
- data/lib/utils/url.rb +3 -1
- data/lib/webhook/webhook.rb +23 -2
- data/lib/workspace/workspace.rb +57 -8
- metadata +15 -7
data/lib/deposit/log.rb
CHANGED
@@ -52,18 +52,49 @@ module StarkBank
|
|
52
52
|
#
|
53
53
|
# ## Parameters (optional):
|
54
54
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
55
|
-
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
56
|
-
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
55
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
56
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
57
57
|
# - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
|
58
58
|
# - deposit_ids [list of strings, default nil]: list of Deposit ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
59
|
-
# - user [Organization/Project object]: Organization or Project object. Not necessary if
|
59
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
60
60
|
#
|
61
61
|
# ## Return:
|
62
62
|
# - list of Log objects with updated attributes
|
63
63
|
def self.query(limit: nil, after: nil, before: nil, types: nil, deposit_ids: nil, user: nil)
|
64
64
|
after = StarkBank::Utils::Checks.check_date(after)
|
65
65
|
before = StarkBank::Utils::Checks.check_date(before)
|
66
|
-
StarkBank::Utils::Rest.
|
66
|
+
StarkBank::Utils::Rest.get_stream(
|
67
|
+
limit: limit,
|
68
|
+
after: after,
|
69
|
+
before: before,
|
70
|
+
types: types,
|
71
|
+
deposit_ids: deposit_ids,
|
72
|
+
user: user,
|
73
|
+
**resource
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# # Retrieve paged Logs
|
78
|
+
#
|
79
|
+
# Receive a list of up to 100 Log objects previously created in the Stark Bank API and the cursor to the next page.
|
80
|
+
# Use this function instead of query if you want to manually page your requests.
|
81
|
+
#
|
82
|
+
# ## Parameters (optional):
|
83
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
84
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
85
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
86
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
87
|
+
# - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
|
88
|
+
# - deposit_ids [list of strings, default nil]: list of Deposit ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
89
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
90
|
+
#
|
91
|
+
# ## Return:
|
92
|
+
# - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
|
93
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, deposit_ids: nil, user: nil)
|
94
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
95
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
96
|
+
return StarkBank::Utils::Rest.get_page(
|
97
|
+
cursor: cursor,
|
67
98
|
limit: limit,
|
68
99
|
after: after,
|
69
100
|
before: before,
|
data/lib/dict_key/dict_key.rb
CHANGED
@@ -17,25 +17,27 @@ module StarkBank
|
|
17
17
|
# - name [string, default nil]: account owner full name. ex: 'Tony Stark'
|
18
18
|
# - tax_id [string, default nil]: key owner tax ID (CNPJ or masked CPF). ex: '***.345.678-**' or '20.018.183/0001-80'
|
19
19
|
# - owner_type [string, default nil]: DICT key owner type. ex 'naturalPerson' or 'legalPerson'
|
20
|
+
# - bank_name [string, default nil]: bank name associated with the DICT key. ex: 'Stark Bank'
|
20
21
|
# - ispb [string, default nil]: bank ISPB associated with the DICT key. ex: '20018183'
|
21
22
|
# - branch_code [string, default nil]: bank account branch code associated with the DICT key. ex: '9585'
|
22
23
|
# - account_number [string, default nil]: bank account number associated with the DICT key. ex: '9828282578010513'
|
23
|
-
# - account_type [string, default nil]: bank account type associated with the DICT key. ex: 'checking', 'saving'
|
24
|
+
# - account_type [string, default nil]: bank account type associated with the DICT key. ex: 'checking', 'saving', 'salary' or 'payment'
|
24
25
|
# - status [string, default nil]: current DICT key status. ex: 'created', 'registered', 'canceled' or 'failed'
|
25
26
|
# - account_created [DateTime or string, default nil]: creation datetime of the bank account associated with the DICT key. ex: '2020-11-05T14:55:08.812665+00:00'
|
26
27
|
# - owned [DateTime or string, default nil]: datetime since when the current owner hold this DICT key. ex : '2020-11-05T14:55:08.812665+00:00'
|
27
28
|
# - created [DateTime or string, default nil]: creation datetime for the DICT key. ex: '2020-03-10 10:30:00.000'
|
28
29
|
class DictKey < StarkBank::Utils::Resource
|
29
|
-
attr_reader :id, :type, :name, :tax_id, :owner_type, :ispb, :branch_code, :account_number, :account_type, :status, :account_created, :owned, :created
|
30
|
+
attr_reader :id, :type, :name, :tax_id, :owner_type, :bank_name, :ispb, :branch_code, :account_number, :account_type, :status, :account_created, :owned, :created
|
30
31
|
def initialize(
|
31
|
-
id:, type:, name:, tax_id:, owner_type:, ispb:, branch_code:, account_number:,
|
32
|
-
status:, account_created:, owned:, created:
|
32
|
+
id:, type:, name:, tax_id:, owner_type:, bank_name:, ispb:, branch_code:, account_number:,
|
33
|
+
account_type:, status:, account_created:, owned:, created:
|
33
34
|
)
|
34
35
|
super(id)
|
35
36
|
@type = type
|
36
37
|
@name = name
|
37
38
|
@tax_id = tax_id
|
38
39
|
@owner_type = owner_type
|
40
|
+
@bank_name = bank_name
|
39
41
|
@ispb = ispb
|
40
42
|
@branch_code = branch_code
|
41
43
|
@account_number = account_number
|
@@ -69,18 +71,51 @@ module StarkBank
|
|
69
71
|
# ## Parameters (optional):
|
70
72
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
71
73
|
# - type [string, default nil]: DictKey type. ex: 'cpf', 'cnpj', 'phone', 'email' or 'evp'
|
72
|
-
# - after [Date
|
73
|
-
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
74
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
75
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
74
76
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
75
77
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'canceled', 'registered'
|
76
|
-
# - user [Organization/Project object]: Organization or Project object. Not necessary if
|
78
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
77
79
|
#
|
78
80
|
# ## Return:
|
79
81
|
# - generator of DitcKey objects with updated attributes
|
80
82
|
def self.query(limit: nil, type: nil, after: nil, before: nil, ids: nil, status: nil, user: nil)
|
81
83
|
after = StarkBank::Utils::Checks.check_date(after)
|
82
84
|
before = StarkBank::Utils::Checks.check_date(before)
|
83
|
-
StarkBank::Utils::Rest.
|
85
|
+
StarkBank::Utils::Rest.get_stream(
|
86
|
+
limit: limit,
|
87
|
+
type: type,
|
88
|
+
after: after,
|
89
|
+
before: before,
|
90
|
+
ids: ids,
|
91
|
+
status: status,
|
92
|
+
user: user,
|
93
|
+
**resource
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
# # Retrieve paged DictKeys
|
98
|
+
#
|
99
|
+
# Receive a list of up to 100 DictKey objects previously created in the Stark Bank API and the cursor to the next page.
|
100
|
+
# Use this function instead of query if you want to manually page your requests.
|
101
|
+
#
|
102
|
+
# ## Parameters (optional):
|
103
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
104
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
105
|
+
# - type [string, default nil]: DictKey type. ex: 'cpf', 'cnpj', 'phone', 'email' or 'evp'
|
106
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
107
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
108
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
109
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'canceled', 'registered'
|
110
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
111
|
+
#
|
112
|
+
# ## Return:
|
113
|
+
# - list of DictKey objects with updated attributes and cursor to retrieve the next page of DictKey objects
|
114
|
+
def self.page(cursor: nil, limit: nil, type: nil, after: nil, before: nil, ids: nil, status: nil, user: nil)
|
115
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
116
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
117
|
+
return StarkBank::Utils::Rest.get_page(
|
118
|
+
cursor: cursor,
|
84
119
|
limit: limit,
|
85
120
|
type: type,
|
86
121
|
after: after,
|
@@ -102,6 +137,7 @@ module StarkBank
|
|
102
137
|
name: json['name'],
|
103
138
|
tax_id: json['tax_id'],
|
104
139
|
owner_type: json['owner_type'],
|
140
|
+
bank_name: json['bank_name'],
|
105
141
|
ispb: json['ispb'],
|
106
142
|
branch_code: json['branch_code'],
|
107
143
|
account_number: json['account_number'],
|
data/lib/error.rb
CHANGED
@@ -4,7 +4,15 @@ require('json')
|
|
4
4
|
|
5
5
|
module StarkBank
|
6
6
|
module Error
|
7
|
-
class
|
7
|
+
class StarkBankError < StandardError
|
8
|
+
attr_reader :message
|
9
|
+
def initialize(message)
|
10
|
+
@message = message
|
11
|
+
super(message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Error < StarkBankError
|
8
16
|
attr_reader :code, :message
|
9
17
|
def initialize(code, message)
|
10
18
|
@code = code
|
@@ -13,7 +21,7 @@ module StarkBank
|
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
16
|
-
class InputErrors <
|
24
|
+
class InputErrors < StarkBankError
|
17
25
|
attr_reader :errors
|
18
26
|
def initialize(content)
|
19
27
|
errors = []
|
@@ -26,19 +34,19 @@ module StarkBank
|
|
26
34
|
end
|
27
35
|
end
|
28
36
|
|
29
|
-
class InternalServerError <
|
37
|
+
class InternalServerError < StarkBankError
|
30
38
|
def initialize(message = 'Houston, we have a problem.')
|
31
39
|
super(message)
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
35
|
-
class UnknownError <
|
43
|
+
class UnknownError < StarkBankError
|
36
44
|
def initialize(message)
|
37
45
|
super("Unknown exception encountered: #{message}")
|
38
46
|
end
|
39
47
|
end
|
40
48
|
|
41
|
-
class InvalidSignatureError <
|
49
|
+
class InvalidSignatureError < StarkBankError
|
42
50
|
end
|
43
51
|
end
|
44
52
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
require_relative('event')
|
7
|
+
|
8
|
+
module StarkBank
|
9
|
+
class Event
|
10
|
+
# # Event::Attempt object
|
11
|
+
#
|
12
|
+
# When an Event delivery fails, an event attempt will be registered.
|
13
|
+
# It carries information meant to help you debug event reception issues.
|
14
|
+
#
|
15
|
+
# ## Attributes:
|
16
|
+
# - id [string]: unique id that identifies the delivery attempt. ex: "5656565656565656"
|
17
|
+
# - code [string]: delivery error code. ex: badHttpStatus, badConnection, timeout
|
18
|
+
# - message [string]: delivery error full description. ex: "HTTP POST request returned status 404"
|
19
|
+
# - event_id [string]: ID of the Event whose delivery failed. ex: "4848484848484848"
|
20
|
+
# - webhook_id [string]: ID of the Webhook that triggered this event. ex: "5656565656565656"
|
21
|
+
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
22
|
+
class Attempt < StarkBank::Utils::Resource
|
23
|
+
attr_reader :id, :code, :message, :event_id, :webhook_id, :created
|
24
|
+
def initialize(id:, code:, message:, event_id:, webhook_id:, created:)
|
25
|
+
super(id)
|
26
|
+
@code = code
|
27
|
+
@message = message
|
28
|
+
@event_id = event_id
|
29
|
+
@webhook_id = webhook_id
|
30
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
31
|
+
end
|
32
|
+
|
33
|
+
# # Retrieve a specific Event::Attempt
|
34
|
+
#
|
35
|
+
# Receive a single Event::Attempt object previously created by the Stark Bank API by its id
|
36
|
+
#
|
37
|
+
# ## Parameters (required):
|
38
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
39
|
+
#
|
40
|
+
# ## Parameters (optional):
|
41
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
42
|
+
#
|
43
|
+
# ## Return:
|
44
|
+
# - Event::Attempt object with updated attributes
|
45
|
+
def self.get(id, user: nil)
|
46
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
47
|
+
end
|
48
|
+
|
49
|
+
# # Retrieve Event::Attempts
|
50
|
+
#
|
51
|
+
# Receive a generator of Event::Attempt objects previously created in the Stark Bank API
|
52
|
+
#
|
53
|
+
# ## Parameters (optional):
|
54
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
55
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
56
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
57
|
+
# - event_ids [list of strings, default None]: list of Event ids to filter attempts. ex: ["5656565656565656", "4545454545454545"]
|
58
|
+
# - webhook_ids [list of strings, default None]: list of Webhook ids to filter attempts. ex: ["5656565656565656", "4545454545454545"]
|
59
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
60
|
+
#
|
61
|
+
# ## Return:
|
62
|
+
# - generator of Event::Attempt objects with updated attributes
|
63
|
+
def self.query(limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
|
64
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
65
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
66
|
+
StarkBank::Utils::Rest.get_stream(
|
67
|
+
limit: limit,
|
68
|
+
after: after,
|
69
|
+
before: before,
|
70
|
+
event_ids: event_ids,
|
71
|
+
webhook_ids: webhook_ids,
|
72
|
+
user: user,
|
73
|
+
**resource
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# # Retrieve paged Attempts
|
78
|
+
#
|
79
|
+
# Receive a list of up to 100 Attempt objects previously created in the Stark Bank API and the cursor to the next page.
|
80
|
+
# Use this function instead of query if you want to manually page your requests.
|
81
|
+
#
|
82
|
+
# ## Parameters (optional):
|
83
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
84
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
85
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
86
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
87
|
+
# - event_ids [list of strings, default None]: list of Event ids to filter attempts. ex: ["5656565656565656", "4545454545454545"]
|
88
|
+
# - webhook_ids [list of strings, default None]: list of Webhook ids to filter attempts. ex: ["5656565656565656", "4545454545454545"]
|
89
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
90
|
+
#
|
91
|
+
# ## Return:
|
92
|
+
# - list of Attempt objects with updated attributes and cursor to retrieve the next page of Attempt objects
|
93
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
|
94
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
95
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
96
|
+
return StarkBank::Utils::Rest.get_page(
|
97
|
+
cursor: cursor,
|
98
|
+
limit: limit,
|
99
|
+
after: after,
|
100
|
+
before: before,
|
101
|
+
event_ids: event_ids,
|
102
|
+
webhook_ids: webhook_ids,
|
103
|
+
user: user,
|
104
|
+
**resource
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.resource
|
109
|
+
{
|
110
|
+
resource_name: 'EventAttempt',
|
111
|
+
resource_maker: proc { |json|
|
112
|
+
Attempt.new(
|
113
|
+
id: json['id'],
|
114
|
+
code: json['code'],
|
115
|
+
message: json['message'],
|
116
|
+
event_id: json['event_id'],
|
117
|
+
webhook_id: json['webhook_id'],
|
118
|
+
created: json['created']
|
119
|
+
)
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/lib/event/event.rb
CHANGED
@@ -15,6 +15,8 @@ require_relative('../brcode_payment/log')
|
|
15
15
|
require_relative('../transfer/log')
|
16
16
|
require_relative('../boleto_payment/log')
|
17
17
|
require_relative('../utility_payment/log')
|
18
|
+
require_relative('../tax_payment/log')
|
19
|
+
require_relative('../darf_payment/log')
|
18
20
|
|
19
21
|
module StarkBank
|
20
22
|
# # Webhook Event object
|
@@ -28,13 +30,15 @@ module StarkBank
|
|
28
30
|
# - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
|
29
31
|
# - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
30
32
|
# - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
|
33
|
+
# - workspace_id [string]: ID of the Workspace that generated this event. Mostly used when multiple Workspaces have Webhooks registered to the same endpoint. ex: '4545454545454545'
|
31
34
|
# - subscription [string]: service that triggered this event. ex: 'transfer', 'utility-payment'
|
32
35
|
class Event < StarkBank::Utils::Resource
|
33
|
-
attr_reader :id, :log, :created, :is_delivered, :subscription
|
34
|
-
def initialize(id:, log:, created:, is_delivered:, subscription:)
|
36
|
+
attr_reader :id, :log, :created, :is_delivered, :workspace_id, :subscription
|
37
|
+
def initialize(id:, log:, created:, is_delivered:, workspace_id:, subscription:)
|
35
38
|
super(id)
|
36
39
|
@created = StarkBank::Utils::Checks.check_datetime(created)
|
37
40
|
@is_delivered = is_delivered
|
41
|
+
@workspace_id = workspace_id
|
38
42
|
@subscription = subscription
|
39
43
|
|
40
44
|
resource = {
|
@@ -45,6 +49,8 @@ module StarkBank
|
|
45
49
|
'boleto': StarkBank::Boleto::Log.resource,
|
46
50
|
'boleto-payment': StarkBank::BoletoPayment::Log.resource,
|
47
51
|
'utility-payment': StarkBank::UtilityPayment::Log.resource,
|
52
|
+
'tax-payment': StarkBank::TaxPayment::Log.resource,
|
53
|
+
'darf-payment': StarkBank::DarfPayment::Log.resource,
|
48
54
|
'boleto-holmes': StarkBank::BoletoHolmes::Log.resource
|
49
55
|
}[subscription.to_sym]
|
50
56
|
|
@@ -77,14 +83,14 @@ module StarkBank
|
|
77
83
|
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
78
84
|
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
79
85
|
# - is_delivered [bool, default nil]: bool to filter successfully delivered events. ex: True or False
|
80
|
-
# - user [Organization/Project object]: Organization or Project object. Not necessary if
|
86
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
81
87
|
#
|
82
88
|
# ## Return:
|
83
89
|
# - generator of Event objects with updated attributes
|
84
90
|
def self.query(limit: nil, after: nil, before: nil, is_delivered: nil, user: nil)
|
85
91
|
after = StarkBank::Utils::Checks.check_date(after)
|
86
92
|
before = StarkBank::Utils::Checks.check_date(before)
|
87
|
-
StarkBank::Utils::Rest.
|
93
|
+
StarkBank::Utils::Rest.get_stream(
|
88
94
|
user: user,
|
89
95
|
limit: limit,
|
90
96
|
after: after,
|
@@ -94,6 +100,35 @@ module StarkBank
|
|
94
100
|
)
|
95
101
|
end
|
96
102
|
|
103
|
+
# # Retrieve paged Events
|
104
|
+
#
|
105
|
+
# Receive a list of up to 100 Event objects previously created in the Stark Bank API and the cursor to the next page.
|
106
|
+
# Use this function instead of query if you want to manually page your requests.
|
107
|
+
#
|
108
|
+
# ## Parameters (optional):
|
109
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
110
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
111
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
112
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
113
|
+
# - is_delivered [bool, default nil]: bool to filter successfully delivered events. ex: True or False
|
114
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
115
|
+
#
|
116
|
+
# ## Return:
|
117
|
+
# - list of Event objects with updated attributes and cursor to retrieve the next page of Event objects
|
118
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, is_delivered: nil, user: nil)
|
119
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
120
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
121
|
+
return StarkBank::Utils::Rest.get_page(
|
122
|
+
cursor: cursor,
|
123
|
+
limit: limit,
|
124
|
+
after: after,
|
125
|
+
before: before,
|
126
|
+
is_delivered: is_delivered,
|
127
|
+
user: user,
|
128
|
+
**resource
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
97
132
|
# # Delete a notification Event
|
98
133
|
#
|
99
134
|
# Delete a of notification Event entity previously created in the Stark Bank API by its ID
|
@@ -185,6 +220,7 @@ module StarkBank
|
|
185
220
|
log: json['log'],
|
186
221
|
created: json['created'],
|
187
222
|
is_delivered: json['is_delivered'],
|
223
|
+
workspace_id: json['workspace_id'],
|
188
224
|
subscription: json['subscription']
|
189
225
|
)
|
190
226
|
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/sub_resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
|
7
|
+
module StarkBank
|
8
|
+
# # Institution object
|
9
|
+
#
|
10
|
+
# This resource is used to get information on the institutions that are recognized by the Brazilian Central Bank.
|
11
|
+
# Besides the display name and full name, they also include the STR code (used for TEDs) and the SPI Code
|
12
|
+
# (used for Pix) for the institutions. Either of these codes may be empty if the institution is not registered on
|
13
|
+
# that Central Bank service.
|
14
|
+
#
|
15
|
+
# ## Attributes (return-only):
|
16
|
+
# - display_name [string]: short version of the institution name that should be displayed to end users. ex: 'Stark Bank'
|
17
|
+
# - name [string]: full version of the institution name. ex: 'Stark Bank S.A.'
|
18
|
+
# - spi_code [string]: SPI code used to identify the institution on Pix transactions. ex: '20018183'
|
19
|
+
# - str_code [string]: STR code used to identify the institution on TED transactions. ex: '123'
|
20
|
+
class Institution < StarkBank::Utils::SubResource
|
21
|
+
attr_reader :display_name, :name, :spi_code, :str_code
|
22
|
+
def initialize(display_name: nil, name: nil, spi_code: nil, str_code: nil)
|
23
|
+
@display_name = display_name
|
24
|
+
@name = name
|
25
|
+
@spi_code = spi_code
|
26
|
+
@str_code = str_code
|
27
|
+
end
|
28
|
+
|
29
|
+
# # Retrieve Bacen Institutions
|
30
|
+
#
|
31
|
+
# Receive a list of Institution objects that are recognized by the Brazilian Central bank for Pix and TED transactions
|
32
|
+
#
|
33
|
+
# ## Parameters (optional):
|
34
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
35
|
+
# - search [string, default nil]: part of the institution name to be searched. ex: 'stark'
|
36
|
+
# - spi_codes [list of strings, default nil]: list of SPI (Pix) codes to be searched. ex: ['20018183']
|
37
|
+
# - str_codes [list of strings, default nil]: list of STR (TED) codes to be searched. ex: ['260']
|
38
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
39
|
+
#
|
40
|
+
# ## Return:
|
41
|
+
# - list of Institution objects with updated attributes
|
42
|
+
def self.query(limit: nil, search: nil, spi_codes: nil, str_codes: nil, user: nil)
|
43
|
+
StarkBank::Utils::Rest.get_page(
|
44
|
+
limit: limit,
|
45
|
+
search: search,
|
46
|
+
spi_codes: spi_codes,
|
47
|
+
str_codes: str_codes,
|
48
|
+
user: user,
|
49
|
+
**resource
|
50
|
+
).first
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.resource
|
54
|
+
{
|
55
|
+
resource_name: 'Institution',
|
56
|
+
resource_maker: proc { |json|
|
57
|
+
Institution.new(
|
58
|
+
display_name: json['display_name'],
|
59
|
+
name: json['name'],
|
60
|
+
spi_code: json['spi_code'],
|
61
|
+
str_code: json['str_code']
|
62
|
+
)
|
63
|
+
}
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|