starkinfra 0.1.0 → 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.
- checksums.yaml +4 -4
- data/lib/brcodepreview/brcodepreview.rb +121 -0
- data/lib/cardmethod/cardmethod.rb +56 -0
- data/lib/creditnote/creditnote.rb +37 -342
- data/lib/creditnote/invoice/description.rb +51 -0
- data/lib/creditnote/invoice/discount.rb +49 -0
- data/lib/creditnote/invoice/invoice.rb +123 -0
- data/lib/creditnote/log.rb +2 -2
- data/lib/creditnote/transfer.rb +90 -0
- data/lib/creditpreview/creditnotepreview.rb +85 -0
- data/lib/creditpreview/creditpreview.rb +83 -0
- data/lib/creditsigner/creditsigner.rb +57 -0
- data/lib/dynamicbrcode/dynamicbrcode.rb +350 -0
- data/lib/event/attempt.rb +4 -3
- data/lib/event/event.rb +10 -10
- data/lib/issuingbalance/issuingbalance.rb +4 -4
- data/lib/issuingcard/issuingcard.rb +32 -29
- data/lib/issuingcard/log.rb +2 -2
- data/lib/issuingholder/issuingholder.rb +13 -8
- data/lib/issuingholder/log.rb +2 -2
- data/lib/issuinginvoice/issuinginvoice.rb +23 -9
- data/lib/issuinginvoice/log.rb +2 -2
- data/lib/{issuingbin/issuingbin.rb → issuingproduct/issuingproduct.rb} +27 -30
- data/lib/issuingpurchase/issuingpurchase.rb +99 -23
- data/lib/issuingpurchase/log.rb +1 -1
- data/lib/issuingrule/issuingrule.rb +64 -18
- data/lib/issuingtransaction/issuingtransaction.rb +5 -7
- data/lib/issuingwithdrawal/issuingwithdrawal.rb +10 -6
- 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 +3 -3
- data/lib/pixchargeback/pixchargeback.rb +32 -20
- data/lib/pixclaim/log.rb +8 -11
- data/lib/pixclaim/pixclaim.rb +42 -32
- data/lib/pixdirector/pixdirector.rb +9 -11
- data/lib/pixdomain/certificate.rb +1 -1
- data/lib/pixdomain/pixdomain.rb +4 -4
- data/lib/pixinfraction/log.rb +2 -2
- data/lib/pixinfraction/pixinfraction.rb +21 -13
- data/lib/pixkey/log.rb +5 -5
- data/lib/pixkey/pixkey.rb +10 -9
- data/lib/pixrequest/log.rb +2 -2
- data/lib/pixrequest/pixrequest.rb +51 -21
- data/lib/pixreversal/log.rb +2 -2
- data/lib/pixreversal/pixreversal.rb +48 -21
- data/lib/pixstatement/pixstatement.rb +12 -7
- data/lib/starkinfra.rb +27 -15
- data/lib/staticbrcode/staticbrcode.rb +164 -0
- data/lib/user/project.rb +1 -1
- data/lib/utils/api.rb +1 -0
- 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 +3 -3
- metadata +16 -4
- data/lib/issuingauthorization/issuingauthorization.rb +0 -141
@@ -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
|
@@ -0,0 +1,123 @@
|
|
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
|
+
# Invoice object to be issued after contract signature and paid by the credit receiver.
|
11
|
+
#
|
12
|
+
# ## Parameters (required):
|
13
|
+
# - amount [integer]: Invoice value in cents. Minimum = 1 (any value will be accepted). ex: 1234 (= R$ 12.34)
|
14
|
+
#
|
15
|
+
# ## Parameters (optional):
|
16
|
+
# - 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
|
17
|
+
# - expiration [integer, default 604800]: time interval in seconds between scheduled date and expiration date. ex 123456789
|
18
|
+
# - tags [list of strings, default nil]: list of strings for tagging. ex: tags=['employees', 'monthly']
|
19
|
+
# - descriptions [list of CreditNote::Invoice::Description objects or hash, default nil]: list Description objects. ex: [Description.new()]
|
20
|
+
#
|
21
|
+
# ## Attributes (return-only):
|
22
|
+
# - id [string]: unique id returned when Invoice is created. ex: '5656565656565656'
|
23
|
+
# - name [string]: payer name. ex: 'Iron Bank S.A.'
|
24
|
+
# - tax_id [string]: payer tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
|
25
|
+
# - pdf [string]: public Invoice PDF URL. ex: 'https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8'
|
26
|
+
# - link [string]: public Invoice webpage URL. ex: 'https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8'
|
27
|
+
# - fine [float, default 2.0]: Invoice fine for overdue payment in %. ex: 2.5
|
28
|
+
# - interest [float, default 1.0]: Invoice monthly interest in overdue payment in %. ex: 5.2
|
29
|
+
# - nominal_amount [integer]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
|
30
|
+
# - fine_amount [integer]: Invoice fine value calculated over nominal_amount. ex: 20000
|
31
|
+
# - interest_amount [integer]: Invoice interest value calculated over nominal_amount. ex: 10000
|
32
|
+
# - discount_amount [integer]: Invoice discount value calculated over nominal_amount. ex: 3000
|
33
|
+
# - discounts [list of CreditNote::Invoice::Discount objects]: list of Discount objects. ex: [Discount.new()]
|
34
|
+
# - brcode [string]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
|
35
|
+
# - status [string]: current Invoice status. ex: 'registered' or 'paid'
|
36
|
+
# - fee [integer]: fee charged by this Invoice. ex: 200 (= R$ 2.00).
|
37
|
+
# - 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']
|
38
|
+
# - created [DateTime]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
39
|
+
# - updated [DateTime]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
40
|
+
class Invoice < StarkInfra::Utils::Resource
|
41
|
+
attr_reader :amount, :id, :due, :expiration, :tags, :descriptions, :name, :tax_id, :pdf, :link, :fine, :interest,
|
42
|
+
:nominal_amount, :fine_amount, :interest_amount, :discount_amount, :discounts, :brcode, :status, :fee,
|
43
|
+
:transaction_ids, :created, :updated
|
44
|
+
def initialize(
|
45
|
+
amount:, id: nil, due: nil, expiration: nil, tags: nil, descriptions: nil, name: nil, tax_id: nil,
|
46
|
+
pdf: nil, link: nil, fine: nil, interest: nil, nominal_amount: nil, fine_amount: nil,
|
47
|
+
interest_amount: nil, discount_amount: nil, discounts: nil, brcode: nil, status: nil, fee: nil,
|
48
|
+
transaction_ids: nil, created: nil, updated: nil
|
49
|
+
)
|
50
|
+
super(id)
|
51
|
+
@tax_id = tax_id
|
52
|
+
@amount = amount
|
53
|
+
@due = due
|
54
|
+
@expiration = expiration
|
55
|
+
@tags = tags
|
56
|
+
@descriptions = Description.parse_descriptions(descriptions)
|
57
|
+
@name = name
|
58
|
+
@tax_id = tax_id
|
59
|
+
@pdf = pdf
|
60
|
+
@link = link
|
61
|
+
@fine = fine
|
62
|
+
@interest = interest
|
63
|
+
@nominal_amount = nominal_amount
|
64
|
+
@fine_amount = fine_amount
|
65
|
+
@interest_amount = interest_amount
|
66
|
+
@discount_amount = discount_amount
|
67
|
+
@discounts = Discount.parse_discounts(discounts)
|
68
|
+
@brcode = brcode
|
69
|
+
@status = status
|
70
|
+
@fee = fee
|
71
|
+
@transaction_ids = transaction_ids
|
72
|
+
@created = StarkInfra::Utils::Checks.check_datetime(created)
|
73
|
+
@updated = StarkInfra::Utils::Checks.check_datetime(updated)
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.parse_invoices(invoices)
|
77
|
+
resource_maker = StarkInfra::Invoice.resource[:resource_maker]
|
78
|
+
return invoices if invoices.nil?
|
79
|
+
|
80
|
+
parsed_invoices = []
|
81
|
+
invoices.each do |invoice|
|
82
|
+
unless invoice.is_a? Invoice
|
83
|
+
invoice = StarkInfra::Utils::API.from_api_json(resource_maker, invoice)
|
84
|
+
end
|
85
|
+
parsed_invoices << invoice
|
86
|
+
end
|
87
|
+
parsed_invoices
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.resource
|
91
|
+
{
|
92
|
+
resource_name: 'Invoice',
|
93
|
+
resource_maker: proc { |json|
|
94
|
+
Invoice.new(
|
95
|
+
id: json['id'],
|
96
|
+
amount: json['amount'],
|
97
|
+
due: json['due'],
|
98
|
+
expiration: json['expiration'],
|
99
|
+
fine: json['fine'],
|
100
|
+
interest: json['interest'],
|
101
|
+
tags: json['tags'],
|
102
|
+
descriptions: json['descriptions'],
|
103
|
+
name: json['name'],
|
104
|
+
tax_id: json['tax_id'],
|
105
|
+
pdf: json['pdf'],
|
106
|
+
link: json['link'],
|
107
|
+
nominal_amount: json['nominal_amount'],
|
108
|
+
fine_amount: json['fine_amount'],
|
109
|
+
interest_amount: json['interest_amount'],
|
110
|
+
discount_amount: json['discount_amount'],
|
111
|
+
discounts: json['discounts'],
|
112
|
+
brcode: json['brcode'],
|
113
|
+
status: json['status'],
|
114
|
+
fee: json['fee'],
|
115
|
+
transaction_ids: json['transaction_ids'],
|
116
|
+
created: json['created'],
|
117
|
+
updated: json['updated']
|
118
|
+
)
|
119
|
+
}
|
120
|
+
}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/lib/creditnote/log.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('
|
3
|
+
require_relative('creditnote')
|
4
4
|
require_relative('../utils/rest')
|
5
5
|
require_relative('../utils/checks')
|
6
|
-
require_relative('
|
6
|
+
require_relative('../utils/resource')
|
7
7
|
|
8
8
|
module StarkInfra
|
9
9
|
class CreditNote
|
@@ -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,83 @@
|
|
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
|
+
# When you initialize a CreditPreview, the entity will not be automatically
|
14
|
+
# created in the Stark Infra API. The 'create' function sends the objects
|
15
|
+
# to the Stark Infra API and returns the list of created objects.
|
16
|
+
#
|
17
|
+
# ## Parameters (required):
|
18
|
+
# - credit [CreditNotePreview object or hash]: Information preview of the informed credit.
|
19
|
+
#
|
20
|
+
# ## Parameters (conditionally required):
|
21
|
+
# - type [string]: Credit type, inferred from the payment parameter if it is not a dictionary. ex: 'credit-note'
|
22
|
+
class CreditPreview < StarkInfra::Utils::SubResource
|
23
|
+
attr_reader :credit, :type
|
24
|
+
def initialize(credit:, type: nil)
|
25
|
+
credit_info = CreditPreview.parse_credit(credit, type)
|
26
|
+
@credit = credit_info['credit']
|
27
|
+
@type = credit_info['type']
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# # Create CreditPreviews
|
32
|
+
#
|
33
|
+
# Send a list of CreditPreview objects for processing in the Stark Infra API
|
34
|
+
#
|
35
|
+
# ## Parameters (required):
|
36
|
+
# - previews [list of CreditPreview objects]: list of CreditPreview objects to be created in the API
|
37
|
+
#
|
38
|
+
# ## Parameters (optional):
|
39
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
40
|
+
#
|
41
|
+
# ## Return:
|
42
|
+
# - list of CreditPreview objects with updated attributes
|
43
|
+
def self.create(previews, user: nil)
|
44
|
+
StarkInfra::Utils::Rest.post(entities: previews, user: user, **resource)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.parse_credit(credit, type)
|
48
|
+
resource_maker = { 'credit-note' => StarkInfra::CreditNotePreview.resource[:resource_maker] }
|
49
|
+
if credit.is_a?(Hash)
|
50
|
+
begin
|
51
|
+
parsed_credit = StarkInfra::Utils::API.from_api_json(resource_maker[type], credit)
|
52
|
+
return { 'credit' => parsed_credit, 'type' => type }
|
53
|
+
|
54
|
+
rescue StandardError
|
55
|
+
return { 'credit' => credit, 'type' => type }
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
return { 'credit' => credit, 'type' => type } if type
|
61
|
+
|
62
|
+
if credit.class == StarkInfra::CreditNotePreview
|
63
|
+
return { 'credit' => credit, 'type' => 'credit-note' }
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
raise 'credit must be either ' + 'a dictionary, ' \
|
68
|
+
'a CreditNote.CreditNotePreview, but not a ' + credit.class.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.resource
|
72
|
+
{
|
73
|
+
resource_name: 'CreditPreview',
|
74
|
+
resource_maker: proc { |json|
|
75
|
+
CreditPreview.new(
|
76
|
+
credit: json['credit'],
|
77
|
+
type: json['type']
|
78
|
+
)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
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
|