starkbank 2.6.0 → 2.7.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 +8 -8
- data/lib/boleto/boleto.rb +22 -19
- data/lib/boleto/log.rb +10 -10
- data/lib/boleto_holmes/boleto_holmes.rb +14 -14
- data/lib/boleto_holmes/log.rb +16 -13
- data/lib/boleto_payment/boleto_payment.rb +21 -18
- data/lib/boleto_payment/log.rb +10 -10
- data/lib/brcode_payment/brcode_payment.rb +23 -20
- data/lib/brcode_payment/log.rb +10 -10
- data/lib/brcode_payment/rule.rb +49 -0
- data/lib/darf_payment/darf_payment.rb +23 -21
- data/lib/darf_payment/log.rb +10 -10
- data/lib/deposit/deposit.rb +9 -9
- data/lib/deposit/log.rb +10 -10
- data/lib/dict_key/dict_key.rb +26 -27
- data/lib/dynamic_brcode/dynamic_brcode.rb +155 -0
- data/lib/error.rb +7 -40
- data/lib/event/attempt.rb +9 -9
- data/lib/event/event.rb +30 -56
- data/lib/institution/institution.rb +2 -3
- data/lib/invoice/invoice.rb +24 -23
- data/lib/invoice/log.rb +10 -10
- data/lib/invoice/payment.rb +1 -2
- data/lib/payment_preview/boleto_preview.rb +4 -5
- data/lib/payment_preview/brcode_preview.rb +2 -3
- data/lib/payment_preview/payment_preview.rb +10 -6
- data/lib/payment_preview/tax_preview.rb +2 -3
- data/lib/payment_preview/utility_preview.rb +2 -3
- data/lib/payment_request/payment_request.rb +22 -16
- data/lib/starkbank.rb +16 -5
- data/lib/tax_payment/log.rb +10 -10
- data/lib/tax_payment/tax_payment.rb +22 -19
- data/lib/transaction/transaction.rb +13 -13
- data/lib/transfer/log.rb +10 -10
- data/lib/transfer/rule.rb +49 -0
- data/lib/transfer/transfer.rb +27 -24
- data/lib/utility_payment/log.rb +10 -10
- data/lib/utility_payment/utility_payment.rb +26 -17
- data/lib/utils/parse.rb +35 -0
- data/lib/utils/rest.rb +132 -109
- data/lib/webhook/webhook.rb +5 -5
- data/lib/workspace/workspace.rb +38 -10
- metadata +15 -25
- data/lib/brcode_preview/brcode_preview.rb +0 -79
- data/lib/key.rb +0 -33
- data/lib/user/organization.rb +0 -54
- data/lib/user/project.rb +0 -37
- data/lib/user/user.rb +0 -20
- data/lib/utils/api.rb +0 -79
- data/lib/utils/cache.rb +0 -10
- data/lib/utils/case.rb +0 -21
- data/lib/utils/checks.rb +0 -101
- data/lib/utils/environment.rb +0 -13
- data/lib/utils/request.rb +0 -79
- data/lib/utils/resource.rb +0 -13
- data/lib/utils/sub_resource.rb +0 -28
- data/lib/utils/url.rb +0 -28
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
module StarkBank
|
8
8
|
# # PaymentRequest object
|
9
|
+
#
|
9
10
|
# A PaymentRequest is an indirect request to access a specific cash-out service
|
10
11
|
# (such as Transfer, BrcodePayments, etc.) which goes through the cost center
|
11
12
|
# approval flow on our website. To emit a PaymentRequest, you must direct it to
|
@@ -16,24 +17,27 @@ module StarkBank
|
|
16
17
|
# - center_id [String]: target cost center ID. ex: '5656565656565656'
|
17
18
|
# - payment [Transfer, BrcodePayment, BoletoPayment, UtilityPayment, Transaction or dictionary]: payment entity that should be approved and executed.
|
18
19
|
#
|
19
|
-
# ## Parameters (
|
20
|
+
# ## Parameters (conditionally required):
|
20
21
|
# - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'brcode-payment'
|
22
|
+
#
|
23
|
+
# ## Parameters (optional):
|
21
24
|
# - due [Date, DateTime, Time or string]: Payment target date in ISO format. ex: 2020-12-31
|
22
25
|
# - tags [list of strings]: list of strings for tagging
|
23
26
|
#
|
24
27
|
# ## Attributes (return-only):
|
25
28
|
# - id [String]: unique id returned when PaymentRequest is created. ex: '5656565656565656'
|
26
|
-
# - amount [integer
|
27
|
-
# -
|
28
|
-
# -
|
29
|
-
# -
|
30
|
-
# -
|
29
|
+
# - amount [integer]: PaymentRequest amount. ex: 100000 = R$1.000,00
|
30
|
+
# - description [string]: payment request description. ex: "Tony Stark's Suit"
|
31
|
+
# - status [string]: current PaymentRequest status.ex: 'pending' or 'approved'
|
32
|
+
# - actions [list of dictionaries]: list of actions that are affecting this PaymentRequest. ex: [{'type': 'member', 'id': '56565656565656, 'action': 'requested'}]
|
33
|
+
# - updated [DateTime]: latest update datetime for the PaymentRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
34
|
+
# - created [DateTime]: creation datetime for the PaymentRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
31
35
|
#
|
32
|
-
class PaymentRequest <
|
33
|
-
attr_reader :center_id, :payment, :type, :due, :tags, :amount, :status, :actions, :updated, :created
|
36
|
+
class PaymentRequest < StarkCore::Utils::Resource
|
37
|
+
attr_reader :center_id, :payment, :type, :due, :tags, :amount, :description, :status, :actions, :updated, :created
|
34
38
|
def initialize(
|
35
39
|
payment:, center_id:, id: nil, type: nil, due: nil, tags: nil, amount: nil, status: nil,
|
36
|
-
actions: nil, updated: nil, created: nil
|
40
|
+
description: nil, actions: nil, updated: nil, created: nil
|
37
41
|
)
|
38
42
|
super(id)
|
39
43
|
@center_id = center_id
|
@@ -42,6 +46,7 @@ module StarkBank
|
|
42
46
|
@amount = amount
|
43
47
|
@status = status
|
44
48
|
@actions = actions
|
49
|
+
@description = description
|
45
50
|
@updated = updated
|
46
51
|
@created = created
|
47
52
|
|
@@ -82,8 +87,8 @@ module StarkBank
|
|
82
87
|
# ## Return:
|
83
88
|
# - generator of PaymentRequest objects with updated attributes
|
84
89
|
def self.query(center_id:, limit: nil, after: nil, before: nil, status: nil, type: nil, sort: nil, tags: nil, ids: nil, user: nil)
|
85
|
-
after =
|
86
|
-
before =
|
90
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
91
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
87
92
|
StarkBank::Utils::Rest.get_stream(
|
88
93
|
center_id: center_id,
|
89
94
|
limit: limit,
|
@@ -117,8 +122,8 @@ module StarkBank
|
|
117
122
|
# ## Return:
|
118
123
|
# - list of PaymentRequest objects with updated attributes and cursor to retrieve the next page of PaymentRequest objects
|
119
124
|
def self.page(cursor: nil, center_id:, limit: nil, after: nil, before: nil, status: nil, type: nil, sort: nil, tags: nil, ids: nil, user: nil)
|
120
|
-
after =
|
121
|
-
before =
|
125
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
126
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
122
127
|
return StarkBank::Utils::Rest.get_page(
|
123
128
|
cursor: cursor,
|
124
129
|
center_id: center_id,
|
@@ -156,7 +161,7 @@ module StarkBank
|
|
156
161
|
'darf-payment': StarkBank::DarfPayment.resource
|
157
162
|
}[type.to_sym]
|
158
163
|
|
159
|
-
payment =
|
164
|
+
payment = StarkCore::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
|
160
165
|
|
161
166
|
[payment, type]
|
162
167
|
end
|
@@ -173,6 +178,7 @@ module StarkBank
|
|
173
178
|
tags: json['tags'],
|
174
179
|
amount: json['amount'],
|
175
180
|
status: json['status'],
|
181
|
+
description: json['description'],
|
176
182
|
actions: json['actions'],
|
177
183
|
updated: json['updated'],
|
178
184
|
created: json['created']
|
data/lib/starkbank.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative('key')
|
4
|
-
require_relative('user/project')
|
5
|
-
require_relative('user/organization')
|
6
3
|
require_relative('workspace/workspace')
|
7
4
|
require_relative('balance/balance')
|
8
5
|
require_relative('transaction/transaction')
|
@@ -10,10 +7,11 @@ require_relative('invoice/invoice')
|
|
10
7
|
require_relative('invoice/log')
|
11
8
|
require_relative('invoice/payment')
|
12
9
|
require_relative('dict_key/dict_key')
|
10
|
+
require_relative('dynamic_brcode/dynamic_brcode')
|
13
11
|
require_relative('deposit/deposit')
|
14
12
|
require_relative('deposit/log')
|
15
|
-
require_relative('brcode_preview/brcode_preview')
|
16
13
|
require_relative('brcode_payment/brcode_payment')
|
14
|
+
require_relative('brcode_payment/rule')
|
17
15
|
require_relative('brcode_payment/log')
|
18
16
|
require_relative('boleto/boleto')
|
19
17
|
require_relative('boleto/log')
|
@@ -21,6 +19,7 @@ require_relative('boleto_holmes/boleto_holmes')
|
|
21
19
|
require_relative('boleto_holmes/log')
|
22
20
|
require_relative('transfer/transfer')
|
23
21
|
require_relative('transfer/log')
|
22
|
+
require_relative('transfer/rule')
|
24
23
|
require_relative('boleto_payment/boleto_payment')
|
25
24
|
require_relative('boleto_payment/log')
|
26
25
|
require_relative('utility_payment/utility_payment')
|
@@ -42,7 +41,19 @@ require_relative('institution/institution')
|
|
42
41
|
|
43
42
|
# SDK to facilitate Ruby integrations with Stark Bank
|
44
43
|
module StarkBank
|
44
|
+
|
45
|
+
API_VERSION = 'v2'
|
46
|
+
SDK_VERSION = '2.7.0'
|
47
|
+
HOST = "bank"
|
48
|
+
public_constant :API_VERSION, :SDK_VERSION, :HOST;
|
49
|
+
|
45
50
|
@user = nil
|
46
51
|
@language = 'en-US'
|
47
|
-
|
52
|
+
@timeout = 15
|
53
|
+
class << self; attr_accessor :user, :language, :timeout; end
|
54
|
+
|
55
|
+
Project = StarkCore::Project
|
56
|
+
Organization = StarkCore::Organization
|
57
|
+
Key = StarkCore::Key
|
58
|
+
|
48
59
|
end
|
data/lib/tax_payment/log.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
require_relative('../utils/checks')
|
6
5
|
require_relative('tax_payment')
|
7
6
|
|
7
|
+
|
8
8
|
module StarkBank
|
9
9
|
class TaxPayment
|
10
10
|
# # TaxPayment::Log object
|
@@ -14,20 +14,20 @@ module StarkBank
|
|
14
14
|
# user, but it can be retrieved to check additional information
|
15
15
|
# on the TaxPayment.
|
16
16
|
#
|
17
|
-
# ## Attributes:
|
17
|
+
# ## Attributes (return-only):
|
18
18
|
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
19
19
|
# - payment [TaxPayment]: TaxPayment entity to which the log refers to.
|
20
20
|
# - errors [list of strings]: list of errors linked to this TaxPayment event
|
21
21
|
# - type [string]: type of the TaxPayment event which triggered the log creation. ex: 'canceled' or 'paid'
|
22
22
|
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
23
|
-
class Log <
|
23
|
+
class Log < StarkCore::Utils::Resource
|
24
24
|
attr_reader :id, :created, :type, :errors, :payment
|
25
25
|
def initialize(id:, created:, type:, errors:, payment:)
|
26
26
|
super(id)
|
27
27
|
@type = type
|
28
28
|
@errors = errors
|
29
29
|
@payment = payment
|
30
|
-
@created =
|
30
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
31
31
|
end
|
32
32
|
|
33
33
|
# # Retrieve a specific Log
|
@@ -61,8 +61,8 @@ module StarkBank
|
|
61
61
|
# ## Return:
|
62
62
|
# - list of Log objects with updated attributes
|
63
63
|
def self.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
|
64
|
-
after =
|
65
|
-
before =
|
64
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
65
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
66
66
|
StarkBank::Utils::Rest.get_stream(
|
67
67
|
limit: limit,
|
68
68
|
after: after,
|
@@ -91,8 +91,8 @@ module StarkBank
|
|
91
91
|
# ## Return:
|
92
92
|
# - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
|
93
93
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
|
94
|
-
after =
|
95
|
-
before =
|
94
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
95
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
96
96
|
return StarkBank::Utils::Rest.get_page(
|
97
97
|
cursor: cursor,
|
98
98
|
limit: limit,
|
@@ -115,7 +115,7 @@ module StarkBank
|
|
115
115
|
created: json['created'],
|
116
116
|
type: json['type'],
|
117
117
|
errors: json['errors'],
|
118
|
-
payment:
|
118
|
+
payment: StarkCore::Utils::API.from_api_json(tax_payment_maker, json['payment'])
|
119
119
|
)
|
120
120
|
}
|
121
121
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
module StarkBank
|
8
8
|
# # TaxPayment object
|
@@ -23,31 +23,33 @@ module StarkBank
|
|
23
23
|
# - tags [list of strings, default nil]: list of strings for tagging
|
24
24
|
#
|
25
25
|
# ## Attributes (return-only):
|
26
|
-
# - id [string
|
27
|
-
# - type [string
|
28
|
-
# - status [string
|
29
|
-
# - amount [int
|
30
|
-
# - fee [integer
|
31
|
-
# -
|
32
|
-
# -
|
33
|
-
|
34
|
-
|
26
|
+
# - id [string]: unique id returned when payment is created. ex: '5656565656565656'
|
27
|
+
# - type [string]: tax type. ex: 'das'
|
28
|
+
# - status [string]: current payment status. ex: 'success' or 'failed'
|
29
|
+
# - amount [int]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)
|
30
|
+
# - fee [integer]: fee charged when tax payment is created. ex: 200 (= R$ 2.00)
|
31
|
+
# - transaction_ids [list of strings]: ledger transaction ids linked to this TaxPayment. ex: ["19827356981273"]
|
32
|
+
# - created [DateTime]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
33
|
+
# - updated [DateTime]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
34
|
+
class TaxPayment < StarkCore::Utils::Resource
|
35
|
+
attr_reader :id, :line, :bar_code, :description, :tags, :scheduled, :status, :amount, :fee, :type, :transaction_ids, :updated, :created
|
35
36
|
def initialize(
|
36
37
|
id: nil, line: nil, bar_code: nil, description:, tags: nil, scheduled: nil,
|
37
|
-
status: nil, amount: nil, fee: nil, type: nil, updated: nil, created: nil
|
38
|
+
status: nil, amount: nil, fee: nil, transaction_ids: nil, type: nil, updated: nil, created: nil
|
38
39
|
)
|
39
40
|
super(id)
|
40
41
|
@line = line
|
41
42
|
@bar_code = bar_code
|
42
43
|
@description = description
|
43
44
|
@tags = tags
|
44
|
-
@scheduled =
|
45
|
+
@scheduled = StarkCore::Utils::Checks.check_date(scheduled)
|
45
46
|
@status = status
|
46
47
|
@amount = amount
|
47
48
|
@fee = fee
|
48
49
|
@type = type
|
49
|
-
@
|
50
|
-
@
|
50
|
+
@transaction_ids = transaction_ids
|
51
|
+
@updated = StarkCore::Utils::Checks.check_datetime(updated)
|
52
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
51
53
|
end
|
52
54
|
|
53
55
|
# # Create TaxPayments
|
@@ -115,8 +117,8 @@ module StarkBank
|
|
115
117
|
# ## Return:
|
116
118
|
# - generator of TaxPayment objects with updated attributes
|
117
119
|
def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
118
|
-
after =
|
119
|
-
before =
|
120
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
121
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
120
122
|
StarkBank::Utils::Rest.get_stream(
|
121
123
|
limit: limit,
|
122
124
|
after: after,
|
@@ -147,8 +149,8 @@ module StarkBank
|
|
147
149
|
# ## Return:
|
148
150
|
# - list of Tax Payment objects with updated attributes and cursor to retrieve the next page of Tax Payment objects
|
149
151
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
150
|
-
after =
|
151
|
-
before =
|
152
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
153
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
152
154
|
return StarkBank::Utils::Rest.get_page(
|
153
155
|
cursor: cursor,
|
154
156
|
limit: limit,
|
@@ -193,6 +195,7 @@ module StarkBank
|
|
193
195
|
amount: json['amount'],
|
194
196
|
fee: json['fee'],
|
195
197
|
type: json['type'],
|
198
|
+
transaction_ids: json['transaction_ids'],
|
196
199
|
updated: json['updated'],
|
197
200
|
created: json['created']
|
198
201
|
)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
module StarkBank
|
8
8
|
# # Transaction object
|
@@ -26,12 +26,12 @@ module StarkBank
|
|
26
26
|
#
|
27
27
|
# ## Attributes (return-only):
|
28
28
|
# - sender_id [string]: unique id of the sending workspace. ex: '5656565656565656'
|
29
|
-
# - source [string
|
30
|
-
# - id [string
|
31
|
-
# - fee [integer
|
32
|
-
# - balance [integer
|
33
|
-
# - created [DateTime
|
34
|
-
class Transaction <
|
29
|
+
# - source [string]: locator of the entity that generated the transaction. ex: 'charge/1827351876292', 'transfer/92873912873/chargeback'
|
30
|
+
# - id [string]: unique id returned when Transaction is created. ex: '7656565656565656'
|
31
|
+
# - fee [integer]: fee charged when transaction is created. ex: 200 (= R$ 2.00)
|
32
|
+
# - balance [integer]: account balance after transaction was processed. ex: 100000000 (= R$ 1,000,000.00)
|
33
|
+
# - created [DateTime]: creation datetime for the boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
34
|
+
class Transaction < StarkCore::Utils::Resource
|
35
35
|
attr_reader :amount, :description, :external_id, :receiver_id, :sender_id, :tags, :id, :fee, :created, :source
|
36
36
|
def initialize(amount:, description:, external_id:, receiver_id:, sender_id: nil, tags: nil, id: nil, fee: nil, source: nil, balance: nil, created: nil)
|
37
37
|
super(id)
|
@@ -44,7 +44,7 @@ module StarkBank
|
|
44
44
|
@fee = fee
|
45
45
|
@source = source
|
46
46
|
@balance = balance
|
47
|
-
@created =
|
47
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
48
48
|
end
|
49
49
|
|
50
50
|
# # Create Transactions
|
@@ -95,8 +95,8 @@ module StarkBank
|
|
95
95
|
# ## Return:
|
96
96
|
# - generator of Transaction objects with updated attributes
|
97
97
|
def self.query(limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil)
|
98
|
-
after =
|
99
|
-
before =
|
98
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
99
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
100
100
|
StarkBank::Utils::Rest.get_stream(
|
101
101
|
limit: limit,
|
102
102
|
after: after,
|
@@ -127,8 +127,8 @@ module StarkBank
|
|
127
127
|
# ## Return:
|
128
128
|
# - list of Transaction objects with updated attributes and cursor to retrieve the next page of Transaction objects
|
129
129
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil)
|
130
|
-
after =
|
131
|
-
before =
|
130
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
131
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
132
132
|
return StarkBank::Utils::Rest.get_page(
|
133
133
|
cursor: cursor,
|
134
134
|
limit: limit,
|
data/lib/transfer/log.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
require_relative('../utils/checks')
|
6
5
|
require_relative('transfer')
|
7
6
|
|
7
|
+
|
8
8
|
module StarkBank
|
9
9
|
class Transfer
|
10
10
|
# # Transfer::Log object
|
@@ -13,20 +13,20 @@ module StarkBank
|
|
13
13
|
# is generated for the entity. This log is never generated by the
|
14
14
|
# user.
|
15
15
|
#
|
16
|
-
# ## Attributes:
|
16
|
+
# ## Attributes (return-only):
|
17
17
|
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
18
18
|
# - transfer [Transfer]: Transfer entity to which the log refers to.
|
19
19
|
# - errors [list of strings]: list of errors linked to this BoletoPayment event.
|
20
20
|
# - type [string]: type of the Transfer event which triggered the log creation. ex: 'processing' or 'success'
|
21
21
|
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
22
|
-
class Log <
|
22
|
+
class Log < StarkCore::Utils::Resource
|
23
23
|
attr_reader :id, :created, :type, :errors, :transfer
|
24
24
|
def initialize(id:, created:, type:, errors:, transfer:)
|
25
25
|
super(id)
|
26
26
|
@type = type
|
27
27
|
@errors = errors
|
28
28
|
@transfer = transfer
|
29
|
-
@created =
|
29
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
30
30
|
end
|
31
31
|
|
32
32
|
# # Retrieve a specific Log
|
@@ -60,8 +60,8 @@ module StarkBank
|
|
60
60
|
# ## Return:
|
61
61
|
# - list of Log objects with updated attributes
|
62
62
|
def self.query(limit: nil, after: nil, before: nil, types: nil, transfer_ids: nil, user: nil)
|
63
|
-
after =
|
64
|
-
before =
|
63
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
64
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
65
65
|
StarkBank::Utils::Rest.get_stream(
|
66
66
|
limit: limit,
|
67
67
|
after: after,
|
@@ -90,8 +90,8 @@ module StarkBank
|
|
90
90
|
# ## Return:
|
91
91
|
# - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
|
92
92
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, transfer_ids: nil, user: nil)
|
93
|
-
after =
|
94
|
-
before =
|
93
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
94
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
95
95
|
return StarkBank::Utils::Rest.get_page(
|
96
96
|
cursor: cursor,
|
97
97
|
limit: limit,
|
@@ -114,7 +114,7 @@ module StarkBank
|
|
114
114
|
created: json['created'],
|
115
115
|
type: json['type'],
|
116
116
|
errors: json['errors'],
|
117
|
-
transfer:
|
117
|
+
transfer: StarkCore::Utils::API.from_api_json(transfer_maker, json['transfer'])
|
118
118
|
)
|
119
119
|
}
|
120
120
|
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/rest')
|
4
|
+
|
5
|
+
|
6
|
+
module StarkBank
|
7
|
+
class Transfer
|
8
|
+
# # Transfer::Rule object
|
9
|
+
#
|
10
|
+
# The Transfer::Rule object modifies the behavior of Transfer objects when passed as an argument upon their creation.
|
11
|
+
#
|
12
|
+
# ## Parameters (required):
|
13
|
+
# - key [string]: Rule to be customized, describes what Transfer behavior will be altered. ex: "resendingLimit"
|
14
|
+
# - value [integer]: Value of the rule. ex: 5
|
15
|
+
class Rule < StarkCore::Utils::SubResource
|
16
|
+
attr_reader :key, :value
|
17
|
+
def initialize(key:, value:)
|
18
|
+
@key = key
|
19
|
+
@value = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.parse_rules(rules)
|
23
|
+
resource_maker = StarkBank::Transfer::Rule.resource[:resource_maker]
|
24
|
+
return rules if rules.nil?
|
25
|
+
|
26
|
+
parsed_rules = []
|
27
|
+
rules.each do |rule|
|
28
|
+
unless rule.is_a? Rule
|
29
|
+
rule = StarkCore::Utils::API.from_api_json(resource_maker, rule)
|
30
|
+
end
|
31
|
+
parsed_rules << rule
|
32
|
+
end
|
33
|
+
return parsed_rules
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.resource
|
37
|
+
{
|
38
|
+
resource_name: 'Rule',
|
39
|
+
resource_maker: proc { |json|
|
40
|
+
Rule.new(
|
41
|
+
key: json['key'],
|
42
|
+
value: json['value']
|
43
|
+
)
|
44
|
+
}
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/transfer/transfer.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require('starkcore')
|
4
4
|
require_relative('../utils/rest')
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
module StarkBank
|
8
8
|
# # Transfer object
|
@@ -15,7 +15,7 @@ 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]: code of the receiver bank institution in Brazil. If an ISPB (8 digits) is informed, a
|
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
20
|
# - account_number [string]: receiver bank account number. Use '-' before the verifier digit. ex: '876543-2'
|
21
21
|
#
|
@@ -25,17 +25,18 @@ module StarkBank
|
|
25
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)
|
26
26
|
# - description [string, default nil]: optional description to override default description to be shown in the bank statement. ex: 'Payment for service #1234'
|
27
27
|
# - tags [list of strings]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
|
28
|
+
# - rules [list of Transfer::Rules, default []]: list of Transfer::Rule objects for modifying transfer behavior. ex: [Transfer::Rule(key: "resendingLimit", value: 5)]
|
28
29
|
#
|
29
30
|
# ## Attributes (return-only):
|
30
|
-
# - id [string
|
31
|
-
# - fee [integer
|
32
|
-
# - status [string
|
33
|
-
# - transaction_ids [list of strings
|
34
|
-
# - created [DateTime
|
35
|
-
# - updated [DateTime
|
36
|
-
class Transfer <
|
37
|
-
attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :external_id, :scheduled, :description, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
|
38
|
-
def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, description: nil, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
|
31
|
+
# - id [string]: unique id returned when Transfer is created. ex: '5656565656565656'
|
32
|
+
# - fee [integer]: fee charged when transfer is created. ex: 200 (= R$ 2.00)
|
33
|
+
# - status [string]: current transfer status. ex: 'success' or 'failed'
|
34
|
+
# - transaction_ids [list of strings]: ledger transaction ids linked to this transfer (if there are two, second is the chargeback). ex: ['19827356981273']
|
35
|
+
# - created [DateTime]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
36
|
+
# - updated [DateTime]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
37
|
+
class Transfer < StarkCore::Utils::Resource
|
38
|
+
attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :external_id, :scheduled, :description, :transaction_ids, :fee, :tags, :rules, :status, :id, :created, :updated
|
39
|
+
def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type: nil, external_id: nil, scheduled: nil, description: nil, transaction_ids: nil, fee: nil, tags: nil, rules: nil, status: nil, id: nil, created: nil, updated: nil)
|
39
40
|
super(id)
|
40
41
|
@amount = amount
|
41
42
|
@name = name
|
@@ -45,14 +46,15 @@ module StarkBank
|
|
45
46
|
@account_number = account_number
|
46
47
|
@account_type = account_type
|
47
48
|
@external_id = external_id
|
48
|
-
@scheduled =
|
49
|
+
@scheduled = StarkCore::Utils::Checks.check_date_or_datetime(scheduled)
|
49
50
|
@description = description
|
50
|
-
@transaction_ids = transaction_ids
|
51
|
-
@fee = fee
|
52
51
|
@tags = tags
|
52
|
+
@rules = StarkBank::Transfer::Rule.parse_rules(rules)
|
53
|
+
@fee = fee
|
53
54
|
@status = status
|
54
|
-
@
|
55
|
-
@
|
55
|
+
@transaction_ids = transaction_ids
|
56
|
+
@created = StarkCore::Utils::Checks.check_datetime(created)
|
57
|
+
@updated = StarkCore::Utils::Checks.check_datetime(updated)
|
56
58
|
end
|
57
59
|
|
58
60
|
# # Create Transfers
|
@@ -138,8 +140,8 @@ module StarkBank
|
|
138
140
|
# ## Return:
|
139
141
|
# - generator of Transfer objects with updated attributes
|
140
142
|
def self.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil)
|
141
|
-
after =
|
142
|
-
before =
|
143
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
144
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
143
145
|
StarkBank::Utils::Rest.get_stream(
|
144
146
|
limit: limit,
|
145
147
|
after: after,
|
@@ -173,8 +175,8 @@ module StarkBank
|
|
173
175
|
# ## Return:
|
174
176
|
# - list of Transfer objects with updated attributes and cursor to retrieve the next page of Transfer objects
|
175
177
|
def self.page(cursor: nil, limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil)
|
176
|
-
after =
|
177
|
-
before =
|
178
|
+
after = StarkCore::Utils::Checks.check_date(after)
|
179
|
+
before = StarkCore::Utils::Checks.check_date(before)
|
178
180
|
return StarkBank::Utils::Rest.get_page(
|
179
181
|
cursor: cursor,
|
180
182
|
limit: limit,
|
@@ -196,7 +198,6 @@ module StarkBank
|
|
196
198
|
resource_name: 'Transfer',
|
197
199
|
resource_maker: proc { |json|
|
198
200
|
Transfer.new(
|
199
|
-
id: json['id'],
|
200
201
|
amount: json['amount'],
|
201
202
|
name: json['name'],
|
202
203
|
tax_id: json['tax_id'],
|
@@ -207,10 +208,12 @@ module StarkBank
|
|
207
208
|
external_id: json['external_id'],
|
208
209
|
scheduled: json['scheduled'],
|
209
210
|
description: json['description'],
|
210
|
-
transaction_ids: json['transaction_ids'],
|
211
|
-
fee: json['fee'],
|
212
211
|
tags: json['tags'],
|
212
|
+
rules: json['rules'],
|
213
|
+
id: json['id'],
|
214
|
+
fee: json['fee'],
|
213
215
|
status: json['status'],
|
216
|
+
transaction_ids: json['transaction_ids'],
|
214
217
|
created: json['created'],
|
215
218
|
updated: json['updated']
|
216
219
|
)
|