starkbank 2.1.0 → 2.4.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/balance/balance.rb +1 -1
- data/lib/boleto/boleto.rb +9 -8
- data/lib/boleto/log.rb +2 -2
- data/lib/boleto_holmes/boleto_holmes.rb +3 -3
- data/lib/boleto_holmes/log.rb +2 -2
- data/lib/boleto_payment/boleto_payment.rb +6 -6
- data/lib/boleto_payment/log.rb +3 -3
- data/lib/brcode_payment/brcode_payment.rb +167 -0
- data/lib/brcode_payment/log.rb +94 -0
- data/lib/brcode_preview/brcode_preview.rb +77 -0
- data/lib/deposit/deposit.rb +121 -0
- data/lib/deposit/log.rb +94 -0
- data/lib/dict_key/dict_key.rb +118 -0
- data/lib/event/event.rb +12 -6
- data/lib/invoice/invoice.rb +211 -0
- data/lib/invoice/log.rb +94 -0
- data/lib/payment_request/payment_request.rb +9 -7
- data/lib/starkbank.rb +10 -0
- data/lib/transaction/transaction.rb +3 -3
- data/lib/transfer/log.rb +2 -2
- data/lib/transfer/transfer.rb +18 -12
- data/lib/user/organization.rb +54 -0
- data/lib/user/project.rb +10 -5
- data/lib/user/user.rb +0 -4
- data/lib/utility_payment/log.rb +2 -2
- data/lib/utility_payment/utility_payment.rb +6 -6
- data/lib/utils/api.rb +14 -12
- data/lib/utils/checks.rb +18 -6
- data/lib/utils/request.rb +1 -1
- data/lib/utils/rest.rb +10 -2
- data/lib/webhook/webhook.rb +8 -8
- data/lib/workspace/workspace.rb +92 -0
- metadata +11 -1
@@ -0,0 +1,211 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
|
7
|
+
module StarkBank
|
8
|
+
# # Invoice object
|
9
|
+
#
|
10
|
+
# When you initialize an Invoice, the entity will not be automatically
|
11
|
+
# sent to the Stark Bank API. The 'create' function sends the objects
|
12
|
+
# to the Stark Bank API and returns the list of created objects.
|
13
|
+
#
|
14
|
+
# ## Parameters (required):
|
15
|
+
# - amount [integer]: Invoice value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34)
|
16
|
+
# - tax_id [string]: payer tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
|
17
|
+
# - name [string]: payer name. ex: 'Iron Bank S.A.'
|
18
|
+
#
|
19
|
+
# ## Parameters (optional):
|
20
|
+
# - due [DateTime or string, default now + 2 days]: Invoice due date in UTC ISO format. ex: '2020-10-28T17:59:26.249976+00:00'
|
21
|
+
# - expiration [integer, default 5097600 (59 days)]: time interval in seconds between due date and expiration date. ex 123456789
|
22
|
+
# - fine [float, default 0.0]: Invoice fine for overdue payment in %. ex: 2.5
|
23
|
+
# - interest [float, default 0.0]: Invoice monthly interest for overdue payment in %. ex: 5.2
|
24
|
+
# - discounts [list of hashes, default nil]: list of hashes with 'percentage':float and 'due':DateTime or string pairs
|
25
|
+
# - descriptions [list of hashes, default nil]: list of hashes with 'key':string and 'value':string pairs
|
26
|
+
# - tags [list of strings, default nil]: list of strings for tagging
|
27
|
+
#
|
28
|
+
# ## Attributes (return-only):
|
29
|
+
# - id [string, default nil]: unique id returned when Invoice is created. ex: '5656565656565656'
|
30
|
+
# - nominal_amount [integer, default nil]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
|
31
|
+
# - fine_amount [integer, default nil]: Invoice fine value calculated over nominal_amount. ex: 20000
|
32
|
+
# - interest_amount [integer, default nil]: Invoice interest value calculated over nominal_amount. ex: 10000
|
33
|
+
# - discount_amount [integer, default nil]: Invoice discount value calculated over nominal_amount. ex: 3000
|
34
|
+
# - brcode [string, default nil]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
|
35
|
+
# - fee [integer, default nil]: fee charged by the Invoice. ex: 65 (= R$ 0.65)
|
36
|
+
# - status [string, default nil]: current Invoice status. ex: 'registered' or 'paid'
|
37
|
+
# - created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
38
|
+
# - updated [DateTime, default nil]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
39
|
+
class Invoice < StarkBank::Utils::Resource
|
40
|
+
attr_reader :amount, :tax_id, :name, :due, :expiration, :fine, :interest, :discounts, :tags, :descriptions, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :id, :brcode, :fee, :status, :created, :updated
|
41
|
+
def initialize(
|
42
|
+
amount:, tax_id:, name:, due: nil, expiration: nil, fine: nil, interest: nil, discounts: nil,
|
43
|
+
tags: nil, descriptions: nil, nominal_amount: nil, fine_amount: nil, interest_amount: nil,
|
44
|
+
discount_amount: nil, id: nil, brcode: nil, fee: nil, status: nil, created: nil, updated: nil
|
45
|
+
)
|
46
|
+
super(id)
|
47
|
+
@amount = amount
|
48
|
+
@due = StarkBank::Utils::Checks.check_datetime(due)
|
49
|
+
@tax_id = tax_id
|
50
|
+
@name = name
|
51
|
+
@expiration = expiration
|
52
|
+
@fine = fine
|
53
|
+
@interest = interest
|
54
|
+
@discounts = discounts
|
55
|
+
@tags = tags
|
56
|
+
@descriptions = descriptions
|
57
|
+
@nominal_amount = nominal_amount
|
58
|
+
@fine_amount = fine_amount
|
59
|
+
@interest_amount = interest_amount
|
60
|
+
@discount_amount = discount_amount
|
61
|
+
@brcode = brcode
|
62
|
+
@fee = fee
|
63
|
+
@status = status
|
64
|
+
@updated = StarkBank::Utils::Checks.check_datetime(updated)
|
65
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
66
|
+
end
|
67
|
+
|
68
|
+
# # Create Invoices
|
69
|
+
#
|
70
|
+
# Send a list of Invoice objects for creation in the Stark Bank API
|
71
|
+
#
|
72
|
+
# ## Parameters (required):
|
73
|
+
# - invoices [list of Invoice objects]: list of Invoice objects to be created in the API
|
74
|
+
#
|
75
|
+
# ## Parameters (optional):
|
76
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
77
|
+
#
|
78
|
+
# ## Return:
|
79
|
+
# - list of Invoice objects with updated attributes
|
80
|
+
def self.create(invoices, user: nil)
|
81
|
+
StarkBank::Utils::Rest.post(entities: invoices, user: user, **resource)
|
82
|
+
end
|
83
|
+
|
84
|
+
# # Retrieve a specific Invoice
|
85
|
+
#
|
86
|
+
# Receive a single Invoice object previously created in the Stark Bank API by passing its id
|
87
|
+
#
|
88
|
+
# ## Parameters (required):
|
89
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
90
|
+
#
|
91
|
+
# ## Parameters (optional):
|
92
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
93
|
+
#
|
94
|
+
# ## Return:
|
95
|
+
# - Invoice object with updated attributes
|
96
|
+
def self.get(id, user: nil)
|
97
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
98
|
+
end
|
99
|
+
|
100
|
+
# # Retrieve a specific Invoice pdf file
|
101
|
+
#
|
102
|
+
# Receive a single Invoice pdf file generated in the Stark Bank API by passing its id.
|
103
|
+
#
|
104
|
+
# ## Parameters (required):
|
105
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
106
|
+
#
|
107
|
+
# ## Parameters (optional):
|
108
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
109
|
+
#
|
110
|
+
# ## Return:
|
111
|
+
# - Invoice pdf file
|
112
|
+
def self.pdf(id, user: nil)
|
113
|
+
StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
|
114
|
+
end
|
115
|
+
|
116
|
+
# # Retrieve a specific Invoice QR Code file
|
117
|
+
#
|
118
|
+
# Receive a single Invoice QR Code png file generated in the Stark Bank API by passing its id.
|
119
|
+
#
|
120
|
+
# ## Parameters (required):
|
121
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
122
|
+
#
|
123
|
+
# ## Parameters (optional):
|
124
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
125
|
+
#
|
126
|
+
# ## Return:
|
127
|
+
# - Invoice QR Code png blob
|
128
|
+
def self.qrcode(id, user: nil)
|
129
|
+
StarkBank::Utils::Rest.get_qrcode(id: id, user: user, **resource)
|
130
|
+
end
|
131
|
+
|
132
|
+
# # Retrieve Invoices
|
133
|
+
#
|
134
|
+
# Receive a generator of Invoice objects previously created in the Stark Bank API
|
135
|
+
#
|
136
|
+
# ## Parameters (optional):
|
137
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
138
|
+
# - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
139
|
+
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
140
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
141
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
142
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
143
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
144
|
+
#
|
145
|
+
# ## Return:
|
146
|
+
# - generator of Invoice objects with updated attributes
|
147
|
+
def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
148
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
149
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
150
|
+
StarkBank::Utils::Rest.get_list(
|
151
|
+
limit: limit,
|
152
|
+
after: after,
|
153
|
+
before: before,
|
154
|
+
status: status,
|
155
|
+
tags: tags,
|
156
|
+
ids: ids,
|
157
|
+
user: user,
|
158
|
+
**resource
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
# # Update an Invoice entity
|
163
|
+
#
|
164
|
+
# Update an Invoice entity previously created in the Stark Bank API
|
165
|
+
#
|
166
|
+
# ## Parameters (required):
|
167
|
+
# - id [string]: Invoice unique id. ex: '5656565656565656'
|
168
|
+
#
|
169
|
+
# ## Parameters (optional):
|
170
|
+
# - status [string, nil]: You may cancel the invoice by passing 'canceled' in the status
|
171
|
+
# - amount [string, nil]: Nominal amount charged by the invoice. ex: 100 (R$1.00)
|
172
|
+
# - due [datetime.date or string, default nil]: Invoice due date in UTC ISO format. ex: DateTime.new(2020, 3, 10, 10, 30, 12, 21)
|
173
|
+
# - expiration [number, default nil]: time interval in seconds between the due date and the expiration date. ex 123456789
|
174
|
+
#
|
175
|
+
# ## Return:
|
176
|
+
# - updated Invoice object
|
177
|
+
def self.update(id, status: nil, amount: nil, due: nil, expiration: nil, user: nil)
|
178
|
+
StarkBank::Utils::Rest.patch_id(id: id, status: status, amount: amount, due: due, expiration: expiration, user: user, **resource)
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.resource
|
182
|
+
{
|
183
|
+
resource_name: 'Invoice',
|
184
|
+
resource_maker: proc { |json|
|
185
|
+
Invoice.new(
|
186
|
+
id: json['id'],
|
187
|
+
amount: json['amount'],
|
188
|
+
due: json['due'],
|
189
|
+
tax_id: json['tax_id'],
|
190
|
+
name: json['name'],
|
191
|
+
expiration: json['expiration'],
|
192
|
+
fine: json['fine'],
|
193
|
+
interest: json['interest'],
|
194
|
+
discounts: json['discounts'],
|
195
|
+
tags: json['tags'],
|
196
|
+
descriptions: json['descriptions'],
|
197
|
+
nominal_amount: json['nominal_amount'],
|
198
|
+
fine_amount: json['fine_amount'],
|
199
|
+
interest_amount: json['interest_amount'],
|
200
|
+
discount_amount: json['discount_amount'],
|
201
|
+
brcode: json['brcode'],
|
202
|
+
fee: json['fee'],
|
203
|
+
status: json['status'],
|
204
|
+
updated: json['updated'],
|
205
|
+
created: json['created'],
|
206
|
+
)
|
207
|
+
}
|
208
|
+
}
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
data/lib/invoice/log.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
require_relative('invoice')
|
7
|
+
|
8
|
+
module StarkBank
|
9
|
+
class Invoice
|
10
|
+
# # Invoice::Log object
|
11
|
+
#
|
12
|
+
# Every time an Invoice entity is updated, a corresponding Invoice::Log
|
13
|
+
# is generated for the entity. This log is never generated by the
|
14
|
+
# user, but it can be retrieved to check additional information
|
15
|
+
# on the Invoice.
|
16
|
+
#
|
17
|
+
# ## Attributes:
|
18
|
+
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
19
|
+
# - invoice [Invoice]: Invoice entity to which the log refers to.
|
20
|
+
# - errors [list of strings]: list of errors linked to this Invoice event
|
21
|
+
# - type [string]: type of the Invoice event which triggered the log creation. ex: 'canceled' or 'paid'
|
22
|
+
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
23
|
+
class Log < StarkBank::Utils::Resource
|
24
|
+
attr_reader :id, :created, :type, :errors, :invoice
|
25
|
+
def initialize(id:, created:, type:, errors:, invoice:)
|
26
|
+
super(id)
|
27
|
+
@type = type
|
28
|
+
@errors = errors
|
29
|
+
@invoice = invoice
|
30
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
31
|
+
end
|
32
|
+
|
33
|
+
# # Retrieve a specific Log
|
34
|
+
#
|
35
|
+
# Receive a single Log object previously created by the Stark Bank API by passing its id
|
36
|
+
#
|
37
|
+
# ## Parameters (required):
|
38
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
39
|
+
#
|
40
|
+
# ## Parameters (optional):
|
41
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
42
|
+
#
|
43
|
+
# ## Return:
|
44
|
+
# - Log object with updated attributes
|
45
|
+
def self.get(id, user: nil)
|
46
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
47
|
+
end
|
48
|
+
|
49
|
+
# # Retrieve Logs
|
50
|
+
#
|
51
|
+
# Receive a generator of Log objects previously created in the Stark Bank API
|
52
|
+
#
|
53
|
+
# ## Parameters (optional):
|
54
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
55
|
+
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
56
|
+
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
57
|
+
# - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
|
58
|
+
# - invoice_ids [list of strings, default nil]: list of Invoice ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
59
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
60
|
+
#
|
61
|
+
# ## Return:
|
62
|
+
# - list of Log objects with updated attributes
|
63
|
+
def self.query(limit: nil, after: nil, before: nil, types: nil, invoice_ids: nil, user: nil)
|
64
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
65
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
66
|
+
StarkBank::Utils::Rest.get_list(
|
67
|
+
limit: limit,
|
68
|
+
after: after,
|
69
|
+
before: before,
|
70
|
+
types: types,
|
71
|
+
invoice_ids: invoice_ids,
|
72
|
+
user: user,
|
73
|
+
**resource
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.resource
|
78
|
+
invoice_maker = StarkBank::Invoice.resource[:resource_maker]
|
79
|
+
{
|
80
|
+
resource_name: 'InvoiceLog',
|
81
|
+
resource_maker: proc { |json|
|
82
|
+
Log.new(
|
83
|
+
id: json['id'],
|
84
|
+
created: json['created'],
|
85
|
+
type: json['type'],
|
86
|
+
errors: json['errors'],
|
87
|
+
invoice: StarkBank::Utils::API.from_api_json(invoice_maker, json['invoice'])
|
88
|
+
)
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -7,17 +7,17 @@ require_relative('../utils/checks')
|
|
7
7
|
module StarkBank
|
8
8
|
# # PaymentRequest object
|
9
9
|
# A PaymentRequest is an indirect request to access a specific cash-out service
|
10
|
-
# (such as Transfer,
|
10
|
+
# (such as Transfer, BrcodePayments, etc.) which goes through the cost center
|
11
11
|
# approval flow on our website. To emit a PaymentRequest, you must direct it to
|
12
12
|
# a specific cost center by its ID, which can be retrieved on our website at the
|
13
13
|
# cost center page.
|
14
14
|
#
|
15
15
|
# ## Parameters (required):
|
16
16
|
# - center_id [String]: target cost center ID. ex: '5656565656565656'
|
17
|
-
# - payment [Transfer, BoletoPayment, UtilityPayment, Transaction or dictionary]: payment entity that should be approved and executed.
|
17
|
+
# - payment [Transfer, BrcodePayment, BoletoPayment, UtilityPayment, Transaction or dictionary]: payment entity that should be approved and executed.
|
18
18
|
#
|
19
19
|
# ## Parameters (optional):
|
20
|
-
# - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', '
|
20
|
+
# - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'brcode-payment'
|
21
21
|
# - due [Date, DateTime, Time or string]: Payment target date in ISO format. ex: 2020-12-31
|
22
22
|
# - tags [list of strings]: list of strings for tagging
|
23
23
|
#
|
@@ -53,7 +53,7 @@ module StarkBank
|
|
53
53
|
#
|
54
54
|
# ## Parameters
|
55
55
|
# - payment_requests [list of PaymentRequest objects]: list of PaymentRequest objects to be created in the API
|
56
|
-
# - user [Project object]: Project object. Not necessary if
|
56
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
57
57
|
#
|
58
58
|
# ## Return
|
59
59
|
# - list of PaymentRequest objects with updated attributes
|
@@ -73,11 +73,11 @@ module StarkBank
|
|
73
73
|
# - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
74
74
|
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
75
75
|
# - status [string, default '-created']: sort order considered in response. Valid options are '-created' or '-due'.
|
76
|
-
# - type [string, default nil]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', '
|
76
|
+
# - type [string, default nil]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'brcode-payment'
|
77
77
|
# - sort [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
78
78
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
79
79
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
80
|
-
# - user [Project object
|
80
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
81
81
|
#
|
82
82
|
# ## Return:
|
83
83
|
# - generator of PaymentRequest objects with updated attributes
|
@@ -102,14 +102,16 @@ module StarkBank
|
|
102
102
|
def parse_payment(payment:, type:)
|
103
103
|
return [payment, 'transfer'] if payment.is_a?(StarkBank::Transfer)
|
104
104
|
return [payment, 'transaction'] if payment.is_a?(StarkBank::Transaction)
|
105
|
+
return [payment, 'brcode-payment'] if payment.is_a?(StarkBank::BrcodePayment)
|
105
106
|
return [payment, 'boleto-payment'] if payment.is_a?(StarkBank::BoletoPayment)
|
106
107
|
return [payment, 'utility-payment'] if payment.is_a?(StarkBank::UtilityPayment)
|
107
108
|
|
108
|
-
raise(Exception('Payment must either be a Transfer, a Transaction, a BoletoPayment, a UtilityPayment or a hash.')) unless payment.is_a?(Hash)
|
109
|
+
raise(Exception('Payment must either be a Transfer, a Transaction, a BrcodePayment, BoletoPayment, a UtilityPayment or a hash.')) unless payment.is_a?(Hash)
|
109
110
|
|
110
111
|
resource = {
|
111
112
|
'transfer': StarkBank::Transfer.resource,
|
112
113
|
'transaction': StarkBank::Transaction.resource,
|
114
|
+
'brcode-payment': StarkBank::BrcodePayment.resource,
|
113
115
|
'boleto-payment': StarkBank::BoletoPayment.resource,
|
114
116
|
'utility-payment': StarkBank::UtilityPayment.resource
|
115
117
|
}[type.to_sym]
|
data/lib/starkbank.rb
CHANGED
@@ -2,8 +2,18 @@
|
|
2
2
|
|
3
3
|
require_relative('key')
|
4
4
|
require_relative('user/project')
|
5
|
+
require_relative('user/organization')
|
6
|
+
require_relative('workspace/workspace')
|
5
7
|
require_relative('balance/balance')
|
6
8
|
require_relative('transaction/transaction')
|
9
|
+
require_relative('invoice/invoice')
|
10
|
+
require_relative('invoice/log')
|
11
|
+
require_relative('dict_key/dict_key')
|
12
|
+
require_relative('deposit/deposit')
|
13
|
+
require_relative('deposit/log')
|
14
|
+
require_relative('brcode_preview/brcode_preview')
|
15
|
+
require_relative('brcode_payment/brcode_payment')
|
16
|
+
require_relative('brcode_payment/log')
|
7
17
|
require_relative('boleto/boleto')
|
8
18
|
require_relative('boleto/log')
|
9
19
|
require_relative('boleto_holmes/boleto_holmes')
|
@@ -55,7 +55,7 @@ module StarkBank
|
|
55
55
|
# - transactions [list of Transaction objects]: list of Transaction objects to be created in the API
|
56
56
|
#
|
57
57
|
# ## Parameters (optional):
|
58
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
58
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
59
59
|
#
|
60
60
|
# ## Return:
|
61
61
|
# - list of Transaction objects with updated attributes
|
@@ -71,7 +71,7 @@ module StarkBank
|
|
71
71
|
# - id [string]: object unique id. ex: '5656565656565656'
|
72
72
|
#
|
73
73
|
# ## Parameters (optional):
|
74
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
74
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
75
75
|
#
|
76
76
|
# ## Return:
|
77
77
|
# - Transaction object with updated attributes
|
@@ -90,7 +90,7 @@ module StarkBank
|
|
90
90
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
91
91
|
# - external_ids [list of strings, default nil]: list of external ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
92
92
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
93
|
-
# - user [Project object
|
93
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
94
94
|
#
|
95
95
|
# ## Return:
|
96
96
|
# - generator of Transaction objects with updated attributes
|
data/lib/transfer/log.rb
CHANGED
@@ -37,7 +37,7 @@ module StarkBank
|
|
37
37
|
# - id [string]: object unique id. ex: '5656565656565656'
|
38
38
|
#
|
39
39
|
# ## Parameters (optional):
|
40
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
40
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
41
41
|
#
|
42
42
|
# ## Return:
|
43
43
|
# - Log object with updated attributes
|
@@ -55,7 +55,7 @@ module StarkBank
|
|
55
55
|
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
56
56
|
# - types [list of strings, default nil]: filter retrieved objects by types. ex: 'success' or 'failed'
|
57
57
|
# - transfer_ids [list of strings, default nil]: list of Transfer ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
58
|
-
# - user [Project object
|
58
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
59
59
|
#
|
60
60
|
# ## Return:
|
61
61
|
# - list of Log objects with updated attributes
|
data/lib/transfer/transfer.rb
CHANGED
@@ -15,13 +15,15 @@ module StarkBank
|
|
15
15
|
# - amount [integer]: amount in cents to be transferred. ex: 1234 (= R$ 12.34)
|
16
16
|
# - name [string]: receiver full name. ex: 'Anthony Edward Stark'
|
17
17
|
# - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
|
18
|
-
# - bank_code [string]:
|
18
|
+
# - bank_code [string]: code of the receiver bank institution in Brazil. If an ISPB (8 digits) is informed, a PIX transfer will be created, else a TED will be issued. ex: '20018183' or '260'
|
19
19
|
# - branch_code [string]: receiver bank account branch. Use '-' in case there is a verifier digit. ex: '1357-9'
|
20
|
-
# - account_number [string]:
|
20
|
+
# - account_number [string]: receiver bank account number. Use '-' before the verifier digit. ex: '876543-2'
|
21
21
|
#
|
22
22
|
# ## Parameters (optional):
|
23
|
+
# - account_type [string, default 'checking']: receiver bank account type. This parameter only has effect on Pix Transfers. ex: 'checking', 'savings' or 'salary'
|
24
|
+
# - external_id [string, default nil]: 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'
|
25
|
+
# - scheduled [string, default now]: datetime when the transfer will be processed. May be pushed to next business day if necessary. ex: DateTime.new(2020, 3, 11, 8, 13, 12, 11)
|
23
26
|
# - tags [list of strings]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
|
24
|
-
# - scheduled [string, default now]: datetime when the transfer will be processed. May be pushed to next business day if necessary. ex: DateTime.new(2020, 3, 11, 8, 0, 0, 0)
|
25
27
|
#
|
26
28
|
# ## Attributes (return-only):
|
27
29
|
# - id [string, default nil]: unique id returned when Transfer is created. ex: '5656565656565656'
|
@@ -31,8 +33,8 @@ module StarkBank
|
|
31
33
|
# - created [DateTime, default nil]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
32
34
|
# - updated [DateTime, default nil]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
33
35
|
class Transfer < StarkBank::Utils::Resource
|
34
|
-
attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :scheduled, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
|
35
|
-
def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, scheduled: nil, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
|
36
|
+
attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :external_id, :scheduled, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
|
37
|
+
def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
|
36
38
|
super(id)
|
37
39
|
@amount = amount
|
38
40
|
@name = name
|
@@ -40,7 +42,9 @@ module StarkBank
|
|
40
42
|
@bank_code = bank_code
|
41
43
|
@branch_code = branch_code
|
42
44
|
@account_number = account_number
|
43
|
-
@
|
45
|
+
@account_type = account_type
|
46
|
+
@external_id = external_id
|
47
|
+
@scheduled = StarkBank::Utils::Checks.check_date_or_datetime(scheduled)
|
44
48
|
@transaction_ids = transaction_ids
|
45
49
|
@fee = fee
|
46
50
|
@tags = tags
|
@@ -57,7 +61,7 @@ module StarkBank
|
|
57
61
|
# - transfers [list of Transfer objects]: list of Transfer objects to be created in the API
|
58
62
|
#
|
59
63
|
# ## Parameters (optional):
|
60
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
64
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
61
65
|
#
|
62
66
|
# ## Return:
|
63
67
|
# - list of Transfer objects with updated attributes
|
@@ -73,7 +77,7 @@ module StarkBank
|
|
73
77
|
# - id [string]: object unique id. ex: '5656565656565656'
|
74
78
|
#
|
75
79
|
# ## Parameters (optional):
|
76
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
80
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
77
81
|
#
|
78
82
|
# ## Return:
|
79
83
|
# - Transfer object with updated attributes
|
@@ -89,7 +93,7 @@ module StarkBank
|
|
89
93
|
# - id [string]: Transfer unique id. ex: '5656565656565656'
|
90
94
|
#
|
91
95
|
# ## Parameters (optional):
|
92
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
96
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
93
97
|
#
|
94
98
|
# ## Return:
|
95
99
|
# - deleted Transfer object
|
@@ -106,7 +110,7 @@ module StarkBank
|
|
106
110
|
# - id [string]: object unique id. ex: '5656565656565656'
|
107
111
|
#
|
108
112
|
# ## Parameters (optional):
|
109
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
113
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
110
114
|
#
|
111
115
|
# ## Return:
|
112
116
|
# - Transfer pdf file
|
@@ -124,10 +128,10 @@ module StarkBank
|
|
124
128
|
# - before [Date, DateTime, Time or string, default nil] date filter for objects created or updated only before specified date. ex: Date.new(2020, 3, 10)
|
125
129
|
# - transactionIds [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
126
130
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
|
127
|
-
# - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex:
|
131
|
+
# - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex: '012.345.678-90'
|
128
132
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
129
133
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
130
|
-
# - user [Project object
|
134
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
131
135
|
#
|
132
136
|
# ## Return:
|
133
137
|
# - generator of Transfer objects with updated attributes
|
@@ -161,6 +165,8 @@ module StarkBank
|
|
161
165
|
bank_code: json['bank_code'],
|
162
166
|
branch_code: json['branch_code'],
|
163
167
|
account_number: json['account_number'],
|
168
|
+
account_type: json['account_type'],
|
169
|
+
external_id: json['external_id'],
|
164
170
|
scheduled: json['scheduled'],
|
165
171
|
transaction_ids: json['transaction_ids'],
|
166
172
|
fee: json['fee'],
|