starkbank 0.5.0 → 2.0.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/payment_request/payment_request.rb +142 -0
- data/lib/starkbank.rb +1 -0
- data/lib/transaction/transaction.rb +12 -2
- data/lib/transfer/transfer.rb +3 -1
- data/lib/utils/api.rb +11 -3
- data/lib/utils/request.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cde164881e744d7dd89ef1890e4793bb3b00b176309fd68878154562204f0fa
|
4
|
+
data.tar.gz: f216ff9ab2526f9807d13e3599412a3c8439d3b20e1ba7396df1aa7b50b75a8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2abcedf46bd193107cbafb446461199d573c72ef8fdf2c9182479e0ee897396f16298debb9d19920fba358babc1247c3f48a2bd8e9b80155d6f7a867de22987e
|
7
|
+
data.tar.gz: 2d95dd80a1fd990aa4d1a71dc32c01674c7c52471e7d8369db5787faf382e3c3043300762bc9d85d15a597e31399e7084eb3a25e943603176ea8503c0b258082
|
@@ -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
@@ -14,6 +14,7 @@ require_relative('utility_payment/utility_payment')
|
|
14
14
|
require_relative('utility_payment/log')
|
15
15
|
require_relative('webhook/webhook')
|
16
16
|
require_relative('event/event')
|
17
|
+
require_relative('payment_request/payment_request')
|
17
18
|
|
18
19
|
# SDK to facilitate Ruby integrations with Stark Bank
|
19
20
|
module StarkBank
|
@@ -89,14 +89,24 @@ module StarkBank
|
|
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
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
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
92
93
|
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
93
94
|
#
|
94
95
|
# ## Return:
|
95
96
|
# - generator of Transaction objects with updated attributes
|
96
|
-
def self.query(limit: nil, after: nil, before: nil, tags: 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)
|
97
98
|
after = StarkBank::Utils::Checks.check_date(after)
|
98
99
|
before = StarkBank::Utils::Checks.check_date(before)
|
99
|
-
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
|
+
)
|
100
110
|
end
|
101
111
|
|
102
112
|
def self.resource
|
data/lib/transfer/transfer.rb
CHANGED
@@ -126,11 +126,12 @@ module StarkBank
|
|
126
126
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
|
127
127
|
# - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex: "012.345.678-90"
|
128
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']
|
129
130
|
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
130
131
|
#
|
131
132
|
# ## Return:
|
132
133
|
# - generator of Transfer objects with updated attributes
|
133
|
-
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)
|
134
135
|
after = StarkBank::Utils::Checks.check_date(after)
|
135
136
|
before = StarkBank::Utils::Checks.check_date(before)
|
136
137
|
StarkBank::Utils::Rest.get_list(
|
@@ -142,6 +143,7 @@ module StarkBank
|
|
142
143
|
tax_id: tax_id,
|
143
144
|
sort: sort,
|
144
145
|
tags: tags,
|
146
|
+
ids: ids,
|
145
147
|
user: user,
|
146
148
|
**resource
|
147
149
|
)
|
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
|
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-0.
|
64
|
+
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.0.0"
|
65
65
|
req['Accept-Language'] = language
|
66
66
|
|
67
67
|
request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
|
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: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- starkbank
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/error.rb
|
81
81
|
- lib/event/event.rb
|
82
82
|
- lib/key.rb
|
83
|
+
- lib/payment_request/payment_request.rb
|
83
84
|
- lib/starkbank.rb
|
84
85
|
- lib/transaction/transaction.rb
|
85
86
|
- lib/transfer/log.rb
|