starkbank 2.8.0 → 2.10.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 +133 -0
- data/lib/corporate_rule/corporaterule.rb +129 -0
- data/lib/corporate_transaction/corporatetransaction.rb +134 -0
- data/lib/corporate_withdrawal/corporatewithdrawal.rb +150 -0
- data/lib/darf_payment/darf_payment.rb +1 -1
- data/lib/invoice/invoice.rb +5 -2
- data/lib/invoice/rule.rb +46 -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 +17 -1
- data/lib/utils/rest.rb +14 -0
- metadata +20 -4
@@ -0,0 +1,265 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkcore')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
|
6
|
+
module StarkBank
|
7
|
+
# # CorporatePurchase object
|
8
|
+
#
|
9
|
+
# Displays the CorporatePurchase objects created in your Workspace.
|
10
|
+
#
|
11
|
+
# ## Attributes (return-only):
|
12
|
+
# - id [string]: unique id returned when CorporatePurchase is created. ex: "5656565656565656"
|
13
|
+
# - holder_id [string]: card holder unique id. ex: "5656565656565656"
|
14
|
+
# - holder_name [string]: card holder name. ex: "Tony Stark"
|
15
|
+
# - center_id [string]: target cost center ID. ex: "5656565656565656"
|
16
|
+
# - card_id [string]: unique id returned when CorporateCard is created. ex: "5656565656565656"
|
17
|
+
# - card_ending [string]: last 4 digits of the card number. ex: "1234"
|
18
|
+
# - description [string]: purchase descriptions. ex: "my_description"
|
19
|
+
# - amount [integer]: CorporatePurchase value in cents. Minimum = 0. ex: 1234 (= R$ 12.34)
|
20
|
+
# - tax [integer]: IOF amount taxed for international purchases. ex: 1234 (= R$ 12.34)
|
21
|
+
# - corporate_amount [integer]: corporate amount. ex: 1234 (= R$ 12.34)
|
22
|
+
# - corporate_currency_code [string]: corporate currency code. ex: "USD"
|
23
|
+
# - corporate_currency_symbol [string]: corporate currency symbol. ex: "$"
|
24
|
+
# - merchant_amount [integer]: merchant amount. ex: 1234 (= R$ 12.34)
|
25
|
+
# - merchant_currency_code [string]: merchant currency code. ex: "USD"
|
26
|
+
# - merchant_currency_symbol [string]: merchant currency symbol. ex: "$"
|
27
|
+
# - merchant_category_code [string]: merchant category code. ex: "fastFoodRestaurants"
|
28
|
+
# - merchant_category_type [string]: merchant category type. ex: "health"
|
29
|
+
# - merchant_country_code [string]: merchant country code. ex: "USA"
|
30
|
+
# - merchant_name [string]: merchant name. ex: "Google Cloud Platform"
|
31
|
+
# - merchant_display_name [string]: merchant name. ex: "Google Cloud Platform"
|
32
|
+
# - merchant_display_url [string]: public merchant icon (png image). ex: "https://sandbox.api.starkbank.com/v2/corporate-icon/merchant/ifood.png"
|
33
|
+
# - merchant_fee [integer]: fee charged by the merchant to cover specific costs, such as ATM withdrawal logistics, etc. ex: 200 (= R$ 2.00)
|
34
|
+
# - method_code [string]: method code. Options: "chip", "token", "server", "manual", "magstripe" or "contactless"
|
35
|
+
# - tags [list of strings]: list of strings for tagging returned by the sub-issuer during the authorization. ex: ["travel", "food"]
|
36
|
+
# - corporate_transaction_ids [list of strings]: ledger transaction ids linked to this Purchase
|
37
|
+
# - status [string]: current CorporateCard status. Options: "approved", "canceled", "denied", "confirmed", "voided"
|
38
|
+
# - updated [DateTime]: latest update datetime for the CorporatePurchase. ex: DateTime(2020, 3, 10, 10, 30, 0, 0)
|
39
|
+
# - created [DateTime]: creation datetime for the CorporatePurchase. ex: DateTime(2020, 3, 10, 10, 30, 0, 0)
|
40
|
+
class CorporatePurchase < StarkCore::Utils::Resource
|
41
|
+
attr_reader :id, :holder_id, :holder_name, :center_id, :card_id, :card_ending, :description, :amount, :tax, :corporate_amount,
|
42
|
+
:corporate_currency_code, :corporate_currency_symbol, :merchant_amount, :merchant_currency_code, :merchant_currency_symbol,
|
43
|
+
:merchant_category_code, :merchant_category_type, :merchant_country_code, :merchant_name, :merchant_display_name,
|
44
|
+
:merchant_display_url, :merchant_fee, :method_code, :tags, :corporate_transaction_ids, :status, :updated, :created
|
45
|
+
def initialize(
|
46
|
+
id: nil, holder_id: nil, holder_name: nil, center_id: nil, card_id: nil, card_ending: nil, description: nil, amount: nil, tax: nil, corporate_amount: nil,
|
47
|
+
corporate_currency_code: nil, corporate_currency_symbol: nil, merchant_amount: nil, merchant_currency_code: nil, merchant_currency_symbol: nil,
|
48
|
+
merchant_category_code: nil, merchant_category_type: nil, merchant_country_code: nil, merchant_name: nil, merchant_display_name: nil,
|
49
|
+
merchant_display_url: nil, merchant_fee: nil, method_code: nil, tags: nil, corporate_transaction_ids: nil, status: nil, updated: nil, created: nil
|
50
|
+
)
|
51
|
+
super(id)
|
52
|
+
@holder_id = holder_id
|
53
|
+
@holder_name = holder_name
|
54
|
+
@center_id = center_id
|
55
|
+
@card_id = card_id
|
56
|
+
@card_ending = card_ending
|
57
|
+
@description = description
|
58
|
+
@amount = amount
|
59
|
+
@tax = tax
|
60
|
+
@corporate_amount = corporate_amount
|
61
|
+
@corporate_currency_code = corporate_currency_code
|
62
|
+
@corporate_currency_symbol = corporate_currency_symbol
|
63
|
+
@merchant_amount = merchant_amount
|
64
|
+
@merchant_currency_code = merchant_currency_code
|
65
|
+
@merchant_currency_symbol = merchant_currency_symbol
|
66
|
+
@merchant_category_code = merchant_category_code
|
67
|
+
@merchant_category_type = merchant_category_type
|
68
|
+
@merchant_country_code = merchant_country_code
|
69
|
+
@merchant_name = merchant_name
|
70
|
+
@merchant_display_name = merchant_display_name
|
71
|
+
@merchant_display_url = merchant_display_url
|
72
|
+
@merchant_fee = merchant_fee
|
73
|
+
@method_code = method_code
|
74
|
+
@tags = tags
|
75
|
+
@corporate_transaction_ids = corporate_transaction_ids
|
76
|
+
@status = status
|
77
|
+
@updated = updated
|
78
|
+
@created = created
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
# # Retrieve a specific CorporatePurchase
|
83
|
+
#
|
84
|
+
# Receive a single CorporatePurchase object previously created in the Stark Bank API by its id
|
85
|
+
#
|
86
|
+
# ## Parameters (required):
|
87
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
88
|
+
#
|
89
|
+
# ## Parameters (optional):
|
90
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
91
|
+
#
|
92
|
+
# ## Return:
|
93
|
+
# - CorporatePurchase object with updated attributes
|
94
|
+
def self.get(id, user: nil)
|
95
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
96
|
+
end
|
97
|
+
|
98
|
+
# # Retrieve CorporatePurchases
|
99
|
+
#
|
100
|
+
# Receive a generator of CorporatePurchases objects previously created in the Stark Bank API
|
101
|
+
#
|
102
|
+
# ## Parameters (optional):
|
103
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
104
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 09)
|
105
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
106
|
+
# - merchant_category_types [list of strings, default nil]: merchant category type. ex: "health"
|
107
|
+
# - holder_ids [list of strings, default nil]: card holder IDs. ex: ["5656565656565656", "4545454545454545"]
|
108
|
+
# - card_ids [list of strings, default nil]: card IDs. ex: ["5656565656565656", "4545454545454545"]
|
109
|
+
# - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['approved', 'canceled', 'denied', 'confirmed', 'voided']
|
110
|
+
# - ids [list of strings, default nil]: purchase IDs. ex: ['5656565656565656', '4545454545454545']
|
111
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
112
|
+
#
|
113
|
+
# ## Return:
|
114
|
+
# - generator of CorporatePurchases objects with updated attributes
|
115
|
+
def self.query(ids: nil, limit: nil, after: nil, before: nil, merchant_category_types: nil, holder_ids: nil, card_ids: nil,
|
116
|
+
status: nil, user: nil)
|
117
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
118
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
119
|
+
StarkBank::Utils::Rest.get_stream(
|
120
|
+
ids: ids,
|
121
|
+
limit: limit,
|
122
|
+
after: after,
|
123
|
+
before: before,
|
124
|
+
merchant_category_types: merchant_category_types,
|
125
|
+
holder_ids: holder_ids,
|
126
|
+
card_ids: card_ids,
|
127
|
+
status: status,
|
128
|
+
user: user,
|
129
|
+
**resource
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
# # Retrieve paged CorporatePurchases
|
134
|
+
#
|
135
|
+
# Receive a list of up to 100 CorporatePurchases objects previously created in the Stark Bank API and the cursor
|
136
|
+
# to the next page. Use this function instead of query if you want to manually page your invoices.
|
137
|
+
#
|
138
|
+
# ## Parameters (optional):
|
139
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call.
|
140
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
141
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
142
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
143
|
+
# - merchant_category_types [list of strings, default nil]: merchant category type. ex: "health"
|
144
|
+
# - holder_ids [list of strings, default nil]: card holder IDs. ex: ["5656565656565656", "4545454545454545"]
|
145
|
+
# - card_ids [list of strings, default nil]: card IDs. ex: ["5656565656565656", "4545454545454545"]
|
146
|
+
# - status [list of strings, default nil]: filter for status of retrieved objects. ex: ['approved', 'canceled', 'denied', 'confirmed', 'voided']
|
147
|
+
# - ids [list of strings, default nil]: purchase IDs. ex: ['5656565656565656', '4545454545454545']
|
148
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
149
|
+
#
|
150
|
+
# ## Return:
|
151
|
+
# - list of CorporatePurchases objects with updated attributes
|
152
|
+
# - cursor to retrieve the next page of CorporatePurchases objects
|
153
|
+
def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, merchant_category_types: nil, holder_ids: nil,
|
154
|
+
card_ids: nil, status: nil, user: nil)
|
155
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
156
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
157
|
+
StarkBank::Utils::Rest.get_page(
|
158
|
+
cursor: cursor,
|
159
|
+
ids: ids,
|
160
|
+
limit: limit,
|
161
|
+
after: after,
|
162
|
+
before: before,
|
163
|
+
merchant_category_types: merchant_category_types,
|
164
|
+
holder_ids: holder_ids,
|
165
|
+
card_ids: card_ids,
|
166
|
+
status: status,
|
167
|
+
user: user,
|
168
|
+
**resource
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
# # Create a single verified CorporatePurchase authorization request from a content string
|
173
|
+
#
|
174
|
+
# Use this method to parse and verify the authenticity of the authorization request received at the informed endpoint.
|
175
|
+
# Authorization requests are posted to your registered endpoint whenever CorporatePurchases are received.
|
176
|
+
# They present CorporatePurchase data that must be analyzed and answered with approval or declination.
|
177
|
+
# If the provided digital signature does not check out with the StarkBank public key, a stark.exception.InvalidSignatureException will be raised.
|
178
|
+
# If the authorization request is not answered within 2 seconds or is not answered with an HTTP status code 200 the
|
179
|
+
# CorporatePurchase will go through the pre-configured stand-in validation.
|
180
|
+
#
|
181
|
+
# ## Parameters (required):
|
182
|
+
# - content [string]: response content from request received at user endpoint (not parsed)
|
183
|
+
# - signature [string]: base-64 digital signature received at response header 'Digital-Signature'
|
184
|
+
#
|
185
|
+
# # ## Parameters (optional):
|
186
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
187
|
+
#
|
188
|
+
# ## Return:
|
189
|
+
# - Parsed CorporatePurchase object
|
190
|
+
def self.parse(content:, signature:, user: nil)
|
191
|
+
StarkBank::Utils::Parse.parse_and_verify(
|
192
|
+
content: content,
|
193
|
+
signature: signature,
|
194
|
+
user: user,
|
195
|
+
key: nil,
|
196
|
+
resource: resource
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
# # Helps you respond CorporatePurchase requests
|
201
|
+
#
|
202
|
+
# ## Parameters (required):
|
203
|
+
# - status [string]: sub-issuer response to the authorization. ex: 'approved' or 'denied'
|
204
|
+
#
|
205
|
+
# ## Parameters (conditionally required):
|
206
|
+
# - reason [string]: denial reason. Options: 'other', 'blocked', 'lostCard', 'stolenCard', 'invalidPin', 'invalidCard', 'cardExpired', 'corporateError', 'concurrency', 'standInDenial', 'subIssuerError', 'invalidPurpose', 'invalidZipCode', 'invalidWalletId', 'inconsistentCard', 'settlementFailed', 'cardRuleMismatch', 'invalidExpiration', 'prepaidInstallment', 'holderRuleMismatch', 'insufficientBalance', 'tooManyTransactions', 'invalidSecurityCode', 'invalidPaymentMethod', 'confirmationDeadline', 'withdrawalAmountLimit', 'insufficientCardLimit', 'insufficientHolderLimit'
|
207
|
+
#
|
208
|
+
# # ## Parameters (optional):
|
209
|
+
# - amount [integer, default nil]: amount in cents that was authorized. ex: 1234 (= R$ 12.34)
|
210
|
+
# - tags [list of strings, default nil]: tags to filter retrieved object. ex: ['tony', 'stark']
|
211
|
+
#
|
212
|
+
# ## Return:
|
213
|
+
# - Dumped JSON string that must be returned to us on the CorporatePurchase request
|
214
|
+
def self.response(
|
215
|
+
status:, reason: nil, amount: nil, tags: nil
|
216
|
+
)
|
217
|
+
params = {
|
218
|
+
'status': status,
|
219
|
+
'reason': reason,
|
220
|
+
'amount': amount,
|
221
|
+
'tags': tags
|
222
|
+
}
|
223
|
+
|
224
|
+
params.to_json
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.resource
|
228
|
+
{
|
229
|
+
resource_name: 'CorporatePurchase',
|
230
|
+
resource_maker: proc { |json|
|
231
|
+
CorporatePurchase.new(
|
232
|
+
id: json['id'],
|
233
|
+
holder_id: json['holder_id'],
|
234
|
+
holder_name: json['holder_name'],
|
235
|
+
center_id: json['center_id'],
|
236
|
+
card_id: json['card_id'],
|
237
|
+
card_ending: json['card_ending'],
|
238
|
+
description: json['description'],
|
239
|
+
amount: json['amount'],
|
240
|
+
tax: json['tax'],
|
241
|
+
corporate_amount: json['corporate_amount'],
|
242
|
+
corporate_currency_code: json['corporate_currency_code'],
|
243
|
+
corporate_currency_symbol: json['corporate_currency_symbol'],
|
244
|
+
merchant_amount: json['merchant_amount'],
|
245
|
+
merchant_currency_code: json['merchant_currency_code'],
|
246
|
+
merchant_currency_symbol: json['merchant_currency_symbol'],
|
247
|
+
merchant_category_code: json['merchant_category_code'],
|
248
|
+
merchant_category_type: json['merchant_category_type'],
|
249
|
+
merchant_country_code: json['merchant_country_code'],
|
250
|
+
merchant_name: json['merchant_name'],
|
251
|
+
merchant_display_name: json['merchant_display_name'],
|
252
|
+
merchant_display_url: json['merchant_display_url'],
|
253
|
+
merchant_fee: json['merchant_fee'],
|
254
|
+
method_code: json['method_code'],
|
255
|
+
tags: json['tags'],
|
256
|
+
corporate_transaction_ids: json['corporate_transaction_ids'],
|
257
|
+
status: json['status'],
|
258
|
+
updated: json['updated'],
|
259
|
+
created: json['created'],
|
260
|
+
)
|
261
|
+
}
|
262
|
+
}
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkcore')
|
4
|
+
require_relative('corporatepurchase')
|
5
|
+
require_relative('../utils/rest')
|
6
|
+
|
7
|
+
module StarkBank
|
8
|
+
class CorporatePurchase
|
9
|
+
# # CorporatePurchase::Log object
|
10
|
+
#
|
11
|
+
# Every time a CorporatePurchase entity is updated, a corresponding CorporatePurchase::Log is generated for the entity.
|
12
|
+
# This Log is never generated by the user, but it can be retrieved to check additional information on the CorporatePurchase.
|
13
|
+
#
|
14
|
+
# ## Attributes (return-only):
|
15
|
+
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
16
|
+
# - purchase [CorporatePurchase]: CorporatePurchase entity to which the log refers to.
|
17
|
+
# - description [string]: purchase descriptions. ex: 'my_description'
|
18
|
+
# - corporate_transaction_id [string]: transaction ID related to the CorporateCard.
|
19
|
+
# - errors [list of strings]: list of errors linked to this CorporatePurchase event
|
20
|
+
# - type [string]: type of the CorporatePurchase event which triggered the log creation. ex: 'approved', 'canceled', 'confirmed', 'denied', 'reversed', 'voided'.
|
21
|
+
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
22
|
+
class Log < StarkCore::Utils::Resource
|
23
|
+
attr_reader :id, :purchase, :description, :corporate_transaction_id, :errors, :type, :created
|
24
|
+
def initialize(id: nil, purchase: nil, description: nil, corporate_transaction_id: nil, errors: nil, type: nil, created: nil)
|
25
|
+
super(id)
|
26
|
+
@purchase = purchase
|
27
|
+
@description = description
|
28
|
+
@corporate_transaction_id = corporate_transaction_id
|
29
|
+
@errors = errors
|
30
|
+
@type = type
|
31
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
32
|
+
end
|
33
|
+
|
34
|
+
# # Retrieve a specific CorporatePurchase::Log
|
35
|
+
#
|
36
|
+
# Receive a single CorporatePurchase::Log object previously created by the Stark Bank API by passing its id
|
37
|
+
#
|
38
|
+
# ## Parameters (required):
|
39
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
40
|
+
#
|
41
|
+
# ## Parameters (optional):
|
42
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
43
|
+
#
|
44
|
+
# ## Return:
|
45
|
+
# - CorporatePurchase::Log object with updated attributes
|
46
|
+
def self.get(id, user: nil)
|
47
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
48
|
+
end
|
49
|
+
|
50
|
+
# # Retrieve CorporatePurchase::Logs
|
51
|
+
#
|
52
|
+
# Receive a generator of CorporatePurchase::Log objects previously created in the Stark Bank API
|
53
|
+
#
|
54
|
+
# ## Parameters (optional):
|
55
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
56
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
57
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
58
|
+
# - types [list of strings, default nil]: filter for log event types. ex: ['approved', 'canceled', 'confirmed', 'denied', 'reversed', 'voided']
|
59
|
+
# - purchase_ids [list of strings, default nil]: list of Purchase ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
60
|
+
# - ids [list of strings, default nil]: list of CorporatePurchase ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
61
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
62
|
+
#
|
63
|
+
# ## Return:
|
64
|
+
# - generator of CorporatePurchase::Log objects with updated attributes
|
65
|
+
def self.query(ids: nil, limit: nil, after: nil, before: nil, types: nil, purchase_ids: nil, user: nil)
|
66
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
67
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
68
|
+
StarkBank::Utils::Rest.get_stream(
|
69
|
+
ids: ids,
|
70
|
+
limit: limit,
|
71
|
+
after: after,
|
72
|
+
before: before,
|
73
|
+
types: types,
|
74
|
+
purchase_ids: purchase_ids,
|
75
|
+
user: user,
|
76
|
+
**resource
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
# # Retrieve paged CorporatePurchase::Logs
|
81
|
+
#
|
82
|
+
# Receive a list of up to 100 Log objects previously created in the Stark Bank API and the cursor to the next page.
|
83
|
+
# Use this function instead of query if you want to manually page your purchases.
|
84
|
+
#
|
85
|
+
# ## Parameters (optional):
|
86
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
87
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
88
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
89
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
90
|
+
# - types [list of strings, default nil]: filter for log event types. ex: ['approved', 'canceled', 'confirmed', 'denied', 'reversed', 'voided']
|
91
|
+
# - purchase_ids [list of strings, default nil]: list of Purchase ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
92
|
+
# - ids [list of strings, default nil]: list of CorporatePurchase ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
93
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
94
|
+
#
|
95
|
+
# ## Return:
|
96
|
+
# - list of CorporatePurchase::Log objects with updated attributes
|
97
|
+
# - cursor to retrieve the next page of Log objects
|
98
|
+
def self.page(cursor: nil, ids: nil, limit: nil, after: nil, before: nil, types: nil, purchase_ids: nil, user: nil)
|
99
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
100
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
101
|
+
StarkBank::Utils::Rest.get_page(
|
102
|
+
cursor: cursor,
|
103
|
+
ids: ids,
|
104
|
+
limit: limit,
|
105
|
+
after: after,
|
106
|
+
before: before,
|
107
|
+
types: types,
|
108
|
+
purchase_ids: purchase_ids,
|
109
|
+
user: user,
|
110
|
+
**resource
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.resource
|
115
|
+
request_maker = StarkBank::CorporatePurchase.resource[:resource_maker]
|
116
|
+
{
|
117
|
+
resource_name: 'CorporatePurchaseLog',
|
118
|
+
resource_maker: proc { |json|
|
119
|
+
Log.new(
|
120
|
+
id: json['id'],
|
121
|
+
purchase: StarkCore::Utils::API.from_api_json(request_maker, json['purchase']),
|
122
|
+
description: json['description'],
|
123
|
+
corporate_transaction_id: json['corporate_transaction_id'],
|
124
|
+
errors: json['errors'],
|
125
|
+
type: json['type'],
|
126
|
+
created: json['created']
|
127
|
+
)
|
128
|
+
}
|
129
|
+
}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/rest')
|
4
|
+
|
5
|
+
module StarkBank
|
6
|
+
# # CorporateRule object
|
7
|
+
#
|
8
|
+
# The CorporateRule object displays the spending rules of CorporateCards and CorporateHolders created in your Workspace.
|
9
|
+
#
|
10
|
+
# ## Parameters (required):
|
11
|
+
# - name [string]: rule name. ex: 'Travel' or 'Food'
|
12
|
+
# - amount [integer]: maximum amount that can be spent in the informed interval. ex: 200000 (= R$ 2000.00)
|
13
|
+
#
|
14
|
+
# ## Parameters (optional):
|
15
|
+
# - interval [string, default 'lifetime']: interval after which the rule amount counter will be reset to 0. ex: 'instant', 'day', 'week', 'month', 'year' or 'lifetime'
|
16
|
+
# - schedule [string, default nil]: schedule time for user to spend. ex: "every monday, wednesday from 00:00 to 23:59 in America/Sao_Paulo"
|
17
|
+
# - purposes [list of string, default []]: list of strings representing the allowed purposes for card purchases, you can use this to restrict ATM withdrawals. ex: ["purchase", "withdrawal"]
|
18
|
+
# - currency_code [string, default 'BRL']: code of the currency that the rule amount refers to. ex: 'BRL' or 'USD'
|
19
|
+
# - categories [list of MerchantCategories, default nil]: merchant categories accepted by the rule. ex: [MerchantCategory(code='fastFoodRestaurants')]
|
20
|
+
# - countries [list of MerchantCountries, default nil]: countries accepted by the rule. ex: [MerchantCountry(code='BRA')]
|
21
|
+
# - methods [list of CardMethods, default nil]: card purchase methods accepted by the rule. ex: [CardMethod(code='magstripe')]
|
22
|
+
#
|
23
|
+
# ## Attributes (expanded return-only):
|
24
|
+
# - id [string]: unique id returned when a CorporateRule is created, used to update a specific CorporateRule. ex: '5656565656565656'
|
25
|
+
# - counter_amount [integer]: current rule spent amount. ex: 1000
|
26
|
+
# - currency_symbol [string]: currency symbol. ex: 'R$'
|
27
|
+
# - currency_name [string]: currency name. ex: 'Brazilian Real'
|
28
|
+
class CorporateRule < StarkCore::Utils::Resource
|
29
|
+
attr_reader :name, :interval, :amount, :currency_code, :counter_amount, :schedule, :purposes, :currency_name, :currency_symbol,
|
30
|
+
:categories, :countries, :methods
|
31
|
+
def initialize(
|
32
|
+
name:, amount:, id: nil, interval: nil, schedule: nil, purposes: nil, currency_code: nil, categories: nil, countries: nil, methods: nil,
|
33
|
+
counter_amount: nil, currency_symbol: nil, currency_name: nil
|
34
|
+
)
|
35
|
+
super(id)
|
36
|
+
@name = name
|
37
|
+
@amount = amount
|
38
|
+
@interval = interval
|
39
|
+
@schedule = schedule
|
40
|
+
@purposes = purposes
|
41
|
+
@currency_code = currency_code
|
42
|
+
@categories = CorporateRule.parse_categories(categories)
|
43
|
+
@countries = CorporateRule.parse_categories(countries)
|
44
|
+
@methods = CorporateRule.parse_categories(methods)
|
45
|
+
@counter_amount = counter_amount
|
46
|
+
@currency_symbol = currency_symbol
|
47
|
+
@currency_name = currency_name
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.parse_categories(categories)
|
51
|
+
resource_maker = StarkBank::MerchantCategory.resource[:resource_maker]
|
52
|
+
return categories if categories.nil?
|
53
|
+
|
54
|
+
parsed_categories = []
|
55
|
+
categories.each do |category|
|
56
|
+
unless category.is_a? MerchantCategory
|
57
|
+
category = StarkCore::Utils::API.from_api_json(resource_maker, category)
|
58
|
+
end
|
59
|
+
parsed_categories << category
|
60
|
+
end
|
61
|
+
parsed_categories
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.parse_countries(countries)
|
65
|
+
resource_maker = StarkBank::MerchantCountry.resource[:resource_maker]
|
66
|
+
return countries if countries.nil?
|
67
|
+
|
68
|
+
parsed_countries = []
|
69
|
+
countries.each do |country|
|
70
|
+
unless country.is_a? MerchantCountry
|
71
|
+
country = StarkCore::Utils::API.from_api_json(resource_maker, country)
|
72
|
+
end
|
73
|
+
parsed_countries << country
|
74
|
+
end
|
75
|
+
parsed_countries
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.parse_methods(methods)
|
79
|
+
resource_maker = StarkBank::CardMethod.resource[:resource_maker]
|
80
|
+
return methods if methods.nil?
|
81
|
+
|
82
|
+
parsed_methods = []
|
83
|
+
methods.each do |method|
|
84
|
+
unless method.is_a? CardMethod
|
85
|
+
method = StarkCore::Utils::API.from_api_json(resource_maker, method)
|
86
|
+
end
|
87
|
+
parsed_methods << method
|
88
|
+
end
|
89
|
+
parsed_methods
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.parse_rules(rules)
|
93
|
+
rule_maker = StarkBank::CorporateRule.resource[:resource_maker]
|
94
|
+
return rules if rules.nil?
|
95
|
+
|
96
|
+
parsed_rules = []
|
97
|
+
rules.each do |rule|
|
98
|
+
unless rule.is_a? CorporateRule
|
99
|
+
rule = StarkCore::Utils::API.from_api_json(rule_maker, rule)
|
100
|
+
end
|
101
|
+
parsed_rules << rule
|
102
|
+
end
|
103
|
+
parsed_rules
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.resource
|
107
|
+
{
|
108
|
+
resource_name: 'CorporateRule',
|
109
|
+
resource_maker: proc { |json|
|
110
|
+
CorporateRule.new(
|
111
|
+
name: json['name'],
|
112
|
+
amount: json['amount'],
|
113
|
+
interval: json['interval'],
|
114
|
+
schedule: json['schedule'],
|
115
|
+
purposes: json['purposes'],
|
116
|
+
currency_code: json['currency_code'],
|
117
|
+
categories: json['categories'],
|
118
|
+
countries: json['countries'],
|
119
|
+
methods: json['methods'],
|
120
|
+
counter_amount: json['counter_amount'],
|
121
|
+
currency_symbol: json['currency_symbol'],
|
122
|
+
currency_name: json['currency_name']
|
123
|
+
)
|
124
|
+
}
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkcore')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
|
6
|
+
module StarkBank
|
7
|
+
# # CorporateTransaction object
|
8
|
+
#
|
9
|
+
# The CorporateTransaction objects created in your Workspace to represent each balance shift.
|
10
|
+
#
|
11
|
+
# ## Attributes (return-only):
|
12
|
+
# - id [string]: unique id returned when CorporateTransaction is created. ex: '5656565656565656'
|
13
|
+
# - amount [integer]: CorporateTransaction value in cents. ex: 1234 (= R$ 12.34)
|
14
|
+
# - balance [integer]: balance amount of the Workspace at the instant of the Transaction in cents. ex: 200 (= R$ 2.00)
|
15
|
+
# - description [string]: CorporateTransaction description. ex: 'Buying food'
|
16
|
+
# - source [string]: source of the transaction. ex: 'corporate-purchase/5656565656565656'
|
17
|
+
# - tags [string]: list of strings inherited from the source resource. ex: ['tony', 'stark']
|
18
|
+
# - created [DateTime]: creation datetime for the CorporateTransaction. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
19
|
+
class CorporateTransaction < StarkCore::Utils::Resource
|
20
|
+
attr_reader :id, :amount, :balance, :description, :source, :tags, :created
|
21
|
+
|
22
|
+
def initialize(id: nil, amount: nil, balance: nil, description: nil, source: nil, tags: nil, created: nil)
|
23
|
+
super(id)
|
24
|
+
@amount = amount
|
25
|
+
@balance = balance
|
26
|
+
@description = description
|
27
|
+
@source = source
|
28
|
+
@tags = tags
|
29
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
30
|
+
end
|
31
|
+
|
32
|
+
# # Retrieve a specific CorporateTransaction
|
33
|
+
#
|
34
|
+
# Receive a single CorporateTransaction object previously created in the Stark Bank API by its id
|
35
|
+
#
|
36
|
+
# ## Parameters (required):
|
37
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
38
|
+
#
|
39
|
+
# ## Parameters (optional):
|
40
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
41
|
+
#
|
42
|
+
# ## Return:
|
43
|
+
# - CorporateTransaction object with updated attributes
|
44
|
+
def self.get(id, user: nil)
|
45
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
46
|
+
end
|
47
|
+
|
48
|
+
# # Retrieve CorporateTransactions
|
49
|
+
#
|
50
|
+
# Receive a generator of CorporateTransaction objects previously created in the Stark Bank API
|
51
|
+
#
|
52
|
+
# ## Parameters (optional):
|
53
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
54
|
+
# - external_ids [list of strings, default nil]: external IDs. ex: ['5656565656565656', '4545454545454545']
|
55
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
56
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
57
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'approved', 'canceled', 'denied', 'confirmed' or 'voided'
|
58
|
+
# - ids [list of strings, default nil]: purchase IDs
|
59
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
60
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
61
|
+
#
|
62
|
+
# ## Return:
|
63
|
+
# - generator of CorporateTransaction objects with updated attributes
|
64
|
+
def self.query(tags: nil, external_ids: nil, after: nil, before: nil, status: nil, ids: nil, limit: nil, user: nil)
|
65
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
66
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
67
|
+
StarkBank::Utils::Rest.get_stream(
|
68
|
+
tags: tags,
|
69
|
+
external_ids: external_ids,
|
70
|
+
after: after,
|
71
|
+
before: before,
|
72
|
+
status: status,
|
73
|
+
ids: ids,
|
74
|
+
limit: limit,
|
75
|
+
user: user,
|
76
|
+
**resource
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
# # Retrieve paged CorporateTransactions
|
81
|
+
#
|
82
|
+
# Receive a list of up to 100 CorporateTransaction objects previously created in the Stark Bank API and the cursor to the next page.
|
83
|
+
# Use this function instead of query if you want to manually page your requests.
|
84
|
+
#
|
85
|
+
# ## Parameters (optional):
|
86
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call.
|
87
|
+
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
88
|
+
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
89
|
+
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
90
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
91
|
+
# - external_ids [list of strings, default nil]: external IDs. ex: ['5656565656565656', '4545454545454545']
|
92
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'approved', 'canceled', 'denied', 'confirmed' or 'voided'
|
93
|
+
# - ids [list of strings, default nil]: purchase IDs
|
94
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
|
95
|
+
#
|
96
|
+
# ## Return:
|
97
|
+
# - list of CorporateTransactions objects with updated attributes
|
98
|
+
# - cursor to retrieve the next page of CorporateTransactions objects
|
99
|
+
def self.page(cursor: nil, tags: nil, external_ids: nil, after: nil, before: nil, status: nil, ids: nil, limit: nil,
|
100
|
+
user: nil)
|
101
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
102
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
103
|
+
StarkBank::Utils::Rest.get_page(
|
104
|
+
cursor: cursor,
|
105
|
+
tags: tags,
|
106
|
+
external_ids: external_ids,
|
107
|
+
after: after,
|
108
|
+
before: before,
|
109
|
+
status: status,
|
110
|
+
ids: ids,
|
111
|
+
limit: limit,
|
112
|
+
user: user,
|
113
|
+
**resource
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.resource
|
118
|
+
{
|
119
|
+
resource_name: 'CorporateTransaction',
|
120
|
+
resource_maker: proc { |json|
|
121
|
+
CorporateTransaction.new(
|
122
|
+
id: json['id'],
|
123
|
+
amount: json['amount'],
|
124
|
+
balance: json['balance'],
|
125
|
+
description: json['description'],
|
126
|
+
source: json['source'],
|
127
|
+
tags: json['tags'],
|
128
|
+
created: json['created']
|
129
|
+
)
|
130
|
+
}
|
131
|
+
}
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|