starkbank 2.8.0 → 2.9.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/card_method/cardmethod.rb +56 -0
- data/lib/corporate_balance/corporatebalance.rb +60 -0
- data/lib/corporate_card/corporatecard.rb +259 -0
- data/lib/corporate_card/log.rb +122 -0
- data/lib/corporate_holder/corporateholder.rb +215 -0
- data/lib/corporate_holder/log.rb +122 -0
- data/lib/corporate_holder/permission.rb +65 -0
- data/lib/corporate_invoice/corporateinvoice.rb +150 -0
- data/lib/corporate_purchase/corporatepurchase.rb +265 -0
- data/lib/corporate_purchase/log.rb +130 -0
- data/lib/corporate_rule/corporaterule.rb +126 -0
- data/lib/corporate_transaction/corporatetransaction.rb +134 -0
- data/lib/corporate_withdrawal/corporatewithdrawal.rb +150 -0
- data/lib/merchant_category/merchantcategory.rb +63 -0
- data/lib/merchant_country/merchantcountry.rb +59 -0
- data/lib/payment_request/payment_request.rb +2 -2
- data/lib/starkbank.rb +16 -1
- data/lib/utils/rest.rb +14 -0
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0dc58311d66ee8900115301e82e6ffdeb7ff667b845a67c7ec42de2d00533ed
|
4
|
+
data.tar.gz: ff84f801db89c14d69e21e287ace3f804c1aed4ca8bd5ea546a5047aec6c221e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4456311856c14f16b8076060fececadb8437b8f379f7ed725a1655381e1dec5ba4f970878c3e1bc12b9569be766e638c8c2667bf29e6ea75d061c2b1b8d50a41
|
7
|
+
data.tar.gz: 5f4293cc4fe23711f6bd1b015771dfb5fb4949803c810fd60eb1f12e1af4361936ff1e6388cebe96e660c6fa8d9e8e4cbe092d885f8282af61024e4fb5b8db57
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkcore')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
|
6
|
+
module StarkBank
|
7
|
+
# # CardMethod object
|
8
|
+
#
|
9
|
+
# CardMethod's codes are used to define method filters in CorporateRules.
|
10
|
+
#
|
11
|
+
# ## Parameters (required):
|
12
|
+
# - code [string]: method's code. Options: 'chip', 'token', 'server', 'manual', 'magstripe', 'contactless'
|
13
|
+
#
|
14
|
+
# Attributes (return-only):
|
15
|
+
# - name [string]: method's name. ex: 'token'
|
16
|
+
# - number [string]: method's number. ex: '81'
|
17
|
+
class CardMethod < StarkCore::Utils::SubResource
|
18
|
+
attr_reader :code, :name, :number
|
19
|
+
def initialize(code:, name: nil, number: nil)
|
20
|
+
@code = code
|
21
|
+
@name = name
|
22
|
+
@number = number
|
23
|
+
end
|
24
|
+
|
25
|
+
# # Retrieve CardMethods
|
26
|
+
#
|
27
|
+
# Receive a generator of CardMethod objects available in the Stark Bank API
|
28
|
+
#
|
29
|
+
# ## Parameters (optional):
|
30
|
+
# - search [string, default nil]: keyword to search for code, name, number or short_code
|
31
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
32
|
+
#
|
33
|
+
# ## Return:
|
34
|
+
# - generator of CardMethod objects with updated attributes
|
35
|
+
def self.query(search: nil, user: nil)
|
36
|
+
StarkBank::Utils::Rest.get_stream(
|
37
|
+
search: search,
|
38
|
+
user: user,
|
39
|
+
**resource
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.resource
|
44
|
+
{
|
45
|
+
resource_name: 'CardMethod',
|
46
|
+
resource_maker: proc { |json|
|
47
|
+
CardMethod.new(
|
48
|
+
code: json['code'],
|
49
|
+
name: json['name'],
|
50
|
+
number: json['number']
|
51
|
+
)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkcore')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
|
6
|
+
module StarkBank
|
7
|
+
# # CorporateBalance object
|
8
|
+
#
|
9
|
+
# The CorporateBalance object displays the current corporate balance of the Workspace, which is the result of the sum of
|
10
|
+
# all transactions within this Workspace. The balance is never generated by the user, but it can be retrieved to see
|
11
|
+
# the available information.
|
12
|
+
#
|
13
|
+
# ## Attributes (return-only):
|
14
|
+
# - id [string]: unique id returned when CorporateBalance is created. ex: '5656565656565656'
|
15
|
+
# - amount [integer]: current corporate balance amount of the Workspace in cents. ex: 200 (= R$ 2.00)
|
16
|
+
# - limit [integer]: the maximum negative balance allowed by the user. ex: 10000 (= R$ 100.00)
|
17
|
+
# - max_limit [integer]: the maximum negative balance allowed by StarkBank. ex: 100000 (= R$ 1000.00)
|
18
|
+
# - currency [string]: currency of the current Workspace. Expect others to be added eventually. ex: 'BRL'
|
19
|
+
# - updated [DateTime]: latest update datetime for the CorporateBalance. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
20
|
+
class CorporateBalance < StarkCore::Utils::Resource
|
21
|
+
attr_reader :amount, :limit, :max_limit, :currency, :updated, :id
|
22
|
+
def initialize(amount: nil, limit: nil, max_limit: nil, currency: nil, updated: nil, id: nil)
|
23
|
+
super(id)
|
24
|
+
@amount = amount
|
25
|
+
@limit = limit
|
26
|
+
@max_limit = max_limit
|
27
|
+
@currency = currency
|
28
|
+
@updated = StarkCore::Utils::Checks.check_datetime(updated)
|
29
|
+
end
|
30
|
+
|
31
|
+
# # Retrieve the CorporateBalance object
|
32
|
+
#
|
33
|
+
# Receive the CorporateBalance object linked to your Workspace in the Stark Infrq API
|
34
|
+
#
|
35
|
+
# ## Parameters (optional):
|
36
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
37
|
+
#
|
38
|
+
# ## Return:
|
39
|
+
# - CorporateBalance object with updated attributes
|
40
|
+
def self.get(user: nil)
|
41
|
+
StarkBank::Utils::Rest.get_stream(user: user, **resource).next
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.resource
|
45
|
+
{
|
46
|
+
resource_name: 'CorporateBalance',
|
47
|
+
resource_maker: proc { |json|
|
48
|
+
CorporateBalance.new(
|
49
|
+
id: json['id'],
|
50
|
+
amount: json['amount'],
|
51
|
+
limit: json['limit'],
|
52
|
+
max_limit: json['max_limit'],
|
53
|
+
currency: json['currency'],
|
54
|
+
updated: json['updated']
|
55
|
+
)
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,259 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkcore')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
|
6
|
+
module StarkBank
|
7
|
+
# # CorporateCard object
|
8
|
+
#
|
9
|
+
# The CorporateCard object displays the information of the cards created in your Workspace.
|
10
|
+
# Sensitive information will only be returned when the 'expand' parameter is used, to avoid security concerns.
|
11
|
+
#
|
12
|
+
# When you initialize a CorporateCard, the entity will not be automatically
|
13
|
+
# created in the Stark Bank API. The 'create' function sends the objects
|
14
|
+
# to the Stark Bank API and returns the created object.
|
15
|
+
#
|
16
|
+
# ## Parameters (required):
|
17
|
+
# - holder_id [string]: card holder tax ID. ex: '012.345.678-90'
|
18
|
+
#
|
19
|
+
# ## Attributes (return-only):
|
20
|
+
# - id [string]: unique id returned when CorporateCard is created. ex: '5656565656565656'
|
21
|
+
# - holder_name [string, default nil]: card holder name. ex: 'Tony Stark'
|
22
|
+
# - display_name [string, default nil]: card displayed name. ex: 'ANTHONY STARK'
|
23
|
+
# - rules [list of CorporateRule objects, default nil]: [EXPANDABLE] list of card spending rules.
|
24
|
+
# - tags [list of strings, default nil]: list of strings for tagging. ex: ['travel', 'food']
|
25
|
+
# - street_line_1 [string, default sub-issuer street line 1]: card holder main address. ex: 'Av. Paulista, 200'
|
26
|
+
# - street_line_2 [string, default sub-issuer street line 2]: card holder address complement. ex: 'Apto. 123'
|
27
|
+
# - district [string, default sub-issuer district]: card holder address district / neighbourhood. ex: 'Bela Vista'
|
28
|
+
# - city [string, default sub-issuer city]: card holder address city. ex: 'Rio de Janeiro'
|
29
|
+
# - state_code [string, default sub-issuer state code]: card holder address state. ex: 'GO'
|
30
|
+
# - zip_code [string, default sub-issuer zip code]: card holder address zip code. ex: '01311-200'
|
31
|
+
# - type [string]: card type. ex: 'virtual'
|
32
|
+
# - status [string]: current CorporateCard status. ex: 'active', 'blocked', 'canceled', 'expired'.
|
33
|
+
# - number [string]: [EXPANDABLE] masked card number. Expand to unmask the value. ex: '123'.
|
34
|
+
# - security_code [string]: [EXPANDABLE] masked card verification value (cvv). Expand to unmask the value. ex: '123'.
|
35
|
+
# - expiration [DateTime]: [EXPANDABLE] masked card expiration datetime. Expand to unmask the value. ex: DateTime.new(2032, 3, 10, 10, 30, 0, 0)
|
36
|
+
# - created [DateTime]: creation datetime for the CorporateCard. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
37
|
+
# - updated [DateTime]: latest update datetime for the CorporateCard. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
38
|
+
class CorporateCard < StarkCore::Utils::Resource
|
39
|
+
attr_reader :holder_id, :id, :holder_name, :display_name, :rules, :tags,
|
40
|
+
:street_line_1, :street_line_2, :district, :city, :state_code, :zip_code,
|
41
|
+
:type, :status, :number, :security_code, :expiration, :created, :updated
|
42
|
+
def initialize(
|
43
|
+
holder_id:, holder_name: nil, display_name: nil, rules: nil, tags: nil,
|
44
|
+
street_line_1: nil, street_line_2: nil, district: nil, city: nil, state_code: nil, zip_code: nil, id: nil,
|
45
|
+
type: nil, status: nil, number: nil, security_code: nil, expiration: nil, created: nil, updated: nil
|
46
|
+
)
|
47
|
+
super(id)
|
48
|
+
@holder_id = holder_id
|
49
|
+
@holder_name = holder_name
|
50
|
+
@display_name = display_name
|
51
|
+
@rules = StarkBank::CorporateRule.parse_rules(rules)
|
52
|
+
@tags = tags
|
53
|
+
@street_line_1 = street_line_1
|
54
|
+
@street_line_2 = street_line_2
|
55
|
+
@district = district
|
56
|
+
@city = city
|
57
|
+
@state_code = state_code
|
58
|
+
@zip_code = zip_code
|
59
|
+
@type = type
|
60
|
+
@status = status
|
61
|
+
@number = number
|
62
|
+
@security_code = security_code
|
63
|
+
expiration = nil if !expiration.nil? && expiration.include?('*')
|
64
|
+
@expiration = StarkCore::Utils::Checks.check_datetime(expiration)
|
65
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
66
|
+
@updated = StarkCore::Utils::Checks.check_datetime(updated)
|
67
|
+
end
|
68
|
+
|
69
|
+
# # Create CorporateCards
|
70
|
+
#
|
71
|
+
# Send a CorporateCard object for creation in the Stark Bank API
|
72
|
+
#
|
73
|
+
# ## Parameters (required):
|
74
|
+
# - card [CorporateCard object]: CorporateCard object to be created in the API
|
75
|
+
#
|
76
|
+
# ## Parameters (optional):
|
77
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
78
|
+
#
|
79
|
+
# ## Return:
|
80
|
+
# - CorporateCard object with updated attributes
|
81
|
+
def self.create(card:, expand: nil, user: nil)
|
82
|
+
path = StarkCore::Utils::API.endpoint(resource[:resource_name]) + '/token'
|
83
|
+
payload = StarkCore::Utils::API.api_json(card)
|
84
|
+
json = StarkBank::Utils::Rest.post_raw(path: path, payload: payload, expand: expand, user: user)
|
85
|
+
entity_json = json[StarkCore::Utils::API.last_name(resource[:resource_name])]
|
86
|
+
StarkCore::Utils::API.from_api_json(resource[:resource_maker], entity_json)
|
87
|
+
end
|
88
|
+
|
89
|
+
# # Retrieve a specific CorporateCard
|
90
|
+
#
|
91
|
+
# Receive a single CorporateCard object previously created in the Stark Bank API by its id
|
92
|
+
#
|
93
|
+
# ## Parameters (required):
|
94
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
95
|
+
#
|
96
|
+
# ## Parameters (optional):
|
97
|
+
# - expand [list of strings, default nil]: fields to expand information. ex: ['rules', 'securityCode', 'number', 'expiration']
|
98
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
99
|
+
#
|
100
|
+
# ## Return:
|
101
|
+
# - CorporateCard object with updated attributes
|
102
|
+
def self.get(id, expand: nil, user: nil)
|
103
|
+
StarkBank::Utils::Rest.get_id(id: id, expand: expand, user: user, **resource)
|
104
|
+
end
|
105
|
+
|
106
|
+
# # Retrieve CorporateCards
|
107
|
+
#
|
108
|
+
# Receive a generator of CorporateCard objects previously created in the Stark Bank API
|
109
|
+
#
|
110
|
+
# ## Parameters (optional):
|
111
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
112
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
113
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
114
|
+
# - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled', 'expired']
|
115
|
+
# - types [list of strings, default nil]: card type. ex: ['virtual']
|
116
|
+
# - holder_ids [list of strings, default nil]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
|
117
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
118
|
+
# - expand [list of strings, default nil]: fields to expand information. ex: ['rules', 'security_code', 'number', 'expiration']
|
119
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
120
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
121
|
+
#
|
122
|
+
# ## Return:
|
123
|
+
# - generator of CorporateCards objects with updated attributes
|
124
|
+
def self.query(limit: nil, ids: nil, after: nil, before: nil, status: nil, types: nil, holder_ids: nil, tags: nil,
|
125
|
+
expand: nil, user: nil)
|
126
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
127
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
128
|
+
StarkBank::Utils::Rest.get_stream(
|
129
|
+
limit: limit,
|
130
|
+
ids: ids,
|
131
|
+
after: after,
|
132
|
+
before: before,
|
133
|
+
status: status,
|
134
|
+
types: types,
|
135
|
+
holder_ids: holder_ids,
|
136
|
+
tags: tags,
|
137
|
+
expand: expand,
|
138
|
+
user: user,
|
139
|
+
**resource
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
# # Retrieve paged CorporateCards
|
144
|
+
#
|
145
|
+
# Receive a list of up to 100 CorporateCard objects previously created in the Stark Bank API and the cursor to the next page.
|
146
|
+
# Use this function instead of query if you want to manually page your identities.
|
147
|
+
#
|
148
|
+
# ## Parameters (optional):
|
149
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call.
|
150
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
151
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
152
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
153
|
+
# - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['active', 'blocked', 'canceled', 'expired']
|
154
|
+
# - types [list of strings, default nil]: card type. ex: ['virtual']
|
155
|
+
# - holder_ids [list of strings, default nil]: card holder IDs. ex: ['5656565656565656', '4545454545454545']
|
156
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
157
|
+
# - expand [list of strings, default nil]: fields to expand information. ex: ['rules', 'security_code', 'number', 'expiration']
|
158
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
159
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
160
|
+
#
|
161
|
+
# ## Return:
|
162
|
+
# - list of CorporateCard objects with updated attributes
|
163
|
+
# - cursor to retrieve the next page of CorporateCards objects
|
164
|
+
def self.page(cursor: nil, limit: nil, ids: nil, after: nil, before: nil, status: nil, types: nil, holder_ids: nil,
|
165
|
+
tags: nil, expand: nil, user: nil)
|
166
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
167
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
168
|
+
StarkBank::Utils::Rest.get_page(
|
169
|
+
cursor: cursor,
|
170
|
+
limit: limit,
|
171
|
+
ids: ids,
|
172
|
+
after: after,
|
173
|
+
before: before,
|
174
|
+
status: status,
|
175
|
+
types: types,
|
176
|
+
holder_ids: holder_ids,
|
177
|
+
tags: tags,
|
178
|
+
expand: expand,
|
179
|
+
user: user,
|
180
|
+
**resource
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
184
|
+
# # Update CorporateCard entity
|
185
|
+
#
|
186
|
+
# Update a CorporateCard by passing id.
|
187
|
+
#
|
188
|
+
# ## Parameters (required):
|
189
|
+
# - id [string]: CorporateCard unique id. ex: '5656565656565656'
|
190
|
+
#
|
191
|
+
# ## Parameters (optional):
|
192
|
+
# - status [string, default nil]: You may block the CorporateCard by passing 'blocked' or activate by passing 'active' in the status
|
193
|
+
# - pin [string, default nil]: You may unlock your physical card by passing its PIN. This is also the PIN you use to authorize a purchase.
|
194
|
+
# - display_name [string, default nil]: card displayed name. ex: "ANTHONY EDWARD"
|
195
|
+
# - rules [list of CorporateRule objects, default nil]: [EXPANDABLE] list of card spending rules.
|
196
|
+
# - tags [list of strings, default nil]: list of strings for tagging
|
197
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
198
|
+
#
|
199
|
+
# ## Return:
|
200
|
+
# - target CorporateCard with updated attributes
|
201
|
+
def self.update(id, status: nil, display_name: nil,pin: nil, rules: nil, tags: nil, user: nil)
|
202
|
+
StarkBank::Utils::Rest.patch_id(
|
203
|
+
id: id,
|
204
|
+
status: status,
|
205
|
+
pin: pin,
|
206
|
+
display_name: display_name,
|
207
|
+
rules: rules,
|
208
|
+
tags: tags,
|
209
|
+
user: user,
|
210
|
+
**resource
|
211
|
+
)
|
212
|
+
end
|
213
|
+
|
214
|
+
# # Cancel a CorporateCard entity
|
215
|
+
#
|
216
|
+
# Cancel a CorporateCard entity previously created in the Stark Bank API
|
217
|
+
#
|
218
|
+
# ## Parameters (required):
|
219
|
+
# - id [string]: CorporateCard unique id. ex: '5656565656565656'
|
220
|
+
#
|
221
|
+
# ## Parameters (optional):
|
222
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
223
|
+
#
|
224
|
+
# ## Return:
|
225
|
+
# - canceled CorporateCard object
|
226
|
+
def self.cancel(id, user: nil)
|
227
|
+
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.resource
|
231
|
+
{
|
232
|
+
resource_name: 'CorporateCard',
|
233
|
+
resource_maker: proc { |json|
|
234
|
+
CorporateCard.new(
|
235
|
+
holder_id: json['holder_id'],
|
236
|
+
id: json['id'],
|
237
|
+
holder_name: json['holder_name'],
|
238
|
+
display_name: json['display_name'],
|
239
|
+
rules: json['rules'],
|
240
|
+
tags: json['tags'],
|
241
|
+
street_line_1: json['street_line_1'],
|
242
|
+
street_line_2: json['street_line_2'],
|
243
|
+
district: json['district'],
|
244
|
+
city: json['city'],
|
245
|
+
state_code: json['state_code'],
|
246
|
+
zip_code: json['zip_code'],
|
247
|
+
type: json['type'],
|
248
|
+
status: json['status'],
|
249
|
+
number: json['number'],
|
250
|
+
security_code: json['security_code'],
|
251
|
+
expiration: json['expiration'],
|
252
|
+
created: json['created'],
|
253
|
+
updated: json['updated']
|
254
|
+
)
|
255
|
+
}
|
256
|
+
}
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkcore')
|
4
|
+
require_relative('corporatecard')
|
5
|
+
require_relative('../utils/rest')
|
6
|
+
|
7
|
+
module StarkBank
|
8
|
+
class CorporateCard
|
9
|
+
# # CorporateCard::Log object
|
10
|
+
#
|
11
|
+
# Every time a CorporateCard entity is updated, a corresponding CorporateCard::Log is generated for the entity. This log
|
12
|
+
# is never generated by the user, but it can be retrieved to check additional information on the CorporateCard.
|
13
|
+
#
|
14
|
+
# ## Attributes (return-only):
|
15
|
+
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
16
|
+
# - card [CorporateCard]: CorporateCard entity to which the log refers to.
|
17
|
+
# - type [string]: type of the CorporateCard event which triggered the log creation. ex: "blocked", "canceled", "created", "expired", "unblocked", "updated"
|
18
|
+
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
19
|
+
class Log < StarkCore::Utils::Resource
|
20
|
+
attr_reader :id, :created, :type, :card
|
21
|
+
def initialize(id:, created:, type:, card:)
|
22
|
+
super(id)
|
23
|
+
@type = type
|
24
|
+
@card = card
|
25
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
26
|
+
end
|
27
|
+
|
28
|
+
# # Retrieve a specific CorporateCard::Log
|
29
|
+
#
|
30
|
+
# Receive a single CorporateCard::Log object previously created by the Stark Bank API by passing its id
|
31
|
+
#
|
32
|
+
# ## Parameters (required):
|
33
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
34
|
+
#
|
35
|
+
# ## Parameters (optional):
|
36
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
37
|
+
#
|
38
|
+
# ## Return:
|
39
|
+
# - CorporateCard::Log object with updated attributes
|
40
|
+
def self.get(id, user: nil)
|
41
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
42
|
+
end
|
43
|
+
|
44
|
+
# # Retrieve CorporateCard::Logs
|
45
|
+
#
|
46
|
+
# Receive a generator of CorporateCard::Log objects previously created in the Stark Bank API
|
47
|
+
#
|
48
|
+
# ## Parameters (optional):
|
49
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
50
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
51
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
52
|
+
# - types [list of strings, default nil]: filter for log event types. ex: ['blocked', 'canceled', 'created', 'expired', 'unblocked', 'updated']
|
53
|
+
# - card_ids [list of strings, default nil]: list of CorporateCard ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
54
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
55
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
56
|
+
#
|
57
|
+
# ## Return:
|
58
|
+
# - generator of CorporateCard::Log objects with updated attributes
|
59
|
+
def self.query(limit: nil, after: nil, before: nil, types: nil, card_ids: nil, user: nil)
|
60
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
61
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
62
|
+
StarkBank::Utils::Rest.get_stream(
|
63
|
+
limit: limit,
|
64
|
+
after: after,
|
65
|
+
before: before,
|
66
|
+
types: types,
|
67
|
+
card_ids: card_ids,
|
68
|
+
user: user,
|
69
|
+
**resource
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
# # Retrieve paged CorporateCard::Logs
|
74
|
+
#
|
75
|
+
# Receive a list of up to 100 CorporateCard::Log objects previously created in the Stark Bank API and the cursor to the next page.
|
76
|
+
# Use this function instead of query if you want to manually page your logs.
|
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
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
82
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
83
|
+
# - types [list of strings, default nil]: filter for log event types. ex: ['blocked', 'canceled', 'created', 'expired', 'unblocked', 'updated']
|
84
|
+
# - card_ids [list of strings, default nil]: list of CorporateCard ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
85
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
86
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
87
|
+
#
|
88
|
+
# ## Return:
|
89
|
+
# - list of CorporateCard::Log objects with updated attributes
|
90
|
+
# - Cursor to retrieve the next page of Log objects
|
91
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, card_ids: nil, user: nil)
|
92
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
93
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
94
|
+
StarkBank::Utils::Rest.get_page(
|
95
|
+
cursor: cursor,
|
96
|
+
limit: limit,
|
97
|
+
after: after,
|
98
|
+
before: before,
|
99
|
+
types: types,
|
100
|
+
card_ids: card_ids,
|
101
|
+
user: user,
|
102
|
+
**resource
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.resource
|
107
|
+
request_maker = StarkBank::CorporateCard.resource[:resource_maker]
|
108
|
+
{
|
109
|
+
resource_name: 'CorporateCardLog',
|
110
|
+
resource_maker: proc { |json|
|
111
|
+
Log.new(
|
112
|
+
id: json['id'],
|
113
|
+
created: json['created'],
|
114
|
+
type: json['type'],
|
115
|
+
card: StarkCore::Utils::API.from_api_json(request_maker, json['card'])
|
116
|
+
)
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|