starkinfra 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brcodepreview/brcodepreview.rb +125 -0
- data/lib/cardmethod/cardmethod.rb +56 -0
- data/lib/creditholmes/creditholmes.rb +160 -0
- data/lib/creditnote/creditnote.rb +51 -355
- data/lib/creditnote/invoice/description.rb +51 -0
- data/lib/creditnote/invoice/discount.rb +49 -0
- data/lib/creditnote/invoice/invoice.rb +124 -0
- data/lib/creditnote/log.rb +18 -19
- data/lib/creditnote/transfer.rb +90 -0
- data/lib/creditpreview/creditnotepreview.rb +85 -0
- data/lib/creditpreview/creditpreview.rb +77 -0
- data/lib/creditsigner/creditsigner.rb +57 -0
- data/lib/dynamicbrcode/dynamicbrcode.rb +350 -0
- data/lib/event/attempt.rb +5 -4
- data/lib/event/event.rb +11 -11
- data/lib/individualdocument/individualdocument.rb +165 -0
- data/lib/individualdocument/log.rb +125 -0
- data/lib/individualidentity/individualidentity.rb +193 -0
- data/lib/individualidentity/log.rb +124 -0
- data/lib/issuingbalance/issuingbalance.rb +4 -4
- data/lib/issuingcard/issuingcard.rb +35 -33
- data/lib/issuingcard/log.rb +21 -21
- data/lib/issuingdesign/issuingdesign.rb +138 -0
- data/lib/issuingembossingkit/issuingembossingkit.rb +121 -0
- data/lib/issuingembossingrequest/issuingembossingrequest.rb +210 -0
- data/lib/issuingembossingrequest/log.rb +128 -0
- data/lib/issuingholder/issuingholder.rb +21 -15
- data/lib/issuingholder/log.rb +19 -19
- data/lib/issuinginvoice/issuinginvoice.rb +29 -14
- data/lib/issuinginvoice/log.rb +18 -18
- data/lib/{issuingbin/issuingbin.rb → issuingproduct/issuingproduct.rb} +27 -30
- data/lib/issuingpurchase/issuingpurchase.rb +111 -31
- data/lib/issuingpurchase/log.rb +16 -16
- data/lib/issuingrestock/issuingrestock.rb +162 -0
- data/lib/issuingrestock/log.rb +127 -0
- data/lib/issuingrule/issuingrule.rb +64 -18
- data/lib/issuingstock/issuingstock.rb +138 -0
- data/lib/issuingstock/log.rb +130 -0
- data/lib/issuingtransaction/issuingtransaction.rb +12 -13
- data/lib/issuingwithdrawal/issuingwithdrawal.rb +12 -11
- data/lib/merchantcategory/merchantcategory.rb +63 -0
- data/lib/merchantcountry/merchantcountry.rb +59 -0
- data/lib/pixbalance/pixbalance.rb +5 -5
- data/lib/pixchargeback/log.rb +15 -15
- data/lib/pixchargeback/pixchargeback.rb +32 -20
- data/lib/pixclaim/log.rb +21 -24
- data/lib/pixclaim/pixclaim.rb +44 -34
- data/lib/pixdirector/pixdirector.rb +9 -11
- data/lib/pixdomain/certificate.rb +1 -1
- data/lib/pixdomain/pixdomain.rb +5 -5
- data/lib/pixinfraction/log.rb +20 -20
- data/lib/pixinfraction/pixinfraction.rb +23 -15
- data/lib/pixkey/log.rb +23 -23
- data/lib/pixkey/pixkey.rb +14 -12
- data/lib/pixrequest/log.rb +24 -20
- data/lib/pixrequest/pixrequest.rb +54 -21
- data/lib/pixreversal/log.rb +3 -3
- data/lib/pixreversal/pixreversal.rb +48 -21
- data/lib/pixstatement/pixstatement.rb +13 -8
- data/lib/starkinfra.rb +40 -15
- data/lib/staticbrcode/staticbrcode.rb +170 -0
- data/lib/user/project.rb +1 -1
- data/lib/utils/api.rb +1 -0
- data/lib/utils/bacenid.rb +1 -1
- data/lib/utils/parse.rb +7 -3
- data/lib/utils/request.rb +1 -1
- data/lib/utils/resource.rb +1 -1
- data/lib/utils/sub_resource.rb +21 -22
- data/lib/webhook/webhook.rb +11 -11
- metadata +29 -4
- data/lib/issuingauthorization/issuingauthorization.rb +0 -141
@@ -1,27 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('../utils/resource')
|
4
3
|
require_relative('../utils/rest')
|
5
|
-
require_relative('../utils/checks')
|
6
4
|
require_relative('../utils/parse')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
require_relative('invoice/invoice')
|
7
|
+
require_relative('invoice/discount')
|
8
|
+
require_relative('../utils/resource')
|
9
|
+
require_relative('invoice/description')
|
10
|
+
require_relative('../creditnote/transfer')
|
7
11
|
|
8
12
|
module StarkInfra
|
9
13
|
# # CreditNote object
|
10
14
|
#
|
11
15
|
# CreditNotes are used to generate CCB contracts between you and your customers.
|
16
|
+
#
|
12
17
|
# When you initialize a CreditNote, the entity will not be automatically
|
13
18
|
# created in the Stark Infra API. The 'create' function sends the objects
|
14
19
|
# to the Stark Infra API and returns the list of created objects.
|
15
20
|
#
|
16
21
|
# ## Parameters (required):
|
17
|
-
# - template_id [string]: ID of the contract template on which the credit note will be based. ex:
|
18
|
-
# - name [string]: credit receiver's full name. ex:
|
22
|
+
# - template_id [string]: ID of the contract template on which the credit note will be based. ex: '0123456789101112'
|
23
|
+
# - name [string]: credit receiver's full name. ex: 'Edward Stark'
|
19
24
|
# - tax_id [string]: credit receiver's tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
|
20
|
-
# -
|
21
|
-
# -
|
22
|
-
# -
|
23
|
-
# -
|
24
|
-
# - signers [list of CreditNote::Signer objects]: signer's name, contact and delivery method for the signature request. ex: signers=[CreditNote::Signer.new(), CreditNote::Signer.new()]
|
25
|
+
# - scheduled [DateTime, Date or string]: date of transfer execution. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
26
|
+
# - invoices [list of CreditNote::Invoice objects]: list of Invoice objects to be created and sent to the credit receiver. ex: [Invoice.new(), Invoice.new()]
|
27
|
+
# - payment [CreditNote::Transfer object]: payment entity to be created and sent to the credit receiver. ex: Transfer.new()
|
28
|
+
# - signers [list of CreditSigner objects]: signer's name, contact and delivery method for the signature request. ex: [CreditSigner.new(), CreditSigner.new()]
|
25
29
|
# - external_id [string]: a string that must be unique among all your CreditNotes, used to avoid resource duplication. ex: 'my-internal-id-123456'
|
26
30
|
# - street_line_1 [string]: credit receiver main address. ex: 'Av. Paulista, 200'
|
27
31
|
# - street_line_2 [string]: credit receiver address complement. ex: 'Apto. 123'
|
@@ -32,43 +36,44 @@ module StarkInfra
|
|
32
36
|
#
|
33
37
|
# ## Parameters (conditionally required):
|
34
38
|
# - payment_type [string]: payment type, inferred from the payment parameter if it is not a hash. ex: 'transfer'
|
39
|
+
# - nominal_amount [integer]: CreditNote value in cents. The nominal_amount parameter is required when amount is not sent. ex: 1234 (= R$ 12.34)
|
40
|
+
# - amount [integer]: amount in cents transferred to the credit receiver, before deductions. The amount parameter is required when nominal_amount is not sent. ex: 1234 (= R$ 12.34)
|
35
41
|
#
|
36
|
-
# Parameters (optional):
|
37
|
-
# - rebate_amount [integer, default nil]: credit analysis fee deducted from lent amount. ex:
|
38
|
-
# - tags [list of strings, default nil]: list of strings for reference when searching for CreditNotes. ex:
|
42
|
+
# ## Parameters (optional):
|
43
|
+
# - rebate_amount [integer, default nil]: credit analysis fee deducted from lent amount. ex: 11234 (= R$ 112.34)
|
44
|
+
# - tags [list of strings, default nil]: list of strings for reference when searching for CreditNotes. ex: ['employees', 'monthly']
|
45
|
+
# - expiration [integer, default 604800]: time interval in seconds between scheduled date and expiration date. ex: 123456789
|
39
46
|
#
|
40
|
-
# Attributes (return-only):
|
47
|
+
# ## Attributes (return-only):
|
41
48
|
# - id [string]: unique id returned when the CreditNote is created. ex: '5656565656565656'
|
42
|
-
# - amount [integer]: CreditNote value in cents. ex: 1234 (= R$ 12.34)
|
43
|
-
# - expiration [integer]: time interval in seconds between due date and expiration date. ex: 123456789
|
44
49
|
# - document_id [string]: ID of the signed document to execute this CreditNote. ex: '4545454545454545'
|
45
50
|
# - status [string]: current status of the CreditNote. ex: 'canceled', 'created', 'expired', 'failed', 'processing', 'signed', 'success'
|
46
51
|
# - transaction_ids [list of strings]: ledger transaction ids linked to this CreditNote. ex: ['19827356981273']
|
47
52
|
# - workspace_id [string]: ID of the Workspace that generated this CreditNote. ex: '4545454545454545'
|
48
53
|
# - tax_amount [integer]: tax amount included in the CreditNote. ex: 100
|
54
|
+
# - nominal_interest [float]: yearly nominal interest rate of the CreditNote, in percentage. ex: 11.5
|
49
55
|
# - interest [float]: yearly effective interest rate of the credit note, in percentage. ex: 12.5
|
50
56
|
# - created [DateTime]: creation datetime for the CreditNote. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
51
57
|
# - updated [DateTime]: latest update datetime for the CreditNote. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
52
58
|
class CreditNote < StarkInfra::Utils::Resource
|
53
|
-
attr_reader :template_id, :name, :tax_id, :
|
54
|
-
:street_line_1, :street_line_2, :district, :city, :state_code, :zip_code, :payment_type,
|
55
|
-
:
|
56
|
-
:interest, :created, :updated
|
59
|
+
attr_reader :template_id, :name, :tax_id, :scheduled, :invoices, :payment, :signers, :external_id,
|
60
|
+
:street_line_1, :street_line_2, :district, :city, :state_code, :zip_code, :payment_type,
|
61
|
+
:nominal_amount, :amount, :rebate_amount, :tags, :expiration, :id, :document_id, :status,
|
62
|
+
:transaction_ids, :workspace_id, :tax_amount, :nominal_interest, :interest, :created, :updated
|
57
63
|
def initialize(
|
58
|
-
template_id:, name:, tax_id:,
|
59
|
-
|
60
|
-
|
61
|
-
document_id: nil, status: nil, transaction_ids: nil, workspace_id: nil, tax_amount: nil,
|
62
|
-
created: nil, updated: nil
|
64
|
+
template_id:, name:, tax_id:, scheduled:, invoices:, payment:, signers:, external_id:,
|
65
|
+
street_line_1:, street_line_2:, district:, city:, state_code:, zip_code:, payment_type: nil,
|
66
|
+
nominal_amount: nil, amount: nil, rebate_amount: nil, tags: nil, expiration: nil, id: nil,
|
67
|
+
document_id: nil, status: nil, transaction_ids: nil, workspace_id: nil, tax_amount: nil,
|
68
|
+
nominal_interest: nil, interest: nil, created: nil, updated: nil
|
63
69
|
)
|
64
70
|
super(id)
|
65
71
|
@template_id = template_id
|
66
72
|
@name = name
|
67
73
|
@tax_id = tax_id
|
68
|
-
@nominal_amount = nominal_amount
|
69
74
|
@scheduled = scheduled
|
70
|
-
@invoices =
|
71
|
-
@signers =
|
75
|
+
@invoices = Invoice.parse_invoices(invoices)
|
76
|
+
@signers = CreditSigner.parse_signers(signers)
|
72
77
|
@external_id = external_id
|
73
78
|
@street_line_1 = street_line_1
|
74
79
|
@street_line_2 = street_line_2
|
@@ -76,15 +81,17 @@ module StarkInfra
|
|
76
81
|
@city = city
|
77
82
|
@state_code = state_code
|
78
83
|
@zip_code = zip_code
|
84
|
+
@nominal_amount = nominal_amount
|
85
|
+
@amount = amount
|
79
86
|
@rebate_amount = rebate_amount
|
80
87
|
@tags = tags
|
81
|
-
@amount = amount
|
82
88
|
@expiration = expiration
|
83
89
|
@document_id = document_id
|
84
90
|
@status = status
|
85
91
|
@transaction_ids = transaction_ids
|
86
92
|
@workspace_id = workspace_id
|
87
93
|
@tax_amount = tax_amount
|
94
|
+
@nominal_interest = nominal_interest
|
88
95
|
@interest = interest
|
89
96
|
@created = StarkInfra::Utils::Checks.check_datetime(created)
|
90
97
|
@updated = StarkInfra::Utils::Checks.check_datetime(updated)
|
@@ -134,7 +141,7 @@ module StarkInfra
|
|
134
141
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
135
142
|
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
136
143
|
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
137
|
-
# - status [string, default nil]: filter for status of retrieved objects. ex:
|
144
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: ["canceled", "created", "expired", "failed", "processing", "signed", "success"]
|
138
145
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
139
146
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
140
147
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
@@ -166,7 +173,7 @@ module StarkInfra
|
|
166
173
|
# - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
|
167
174
|
# - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
168
175
|
# - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
169
|
-
# - status [string, default nil]: filter for status of retrieved objects. ex:
|
176
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: ["canceled", "created", "expired", "failed", "processing", "signed", "success"]
|
170
177
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
171
178
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
172
179
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
@@ -190,9 +197,9 @@ module StarkInfra
|
|
190
197
|
)
|
191
198
|
end
|
192
199
|
|
193
|
-
# # Cancel a
|
200
|
+
# # Cancel a CreditNote entity
|
194
201
|
#
|
195
|
-
# Cancel a
|
202
|
+
# Cancel a CreditNote entity previously created in the Stark Infra API
|
196
203
|
#
|
197
204
|
# ## Parameters (required):
|
198
205
|
# - id [string]: object unique id. ex: '5656565656565656'
|
@@ -201,26 +208,30 @@ module StarkInfra
|
|
201
208
|
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
|
202
209
|
#
|
203
210
|
# ## Return:
|
204
|
-
# - canceled CreditNote object
|
211
|
+
# - canceled CreditNote object
|
205
212
|
def self.cancel(id, user: nil)
|
206
213
|
StarkInfra::Utils::Rest.delete_id(id: id, user: user, **resource)
|
207
214
|
end
|
208
215
|
|
209
216
|
def self.parse_payment(payment, payment_type)
|
210
|
-
|
217
|
+
resource_maker = { 'transfer' => Transfer.resource[:resource_maker] }
|
211
218
|
if payment.is_a?(Hash)
|
212
219
|
begin
|
213
|
-
parsed_payment = StarkInfra::Utils::API.from_api_json(
|
220
|
+
parsed_payment = StarkInfra::Utils::API.from_api_json(resource_maker[payment_type], payment)
|
214
221
|
return { 'payment' => parsed_payment, 'payment_type' => payment_type }
|
222
|
+
|
215
223
|
rescue StandardError
|
216
224
|
return { 'payment' => payment, 'payment_type' => payment_type }
|
225
|
+
|
217
226
|
end
|
218
227
|
end
|
219
228
|
|
220
|
-
return { 'payment' => payment, 'payment_type' => payment_type} if payment_type
|
229
|
+
return { 'payment' => payment, 'payment_type' => payment_type } if payment_type
|
230
|
+
|
221
231
|
if payment.class == StarkInfra::Transfer
|
222
|
-
return { 'payment' => payment, 'payment_type' => 'transfer'}
|
232
|
+
return { 'payment' => payment, 'payment_type' => 'transfer' }
|
223
233
|
end
|
234
|
+
|
224
235
|
raise 'payment must be either ' + 'a dictionary, ' \
|
225
236
|
'a CreditNote.Transfer, but not a ' + payment.class.to_s
|
226
237
|
end
|
@@ -234,7 +245,6 @@ module StarkInfra
|
|
234
245
|
template_id: json['template_id'],
|
235
246
|
name: json['name'],
|
236
247
|
tax_id: json['tax_id'],
|
237
|
-
nominal_amount: json['nominal_amount'],
|
238
248
|
scheduled: json['scheduled'],
|
239
249
|
invoices: json['invoices'],
|
240
250
|
payment: json['payment'],
|
@@ -247,15 +257,17 @@ module StarkInfra
|
|
247
257
|
state_code: json['state_code'],
|
248
258
|
zip_code: json['zip_code'],
|
249
259
|
payment_type: json['payment_type'],
|
260
|
+
nominal_amount: json['nominal_amount'],
|
261
|
+
amount: json['amount'],
|
250
262
|
rebate_amount: json['rebate_amount'],
|
251
263
|
tags: json['tags'],
|
252
|
-
amount: json['amount'],
|
253
264
|
expiration: json['expiration'],
|
254
265
|
document_id: json['document_id'],
|
255
266
|
status: json['status'],
|
256
267
|
transaction_ids: json['transaction_ids'],
|
257
268
|
workspace_id: json['workspace_id'],
|
258
269
|
tax_amount: json['tax_amount'],
|
270
|
+
nominal_interest: json['nominal_interest'],
|
259
271
|
interest: json['interest'],
|
260
272
|
created: json['created'],
|
261
273
|
updated: json['updated']
|
@@ -263,321 +275,5 @@ module StarkInfra
|
|
263
275
|
}
|
264
276
|
}
|
265
277
|
end
|
266
|
-
|
267
|
-
# # CreditNote::Transfer object
|
268
|
-
#
|
269
|
-
# Transfer sent to the credit receiver after the contract is signed.
|
270
|
-
#
|
271
|
-
# ## Parameters (required):
|
272
|
-
# - name [string]: receiver full name. ex: 'Anthony Edward Stark'
|
273
|
-
# - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
|
274
|
-
# - bank_code [string]: code of the receiver bank institution in Brazil. ex: '20018183'
|
275
|
-
# - branch_code [string]: receiver bank account branch. Use '-' in case there is a verifier digit. ex: '1357-9'
|
276
|
-
# - account_number [string]: receiver bank account number. Use '-' before the verifier digit. ex: '876543-2'
|
277
|
-
#
|
278
|
-
# ## Parameters (optional):
|
279
|
-
# - account_type [string, default 'checking']: Receiver bank account type. This parameter only has effect on Pix Transfers. ex: 'checking', 'savings', 'salary' or 'payment'
|
280
|
-
# - tags [list of strings, default nil]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
|
281
|
-
#
|
282
|
-
# ## Attributes (return-only):
|
283
|
-
# - amount [integer]: amount in cents to be transferred. ex: 1234 (= R$ 12.34)
|
284
|
-
# - external_id [string]: url safe string that must be unique among all your transfers. Duplicated external_ids will cause failures. By default, this parameter will block any transfer that repeats amount and receiver information on the same date. ex: 'my-internal-id-123456'
|
285
|
-
# - scheduled [DateTime, Date or string]: date or datetime when the transfer will be processed. May be pushed to next business day if necessary. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
286
|
-
# - description [string]: optional description to override default description to be shown in the bank statement. ex: 'Payment for service #1234'
|
287
|
-
# - id [string]: unique id returned when the transfer is created. ex: '5656565656565656'
|
288
|
-
# - fee [integer]: fee charged when the Transfer is processed. ex: 200 (= R$ 2.00)
|
289
|
-
# - status [string]: current transfer status. ex: 'success' or 'failed'
|
290
|
-
# - transaction_ids [list of strings]: ledger Transaction IDs linked to this Transfer (if there are two, the second is the chargeback). ex: ['19827356981273']
|
291
|
-
# - created [DateTime]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
292
|
-
# - updated [DateTime]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
293
|
-
class Transfer < StarkInfra::Utils::Resource
|
294
|
-
attr_reader :tax_id, :name, :bank_code, :branch_code, :account_number, :amount, :account_type, :external_id, :scheduled, :description, :tags, :fee, :status, :created, :updated, :transaction_ids
|
295
|
-
def initialize(
|
296
|
-
name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil,
|
297
|
-
tags: nil, id: nil, amount: nil, external_id: nil, scheduled: nil,
|
298
|
-
description: nil, fee: nil, status: nil, created: nil, updated: nil,
|
299
|
-
transaction_ids: nil
|
300
|
-
)
|
301
|
-
super(id)
|
302
|
-
@name = name
|
303
|
-
@tax_id = tax_id
|
304
|
-
@bank_code = bank_code
|
305
|
-
@branch_code = branch_code
|
306
|
-
@account_number = account_number
|
307
|
-
@account_type = account_type
|
308
|
-
@tags = tags
|
309
|
-
@amount = amount
|
310
|
-
@external_id = external_id
|
311
|
-
@scheduled = scheduled
|
312
|
-
@description = description
|
313
|
-
@fee = fee
|
314
|
-
@status = status
|
315
|
-
@transaction_ids = transaction_ids
|
316
|
-
@created = StarkInfra::Utils::Checks.check_datetime(created)
|
317
|
-
@updated = StarkInfra::Utils::Checks.check_datetime(updated)
|
318
|
-
end
|
319
|
-
|
320
|
-
def self.resource
|
321
|
-
{
|
322
|
-
resource_name: 'Transfer',
|
323
|
-
resource_maker: proc { |json|
|
324
|
-
Transfer.new(
|
325
|
-
id: json['id'],
|
326
|
-
tax_id: json['tax_id'],
|
327
|
-
name: json['name'],
|
328
|
-
bank_code: json['bank_code'],
|
329
|
-
branch_code: json['branch_code'],
|
330
|
-
account_number: json['account_number'],
|
331
|
-
amount: json['amount'],
|
332
|
-
account_type: json['account_type'],
|
333
|
-
external_id: json['external_id'],
|
334
|
-
scheduled: json['scheduled'],
|
335
|
-
description: json['description'],
|
336
|
-
tags: json['tags'],
|
337
|
-
fee: json['fee'],
|
338
|
-
status: json['status'],
|
339
|
-
created: json['created'],
|
340
|
-
updated: json['updated'],
|
341
|
-
transaction_ids: json['transaction_ids']
|
342
|
-
)
|
343
|
-
}
|
344
|
-
}
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
# # CreditNote::Signer object
|
349
|
-
#
|
350
|
-
# The Signer object stores the CreditNote signer's information.
|
351
|
-
#
|
352
|
-
# ## Parameters (required):
|
353
|
-
# - name [string]: signer's name. ex: 'Tony Stark'
|
354
|
-
# - contact [string]: signer's contact information. ex: 'tony@starkindustries.com'
|
355
|
-
# - method [string]: delivery method for the contract. ex: 'link'
|
356
|
-
class Signer < StarkInfra::Utils::SubResource
|
357
|
-
attr_reader :name, :contact, :method
|
358
|
-
def initialize(name:, contact:, method:)
|
359
|
-
@name = name
|
360
|
-
@contact = contact
|
361
|
-
@method = method
|
362
|
-
end
|
363
|
-
|
364
|
-
def self.parse_signers(signers)
|
365
|
-
return signers if signers.nil?
|
366
|
-
|
367
|
-
parsed_signers = []
|
368
|
-
signers.each do |signer|
|
369
|
-
unless signer.is_a? Signer
|
370
|
-
signer = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], signer)
|
371
|
-
end
|
372
|
-
parsed_signers << signer
|
373
|
-
end
|
374
|
-
parsed_signers
|
375
|
-
end
|
376
|
-
|
377
|
-
def self.resource
|
378
|
-
{
|
379
|
-
resource_name: 'Signer',
|
380
|
-
resource_maker: proc { |json|
|
381
|
-
Signer.new(
|
382
|
-
name: json['name'],
|
383
|
-
contact: json['contact'],
|
384
|
-
method: json['method']
|
385
|
-
)
|
386
|
-
}
|
387
|
-
}
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
# CreditNote::Invoice object
|
392
|
-
# Invoice object to be issued after contract signature and paid by the credit receiver.
|
393
|
-
#
|
394
|
-
# ## Parameters (required):
|
395
|
-
# - amount [integer]: Invoice value in cents. Minimum = 1 (any value will be accepted). ex: 1234 (= R$ 12.34)
|
396
|
-
#
|
397
|
-
# ## Parameters (optional):
|
398
|
-
# - due [DateTime, Date or string, default now + 2 days]: Invoice due date in UTC ISO format. ex: '2020-10-28T17:59:26.249976+00:00' for immediate invoices and '2020-10-28' for scheduled invoices
|
399
|
-
# - expiration [integer, default 5097600 (59 days)]: time interval in seconds between due date and expiration date. ex: 123456789
|
400
|
-
# - fine [float, default 2.0]: Invoice fine for overdue payment in %. ex: 2.5
|
401
|
-
# - interest [float, default 1.0]: Invoice monthly interest in overdue payment in %. ex: 5.2
|
402
|
-
# - tags [list of strings, default nil]: list of strings for tagging
|
403
|
-
# - descriptions [list of CreditNote::Invoice::Description objects, default nil]: list Description objects. ex: [CreditNote::Invoice::Description.new()]
|
404
|
-
#
|
405
|
-
# ## Attributes (return-only):
|
406
|
-
# - id [string]: unique id returned when Invoice is created. ex: '5656565656565656'
|
407
|
-
# - name [string]: payer name. ex: 'Iron Bank S.A.'
|
408
|
-
# - tax_id [string]: payer tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
|
409
|
-
# - pdf [string]: public Invoice PDF URL. ex: 'https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8'
|
410
|
-
# - link [string]: public Invoice webpage URL. ex: 'https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8'
|
411
|
-
# - nominal_amount [integer]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
|
412
|
-
# - fine_amount [integer]: Invoice fine value calculated over nominal_amount. ex: 20000
|
413
|
-
# - interest_amount [integer]: Invoice interest value calculated over nominal_amount. ex: 10000
|
414
|
-
# - discount_amount [integer]: Invoice discount value calculated over nominal_amount. ex: 3000
|
415
|
-
# - discounts [list of CreditNote::Invoice::Discount objects]: list of Discount objects. ex: [CreditNote::Invoice::Discount.new()]
|
416
|
-
# - brcode [string]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
|
417
|
-
# - status [string]: current Invoice status. ex: 'registered' or 'paid'
|
418
|
-
# - fee [integer]: fee charged by this Invoice. ex: 200 (= R$ 2.00)
|
419
|
-
# - transaction_ids [list of strings]: ledger transaction ids linked to this Invoice (if there are more than one, all but the first are reversals or failed reversal chargebacks). ex: ['19827356981273']
|
420
|
-
# - created [DateTime]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
421
|
-
# - updated [DateTime]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
422
|
-
class Invoice < StarkInfra::Utils::Resource
|
423
|
-
attr_reader :id, :amount, :due, :expiration, :fine, :interest, :tags, :descriptions, :name, :tax_id, :pdf, :link, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :discounts, :brcode, :status, :fee, :transaction_ids, :created, :updated
|
424
|
-
def initialize(
|
425
|
-
amount:, due: nil, expiration: nil, fine: nil, interest: nil, tags: nil, descriptions: nil,
|
426
|
-
id: nil, name: nil, tax_id: nil, pdf: nil, link: nil, nominal_amount: nil, fine_amount: nil,
|
427
|
-
interest_amount: nil, discount_amount: nil, discounts: nil, brcode: nil, status: nil, fee: nil,
|
428
|
-
transaction_ids: nil, created: nil, updated: nil
|
429
|
-
)
|
430
|
-
super(id)
|
431
|
-
@tax_id = tax_id
|
432
|
-
@amount = amount
|
433
|
-
@due = due
|
434
|
-
@expiration = expiration
|
435
|
-
@fine = fine
|
436
|
-
@interest = interest
|
437
|
-
@tags = tags
|
438
|
-
@descriptions = Description.parse_descriptions(descriptions)
|
439
|
-
@name = name
|
440
|
-
@tax_id = tax_id
|
441
|
-
@pdf = pdf
|
442
|
-
@link = link
|
443
|
-
@nominal_amount = nominal_amount
|
444
|
-
@fine_amount = fine_amount
|
445
|
-
@interest_amount = interest_amount
|
446
|
-
@discount_amount = discount_amount
|
447
|
-
@discounts = Discount.parse_discounts(discounts)
|
448
|
-
@brcode = brcode
|
449
|
-
@status = status
|
450
|
-
@fee = fee
|
451
|
-
@transaction_ids = transaction_ids
|
452
|
-
@created = StarkInfra::Utils::Checks.check_datetime(created)
|
453
|
-
@updated = StarkInfra::Utils::Checks.check_datetime(updated)
|
454
|
-
end
|
455
|
-
|
456
|
-
def self.parse_invoices(invoices)
|
457
|
-
return invoices if invoices.nil?
|
458
|
-
parsed_invoices = []
|
459
|
-
invoices.each do |invoice|
|
460
|
-
unless invoice.is_a? Invoice
|
461
|
-
invoice = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], invoice)
|
462
|
-
end
|
463
|
-
parsed_invoices << invoice
|
464
|
-
end
|
465
|
-
parsed_invoices
|
466
|
-
end
|
467
|
-
|
468
|
-
def self.resource
|
469
|
-
{
|
470
|
-
resource_name: 'Invoice',
|
471
|
-
resource_maker: proc { |json|
|
472
|
-
Invoice.new(
|
473
|
-
id: json['id'],
|
474
|
-
amount: json['amount'],
|
475
|
-
due: json['due'],
|
476
|
-
expiration: json['expiration'],
|
477
|
-
fine: json['fine'],
|
478
|
-
interest: json['interest'],
|
479
|
-
tags: json['tags'],
|
480
|
-
descriptions: json['descriptions'],
|
481
|
-
name: json['name'],
|
482
|
-
tax_id: json['tax_id'],
|
483
|
-
pdf: json['pdf'],
|
484
|
-
link: json['link'],
|
485
|
-
nominal_amount: json['nominal_amount'],
|
486
|
-
fine_amount: json['fine_amount'],
|
487
|
-
interest_amount: json['interest_amount'],
|
488
|
-
discount_amount: json['discount_amount'],
|
489
|
-
discounts: json['discounts'],
|
490
|
-
brcode: json['brcode'],
|
491
|
-
status: json['status'],
|
492
|
-
fee: json['fee'],
|
493
|
-
transaction_ids: json['transaction_ids'],
|
494
|
-
created: json['created'],
|
495
|
-
updated: json['updated']
|
496
|
-
)
|
497
|
-
}
|
498
|
-
}
|
499
|
-
end
|
500
|
-
|
501
|
-
# # CreditNote::Invoice::Discount object
|
502
|
-
#
|
503
|
-
# Invoice discount information.
|
504
|
-
#
|
505
|
-
# ## Parameters (required):
|
506
|
-
# - percentage [float]: percentage of discount applied until specified due date
|
507
|
-
# - due [DateTime or string]: due datetime for the discount
|
508
|
-
class Discount < StarkInfra::Utils::SubResource
|
509
|
-
attr_reader :percentage, :due
|
510
|
-
def initialize(percentage:, due:)
|
511
|
-
@percentage = percentage
|
512
|
-
@due = due
|
513
|
-
end
|
514
|
-
|
515
|
-
def self.parse_discounts(discounts)
|
516
|
-
return discounts if discounts.nil?
|
517
|
-
|
518
|
-
parsed_discounts = []
|
519
|
-
discounts.each do |discount|
|
520
|
-
unless discount.is_a? Discount
|
521
|
-
discount = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], discount)
|
522
|
-
end
|
523
|
-
parsed_discounts << discount
|
524
|
-
end
|
525
|
-
parsed_discounts
|
526
|
-
end
|
527
|
-
|
528
|
-
def self.resource
|
529
|
-
{
|
530
|
-
resource_name: 'Discount',
|
531
|
-
resource_maker: proc { |json|
|
532
|
-
Discount.new(
|
533
|
-
percentage: json['percentage'],
|
534
|
-
due: json['due']
|
535
|
-
)
|
536
|
-
}
|
537
|
-
}
|
538
|
-
end
|
539
|
-
end
|
540
|
-
|
541
|
-
# # CreditNote::Invoice::Description object
|
542
|
-
#
|
543
|
-
# Invoice description information.
|
544
|
-
#
|
545
|
-
# ## Parameters (required):
|
546
|
-
# - key [string]: Description for the value. ex: 'Taxes'
|
547
|
-
#
|
548
|
-
# ## Parameters (optional):
|
549
|
-
# - value [string]: amount related to the described key. ex: 'R$100,00'
|
550
|
-
class Description < StarkInfra::Utils::SubResource
|
551
|
-
attr_reader :percentage, :due
|
552
|
-
def initialize(key:, value:)
|
553
|
-
@key = key
|
554
|
-
@value = value
|
555
|
-
end
|
556
|
-
|
557
|
-
def self.parse_descriptions(descriptions)
|
558
|
-
return descriptions if descriptions.nil?
|
559
|
-
parsed_descriptions = []
|
560
|
-
descriptions.each do |description|
|
561
|
-
unless description.is_a? Description
|
562
|
-
description = StarkInfra::Utils::API.from_api_json(resource[:resource_maker], description)
|
563
|
-
end
|
564
|
-
parsed_descriptions << description
|
565
|
-
end
|
566
|
-
parsed_descriptions
|
567
|
-
end
|
568
|
-
|
569
|
-
def self.resource
|
570
|
-
{
|
571
|
-
resource_name: 'Description',
|
572
|
-
resource_maker: proc { |json|
|
573
|
-
Description.new(
|
574
|
-
key: json['key'],
|
575
|
-
value: json['value']
|
576
|
-
)
|
577
|
-
}
|
578
|
-
}
|
579
|
-
end
|
580
|
-
end
|
581
|
-
end
|
582
278
|
end
|
583
279
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../../utils/api')
|
4
|
+
require_relative('../../utils/rest')
|
5
|
+
require_relative('../../utils/sub_resource')
|
6
|
+
|
7
|
+
module StarkInfra
|
8
|
+
|
9
|
+
# CreditNote::Invoice::Description object
|
10
|
+
#
|
11
|
+
# Invoice description information.
|
12
|
+
#
|
13
|
+
# ## Parameters (required):
|
14
|
+
# - key [string]: Description for the value. ex: 'Taxes'
|
15
|
+
#
|
16
|
+
# ## Parameters (optional):
|
17
|
+
# - value [string, default nil]: amount related to the described key. ex: 'R$100,00'
|
18
|
+
class Description < StarkInfra::Utils::SubResource
|
19
|
+
attr_reader :percentage, :due
|
20
|
+
def initialize(key:, value: nil)
|
21
|
+
@key = key
|
22
|
+
@value = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_descriptions(descriptions)
|
26
|
+
resource_maker = StarkInfra::Description.resource[:resource_maker]
|
27
|
+
return descriptions if descriptions.nil?
|
28
|
+
|
29
|
+
parsed_descriptions = []
|
30
|
+
descriptions.each do |description|
|
31
|
+
unless description.is_a? Description
|
32
|
+
description = StarkInfra::Utils::API.from_api_json(resource_maker, description)
|
33
|
+
end
|
34
|
+
parsed_descriptions << description
|
35
|
+
end
|
36
|
+
parsed_descriptions
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.resource
|
40
|
+
{
|
41
|
+
resource_name: 'Description',
|
42
|
+
resource_maker: proc { |json|
|
43
|
+
Description.new(
|
44
|
+
key: json['key'],
|
45
|
+
value: json['value']
|
46
|
+
)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../../utils/api')
|
4
|
+
require_relative('../../utils/rest')
|
5
|
+
require_relative('../../utils/sub_resource')
|
6
|
+
|
7
|
+
module StarkInfra
|
8
|
+
|
9
|
+
# # CreditNote::Invoice::Discount object
|
10
|
+
#
|
11
|
+
# Invoice discount information.
|
12
|
+
#
|
13
|
+
# ## Parameters (required):
|
14
|
+
# - percentage [float]: percentage of discount applied until specified due date.
|
15
|
+
# - due [DateTime or string]: due datetime for the discount. ex: '2020-03-10T10:30:00.000000+00:00' or DateTime.new(2020, 3, 10, 10, 30, 0, 0).
|
16
|
+
class Discount < StarkInfra::Utils::SubResource
|
17
|
+
attr_reader :percentage, :due
|
18
|
+
def initialize(percentage:, due:)
|
19
|
+
@percentage = percentage
|
20
|
+
@due = due
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.parse_discounts(discounts)
|
24
|
+
resource_maker = StarkInfra::Discount.resource[:resource_maker]
|
25
|
+
return discounts if discounts.nil?
|
26
|
+
|
27
|
+
parsed_discounts = []
|
28
|
+
discounts.each do |discount|
|
29
|
+
unless discount.is_a? Discount
|
30
|
+
discount = StarkInfra::Utils::API.from_api_json(resource_maker, discount)
|
31
|
+
end
|
32
|
+
parsed_discounts << discount
|
33
|
+
end
|
34
|
+
parsed_discounts
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.resource
|
38
|
+
{
|
39
|
+
resource_name: 'Discount',
|
40
|
+
resource_maker: proc { |json|
|
41
|
+
Discount.new(
|
42
|
+
percentage: json['percentage'],
|
43
|
+
due: json['due']
|
44
|
+
)
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|