starkbank 0.4.2 → 2.1.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/boleto/boleto.rb +1 -1
- data/lib/boleto_holmes/boleto_holmes.rb +121 -0
- data/lib/boleto_holmes/log.rb +91 -0
- data/lib/boleto_payment/boleto_payment.rb +1 -1
- data/lib/event/event.rb +4 -2
- data/lib/payment_request/payment_request.rb +142 -0
- data/lib/starkbank.rb +3 -0
- data/lib/transaction/transaction.rb +13 -2
- data/lib/transfer/transfer.rb +24 -3
- data/lib/utility_payment/utility_payment.rb +1 -1
- data/lib/utils/api.rb +17 -4
- data/lib/utils/request.rb +1 -1
- data/lib/webhook/webhook.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21f296f6ce46e6451eb4650fcc5bd8f77b657184b10662daae70c79c4df26cc3
|
4
|
+
data.tar.gz: 2a0355e608aa51c1302ea55c8491741981afbfefd2bb86f56fb606fc4ab38c76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cce7c99b52dc834e4110caa9861a89dbb039d02d080d17631995666298798f6c1ca7024796958cc170d7f08d5a594a8f8ee4bb98078f8897e75a8455dad55987
|
7
|
+
data.tar.gz: 2e5c9d0a3d0f33b050f08b29e35453db3011190760145aec59a87a993a1086c038e9d430004cd8bdf7fe1ef657d08554d4eea4fec14d5e9d2692f57df71808c5
|
data/lib/boleto/boleto.rb
CHANGED
@@ -164,7 +164,7 @@ module StarkBank
|
|
164
164
|
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
165
165
|
#
|
166
166
|
# ## Return:
|
167
|
-
# - deleted Boleto
|
167
|
+
# - deleted Boleto object
|
168
168
|
def self.delete(id, user: nil)
|
169
169
|
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
170
170
|
end
|
@@ -0,0 +1,121 @@
|
|
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
|
+
# # BoletoHolmes object
|
9
|
+
#
|
10
|
+
# When you initialize a BoletoHolmes, the entity will not be automatically
|
11
|
+
# created in 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
|
+
# - boleto_id [string]: investigated boleto entity ID. ex: '5656565656565656'
|
16
|
+
#
|
17
|
+
# ## Parameters (optional):
|
18
|
+
# - tags [list of strings]: list of strings for tagging
|
19
|
+
#
|
20
|
+
# ## Attributes (return-only):
|
21
|
+
# - id [string, default nil]: unique id returned when holmes is created. ex: '5656565656565656'
|
22
|
+
# - status [string, default nil]: current holmes status. ex: 'solving' or 'solved'
|
23
|
+
# - result [string, default nil]: result of boleto status investigation. ex: 'paid' or 'cancelled'
|
24
|
+
# - created [DateTime, default nil]: creation datetime for the Boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
25
|
+
# - updated [DateTime, default nil]: latest update datetime for the holmes. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
26
|
+
class BoletoHolmes < StarkBank::Utils::Resource
|
27
|
+
attr_reader :boleto_id, :tags, :id, :status, :result, :created, :updated
|
28
|
+
def initialize(
|
29
|
+
boleto_id:, tags: nil, id: nil, status: nil, result: nil, created: nil, updated: nil
|
30
|
+
)
|
31
|
+
super(id)
|
32
|
+
@boleto_id = boleto_id
|
33
|
+
@tags = tags
|
34
|
+
@status = status
|
35
|
+
@result = result
|
36
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
37
|
+
@updated = StarkBank::Utils::Checks.check_datetime(updated)
|
38
|
+
end
|
39
|
+
|
40
|
+
# # Create BoletoHolmes
|
41
|
+
#
|
42
|
+
# Send a list of BoletoHolmes objects for creation in the Stark Bank API
|
43
|
+
#
|
44
|
+
# ## Parameters (required):
|
45
|
+
# - holmes [list of BoletoHolmes objects]: list of BoletoHolmes objects to be created in the API
|
46
|
+
#
|
47
|
+
# ## Parameters (optional):
|
48
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
49
|
+
#
|
50
|
+
# ## Return:
|
51
|
+
# - list of BoletoHolmes objects with updated attributes
|
52
|
+
def self.create(holmes, user: nil)
|
53
|
+
StarkBank::Utils::Rest.post(entities: holmes, user: user, **resource)
|
54
|
+
end
|
55
|
+
|
56
|
+
# # Retrieve a specific BoletoHolmes
|
57
|
+
#
|
58
|
+
# Receive a single BoletoHolmes object previously created by the Stark Bank API by passing its id
|
59
|
+
#
|
60
|
+
# ## Parameters (required):
|
61
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
62
|
+
#
|
63
|
+
# ## Parameters (optional):
|
64
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
65
|
+
#
|
66
|
+
# ## Return:
|
67
|
+
# - BoletoHolmes object with updated attributes
|
68
|
+
def self.get(id, user: nil)
|
69
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
70
|
+
end
|
71
|
+
|
72
|
+
# # Retrieve BoletoHolmes
|
73
|
+
#
|
74
|
+
# Receive a generator of BoletoHolmes objects previously created in the Stark Bank API
|
75
|
+
#
|
76
|
+
# ## Parameters (optional):
|
77
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
78
|
+
# - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
79
|
+
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
80
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'solved'
|
81
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
82
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
83
|
+
# - boleto_id [string, default nil]: filter for holmes that investigate a specific boleto by its ID. ex: '5656565656565656'
|
84
|
+
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
85
|
+
#
|
86
|
+
# ## Return:
|
87
|
+
# - generator of BoletoHolmes objects with updated attributes
|
88
|
+
def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, boleto_id: nil, user: nil)
|
89
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
90
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
91
|
+
StarkBank::Utils::Rest.get_list(
|
92
|
+
limit: limit,
|
93
|
+
after: after,
|
94
|
+
before: before,
|
95
|
+
status: status,
|
96
|
+
tags: tags,
|
97
|
+
ids: ids,
|
98
|
+
boleto_id: boleto_id,
|
99
|
+
user: user,
|
100
|
+
**resource
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.resource
|
105
|
+
{
|
106
|
+
resource_name: 'BoletoHolmes',
|
107
|
+
resource_maker: proc { |json|
|
108
|
+
BoletoHolmes.new(
|
109
|
+
boleto_id: json['boleto_id'],
|
110
|
+
tags: json['tags'],
|
111
|
+
id: json['id'],
|
112
|
+
status: json['status'],
|
113
|
+
result: json['result'],
|
114
|
+
created: json['created'],
|
115
|
+
updated: json['updated']
|
116
|
+
)
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
require_relative('boleto_holmes')
|
7
|
+
|
8
|
+
module StarkBank
|
9
|
+
class BoletoHolmes
|
10
|
+
# # BoletoHolmes::Log object
|
11
|
+
#
|
12
|
+
# Every time a BoletoHolmes entity is modified, a corresponding BoletoHolmes::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 BoletoHolmes.
|
16
|
+
#
|
17
|
+
# ## Attributes:
|
18
|
+
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
19
|
+
# - holmes [BoletoHolmes]: BoletoHolmes entity to which the log refers to.
|
20
|
+
# - type [string]: type of the Boleto event which triggered the log creation. ex: 'registered' or 'paid'
|
21
|
+
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
22
|
+
class Log < StarkBank::Utils::Resource
|
23
|
+
attr_reader :id, :holmes, :type, :created
|
24
|
+
def initialize(id:, holmes:, type:, created:)
|
25
|
+
super(id)
|
26
|
+
@holmes = holmes
|
27
|
+
@type = type
|
28
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
29
|
+
end
|
30
|
+
|
31
|
+
# # Retrieve a specific Log
|
32
|
+
#
|
33
|
+
# Receive a single Log object previously created by the Stark Bank API by passing its id
|
34
|
+
#
|
35
|
+
# ## Parameters (required):
|
36
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
37
|
+
#
|
38
|
+
# ## Parameters (optional):
|
39
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
40
|
+
#
|
41
|
+
# ## Return:
|
42
|
+
# - Log object with updated attributes
|
43
|
+
def self.get(id, user: nil)
|
44
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
45
|
+
end
|
46
|
+
|
47
|
+
# # Retrieve Logs
|
48
|
+
#
|
49
|
+
# Receive a generator of Log objects previously created in the Stark Bank API
|
50
|
+
#
|
51
|
+
# ## Parameters (optional):
|
52
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
53
|
+
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
54
|
+
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
55
|
+
# - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'registered'
|
56
|
+
# - holmes_ids [list of strings, default nil]: list of BoletoHolmes ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
57
|
+
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
58
|
+
#
|
59
|
+
# ## Return:
|
60
|
+
# - list of Log objects with updated attributes
|
61
|
+
def self.query(limit: nil, after: nil, before: nil, types: nil, holmes_ids: nil, user: nil)
|
62
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
63
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
64
|
+
StarkBank::Utils::Rest.get_list(
|
65
|
+
limit: limit,
|
66
|
+
after: after,
|
67
|
+
before: before,
|
68
|
+
types: types,
|
69
|
+
holmes_ids: holmes_ids,
|
70
|
+
user: user,
|
71
|
+
**resource
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.resource
|
76
|
+
holmes_maker = StarkBank::BoletoHolmes.resource[:resource_maker]
|
77
|
+
{
|
78
|
+
resource_name: 'BoletoHolmesLog',
|
79
|
+
resource_maker: proc { |json|
|
80
|
+
Log.new(
|
81
|
+
id: json['id'],
|
82
|
+
holmes: StarkBank::Utils::API.from_api_json(holmes_maker, json['holmes']),
|
83
|
+
type: json['type'],
|
84
|
+
created: json['created']
|
85
|
+
)
|
86
|
+
}
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -133,7 +133,7 @@ module StarkBank
|
|
133
133
|
# Parameters (optional):
|
134
134
|
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
135
135
|
# Return:
|
136
|
-
# - deleted BoletoPayment
|
136
|
+
# - deleted BoletoPayment object
|
137
137
|
def self.delete(id, user: nil)
|
138
138
|
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
139
139
|
end
|
data/lib/event/event.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative('../utils/checks')
|
|
8
8
|
require_relative('../utils/cache')
|
9
9
|
require_relative('../error')
|
10
10
|
require_relative('../boleto/log')
|
11
|
+
require_relative('../boleto_holmes/log')
|
11
12
|
require_relative('../transfer/log')
|
12
13
|
require_relative('../boleto_payment/log')
|
13
14
|
require_relative('../utility_payment/log')
|
@@ -37,7 +38,8 @@ module StarkBank
|
|
37
38
|
'transfer': StarkBank::Transfer::Log.resource,
|
38
39
|
'boleto': StarkBank::Boleto::Log.resource,
|
39
40
|
'boleto-payment': StarkBank::BoletoPayment::Log.resource,
|
40
|
-
'utility-payment': StarkBank::UtilityPayment::Log.resource
|
41
|
+
'utility-payment': StarkBank::UtilityPayment::Log.resource,
|
42
|
+
'boleto-holmes': StarkBank::BoletoHolmes::Log.resource
|
41
43
|
}[subscription.to_sym]
|
42
44
|
|
43
45
|
@log = log
|
@@ -97,7 +99,7 @@ module StarkBank
|
|
97
99
|
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
98
100
|
#
|
99
101
|
# ## Return:
|
100
|
-
# - deleted Event
|
102
|
+
# - deleted Event object
|
101
103
|
def self.delete(id, user: nil)
|
102
104
|
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
103
105
|
end
|
@@ -0,0 +1,142 @@
|
|
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
|
+
# # PaymentRequest object
|
9
|
+
# A PaymentRequest is an indirect request to access a specific cash-out service
|
10
|
+
# (such as Transfer, BoletoPayments, etc.) which goes through the cost center
|
11
|
+
# approval flow on our website. To emit a PaymentRequest, you must direct it to
|
12
|
+
# a specific cost center by its ID, which can be retrieved on our website at the
|
13
|
+
# cost center page.
|
14
|
+
#
|
15
|
+
# ## Parameters (required):
|
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.
|
18
|
+
#
|
19
|
+
# ## Parameters (optional):
|
20
|
+
# - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'boleto-payment'
|
21
|
+
# - due [Date, DateTime, Time or string]: Payment target date in ISO format. ex: 2020-12-31
|
22
|
+
# - tags [list of strings]: list of strings for tagging
|
23
|
+
#
|
24
|
+
# ## Attributes (return-only):
|
25
|
+
# - id [String]: unique id returned when PaymentRequest is created. ex: '5656565656565656'
|
26
|
+
# - amount [integer, default nil]: PaymentRequest amount. ex: 100000 = R$1.000,00
|
27
|
+
# - status [string, default nil]: current PaymentRequest status.ex: 'pending' or 'approved'
|
28
|
+
# - actions [list of dictionaries, default nil]: list of actions that are affecting this PaymentRequest. ex: [{'type': 'member', 'id': '56565656565656, 'action': 'requested'}]
|
29
|
+
# - updated [DateTime, default nil]: latest update datetime for the PaymentRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
30
|
+
# - created [DateTime, default nil]: creation datetime for the PaymentRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
31
|
+
#
|
32
|
+
class PaymentRequest < StarkBank::Utils::Resource
|
33
|
+
attr_reader :center_id, :payment, :type, :due, :tags, :amount, :status, :actions, :updated, :created
|
34
|
+
def initialize(
|
35
|
+
payment:, center_id:, id: nil, type: nil, due: nil, tags: nil, amount: nil, status: nil,
|
36
|
+
actions: nil, updated: nil, created: nil
|
37
|
+
)
|
38
|
+
super(id)
|
39
|
+
@center_id = center_id
|
40
|
+
@due = due
|
41
|
+
@tags = tags
|
42
|
+
@amount = amount
|
43
|
+
@status = status
|
44
|
+
@actions = actions
|
45
|
+
@updated = updated
|
46
|
+
@created = created
|
47
|
+
|
48
|
+
@payment, @type = parse_payment(payment: payment, type: type)
|
49
|
+
end
|
50
|
+
|
51
|
+
## Create PaymentRequests
|
52
|
+
# Sends a list of PaymentRequests objects for creating in the Stark Bank API
|
53
|
+
#
|
54
|
+
# ## Parameters
|
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 StarkBank.User.Default was set before function call
|
57
|
+
#
|
58
|
+
# ## Return
|
59
|
+
# - list of PaymentRequest objects with updated attributes
|
60
|
+
#
|
61
|
+
def self.create(payment_requests, user: nil)
|
62
|
+
StarkBank::Utils::Rest.post(entities: payment_requests, user: user, **resource)
|
63
|
+
end
|
64
|
+
|
65
|
+
# # Retrieve PaymentRequests
|
66
|
+
#
|
67
|
+
# Receive a generator of PaymentRequest objects previously created in the Stark Bank API
|
68
|
+
#
|
69
|
+
# ## Parameters (required):
|
70
|
+
# - center_id [string]: target cost center ID. ex: '5656565656565656'
|
71
|
+
# ## Parameters (optional):
|
72
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
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
|
+
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
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', 'boleto-payment'
|
77
|
+
# - sort [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
78
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
79
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
80
|
+
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
81
|
+
#
|
82
|
+
# ## Return:
|
83
|
+
# - generator of PaymentRequest objects with updated attributes
|
84
|
+
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 = StarkBank::Utils::Checks.check_date(after)
|
86
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
87
|
+
StarkBank::Utils::Rest.get_list(
|
88
|
+
center_id: center_id,
|
89
|
+
limit: limit,
|
90
|
+
after: after,
|
91
|
+
before: before,
|
92
|
+
status: status,
|
93
|
+
type: type,
|
94
|
+
sort: sort,
|
95
|
+
tags: tags,
|
96
|
+
ids: ids,
|
97
|
+
user: user,
|
98
|
+
**resource
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def parse_payment(payment:, type:)
|
103
|
+
return [payment, 'transfer'] if payment.is_a?(StarkBank::Transfer)
|
104
|
+
return [payment, 'transaction'] if payment.is_a?(StarkBank::Transaction)
|
105
|
+
return [payment, 'boleto-payment'] if payment.is_a?(StarkBank::BoletoPayment)
|
106
|
+
return [payment, 'utility-payment'] if payment.is_a?(StarkBank::UtilityPayment)
|
107
|
+
|
108
|
+
raise(Exception('Payment must either be a Transfer, a Transaction, a BoletoPayment, a UtilityPayment or a hash.')) unless payment.is_a?(Hash)
|
109
|
+
|
110
|
+
resource = {
|
111
|
+
'transfer': StarkBank::Transfer.resource,
|
112
|
+
'transaction': StarkBank::Transaction.resource,
|
113
|
+
'boleto-payment': StarkBank::BoletoPayment.resource,
|
114
|
+
'utility-payment': StarkBank::UtilityPayment.resource
|
115
|
+
}[type.to_sym]
|
116
|
+
|
117
|
+
payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
|
118
|
+
|
119
|
+
[payment, type]
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.resource
|
123
|
+
{
|
124
|
+
resource_name: 'PaymentRequest',
|
125
|
+
resource_maker: proc { |json|
|
126
|
+
PaymentRequest.new(
|
127
|
+
id: json['id'],
|
128
|
+
payment: json['payment'],
|
129
|
+
center_id: json['centerId'],
|
130
|
+
type: json['type'],
|
131
|
+
tags: json['tags'],
|
132
|
+
amount: json['amount'],
|
133
|
+
status: json['status'],
|
134
|
+
actions: json['actions'],
|
135
|
+
updated: json['updated'],
|
136
|
+
created: json['created']
|
137
|
+
)
|
138
|
+
}
|
139
|
+
}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/lib/starkbank.rb
CHANGED
@@ -6,6 +6,8 @@ require_relative('balance/balance')
|
|
6
6
|
require_relative('transaction/transaction')
|
7
7
|
require_relative('boleto/boleto')
|
8
8
|
require_relative('boleto/log')
|
9
|
+
require_relative('boleto_holmes/boleto_holmes')
|
10
|
+
require_relative('boleto_holmes/log')
|
9
11
|
require_relative('transfer/transfer')
|
10
12
|
require_relative('transfer/log')
|
11
13
|
require_relative('boleto_payment/boleto_payment')
|
@@ -14,6 +16,7 @@ require_relative('utility_payment/utility_payment')
|
|
14
16
|
require_relative('utility_payment/log')
|
15
17
|
require_relative('webhook/webhook')
|
16
18
|
require_relative('event/event')
|
19
|
+
require_relative('payment_request/payment_request')
|
17
20
|
|
18
21
|
# SDK to facilitate Ruby integrations with Stark Bank
|
19
22
|
module StarkBank
|
@@ -87,15 +87,26 @@ module StarkBank
|
|
87
87
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
88
88
|
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
89
89
|
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
90
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
90
91
|
# - external_ids [list of strings, default nil]: list of external ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
92
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
91
93
|
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
92
94
|
#
|
93
95
|
# ## Return:
|
94
96
|
# - generator of Transaction objects with updated attributes
|
95
|
-
def self.query(limit: nil, after: nil, before: nil, external_ids: nil, user: nil)
|
97
|
+
def self.query(limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil)
|
96
98
|
after = StarkBank::Utils::Checks.check_date(after)
|
97
99
|
before = StarkBank::Utils::Checks.check_date(before)
|
98
|
-
StarkBank::Utils::Rest.get_list(
|
100
|
+
StarkBank::Utils::Rest.get_list(
|
101
|
+
limit: limit,
|
102
|
+
after: after,
|
103
|
+
before: before,
|
104
|
+
tags: tags,
|
105
|
+
external_ids: external_ids,
|
106
|
+
ids: ids,
|
107
|
+
user: user,
|
108
|
+
**resource
|
109
|
+
)
|
99
110
|
end
|
100
111
|
|
101
112
|
def self.resource
|
data/lib/transfer/transfer.rb
CHANGED
@@ -21,6 +21,7 @@ module StarkBank
|
|
21
21
|
#
|
22
22
|
# ## Parameters (optional):
|
23
23
|
# - 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)
|
24
25
|
#
|
25
26
|
# ## Attributes (return-only):
|
26
27
|
# - id [string, default nil]: unique id returned when Transfer is created. ex: '5656565656565656'
|
@@ -30,8 +31,8 @@ module StarkBank
|
|
30
31
|
# - created [DateTime, default nil]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
31
32
|
# - updated [DateTime, default nil]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
32
33
|
class Transfer < StarkBank::Utils::Resource
|
33
|
-
attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
|
34
|
-
def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
|
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)
|
35
36
|
super(id)
|
36
37
|
@amount = amount
|
37
38
|
@name = name
|
@@ -39,6 +40,7 @@ module StarkBank
|
|
39
40
|
@bank_code = bank_code
|
40
41
|
@branch_code = branch_code
|
41
42
|
@account_number = account_number
|
43
|
+
@scheduled = StarkBank::Utils::Checks.check_datetime(scheduled)
|
42
44
|
@transaction_ids = transaction_ids
|
43
45
|
@fee = fee
|
44
46
|
@tags = tags
|
@@ -79,6 +81,22 @@ module StarkBank
|
|
79
81
|
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
80
82
|
end
|
81
83
|
|
84
|
+
# # Delete a Transfer entity
|
85
|
+
#
|
86
|
+
# Delete a Transfer entity previously created in the Stark Bank API
|
87
|
+
#
|
88
|
+
# ## Parameters (required):
|
89
|
+
# - id [string]: Transfer unique id. ex: '5656565656565656'
|
90
|
+
#
|
91
|
+
# ## Parameters (optional):
|
92
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
93
|
+
#
|
94
|
+
# ## Return:
|
95
|
+
# - deleted Transfer object
|
96
|
+
def self.delete(id, user: nil)
|
97
|
+
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
98
|
+
end
|
99
|
+
|
82
100
|
# # Retrieve a specific Transfer pdf file
|
83
101
|
#
|
84
102
|
# Receive a single Transfer pdf receipt file generated in the Stark Bank API by passing its id.
|
@@ -108,11 +126,12 @@ module StarkBank
|
|
108
126
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
|
109
127
|
# - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex: "012.345.678-90"
|
110
128
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
129
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
111
130
|
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
112
131
|
#
|
113
132
|
# ## Return:
|
114
133
|
# - generator of Transfer objects with updated attributes
|
115
|
-
def self.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, user: nil)
|
134
|
+
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)
|
116
135
|
after = StarkBank::Utils::Checks.check_date(after)
|
117
136
|
before = StarkBank::Utils::Checks.check_date(before)
|
118
137
|
StarkBank::Utils::Rest.get_list(
|
@@ -124,6 +143,7 @@ module StarkBank
|
|
124
143
|
tax_id: tax_id,
|
125
144
|
sort: sort,
|
126
145
|
tags: tags,
|
146
|
+
ids: ids,
|
127
147
|
user: user,
|
128
148
|
**resource
|
129
149
|
)
|
@@ -141,6 +161,7 @@ module StarkBank
|
|
141
161
|
bank_code: json['bank_code'],
|
142
162
|
branch_code: json['branch_code'],
|
143
163
|
account_number: json['account_number'],
|
164
|
+
scheduled: json['scheduled'],
|
144
165
|
transaction_ids: json['transaction_ids'],
|
145
166
|
fee: json['fee'],
|
146
167
|
tags: json['tags'],
|
@@ -133,7 +133,7 @@ module StarkBank
|
|
133
133
|
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
134
134
|
#
|
135
135
|
# ## Return:
|
136
|
-
# - deleted UtilityPayment
|
136
|
+
# - deleted UtilityPayment object
|
137
137
|
def self.delete(id, user: nil)
|
138
138
|
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
139
139
|
end
|
data/lib/utils/api.rb
CHANGED
@@ -5,16 +5,22 @@ require_relative('case')
|
|
5
5
|
module StarkBank
|
6
6
|
module Utils
|
7
7
|
module API
|
8
|
-
def self.
|
8
|
+
def self.build_entity_hash(entity)
|
9
9
|
if entity.is_a?(Hash)
|
10
10
|
entity_hash = entity
|
11
11
|
else
|
12
12
|
entity_hash = {}
|
13
13
|
entity.instance_variables.each do |key|
|
14
|
-
|
14
|
+
variable = entity.instance_variable_get(key)
|
15
|
+
entity_hash[key[1..-1]] = variable.is_a?(StarkBank::Utils::Resource) ? build_entity_hash(variable) : entity.instance_variable_get(key)
|
15
16
|
end
|
16
17
|
end
|
17
|
-
|
18
|
+
entity_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.api_json(entity)
|
22
|
+
built_hash = build_entity_hash(entity)
|
23
|
+
cast_json_to_api_format(built_hash)
|
18
24
|
end
|
19
25
|
|
20
26
|
def self.cast_json_to_api_format(hash)
|
@@ -30,6 +36,8 @@ module StarkBank
|
|
30
36
|
list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
|
31
37
|
end
|
32
38
|
value = list
|
39
|
+
elsif value.is_a?(Hash)
|
40
|
+
value = cast_json_to_api_format(value)
|
33
41
|
end
|
34
42
|
|
35
43
|
entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = value
|
@@ -52,7 +60,12 @@ module StarkBank
|
|
52
60
|
end
|
53
61
|
|
54
62
|
def self.last_name_plural(resource_name)
|
55
|
-
|
63
|
+
base = last_name(resource_name)
|
64
|
+
|
65
|
+
return base if base[-1].eql?('s')
|
66
|
+
return "#{base[0...-1]}ies" if base[-1].eql?('y')
|
67
|
+
|
68
|
+
"#{base}s"
|
56
69
|
end
|
57
70
|
|
58
71
|
def self.last_name(resource_name)
|
data/lib/utils/request.rb
CHANGED
@@ -61,7 +61,7 @@ module StarkBank
|
|
61
61
|
req['Access-Time'] = access_time
|
62
62
|
req['Access-Signature'] = signature
|
63
63
|
req['Content-Type'] = 'application/json'
|
64
|
-
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-
|
64
|
+
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.1.0"
|
65
65
|
req['Accept-Language'] = language
|
66
66
|
|
67
67
|
request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
|
data/lib/webhook/webhook.rb
CHANGED
@@ -83,7 +83,7 @@ module StarkBank
|
|
83
83
|
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
84
84
|
#
|
85
85
|
# ## Return:
|
86
|
-
# - deleted Webhook
|
86
|
+
# - deleted Webhook object
|
87
87
|
def self.delete(id, user: nil)
|
88
88
|
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
89
89
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: starkbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- starkbank
|
@@ -75,11 +75,14 @@ files:
|
|
75
75
|
- lib/balance/balance.rb
|
76
76
|
- lib/boleto/boleto.rb
|
77
77
|
- lib/boleto/log.rb
|
78
|
+
- lib/boleto_holmes/boleto_holmes.rb
|
79
|
+
- lib/boleto_holmes/log.rb
|
78
80
|
- lib/boleto_payment/boleto_payment.rb
|
79
81
|
- lib/boleto_payment/log.rb
|
80
82
|
- lib/error.rb
|
81
83
|
- lib/event/event.rb
|
82
84
|
- lib/key.rb
|
85
|
+
- lib/payment_request/payment_request.rb
|
83
86
|
- lib/starkbank.rb
|
84
87
|
- lib/transaction/transaction.rb
|
85
88
|
- lib/transfer/log.rb
|