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