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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 407cfd041d62916d22344d376a24ff392b4ef1fcf38cf3ae1c6ab38f01916e3a
|
4
|
+
data.tar.gz: 29d6b4e29af482ce49862a6e77eb72c570bad1844e66fcf1171f6148497179ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4a549b1f028df0b976c790587c5f7c3989a5290f356e93816aa6051537241f6a490617c5cd19fabf6755ec31ec9a085b1049907d2b6df35d342def6e0b065b8
|
7
|
+
data.tar.gz: 22556e362fb270328d57d12875797961ecb06bf87f2e19a15fa6a37b598c4d37fe76209f0a9be93289ce68c0e6c82f63fc6156745b93eb662403bb73671f618a
|
@@ -0,0 +1,121 @@
|
|
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
|
+
# # BrcodePreview object
|
10
|
+
#
|
11
|
+
# A BrcodePreview is used to get information from a BR Code you received to check the information before paying it.
|
12
|
+
#
|
13
|
+
# When you initialize a BrcodePreview, 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
|
+
# - id [string]: BR Code string for the Pix payment. This is also de information directly encoded in a QR Code. ex: '00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A'
|
19
|
+
#
|
20
|
+
# Attributes (return-only):
|
21
|
+
# - account_number [string]: Payment receiver account number. ex: '1234567'
|
22
|
+
# - account_type [string]: Payment receiver account type. ex: 'checking'
|
23
|
+
# - amount [integer]: Value in cents that this payment is expecting to receive. If 0, any value is accepted. ex: 123 (= R$1,23)
|
24
|
+
# - amount_type [string]: amount type of the BR Code. If the amount type is 'custom' the BR Code's amount can be changed by the sender at the moment of payment. Options: 'fixed' or 'custom'
|
25
|
+
# - bank_code [string]: Payment receiver bank code. ex: '20018183'
|
26
|
+
# - branch_code [string]: Payment receiver branch code. ex: '0001'
|
27
|
+
# - cash_amount [integer]: Amount to be withdrawn from the cashier in cents. ex: 1000 (= R$ 10.00)
|
28
|
+
# - cashier_bank_code [string]: Cashier's bank code. ex: '20018183'
|
29
|
+
# - cashier_type [string]: Cashier's type. Options: 'merchant', 'participant' and 'other'
|
30
|
+
# - discount_amount [integer]: Discount value calculated over nominal_amount. ex: 3000
|
31
|
+
# - fine_amount [integer]: Fine value calculated over nominal_amount. ex: 20000
|
32
|
+
# - key_id [string]: Receiver's PixKey id. ex: '+5511989898989'
|
33
|
+
# - interest_amount [integer]: Interest value calculated over nominal_amount. ex: 10000
|
34
|
+
# - name [string]: Payment receiver name. ex: 'Tony Stark'
|
35
|
+
# - nominal_amount [integer]: BR Code emission amount, without fines, fees and discounts. ex: 1234 (= R$ 12.34)
|
36
|
+
# - reconciliation_id [string]: Reconciliation ID linked to this payment. If the BR Code is dynamic, the reconciliation_id will have from 26 to 35 alphanumeric characters, ex: 'cd65c78aeb6543eaaa0170f68bd741ee'. If the brcode is static, the reconciliation_id will have up to 25 alphanumeric characters 'ah27s53agj6493hjds6836v49'
|
37
|
+
# - reduction_amount [integer]: Reduction value to discount from nominal_amount. ex: 1000
|
38
|
+
# - scheduled [DateTime]: date of payment execution. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0).
|
39
|
+
# - status [string]: Payment status. ex: 'active', 'paid', 'canceled' or 'unknown'
|
40
|
+
# - tax_id [string]: Payment receiver tax ID. ex: '012.345.678-90'
|
41
|
+
class BrcodePreview < StarkInfra::Utils::Resource
|
42
|
+
attr_reader :id, :account_number, :account_type, :amount, :amount_type, :bank_code, :branch_code, :cash_amount,
|
43
|
+
:cashier_bank_code, :cashier_type, :discount_amount, :fine_amount, :key_id, :interest_amount, :name,
|
44
|
+
:nominal_amount, :reconciliation_id, :reduction_amount, :scheduled, :status, :tax_id
|
45
|
+
def initialize(
|
46
|
+
id:, account_number: nil, account_type: nil, amount: nil, amount_type: nil, bank_code: nil,
|
47
|
+
branch_code: nil, cash_amount: nil, cashier_bank_code:nil, cashier_type:nil, discount_amount: nil,
|
48
|
+
fine_amount: nil, key_id: nil, interest_amount: nil, name: nil, nominal_amount: nil,
|
49
|
+
reconciliation_id: nil, reduction_amount: nil, scheduled: nil, status: nil, tax_id: nil
|
50
|
+
)
|
51
|
+
super(id)
|
52
|
+
@account_number = account_number
|
53
|
+
@account_type = account_type
|
54
|
+
@amount = amount
|
55
|
+
@amount_type = amount_type
|
56
|
+
@bank_code = bank_code
|
57
|
+
@branch_code = branch_code
|
58
|
+
@cash_amount = cash_amount
|
59
|
+
@cashier_bank_code = cashier_bank_code
|
60
|
+
@cashier_type = cashier_type
|
61
|
+
@discount_amount = discount_amount
|
62
|
+
@fine_amount = fine_amount
|
63
|
+
@key_id = key_id
|
64
|
+
@interest_amount = interest_amount
|
65
|
+
@name = name
|
66
|
+
@nominal_amount = nominal_amount
|
67
|
+
@reconciliation_id = reconciliation_id
|
68
|
+
@reduction_amount = reduction_amount
|
69
|
+
@scheduled = scheduled
|
70
|
+
@status = status
|
71
|
+
@tax_id = tax_id
|
72
|
+
end
|
73
|
+
|
74
|
+
# # Retrieve BrcodePreviews
|
75
|
+
#
|
76
|
+
# Process BR Codes before paying them.
|
77
|
+
#
|
78
|
+
# ## Parameters (required):
|
79
|
+
# - previews [list of BrcodePreview objects]: List of BrcodePreview objects to preview. ex: [starkinfra.BrcodePreview('00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A')]
|
80
|
+
#
|
81
|
+
# ## Parameters (optional):
|
82
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
83
|
+
#
|
84
|
+
# ## Return:
|
85
|
+
# - list of BrcodePreview objects with updated attributes
|
86
|
+
def self.create(previews, user: nil)
|
87
|
+
StarkInfra::Utils::Rest.post(entities: previews, user: user, **resource)
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.resource
|
91
|
+
{
|
92
|
+
resource_name: 'BrcodePreview',
|
93
|
+
resource_maker: proc { |json|
|
94
|
+
BrcodePreview.new(
|
95
|
+
id: json['id'],
|
96
|
+
account_number: json['account_number'],
|
97
|
+
account_type: json['account_type'],
|
98
|
+
amount: json['amount'],
|
99
|
+
amount_type: json['amount_type'],
|
100
|
+
bank_code: json['bank_code'],
|
101
|
+
branch_code: json['branch_code'],
|
102
|
+
cash_amount: json['cash_amount'],
|
103
|
+
cashier_bank_code: json['cashier_bank_code'],
|
104
|
+
cashier_type: json['cashier_type'],
|
105
|
+
discount_amount: json['discount_amount'],
|
106
|
+
fine_amount: json['fine_amount'],
|
107
|
+
key_id: json['key_id'],
|
108
|
+
interest_amount: json['interest_amount'],
|
109
|
+
name: json['name'],
|
110
|
+
nominal_amount: json['nominal_amount'],
|
111
|
+
reconciliation_id: json['reconciliation_id'],
|
112
|
+
reduction_amount: json['reduction_amount'],
|
113
|
+
scheduled: json['scheduled'],
|
114
|
+
status: json['status'],
|
115
|
+
tax_id: json['tax_id']
|
116
|
+
)
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/rest')
|
4
|
+
require_relative('../utils/sub_resource')
|
5
|
+
|
6
|
+
module StarkInfra
|
7
|
+
# # CardMethod object
|
8
|
+
#
|
9
|
+
# CardMethod's codes are used to define method filters in IssuingRules.
|
10
|
+
#
|
11
|
+
# ## Parameters (required):
|
12
|
+
# - code [string]: method's code. Options: 'chip', 'token', 'server', 'manual', 'magstripe', 'contactless'
|
13
|
+
#
|
14
|
+
# Attributes (return-only):
|
15
|
+
# - name [string]: method's name. ex: 'token'
|
16
|
+
# - number [string]: method's number. ex: '81'
|
17
|
+
class CardMethod < StarkInfra::Utils::SubResource
|
18
|
+
attr_reader :code, :name, :number
|
19
|
+
def initialize(code:, name: nil, number: nil)
|
20
|
+
@code = code
|
21
|
+
@name = name
|
22
|
+
@number = number
|
23
|
+
end
|
24
|
+
|
25
|
+
# # Retrieve CardMethods
|
26
|
+
#
|
27
|
+
# Receive a generator of CardMethod objects available in the Stark Infra API
|
28
|
+
#
|
29
|
+
# ## Parameters (optional):
|
30
|
+
# - search [string, default nil]: keyword to search for code, name, number or short_code. ex: 'token'
|
31
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
|
32
|
+
#
|
33
|
+
# ## Return:
|
34
|
+
# - generator of CardMethod objects with updated attributes
|
35
|
+
def self.query(search: nil, user: nil)
|
36
|
+
StarkInfra::Utils::Rest.get_stream(
|
37
|
+
search: search,
|
38
|
+
user: user,
|
39
|
+
**resource
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.resource
|
44
|
+
{
|
45
|
+
resource_name: 'CardMethod',
|
46
|
+
resource_maker: proc { |json|
|
47
|
+
CardMethod.new(
|
48
|
+
code: json['code'],
|
49
|
+
name: json['name'],
|
50
|
+
number: json['number']
|
51
|
+
)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,27 +1,32 @@
|
|
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
|
-
# - nominal_amount [integer]: amount in cents transferred to the credit receiver, before deductions. ex:
|
21
|
-
# - scheduled [DateTime, Date or string
|
22
|
-
# - invoices [list of CreditNote::Invoice objects]: list of Invoice objects to be created and sent to the credit receiver. ex:
|
23
|
-
# - payment [CreditNote::Transfer object]: payment entity to be created and sent to the credit receiver. ex:
|
24
|
-
# - signers [list of
|
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'
|
26
31
|
# - street_line_1 [string]: credit receiver main address. ex: 'Av. Paulista, 200'
|
27
32
|
# - street_line_2 [string]: credit receiver address complement. ex: 'Apto. 123'
|
@@ -33,33 +38,34 @@ module StarkInfra
|
|
33
38
|
# ## Parameters (conditionally required):
|
34
39
|
# - payment_type [string]: payment type, inferred from the payment parameter if it is not a hash. ex: 'transfer'
|
35
40
|
#
|
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:
|
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
|
39
45
|
#
|
40
|
-
# Attributes (return-only):
|
46
|
+
# ## Attributes (return-only):
|
41
47
|
# - id [string]: unique id returned when the CreditNote is created. ex: '5656565656565656'
|
42
48
|
# - 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
59
|
attr_reader :template_id, :name, :tax_id, :nominal_amount, :scheduled, :invoices, :payment, :signers, :external_id,
|
54
60
|
:street_line_1, :street_line_2, :district, :city, :state_code, :zip_code, :payment_type, :rebate_amount,
|
55
|
-
:tags, :
|
56
|
-
:interest, :created, :updated
|
61
|
+
:tags, :expiration, :id, :amount, :document_id, :status, :transaction_ids, :workspace_id, :tax_amount,
|
62
|
+
:nominal_interest, :interest, :created, :updated
|
57
63
|
def initialize(
|
58
64
|
template_id:, name:, tax_id:, nominal_amount:, scheduled:, invoices:, payment:,
|
59
65
|
signers:, external_id:, street_line_1:, street_line_2:, district:, city:, state_code:, zip_code:,
|
60
|
-
payment_type: nil, rebate_amount: nil, tags: nil,
|
61
|
-
document_id: nil, status: nil, transaction_ids: nil, workspace_id: nil, tax_amount: nil,
|
62
|
-
created: nil, updated: nil
|
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
|
63
69
|
)
|
64
70
|
super(id)
|
65
71
|
@template_id = template_id
|
@@ -67,8 +73,8 @@ module StarkInfra
|
|
67
73
|
@tax_id = tax_id
|
68
74
|
@nominal_amount = nominal_amount
|
69
75
|
@scheduled = scheduled
|
70
|
-
@invoices =
|
71
|
-
@signers =
|
76
|
+
@invoices = Invoice.parse_invoices(invoices)
|
77
|
+
@signers = CreditSigner.parse_signers(signers)
|
72
78
|
@external_id = external_id
|
73
79
|
@street_line_1 = street_line_1
|
74
80
|
@street_line_2 = street_line_2
|
@@ -85,6 +91,7 @@ module StarkInfra
|
|
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)
|
@@ -207,20 +214,24 @@ module StarkInfra
|
|
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
|
@@ -249,8 +260,8 @@ module StarkInfra
|
|
249
260
|
payment_type: json['payment_type'],
|
250
261
|
rebate_amount: json['rebate_amount'],
|
251
262
|
tags: json['tags'],
|
252
|
-
amount: json['amount'],
|
253
263
|
expiration: json['expiration'],
|
264
|
+
amount: json['amount'],
|
254
265
|
document_id: json['document_id'],
|
255
266
|
status: json['status'],
|
256
267
|
transaction_ids: json['transaction_ids'],
|
@@ -263,321 +274,5 @@ module StarkInfra
|
|
263
274
|
}
|
264
275
|
}
|
265
276
|
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
277
|
end
|
583
278
|
end
|