starkbank 0.0.1
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 +7 -0
- data/lib/boleto/boleto.rb +186 -0
- data/lib/boleto/log.rb +86 -0
- data/lib/error.rb +44 -0
- data/lib/key.rb +32 -0
- data/lib/ledger/balance.rb +60 -0
- data/lib/ledger/transaction.rb +116 -0
- data/lib/payment/boleto/boleto.rb +152 -0
- data/lib/payment/boleto/log.rb +82 -0
- data/lib/payment/utility/log.rb +81 -0
- data/lib/payment/utility/utility.rb +152 -0
- data/lib/starkbank.rb +22 -0
- data/lib/transfer/log.rb +85 -0
- data/lib/transfer/transfer.rb +143 -0
- data/lib/user/project.rb +32 -0
- data/lib/user/user.rb +24 -0
- data/lib/utils/api.rb +50 -0
- data/lib/utils/cache.rb +10 -0
- data/lib/utils/case.rb +21 -0
- data/lib/utils/checks.rb +81 -0
- data/lib/utils/environment.rb +13 -0
- data/lib/utils/request.rb +77 -0
- data/lib/utils/resource.rb +32 -0
- data/lib/utils/rest.rb +111 -0
- data/lib/utils/url.rb +26 -0
- data/lib/webhook/event.rb +174 -0
- data/lib/webhook/webhook.rb +104 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6d65ed1998822eddbae0c884f2ab425848c2a05711b680fed40a245fa5538d98
|
4
|
+
data.tar.gz: 34bc16683bbc9a2c3cfb8dcc3c3877ba2cd63be33553497e458d76052e0ba00d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7013c769d56db0763f01d385b0f5e5d58b606d00efe7253537aaa738d0e20234c25daf5871cea0d18c0cca5ae0546597234d8d970b29e847c895280629445da
|
7
|
+
data.tar.gz: 6a71ddbe5114747fedc06ec97390a390c0017f2f7c4aae4637636595191a560aba3e266f66e48a883a987427b496a46d0395e5f45d984a375ec8d398cea69e43
|
@@ -0,0 +1,186 @@
|
|
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
|
+
# # Boleto object
|
9
|
+
#
|
10
|
+
# When you initialize a Boleto, 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]: Boleto value in cents. Minimum = 200 (R$2,00). ex: 1234 (= R$ 12.34)
|
16
|
+
# - name [string]: payer full name. ex: "Anthony Edward Stark"
|
17
|
+
# - tax_id [string]: payer tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80"
|
18
|
+
# - street_line_1 [string]: payer main address. ex: Av. Paulista, 200
|
19
|
+
# - street_line_2 [string]: payer address complement. ex: Apto. 123
|
20
|
+
# - district [string]: payer address district / neighbourhood. ex: Bela Vista
|
21
|
+
# - city [string]: payer address city. ex: Rio de Janeiro
|
22
|
+
# - state_code [string]: payer address state. ex: GO
|
23
|
+
# - zip_code [string]: payer address zip code. ex: 01311-200
|
24
|
+
# - due [Date, default today + 2 days]: Boleto due date in ISO format. ex: 2020-04-30
|
25
|
+
#
|
26
|
+
# ## Parameters (optional):
|
27
|
+
# - fine [float, default 0.0]: Boleto fine for overdue payment in %. ex: 2.5
|
28
|
+
# - interest [float, default 0.0]: Boleto monthly interest for overdue payment in %. ex: 5.2
|
29
|
+
# - overdue_limit [integer, default 59]: limit in days for automatic Boleto cancellation after due date. ex: 7 (max: 59)
|
30
|
+
# - descriptions [list of dictionaries, default nil]: list of dictionaries with "text":string and (optional) "amount":int pairs
|
31
|
+
# - tags [list of strings]: list of strings for tagging
|
32
|
+
#
|
33
|
+
# ## Attributes (return-only):
|
34
|
+
# - id [string, default nil]: unique id returned when Boleto is created. ex: "5656565656565656"
|
35
|
+
# - fee [integer, default nil]: fee charged when Boleto is paid. ex: 200 (= R$ 2.00)
|
36
|
+
# - line [string, default nil]: generated Boleto line for payment. ex: "34191.09008 63571.277308 71444.640008 5 81960000000062"
|
37
|
+
# - bar_code [string, default nil]: generated Boleto bar-code for payment. ex: "34195819600000000621090063571277307144464000"
|
38
|
+
# - status [string, default nil]: current Boleto status. ex: "registered" or "paid"
|
39
|
+
# - created [DateTime, default nil]: creation datetime for the Boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
40
|
+
class Boleto < StarkBank::Utils::Resource
|
41
|
+
attr_reader :amount, :name, :tax_id, :street_line_1, :street_line_2, :district, :city, :state_code, :zip_code, :due, :fine, :interest, :overdue_limit, :tags, :descriptions, :id, :fee, :line, :bar_code, :status, :created
|
42
|
+
def initialize(
|
43
|
+
amount:, name:, tax_id:, street_line_1:, street_line_2:, district:, city:, state_code:, zip_code:,
|
44
|
+
due: nil, fine: nil, interest: nil, overdue_limit: nil, tags: nil, descriptions: nil, id: nil, fee: nil, line: nil,
|
45
|
+
bar_code: nil, status: nil, created: nil
|
46
|
+
)
|
47
|
+
super(id)
|
48
|
+
@amount = amount
|
49
|
+
@name = name
|
50
|
+
@tax_id = tax_id
|
51
|
+
@street_line_1 = street_line_1
|
52
|
+
@street_line_2 = street_line_2
|
53
|
+
@district = district
|
54
|
+
@city = city
|
55
|
+
@state_code = state_code
|
56
|
+
@zip_code = zip_code
|
57
|
+
@due = due
|
58
|
+
@fine = fine
|
59
|
+
@interest = interest
|
60
|
+
@overdue_limit = overdue_limit
|
61
|
+
@tags = tags
|
62
|
+
@descriptions = descriptions
|
63
|
+
@fee = fee
|
64
|
+
@line = line
|
65
|
+
@bar_code = bar_code
|
66
|
+
@status = status
|
67
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
68
|
+
end
|
69
|
+
|
70
|
+
# # Create Boletos
|
71
|
+
#
|
72
|
+
# Send a list of Boleto objects for creation in the Stark Bank API
|
73
|
+
#
|
74
|
+
# ## Parameters (required):
|
75
|
+
# - boletos [list of Boleto objects]: list of Boleto objects to be created in the API
|
76
|
+
#
|
77
|
+
# ## Parameters (optional):
|
78
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
79
|
+
#
|
80
|
+
# ## Return:
|
81
|
+
# - list of Boleto objects with updated attributes
|
82
|
+
def self.create(boletos:, user: nil)
|
83
|
+
StarkBank::Utils::Rest.post(entities: boletos, user: user, **resource)
|
84
|
+
end
|
85
|
+
|
86
|
+
# # Retrieve a specific Boleto
|
87
|
+
#
|
88
|
+
# Receive a single Boleto object previously created in the Stark Bank API by passing its id
|
89
|
+
#
|
90
|
+
# ## Parameters (required):
|
91
|
+
# - id [string]: object unique id. ex: "5656565656565656"
|
92
|
+
#
|
93
|
+
# ## Parameters (optional):
|
94
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
95
|
+
#
|
96
|
+
# ## Return:
|
97
|
+
# - Boleto object with updated attributes
|
98
|
+
def self.get(id:, user: nil)
|
99
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
100
|
+
end
|
101
|
+
|
102
|
+
# # Retrieve a specific Boleto pdf file
|
103
|
+
#
|
104
|
+
# Receive a single Boleto pdf file generated in the Stark Bank API by passing its id.
|
105
|
+
#
|
106
|
+
# ## Parameters (required):
|
107
|
+
# - id [string]: object unique id. ex: "5656565656565656"
|
108
|
+
#
|
109
|
+
# ## Parameters (optional):
|
110
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
111
|
+
#
|
112
|
+
# ## Return:
|
113
|
+
# - Boleto pdf file
|
114
|
+
def self.pdf(id:, user: nil)
|
115
|
+
StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
|
116
|
+
end
|
117
|
+
|
118
|
+
# # Retrieve Boletos
|
119
|
+
#
|
120
|
+
# Receive a generator of Boleto objects previously created in the Stark Bank API
|
121
|
+
#
|
122
|
+
# ## Parameters (optional):
|
123
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
124
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: "paid" or "registered"
|
125
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"]
|
126
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
|
127
|
+
# - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
128
|
+
# - before [Date, default nil] date filter for objects only before specified date. ex: Date.new(2020, 3, 10)
|
129
|
+
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
130
|
+
#
|
131
|
+
# ## Return:
|
132
|
+
# - generator of Boleto objects with updated attributes
|
133
|
+
def self.query(limit: nil, status: nil, tags: nil, ids: nil, after: nil, before: nil, user: nil)
|
134
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
135
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
136
|
+
StarkBank::Utils::Rest.get_list(user: user, limit: limit, status: status, tags: tags, ids: ids, after: after, before: before, **resource)
|
137
|
+
end
|
138
|
+
|
139
|
+
# # Delete a Boleto entity
|
140
|
+
#
|
141
|
+
# Delete a Boleto entity previously created in the Stark Bank API
|
142
|
+
#
|
143
|
+
# ## Parameters (required):
|
144
|
+
# - id [string]: Boleto unique id. ex: "5656565656565656"
|
145
|
+
#
|
146
|
+
# ## Parameters (optional):
|
147
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
148
|
+
#
|
149
|
+
# ## Return:
|
150
|
+
# - deleted Boleto with updated attributes
|
151
|
+
def self.delete(id:, user: nil)
|
152
|
+
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.resource
|
156
|
+
{
|
157
|
+
resource_name: 'Boleto',
|
158
|
+
resource_maker: proc { |json|
|
159
|
+
Boleto.new(
|
160
|
+
amount: json['amount'],
|
161
|
+
name: json['name'],
|
162
|
+
tax_id: json['tax_id'],
|
163
|
+
street_line_1: json['street_line_1'],
|
164
|
+
street_line_2: json['street_line_2'],
|
165
|
+
district: json['district'],
|
166
|
+
city: json['city'],
|
167
|
+
state_code: json['state_code'],
|
168
|
+
zip_code: json['zip_code'],
|
169
|
+
due: json['due'],
|
170
|
+
fine: json['fine'],
|
171
|
+
interest: json['interest'],
|
172
|
+
overdue_limit: json['overdue_limit'],
|
173
|
+
tags: json['tags'],
|
174
|
+
descriptions: json['descriptions'],
|
175
|
+
id: json['id'],
|
176
|
+
fee: json['fee'],
|
177
|
+
line: json['line'],
|
178
|
+
bar_code: json['bar_code'],
|
179
|
+
status: json['status'],
|
180
|
+
created: json['created']
|
181
|
+
)
|
182
|
+
}
|
183
|
+
}
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
data/lib/boleto/log.rb
ADDED
@@ -0,0 +1,86 @@
|
|
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')
|
7
|
+
|
8
|
+
module StarkBank
|
9
|
+
class Boleto
|
10
|
+
# # Boleto::Log object
|
11
|
+
#
|
12
|
+
# Every time a Boleto entity is updated, a corresponding Boleto::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 Boleto.
|
16
|
+
#
|
17
|
+
# ## Attributes:
|
18
|
+
# - id [string]: unique id returned when the log is created. ex: "5656565656565656"
|
19
|
+
# - boleto [Boleto]: Boleto entity to which the log refers to.
|
20
|
+
# - errors [list of strings]: list of errors linked to this Boleto event
|
21
|
+
# - type [string]: type of the Boleto event which triggered the log creation. ex: "registered" or "paid"
|
22
|
+
# - created [DateTime]: creation datetime for the boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
23
|
+
class Log < StarkBank::Utils::Resource
|
24
|
+
attr_reader :id, :created, :type, :errors, :boleto
|
25
|
+
def initialize(id:, created:, type:, errors:, boleto:)
|
26
|
+
super(id)
|
27
|
+
@type = type
|
28
|
+
@errors = errors
|
29
|
+
@boleto = boleto
|
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 [Project object]: 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
|
+
# - boleto_ids [list of strings, default nil]: list of Boleto ids to filter logs. ex: ["5656565656565656", "4545454545454545"]
|
56
|
+
# - types [list of strings, default nil]: filter for log event types. ex: "paid" or "registered"
|
57
|
+
# - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
58
|
+
# - before [Date, default nil] date filter for objects only before specified date. ex: Date.new(2020, 3, 10)
|
59
|
+
# - user [Project object, default nil]: 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, boleto_ids: nil, types: nil, after: nil, before: 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(user: user, limit: limit, boleto_ids: boleto_ids, types: types, after: after, before: before, **resource)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.resource
|
70
|
+
boleto_maker = StarkBank::Boleto.resource[:resource_maker]
|
71
|
+
{
|
72
|
+
resource_name: 'BoletoLog',
|
73
|
+
resource_maker: proc { |json|
|
74
|
+
Log.new(
|
75
|
+
id: json['id'],
|
76
|
+
created: json['created'],
|
77
|
+
type: json['type'],
|
78
|
+
errors: json['errors'],
|
79
|
+
boleto: StarkBank::Utils::API.from_api_json(boleto_maker, json['boleto'])
|
80
|
+
)
|
81
|
+
}
|
82
|
+
}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/error.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('json')
|
4
|
+
|
5
|
+
module StarkBank
|
6
|
+
module Error
|
7
|
+
class Error < StandardError
|
8
|
+
attr_reader :code, :message
|
9
|
+
def initialize(code, message)
|
10
|
+
@code = code
|
11
|
+
@message = message
|
12
|
+
super("#{code}: #{message}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class InputErrors < StandardError
|
17
|
+
attr_reader :errors
|
18
|
+
def initialize(content)
|
19
|
+
errors = []
|
20
|
+
content.each do |error|
|
21
|
+
errors << Error.new(error['code'], error['message'])
|
22
|
+
end
|
23
|
+
@errors = errors
|
24
|
+
|
25
|
+
super(content.to_json)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class InternalServerError < StandardError
|
30
|
+
def initialize(message = 'Houston, we have a problem.')
|
31
|
+
super(message)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class UnknownError < StandardError
|
36
|
+
def initialize(message)
|
37
|
+
super("Unknown exception encountered: #{message}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class InvalidSignatureError < StandardError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/key.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require('starkbank-ecdsa')
|
4
|
+
|
5
|
+
module StarkBank
|
6
|
+
module Key
|
7
|
+
# # Generate a new key pair
|
8
|
+
# Generates a secp256k1 ECDSA private/public key pair to be used in the API
|
9
|
+
# authentications
|
10
|
+
#
|
11
|
+
# ## Parameters (optional):
|
12
|
+
# - path [string]: path to save the keys .pem files. No files will be saved if this parameter isn't provided
|
13
|
+
#
|
14
|
+
# ## Return:
|
15
|
+
# - private and public key pems
|
16
|
+
def self.create(path = nil)
|
17
|
+
private_key = PrivateKey.new
|
18
|
+
public_key = private_key.publicKey
|
19
|
+
|
20
|
+
private_key_pem = private_key.toPem
|
21
|
+
public_key_pem = public_key.toPem
|
22
|
+
|
23
|
+
unless path.nil?
|
24
|
+
FileUtils.mkdir_p(path)
|
25
|
+
File.write(File.join(path, 'private.pem'), private_key_pem)
|
26
|
+
File.write(File.join(path, 'public.pem'), public_key_pem)
|
27
|
+
end
|
28
|
+
|
29
|
+
[private_key_pem, public_key_pem]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
# # Balance object
|
9
|
+
#
|
10
|
+
# The Balance object displays the current balance of the workspace,
|
11
|
+
# which is the result of the sum of all transactions within this
|
12
|
+
# workspace. The balance is never generated by the user, but it
|
13
|
+
# can be retrieved to see the available information.
|
14
|
+
#
|
15
|
+
# ## Attributes (return-only):
|
16
|
+
# - id [string, default nil]: unique id returned when Boleto is created. ex: "5656565656565656"
|
17
|
+
# - amount [integer, default nil]: current balance amount of the workspace in cents. ex: 200 (= R$ 2.00)
|
18
|
+
# - currency [string, default nil]: currency of the current workspace. Expect others to be added eventually. ex: "BRL"
|
19
|
+
# - updated [DateTime, default nil]: update datetime for the balance. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
20
|
+
class Balance < StarkBank::Utils::Resource
|
21
|
+
attr_reader :amount, :currency, :updated
|
22
|
+
def initialize(amount:, currency:, updated:, id:)
|
23
|
+
super(id)
|
24
|
+
@amount = amount
|
25
|
+
@currency = currency
|
26
|
+
@updated = StarkBank::Utils::Checks.check_datetime(updated)
|
27
|
+
end
|
28
|
+
|
29
|
+
# # Retrieve the Balance object
|
30
|
+
#
|
31
|
+
# Receive the Balance object linked to your workspace in the Stark Bank API
|
32
|
+
#
|
33
|
+
# ## Parameters (optional):
|
34
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
35
|
+
#
|
36
|
+
# ## Return:
|
37
|
+
# - Balance object with updated attributes
|
38
|
+
def self.get(user: nil)
|
39
|
+
StarkBank::Utils::Rest.get_list(user: user, **resource).next
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
private
|
44
|
+
|
45
|
+
def resource
|
46
|
+
{
|
47
|
+
resource_name: 'Balance',
|
48
|
+
resource_maker: proc { |json|
|
49
|
+
Balance.new(
|
50
|
+
amount: json['amount'],
|
51
|
+
currency: json['currency'],
|
52
|
+
updated: json['updated'],
|
53
|
+
id: json['id']
|
54
|
+
)
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,116 @@
|
|
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
|
+
# # Transaction object
|
9
|
+
#
|
10
|
+
# A Transaction is a transfer of funds between workspaces inside Stark Bank.
|
11
|
+
# Transactions created by the user are only for internal transactions.
|
12
|
+
# Other operations (such as transfer or charge-payment) will automatically
|
13
|
+
# create a transaction for the user which can be retrieved for the statement.
|
14
|
+
# When you initialize a Transaction, the entity will not be automatically
|
15
|
+
# created in the Stark Bank API. The 'create' function sends the objects
|
16
|
+
# to the Stark Bank API and returns the list of created objects.
|
17
|
+
#
|
18
|
+
# ## Parameters (required):
|
19
|
+
# - amount [integer]: amount in cents to be transferred. ex: 1234 (= R$ 12.34)
|
20
|
+
# - description [string]: text to be displayed in the receiver and the sender statements (Min. 10 characters). ex: "funds redistribution"
|
21
|
+
# - external_id [string]: unique id, generated by user, to avoid duplicated transactions. ex: "transaction ABC 2020-03-30"
|
22
|
+
# - received_id [string]: unique id of the receiving workspace. ex: "5656565656565656"
|
23
|
+
#
|
24
|
+
# ## Parameters (optional):
|
25
|
+
# - tags [list of strings]: list of strings for reference when searching transactions (may be empty). ex: ["abc", "test"]
|
26
|
+
#
|
27
|
+
# ## Attributes (return-only):
|
28
|
+
# - source [string, default nil]: locator of the entity that generated the transaction. ex: "charge/1827351876292", "transfer/92873912873/chargeback"
|
29
|
+
# - id [string, default nil]: unique id returned when Transaction is created. ex: "7656565656565656"
|
30
|
+
# - fee [integer, default nil]: fee charged when transfer is created. ex: 200 (= R$ 2.00)
|
31
|
+
# - created [DateTime, default nil]: creation datetime for the boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
32
|
+
class Transaction < StarkBank::Utils::Resource
|
33
|
+
attr_reader :amount, :description, :external_id, :receiver_id, :tags, :id, :fee, :created, :source
|
34
|
+
def initialize(amount:, description:, external_id:, receiver_id:, tags: nil, id: nil, fee: nil, created: nil, source: nil)
|
35
|
+
super(id)
|
36
|
+
@amount = amount
|
37
|
+
@description = description
|
38
|
+
@external_id = external_id
|
39
|
+
@receiver_id = receiver_id
|
40
|
+
@tags = tags
|
41
|
+
@fee = fee
|
42
|
+
@source = source
|
43
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
44
|
+
end
|
45
|
+
|
46
|
+
# # Create Transactions
|
47
|
+
#
|
48
|
+
# Send a list of Transaction objects for creation in the Stark Bank API
|
49
|
+
#
|
50
|
+
# ## Parameters (required):
|
51
|
+
# - transactions [list of Transaction objects]: list of Transaction objects to be created in the API
|
52
|
+
#
|
53
|
+
# ## Parameters (optional):
|
54
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
55
|
+
#
|
56
|
+
# ## Return:
|
57
|
+
# - list of Transaction objects with updated attributes
|
58
|
+
def self.create(transactions:, user: nil)
|
59
|
+
StarkBank::Utils::Rest.post(entities: transactions, user: user, **resource)
|
60
|
+
end
|
61
|
+
|
62
|
+
# # Retrieve a specific Transaction
|
63
|
+
#
|
64
|
+
# Receive a single Transaction object previously created in the Stark Bank API by passing its id
|
65
|
+
#
|
66
|
+
# ## Parameters (required):
|
67
|
+
# - id [string]: object unique id. ex: "5656565656565656"
|
68
|
+
#
|
69
|
+
# ## Parameters (optional):
|
70
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
71
|
+
#
|
72
|
+
# ## Return:
|
73
|
+
# - Transaction object with updated attributes
|
74
|
+
def self.get(id:, user: nil)
|
75
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
76
|
+
end
|
77
|
+
|
78
|
+
# # Retrieve Transactions
|
79
|
+
#
|
80
|
+
# Receive a generator of Transaction objects previously created in the Stark Bank API
|
81
|
+
#
|
82
|
+
# ## Parameters (optional):
|
83
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
84
|
+
# - external_ids [list of strings, default nil]: list of external ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
|
85
|
+
# - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
86
|
+
# - before [Date, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
87
|
+
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
88
|
+
#
|
89
|
+
# ## Return:
|
90
|
+
# - generator of Transaction objects with updated attributes
|
91
|
+
def self.query(limit: nil, external_ids: nil, after: nil, before: nil, user: nil)
|
92
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
93
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
94
|
+
StarkBank::Utils::Rest.get_list(user: user, limit: limit, external_ids: external_ids, after: after, before: before, **resource)
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.resource
|
98
|
+
{
|
99
|
+
resource_name: 'Transaction',
|
100
|
+
resource_maker: proc { |json|
|
101
|
+
Transaction.new(
|
102
|
+
amount: json['amount'],
|
103
|
+
description: json['description'],
|
104
|
+
external_id: json['external_id'],
|
105
|
+
receiver_id: json['receiver_id'],
|
106
|
+
tags: json['tags'],
|
107
|
+
id: json['id'],
|
108
|
+
fee: json['fee'],
|
109
|
+
created: json['created'],
|
110
|
+
source: json['source']
|
111
|
+
)
|
112
|
+
}
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,152 @@
|
|
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
|
+
# # BoletoPayment object
|
9
|
+
#
|
10
|
+
# When you initialize a BoletoPayment, 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 (conditionally required):
|
15
|
+
# - line [string, default nil]: Number sequence that describes the payment. Either 'line' or 'bar_code' parameters are required. If both are sent, they must match. ex: "34191.09008 63571.277308 71444.640008 5 81960000000062"
|
16
|
+
# - bar_code [string, default nil]: Bar code number that describes the payment. Either 'line' or 'barCode' parameters are required. If both are sent, they must match. ex: "34195819600000000621090063571277307144464000"
|
17
|
+
#
|
18
|
+
# ## Parameters (required):
|
19
|
+
# - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: "01234567890" or "20.018.183/0001-80"
|
20
|
+
# - description [string]: Text to be displayed in your statement (min. 10 characters). ex: "payment ABC"
|
21
|
+
#
|
22
|
+
# ## Parameters (optional):
|
23
|
+
# - scheduled [Date, default today]: payment scheduled date. ex: Date.new(2020, 3, 10)
|
24
|
+
# - tags [list of strings]: list of strings for tagging
|
25
|
+
#
|
26
|
+
# ## Attributes (return-only):
|
27
|
+
# - id [string, default nil]: unique id returned when payment is created. ex: "5656565656565656"
|
28
|
+
# - status [string, default nil]: current payment status. ex: "registered" or "paid"
|
29
|
+
# - amount [int, default nil]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)
|
30
|
+
# - fee [integer, default nil]: fee charged when boleto payment is created. ex: 200 (= R$ 2.00)
|
31
|
+
# - created [DateTime, default nil]: creation datetime for the payment. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
32
|
+
class BoletoPayment < StarkBank::Utils::Resource
|
33
|
+
attr_reader :tax_id, :description, :line, :bar_code, :scheduled, :tags, :id, :status, :amount, :fee, :created
|
34
|
+
def initialize(tax_id:, description:, line: nil, bar_code: nil, scheduled: nil, tags: nil, id: nil, status: nil, amount: nil, fee: nil, created: nil)
|
35
|
+
super(id)
|
36
|
+
@tax_id = tax_id
|
37
|
+
@description = description
|
38
|
+
@line = line
|
39
|
+
@bar_code = bar_code
|
40
|
+
@scheduled = StarkBank::Utils::Checks.check_datetime(scheduled)
|
41
|
+
@tags = tags
|
42
|
+
@status = status
|
43
|
+
@amount = amount
|
44
|
+
@fee = fee
|
45
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
46
|
+
end
|
47
|
+
|
48
|
+
# # Create BoletoPayments
|
49
|
+
#
|
50
|
+
# Send a list of BoletoPayment objects for creation in the Stark Bank API
|
51
|
+
#
|
52
|
+
# ## Parameters (required):
|
53
|
+
# - payments [list of BoletoPayment objects]: list of BoletoPayment objects to be created in the API
|
54
|
+
#
|
55
|
+
# ## Parameters (optional):
|
56
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
57
|
+
#
|
58
|
+
# ## Return:
|
59
|
+
# - list of BoletoPayment objects with updated attributes
|
60
|
+
def self.create(payments:, user: nil)
|
61
|
+
StarkBank::Utils::Rest.post(entities: payments, user: user, **resource)
|
62
|
+
end
|
63
|
+
|
64
|
+
# # Retrieve a specific BoletoPayment
|
65
|
+
#
|
66
|
+
# Receive a single BoletoPayment object previously created by the Stark Bank API by passing its id
|
67
|
+
#
|
68
|
+
# ## Parameters (required):
|
69
|
+
# - id [string]: object unique id. ex: "5656565656565656"
|
70
|
+
#
|
71
|
+
# ## Parameters (optional):
|
72
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
73
|
+
#
|
74
|
+
# ## Return:
|
75
|
+
# - BoletoPayment object with updated attributes
|
76
|
+
def self.get(id:, user: nil)
|
77
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
78
|
+
end
|
79
|
+
|
80
|
+
# # Retrieve a specific BoletoPayment pdf file
|
81
|
+
#
|
82
|
+
# Receive a single BoletoPayment pdf file generated in the Stark Bank API by passing its id.
|
83
|
+
# Only valid for boleto payments with "success" status.
|
84
|
+
#
|
85
|
+
# ## Parameters (required):
|
86
|
+
# - id [string]: object unique id. ex: "5656565656565656"
|
87
|
+
#
|
88
|
+
# ## Parameters (optional):
|
89
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
90
|
+
#
|
91
|
+
# ## Return:
|
92
|
+
# - BoletoPayment pdf file
|
93
|
+
def self.pdf(id:, user: nil)
|
94
|
+
StarkBank::Utils::Rest.get_pdf(id: id, user: user, **resource)
|
95
|
+
end
|
96
|
+
|
97
|
+
# # Retrieve BoletoPayments
|
98
|
+
#
|
99
|
+
# Receive a generator of BoletoPayment objects previously created in the Stark Bank API
|
100
|
+
#
|
101
|
+
# ## Parameters (optional):
|
102
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
103
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: "paid"
|
104
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ["tony", "stark"]
|
105
|
+
# - after [Date, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
106
|
+
# - before [Date, default nil] date filter for objects only before specified date. ex: Date.new(2020, 3, 10)
|
107
|
+
# - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
|
108
|
+
#
|
109
|
+
# ## Return:
|
110
|
+
# - generator of BoletoPayment objects with updated attributes
|
111
|
+
def self.query(limit: nil, status: nil, tags: nil, ids: nil, after: nil, before: nil, user: nil)
|
112
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
113
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
114
|
+
StarkBank::Utils::Rest.get_list(user: user, limit: limit, status: status, tags: tags, ids: ids, after: after, before: before, **resource)
|
115
|
+
end
|
116
|
+
|
117
|
+
# # Delete a BoletoPayment entity
|
118
|
+
#
|
119
|
+
# Delete a BoletoPayment entity previously created in the Stark Bank API
|
120
|
+
#
|
121
|
+
# Parameters (required):
|
122
|
+
# - id [string]: BoletoPayment unique id. ex: "5656565656565656"
|
123
|
+
# Parameters (optional):
|
124
|
+
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
125
|
+
# Return:
|
126
|
+
# - deleted BoletoPayment with updated attributes
|
127
|
+
def self.delete(id:, user: nil)
|
128
|
+
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.resource
|
132
|
+
{
|
133
|
+
resource_name: 'BoletoPayment',
|
134
|
+
resource_maker: proc { |json|
|
135
|
+
BoletoPayment.new(
|
136
|
+
id: json['id'],
|
137
|
+
tax_id: json['tax_id'],
|
138
|
+
description: json['description'],
|
139
|
+
line: json['line'],
|
140
|
+
bar_code: json['bar_code'],
|
141
|
+
scheduled: json['scheduled'],
|
142
|
+
tags: json['tags'],
|
143
|
+
status: json['status'],
|
144
|
+
amount: json['amount'],
|
145
|
+
fee: json['fee'],
|
146
|
+
created: json['created']
|
147
|
+
)
|
148
|
+
}
|
149
|
+
}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|