starkinfra 0.1.0 → 0.3.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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcodepreview/brcodepreview.rb +125 -0
  3. data/lib/cardmethod/cardmethod.rb +56 -0
  4. data/lib/creditholmes/creditholmes.rb +160 -0
  5. data/lib/creditnote/creditnote.rb +51 -355
  6. data/lib/creditnote/invoice/description.rb +51 -0
  7. data/lib/creditnote/invoice/discount.rb +49 -0
  8. data/lib/creditnote/invoice/invoice.rb +124 -0
  9. data/lib/creditnote/log.rb +18 -19
  10. data/lib/creditnote/transfer.rb +90 -0
  11. data/lib/creditpreview/creditnotepreview.rb +85 -0
  12. data/lib/creditpreview/creditpreview.rb +77 -0
  13. data/lib/creditsigner/creditsigner.rb +57 -0
  14. data/lib/dynamicbrcode/dynamicbrcode.rb +350 -0
  15. data/lib/event/attempt.rb +5 -4
  16. data/lib/event/event.rb +11 -11
  17. data/lib/individualdocument/individualdocument.rb +165 -0
  18. data/lib/individualdocument/log.rb +125 -0
  19. data/lib/individualidentity/individualidentity.rb +193 -0
  20. data/lib/individualidentity/log.rb +124 -0
  21. data/lib/issuingbalance/issuingbalance.rb +4 -4
  22. data/lib/issuingcard/issuingcard.rb +35 -33
  23. data/lib/issuingcard/log.rb +21 -21
  24. data/lib/issuingdesign/issuingdesign.rb +138 -0
  25. data/lib/issuingembossingkit/issuingembossingkit.rb +121 -0
  26. data/lib/issuingembossingrequest/issuingembossingrequest.rb +210 -0
  27. data/lib/issuingembossingrequest/log.rb +128 -0
  28. data/lib/issuingholder/issuingholder.rb +21 -15
  29. data/lib/issuingholder/log.rb +19 -19
  30. data/lib/issuinginvoice/issuinginvoice.rb +29 -14
  31. data/lib/issuinginvoice/log.rb +18 -18
  32. data/lib/{issuingbin/issuingbin.rb → issuingproduct/issuingproduct.rb} +27 -30
  33. data/lib/issuingpurchase/issuingpurchase.rb +111 -31
  34. data/lib/issuingpurchase/log.rb +16 -16
  35. data/lib/issuingrestock/issuingrestock.rb +162 -0
  36. data/lib/issuingrestock/log.rb +127 -0
  37. data/lib/issuingrule/issuingrule.rb +64 -18
  38. data/lib/issuingstock/issuingstock.rb +138 -0
  39. data/lib/issuingstock/log.rb +130 -0
  40. data/lib/issuingtransaction/issuingtransaction.rb +12 -13
  41. data/lib/issuingwithdrawal/issuingwithdrawal.rb +12 -11
  42. data/lib/merchantcategory/merchantcategory.rb +63 -0
  43. data/lib/merchantcountry/merchantcountry.rb +59 -0
  44. data/lib/pixbalance/pixbalance.rb +5 -5
  45. data/lib/pixchargeback/log.rb +15 -15
  46. data/lib/pixchargeback/pixchargeback.rb +32 -20
  47. data/lib/pixclaim/log.rb +21 -24
  48. data/lib/pixclaim/pixclaim.rb +44 -34
  49. data/lib/pixdirector/pixdirector.rb +9 -11
  50. data/lib/pixdomain/certificate.rb +1 -1
  51. data/lib/pixdomain/pixdomain.rb +5 -5
  52. data/lib/pixinfraction/log.rb +20 -20
  53. data/lib/pixinfraction/pixinfraction.rb +23 -15
  54. data/lib/pixkey/log.rb +23 -23
  55. data/lib/pixkey/pixkey.rb +14 -12
  56. data/lib/pixrequest/log.rb +24 -20
  57. data/lib/pixrequest/pixrequest.rb +54 -21
  58. data/lib/pixreversal/log.rb +3 -3
  59. data/lib/pixreversal/pixreversal.rb +48 -21
  60. data/lib/pixstatement/pixstatement.rb +13 -8
  61. data/lib/starkinfra.rb +40 -15
  62. data/lib/staticbrcode/staticbrcode.rb +170 -0
  63. data/lib/user/project.rb +1 -1
  64. data/lib/utils/api.rb +1 -0
  65. data/lib/utils/bacenid.rb +1 -1
  66. data/lib/utils/parse.rb +7 -3
  67. data/lib/utils/request.rb +1 -1
  68. data/lib/utils/resource.rb +1 -1
  69. data/lib/utils/sub_resource.rb +21 -22
  70. data/lib/webhook/webhook.rb +11 -11
  71. metadata +29 -4
  72. data/lib/issuingauthorization/issuingauthorization.rb +0 -141
@@ -0,0 +1,124 @@
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 object
10
+ #
11
+ # Invoice issued after the contract is signed, to be paid by the credit receiver.
12
+ #
13
+ # ## Parameters (required):
14
+ # - amount [integer]: Invoice value in cents. Minimum = 1 (any value will be accepted). ex: 1234 (= R$ 12.34)
15
+ #
16
+ # ## Parameters (optional):
17
+ # - due [DateTime, Date or string, default now + 2 days]: Invoice due date in UTC ISO format. DateTime.new(2020, 3, 10, 10, 30, 0, 0) for immediate invoices and '2020-10-28' for scheduled invoices
18
+ # - expiration [integer, default 604800]: time interval in seconds between scheduled date and expiration date. ex: 123456789
19
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['employees', 'monthly']
20
+ # - descriptions [list of CreditNote::Invoice::Description objects or hash, default nil]: list Description objects. ex: [Description.new()]
21
+ #
22
+ # ## Attributes (return-only):
23
+ # - id [string]: unique id returned when Invoice is created. ex: '5656565656565656'
24
+ # - name [string]: payer name. ex: 'Iron Bank S.A.'
25
+ # - tax_id [string]: payer tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
26
+ # - pdf [string]: public Invoice PDF URL. ex: 'https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8'
27
+ # - link [string]: public Invoice webpage URL. ex: 'https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8'
28
+ # - fine [float, default 2.0]: Invoice fine for overdue payment in %. ex: 2.5
29
+ # - interest [float, default 1.0]: Invoice monthly interest in overdue payment in %. ex: 5.2
30
+ # - nominal_amount [integer]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
31
+ # - fine_amount [integer]: Invoice fine value calculated over nominal_amount. ex: 20000
32
+ # - interest_amount [integer]: Invoice interest value calculated over nominal_amount. ex: 10000
33
+ # - discount_amount [integer]: Invoice discount value calculated over nominal_amount. ex: 3000
34
+ # - discounts [list of CreditNote::Invoice::Discount objects]: list of Discount objects. ex: [Discount.new()]
35
+ # - brcode [string]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
36
+ # - status [string]: current Invoice status. ex: 'registered' or 'paid'
37
+ # - fee [integer]: fee charged by this Invoice. ex: 200 (= R$ 2.00).
38
+ # - 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']
39
+ # - created [DateTime]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
40
+ # - updated [DateTime]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
41
+ class Invoice < StarkInfra::Utils::Resource
42
+ attr_reader :amount, :id, :due, :expiration, :tags, :descriptions, :name, :tax_id, :pdf, :link, :fine, :interest,
43
+ :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :discounts, :brcode, :status, :fee,
44
+ :transaction_ids, :created, :updated
45
+ def initialize(
46
+ amount:, id: nil, due: nil, expiration: nil, tags: nil, descriptions: nil, name: nil, tax_id: nil,
47
+ pdf: nil, link: nil, fine: nil, interest: nil, nominal_amount: nil, fine_amount: nil,
48
+ interest_amount: nil, discount_amount: nil, discounts: nil, brcode: nil, status: nil, fee: nil,
49
+ transaction_ids: nil, created: nil, updated: nil
50
+ )
51
+ super(id)
52
+ @tax_id = tax_id
53
+ @amount = amount
54
+ @due = due
55
+ @expiration = expiration
56
+ @tags = tags
57
+ @descriptions = Description.parse_descriptions(descriptions)
58
+ @name = name
59
+ @tax_id = tax_id
60
+ @pdf = pdf
61
+ @link = link
62
+ @fine = fine
63
+ @interest = interest
64
+ @nominal_amount = nominal_amount
65
+ @fine_amount = fine_amount
66
+ @interest_amount = interest_amount
67
+ @discount_amount = discount_amount
68
+ @discounts = Discount.parse_discounts(discounts)
69
+ @brcode = brcode
70
+ @status = status
71
+ @fee = fee
72
+ @transaction_ids = transaction_ids
73
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
74
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
75
+ end
76
+
77
+ def self.parse_invoices(invoices)
78
+ resource_maker = StarkInfra::Invoice.resource[:resource_maker]
79
+ return invoices if invoices.nil?
80
+
81
+ parsed_invoices = []
82
+ invoices.each do |invoice|
83
+ unless invoice.is_a? Invoice
84
+ invoice = StarkInfra::Utils::API.from_api_json(resource_maker, invoice)
85
+ end
86
+ parsed_invoices << invoice
87
+ end
88
+ parsed_invoices
89
+ end
90
+
91
+ def self.resource
92
+ {
93
+ resource_name: 'Invoice',
94
+ resource_maker: proc { |json|
95
+ Invoice.new(
96
+ id: json['id'],
97
+ amount: json['amount'],
98
+ due: json['due'],
99
+ expiration: json['expiration'],
100
+ fine: json['fine'],
101
+ interest: json['interest'],
102
+ tags: json['tags'],
103
+ descriptions: json['descriptions'],
104
+ name: json['name'],
105
+ tax_id: json['tax_id'],
106
+ pdf: json['pdf'],
107
+ link: json['link'],
108
+ nominal_amount: json['nominal_amount'],
109
+ fine_amount: json['fine_amount'],
110
+ interest_amount: json['interest_amount'],
111
+ discount_amount: json['discount_amount'],
112
+ discounts: json['discounts'],
113
+ brcode: json['brcode'],
114
+ status: json['status'],
115
+ fee: json['fee'],
116
+ transaction_ids: json['transaction_ids'],
117
+ created: json['created'],
118
+ updated: json['updated']
119
+ )
120
+ }
121
+ }
122
+ end
123
+ end
124
+ end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require_relative('creditnote')
4
4
  require_relative('../utils/rest')
5
5
  require_relative('../utils/checks')
6
- require_relative('creditnote')
6
+ require_relative('../utils/resource')
7
7
 
8
8
  module StarkInfra
9
9
  class CreditNote
@@ -13,25 +13,25 @@ module StarkInfra
13
13
  # is generated for the entity. This log is never generated by the
14
14
  # user.
15
15
  #
16
- # ## Attributes:
16
+ # ## Attributes (return-only):
17
17
  # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
- # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
- # - type [string]: type of the CreditNote event which triggered the log creation. Options: 'canceled', 'created', 'expired', 'failed', 'refunded', 'registered', 'sending', 'sent', 'signed', 'success'
20
- # - errors [list of strings]: list of errors linked to this CreditNote event.
21
18
  # - note [CreditNote]: CreditNote entity to which the log refers to.
19
+ # - errors [list of strings]: list of errors linked to this CreditNote event.
20
+ # - type [string]: type of the CreditNote event which triggered the log creation. Options: 'canceled', 'created', 'expired', 'failed', 'refunded', 'registered', 'sending', 'sent', 'signed', 'success'
21
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
22
  class Log < StarkInfra::Utils::Resource
23
23
  attr_reader :id, :created, :type, :errors, :note
24
24
  def initialize(id:, created:, type:, errors:, note:)
25
25
  super(id)
26
- @created = StarkInfra::Utils::Checks.check_datetime(created)
27
- @type = type
28
- @errors = errors
29
26
  @note = note
27
+ @errors = errors
28
+ @type = type
29
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
30
30
  end
31
31
 
32
- # # Retrieve a specific Log
32
+ # # Retrieve a specific CreditNote::Log
33
33
  #
34
- # Receive a single Log object previously created by the Stark Infra API by passing its id
34
+ # Receive a single CreditNote::Log object previously created by the Stark Infra API by passing its id
35
35
  #
36
36
  # ## Parameters (required):
37
37
  # - id [string]: object unique id. ex: '5656565656565656'
@@ -45,12 +45,11 @@ module StarkInfra
45
45
  StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
46
46
  end
47
47
 
48
- # # Retrieve Logs
48
+ # # Retrieve CreditNote::Logs
49
49
  #
50
- # Receive a generator of Log objects previously created in the Stark Infra API
50
+ # Receive a generator of CreditNote::Log objects previously created in the Stark Infra API
51
51
  #
52
52
  # ## Parameters (optional):
53
- # - ids [list of strings, default nil]: Log ids to filter PixKey Logs. ex: ['5656565656565656']
54
53
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
54
  # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
55
  # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
@@ -74,9 +73,9 @@ module StarkInfra
74
73
  )
75
74
  end
76
75
 
77
- # # Retrieve paged Logs
76
+ # # Retrieve paged CreditNote::Logs
78
77
  #
79
- # Receive a list of up to 100 Log objects previously created in the Stark Infra API and the cursor to the next page.
78
+ # Receive a list of up to 100 CreditNote::Log objects previously created in the Stark Infra API and the cursor to the next page.
80
79
  # Use this function instead of query if you want to manually page your notes.
81
80
  #
82
81
  # ## Parameters (optional):
@@ -113,10 +112,10 @@ module StarkInfra
113
112
  resource_maker: proc { |json|
114
113
  Log.new(
115
114
  id: json['id'],
116
- created: json['created'],
117
- type: json['type'],
115
+ note: StarkInfra::Utils::API.from_api_json(note_maker, json['note']),
118
116
  errors: json['errors'],
119
- note: StarkInfra::Utils::API.from_api_json(note_maker, json['note'])
117
+ type: json['type'],
118
+ created: json['created']
120
119
  )
121
120
  }
122
121
  }
@@ -0,0 +1,90 @@
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::Transfer object
10
+ #
11
+ # Transfer sent to the credit receiver after the contract is signed.
12
+ #
13
+ # ## Parameters (required):
14
+ # - name [string]: receiver full name. ex: 'Anthony Edward Stark'
15
+ # - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
16
+ # - bank_code [string]: code of the receiver bank institution in Brazil. ex: '20018183'
17
+ # - branch_code [string]: receiver bank account branch. Use '-' in case there is a verifier digit. ex: '1357-9'
18
+ # - account_number [string]: receiver bank account number. Use '-' before the verifier digit. ex: '876543-2'
19
+ #
20
+ # ## Parameters (optional):
21
+ # - account_type [string, default 'checking']: Receiver bank account type. This parameter only has effect on Pix Transfers. ex: 'checking', 'savings', 'salary' or 'payment'
22
+ # - tags [list of strings, default nil]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
23
+ #
24
+ # ## Attributes (return-only):
25
+ # - id [string]: unique id returned when the transfer is created. ex: '5656565656565656'
26
+ # - amount [integer]: amount in cents to be transferred. ex: 1234 (= R$ 12.34)
27
+ # - 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'
28
+ # - scheduled [DateTime]: 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)
29
+ # - description [string]: optional description to override default description to be shown in the bank statement. ex: 'Payment for service #1234'
30
+ # - fee [integer]: fee charged when the Transfer is processed. ex: 200 (= R$ 2.00)
31
+ # - status [string]: current transfer status. ex: 'success' or 'failed'
32
+ # - transaction_ids [list of strings]: ledger Transaction IDs linked to this Transfer (if there are two, the second is the chargeback). ex: ['19827356981273']
33
+ # - created [DateTime]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ # - updated [DateTime]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
35
+ class Transfer < StarkInfra::Utils::Resource
36
+ attr_reader :id, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :tags, :amount, :external_id,
37
+ :scheduled, :description, :fee, :status, :created, :updated, :transaction_ids
38
+ def initialize(
39
+ name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil,
40
+ tags: nil, id: nil, amount: nil, external_id: nil, scheduled: nil,
41
+ description: nil, fee: nil, status: nil, created: nil, updated: nil,
42
+ transaction_ids: nil
43
+ )
44
+ super(id)
45
+ @name = name
46
+ @tax_id = tax_id
47
+ @bank_code = bank_code
48
+ @branch_code = branch_code
49
+ @account_number = account_number
50
+ @account_type = account_type
51
+ @tags = tags
52
+ @amount = amount
53
+ @external_id = external_id
54
+ @scheduled = scheduled
55
+ @description = description
56
+ @fee = fee
57
+ @status = status
58
+ @transaction_ids = transaction_ids
59
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
60
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
61
+ end
62
+
63
+ def self.resource
64
+ {
65
+ resource_name: 'Transfer',
66
+ resource_maker: proc { |json|
67
+ Transfer.new(
68
+ id: json['id'],
69
+ name: json['name'],
70
+ tax_id: json['tax_id'],
71
+ bank_code: json['bank_code'],
72
+ branch_code: json['branch_code'],
73
+ account_number: json['account_number'],
74
+ amount: json['amount'],
75
+ account_type: json['account_type'],
76
+ external_id: json['external_id'],
77
+ scheduled: json['scheduled'],
78
+ description: json['description'],
79
+ tags: json['tags'],
80
+ fee: json['fee'],
81
+ status: json['status'],
82
+ created: json['created'],
83
+ updated: json['updated'],
84
+ transaction_ids: json['transaction_ids']
85
+ )
86
+ }
87
+ }
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,85 @@
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
+ # # CreditNotePreview object
9
+ #
10
+ # A CreditNotePreview is used to preview a CCB contract between the borrower and lender with a specific table type.
11
+ #
12
+ # When you initialize a CreditPreview, the entity will not be automatically
13
+ # created in the Stark Infra API. The 'create' function sends the objects
14
+ # to the Stark Infra API and returns the list of created objects.
15
+ #
16
+ # ## Parameters (required):
17
+ # - type [string]: table type that defines the amortization system. Options: 'sac', 'price', 'american', 'bullet', 'custom'
18
+ # - nominal_amount [integer]: amount in cents transferred to the credit receiver, before deductions. ex: 11234 (= R$ 112.34)
19
+ # - scheduled [DateTime, Date or string]: date of transfer execution. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
20
+ # - tax_id [string]: credit receiver's tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
21
+ #
22
+ # ## Parameters (conditionally required):
23
+ # - invoices [list of CreditNote::Invoice objects]: list of CreditNote.Invoice objects to be created and sent to the credit receiver.
24
+ # - nominal_interest [float]: yearly nominal interest rate of the credit note, in percentage. ex: 12.5
25
+ # - initial_due [DateTime, Date or string]: date of the first invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0), Date.new(2020, 3, 10) or '2020-03-10'
26
+ # - count [integer]: quantity of invoices for payment. ex: 12
27
+ # - initial_amount [integer]: value of the first invoice in cents. ex: 1234 (= R$12.34)
28
+ # - interval [string]: interval between invoices. ex: 'year', 'month'
29
+ #
30
+ # ## Parameters (optional):
31
+ # - rebate_amount [integer, default nil]: credit analysis fee deducted from lent amount. ex: 11234 (= R$ 112.34)
32
+ #
33
+ # ## Attributes (return-only):
34
+ # - amount [integer]: credit note value in cents. ex: 1234 (= R$ 12.34)
35
+ # - interest [float]: yearly effective interest rate of the credit note, in percentage. ex: 12.5
36
+ # - tax_amount [integer]: tax amount included in the credit note. ex: 100
37
+ class CreditNotePreview < StarkInfra::Utils::SubResource
38
+ attr_reader :type, :nominal_amount, :scheduled, :tax_id, :invoices, :nominal_interest, :initial_due, :count,
39
+ :initial_amount, :interval, :rebate_amount, :amount, :interest, :tax_amount
40
+ def initialize(
41
+ type:, nominal_amount:, scheduled:, tax_id:, invoices: nil, nominal_interest: nil,
42
+ initial_due: nil, count: nil, initial_amount: nil, interval: nil, rebate_amount: nil,
43
+ amount: nil, interest: nil, tax_amount: nil
44
+ )
45
+ @type = type
46
+ @nominal_amount = nominal_amount
47
+ @scheduled = scheduled
48
+ @tax_id = tax_id
49
+ @invoices = Invoice.parse_invoices(invoices)
50
+ @nominal_interest = nominal_interest
51
+ @initial_due = initial_due
52
+ @count = count
53
+ @initial_amount = initial_amount
54
+ @interval = interval
55
+ @rebate_amount = rebate_amount
56
+ @amount = amount
57
+ @interest = interest
58
+ @tax_amount = tax_amount
59
+ end
60
+
61
+ def self.resource
62
+ {
63
+ resource_name: 'CreditNotePreview',
64
+ resource_maker: proc { |json|
65
+ CreditNotePreview.new(
66
+ type: json['type'],
67
+ nominal_amount: json['nominal_amount'],
68
+ scheduled: json['scheduled'],
69
+ tax_id: json['tax_id'],
70
+ invoices: json['invoices'],
71
+ nominal_interest: json['nominal_interest'],
72
+ initial_due: json['initial_due'],
73
+ count: json['count'],
74
+ initial_amount: json['initial_amount'],
75
+ interval: json['interval'],
76
+ rebate_amount: json['rebate_amount'],
77
+ amount: json['amount'],
78
+ interest: json['interest'],
79
+ tax_amount: json['tax_amount']
80
+ )
81
+ }
82
+ }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,77 @@
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
+ # # CreditPreview object
9
+ #
10
+ # A CreditPreview is used to get information from a credit before taking it.
11
+ # This resource can be used to preview credit notes.
12
+ #
13
+ # ## Parameters (required):
14
+ # - credit [CreditNotePreview object]: Information preview of the informed credit.
15
+ # - type [string]: Credit type. ex: "credit-note"
16
+ class CreditPreview < StarkInfra::Utils::SubResource
17
+ attr_reader :credit, :type
18
+ def initialize(credit:, type: nil)
19
+ credit_info = CreditPreview.parse_credit(credit, type)
20
+ @credit = credit_info['credit']
21
+ @type = credit_info['type']
22
+
23
+ end
24
+
25
+ # # Create CreditPreviews
26
+ #
27
+ # Send a list of CreditPreview objects for processing in the Stark Infra API
28
+ #
29
+ # ## Parameters (required):
30
+ # - previews [list of CreditPreview objects]: list of CreditPreview objects to be created in the API
31
+ #
32
+ # ## Parameters (optional):
33
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
34
+ #
35
+ # ## Return:
36
+ # - list of CreditPreview objects with updated attributes
37
+ def self.create(previews, user: nil)
38
+ StarkInfra::Utils::Rest.post(entities: previews, user: user, **resource)
39
+ end
40
+
41
+ def self.parse_credit(credit, type)
42
+ resource_maker = { 'credit-note' => StarkInfra::CreditNotePreview.resource[:resource_maker] }
43
+ if credit.is_a?(Hash)
44
+ begin
45
+ parsed_credit = StarkInfra::Utils::API.from_api_json(resource_maker[type], credit)
46
+ return { 'credit' => parsed_credit, 'type' => type }
47
+
48
+ rescue StandardError
49
+ return { 'credit' => credit, 'type' => type }
50
+
51
+ end
52
+ end
53
+
54
+ return { 'credit' => credit, 'type' => type } if type
55
+
56
+ if credit.class == StarkInfra::CreditNotePreview
57
+ return { 'credit' => credit, 'type' => 'credit-note' }
58
+
59
+ end
60
+
61
+ raise 'credit must be either ' + 'a dictionary, ' \
62
+ 'a CreditNote.CreditNotePreview, but not a ' + credit.class.to_s
63
+ end
64
+
65
+ def self.resource
66
+ {
67
+ resource_name: 'CreditPreview',
68
+ resource_maker: proc { |json|
69
+ CreditPreview.new(
70
+ credit: json['credit'],
71
+ type: json['type']
72
+ )
73
+ }
74
+ }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+ require_relative('../utils/parse')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ # # CreditSigner object
10
+ #
11
+ # CreditNote signer's information.
12
+ #
13
+ # ## Parameters (required):
14
+ # - name [string]: signer's name. ex: 'Tony Stark'
15
+ # - contact [string]: signer's contact information. ex: 'tony@starkindustries.com'
16
+ # - method [string]: delivery method for the contract. ex: 'link'
17
+ #
18
+ # ## Attributes (return-only):
19
+ # - id [string]: unique id returned when the CreditSigner is created. ex: '5656565656565656'
20
+ class CreditSigner < StarkInfra::Utils::Resource
21
+ attr_reader :name, :contact, :method, :id
22
+ def initialize(name:, contact:, method:, id: nil)
23
+ super(id)
24
+ @name = name
25
+ @contact = contact
26
+ @method = method
27
+ end
28
+
29
+ def self.parse_signers(signers)
30
+ resource_maker = StarkInfra::CreditSigner.resource[:resource_maker]
31
+ return signers if signers.nil?
32
+
33
+ parsed_signers = []
34
+ signers.each do |signer|
35
+ unless signer.is_a? CreditSigner
36
+ signer = StarkInfra::Utils::API.from_api_json(resource_maker, signer)
37
+ end
38
+ parsed_signers << signer
39
+ end
40
+ parsed_signers
41
+ end
42
+
43
+ def self.resource
44
+ {
45
+ resource_name: 'CreditSigner',
46
+ resource_maker: proc { |json|
47
+ CreditSigner.new(
48
+ id: json['id'],
49
+ name: json['name'],
50
+ contact: json['contact'],
51
+ method: json['method']
52
+ )
53
+ }
54
+ }
55
+ end
56
+ end
57
+ end