starkbank 2.0.0 → 2.2.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 +4 -3
- 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/boleto_payment/log.rb +1 -1
- data/lib/brcode_payment/brcode_payment.rb +167 -0
- data/lib/brcode_payment/log.rb +94 -0
- data/lib/brcode_preview/brcode_preview.rb +77 -0
- data/lib/deposit/deposit.rb +121 -0
- data/lib/deposit/log.rb +94 -0
- data/lib/dict_key/dict_key.rb +118 -0
- data/lib/event/event.rb +10 -2
- data/lib/invoice/invoice.rb +211 -0
- data/lib/invoice/log.rb +94 -0
- data/lib/starkbank.rb +10 -0
- data/lib/transfer/transfer.rb +3 -3
- data/lib/utility_payment/utility_payment.rb +1 -1
- data/lib/utils/api.rb +20 -13
- data/lib/utils/checks.rb +18 -6
- data/lib/utils/request.rb +1 -1
- data/lib/utils/rest.rb +9 -0
- metadata +11 -1
data/lib/invoice/log.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
require_relative('invoice')
|
7
|
+
|
8
|
+
module StarkBank
|
9
|
+
class Invoice
|
10
|
+
# # Invoice::Log object
|
11
|
+
#
|
12
|
+
# Every time an Invoice entity is updated, a corresponding Invoice::Log
|
13
|
+
# is generated for the entity. This log is never generated by the
|
14
|
+
# user, but it can be retrieved to check additional information
|
15
|
+
# on the Invoice.
|
16
|
+
#
|
17
|
+
# ## Attributes:
|
18
|
+
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
19
|
+
# - invoice [Invoice]: Invoice entity to which the log refers to.
|
20
|
+
# - errors [list of strings]: list of errors linked to this Invoice event
|
21
|
+
# - type [string]: type of the Invoice event which triggered the log creation. ex: 'canceled' or 'paid'
|
22
|
+
# - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
23
|
+
class Log < StarkBank::Utils::Resource
|
24
|
+
attr_reader :id, :created, :type, :errors, :invoice
|
25
|
+
def initialize(id:, created:, type:, errors:, invoice:)
|
26
|
+
super(id)
|
27
|
+
@type = type
|
28
|
+
@errors = errors
|
29
|
+
@invoice = invoice
|
30
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
31
|
+
end
|
32
|
+
|
33
|
+
# # Retrieve a specific Log
|
34
|
+
#
|
35
|
+
# Receive a single Log object previously created by the Stark Bank API by passing its id
|
36
|
+
#
|
37
|
+
# ## Parameters (required):
|
38
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
39
|
+
#
|
40
|
+
# ## Parameters (optional):
|
41
|
+
# - user [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
|
+
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
56
|
+
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
57
|
+
# - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
|
58
|
+
# - invoice_ids [list of strings, default nil]: list of Invoice ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
59
|
+
# - user [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, after: nil, before: nil, types: nil, invoice_ids: nil, user: nil)
|
64
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
65
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
66
|
+
StarkBank::Utils::Rest.get_list(
|
67
|
+
limit: limit,
|
68
|
+
after: after,
|
69
|
+
before: before,
|
70
|
+
types: types,
|
71
|
+
invoice_ids: invoice_ids,
|
72
|
+
user: user,
|
73
|
+
**resource
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.resource
|
78
|
+
invoice_maker = StarkBank::Invoice.resource[:resource_maker]
|
79
|
+
{
|
80
|
+
resource_name: 'InvoiceLog',
|
81
|
+
resource_maker: proc { |json|
|
82
|
+
Log.new(
|
83
|
+
id: json['id'],
|
84
|
+
created: json['created'],
|
85
|
+
type: json['type'],
|
86
|
+
errors: json['errors'],
|
87
|
+
invoice: StarkBank::Utils::API.from_api_json(invoice_maker, json['invoice'])
|
88
|
+
)
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/starkbank.rb
CHANGED
@@ -4,8 +4,18 @@ require_relative('key')
|
|
4
4
|
require_relative('user/project')
|
5
5
|
require_relative('balance/balance')
|
6
6
|
require_relative('transaction/transaction')
|
7
|
+
require_relative('invoice/invoice')
|
8
|
+
require_relative('invoice/log')
|
9
|
+
require_relative('dict_key/dict_key')
|
10
|
+
require_relative('deposit/deposit')
|
11
|
+
require_relative('deposit/log')
|
12
|
+
require_relative('brcode_preview/brcode_preview')
|
13
|
+
require_relative('brcode_payment/brcode_payment')
|
14
|
+
require_relative('brcode_payment/log')
|
7
15
|
require_relative('boleto/boleto')
|
8
16
|
require_relative('boleto/log')
|
17
|
+
require_relative('boleto_holmes/boleto_holmes')
|
18
|
+
require_relative('boleto_holmes/log')
|
9
19
|
require_relative('transfer/transfer')
|
10
20
|
require_relative('transfer/log')
|
11
21
|
require_relative('boleto_payment/boleto_payment')
|
data/lib/transfer/transfer.rb
CHANGED
@@ -15,13 +15,13 @@ module StarkBank
|
|
15
15
|
# - amount [integer]: amount in cents to be transferred. ex: 1234 (= R$ 12.34)
|
16
16
|
# - name [string]: receiver full name. ex: 'Anthony Edward Stark'
|
17
17
|
# - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
|
18
|
-
# - bank_code [string]:
|
18
|
+
# - bank_code [string]: code of the receiver bank institution in Brazil. If an ISPB (8 digits) is informed, a PIX transfer will be created, else a TED will be issued. ex: '20018183' or '260'
|
19
19
|
# - branch_code [string]: receiver bank account branch. Use '-' in case there is a verifier digit. ex: '1357-9'
|
20
20
|
# - account_number [string]: Receiver Bank Account number. Use '-' before the verifier digit. ex: '876543-2'
|
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,
|
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, 13, 12, 11)
|
25
25
|
#
|
26
26
|
# ## Attributes (return-only):
|
27
27
|
# - id [string, default nil]: unique id returned when Transfer is created. ex: '5656565656565656'
|
@@ -40,7 +40,7 @@ module StarkBank
|
|
40
40
|
@bank_code = bank_code
|
41
41
|
@branch_code = branch_code
|
42
42
|
@account_number = account_number
|
43
|
-
@scheduled = StarkBank::Utils::Checks.
|
43
|
+
@scheduled = StarkBank::Utils::Checks.check_date_or_datetime(scheduled)
|
44
44
|
@transaction_ids = transaction_ids
|
45
45
|
@fee = fee
|
46
46
|
@tags = tags
|
data/lib/utils/api.rb
CHANGED
@@ -28,21 +28,22 @@ module StarkBank
|
|
28
28
|
hash.each do |key, value|
|
29
29
|
next if value.nil?
|
30
30
|
|
31
|
-
|
31
|
+
entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = parse_value(value)
|
32
|
+
end
|
33
|
+
entity_hash
|
34
|
+
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
value = list
|
39
|
-
elsif value.is_a?(Hash)
|
40
|
-
value = cast_json_to_api_format(value)
|
41
|
-
end
|
36
|
+
def self.parse_value(value)
|
37
|
+
return value.strftime('%Y-%m-%d') if value.is_a?(Date)
|
38
|
+
return value.strftime('%Y-%m-%dT%H:%M:%S+00:00') if value.is_a?(DateTime) || value.is_a?(Time)
|
39
|
+
return cast_json_to_api_format(value) if value.is_a?(Hash)
|
40
|
+
return value unless value.is_a?(Array)
|
42
41
|
|
43
|
-
|
42
|
+
list = []
|
43
|
+
value.each do |v|
|
44
|
+
list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
|
44
45
|
end
|
45
|
-
|
46
|
+
list
|
46
47
|
end
|
47
48
|
|
48
49
|
def self.from_api_json(resource_maker, json)
|
@@ -60,7 +61,13 @@ module StarkBank
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def self.last_name_plural(resource_name)
|
63
|
-
|
64
|
+
base = last_name(resource_name)
|
65
|
+
|
66
|
+
return base if base[-1].eql?('s')
|
67
|
+
return "#{base}s" if base[-2..-1].eql?('ey')
|
68
|
+
return "#{base[0...-1]}ies" if base[-1].eql?('y')
|
69
|
+
|
70
|
+
"#{base}s"
|
64
71
|
end
|
65
72
|
|
66
73
|
def self.last_name(resource_name)
|
data/lib/utils/checks.rb
CHANGED
@@ -39,6 +39,17 @@ module StarkBank
|
|
39
39
|
raise(ArgumentError, 'Private-key must be a valid secp256k1 ECDSA string in pem format')
|
40
40
|
end
|
41
41
|
|
42
|
+
def self.check_date_or_datetime(data)
|
43
|
+
return if data.nil?
|
44
|
+
|
45
|
+
return data if data.is_a?(Time) || data.is_a?(DateTime)
|
46
|
+
|
47
|
+
return data if data.is_a?(Date)
|
48
|
+
|
49
|
+
data, type = check_datetime_string(data)
|
50
|
+
type == 'date' ? Date.new(data.year, data.month, data.day) : data
|
51
|
+
end
|
52
|
+
|
42
53
|
def self.check_datetime(data)
|
43
54
|
return if data.nil?
|
44
55
|
|
@@ -46,7 +57,8 @@ module StarkBank
|
|
46
57
|
|
47
58
|
return Time.new(data.year, data.month, data.day) if data.is_a?(Date)
|
48
59
|
|
49
|
-
check_datetime_string(data)
|
60
|
+
data, _type = check_datetime_string(data)
|
61
|
+
data
|
50
62
|
end
|
51
63
|
|
52
64
|
def self.check_date(data)
|
@@ -56,9 +68,9 @@ module StarkBank
|
|
56
68
|
|
57
69
|
return data if data.is_a?(Date)
|
58
70
|
|
59
|
-
data = check_datetime_string(data)
|
71
|
+
data, type = check_datetime_string(data)
|
60
72
|
|
61
|
-
Date.new(data.year, data.month, data.day)
|
73
|
+
type == 'date' ? Date.new(data.year, data.month, data.day) : data
|
62
74
|
end
|
63
75
|
|
64
76
|
class << self
|
@@ -68,17 +80,17 @@ module StarkBank
|
|
68
80
|
data = data.to_s
|
69
81
|
|
70
82
|
begin
|
71
|
-
return DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00')
|
83
|
+
return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00'), 'datetime']
|
72
84
|
rescue ArgumentError
|
73
85
|
end
|
74
86
|
|
75
87
|
begin
|
76
|
-
return DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00')
|
88
|
+
return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00'), 'datetime']
|
77
89
|
rescue ArgumentError
|
78
90
|
end
|
79
91
|
|
80
92
|
begin
|
81
|
-
return DateTime.strptime(data, '%Y-%m-%d')
|
93
|
+
return [DateTime.strptime(data, '%Y-%m-%d'), 'date']
|
82
94
|
rescue ArgumentError
|
83
95
|
raise(ArgumentError, 'invalid datetime string ' + data)
|
84
96
|
end
|
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-2.
|
64
|
+
req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.2.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/utils/rest.rb
CHANGED
@@ -56,6 +56,15 @@ module StarkBank
|
|
56
56
|
).content
|
57
57
|
end
|
58
58
|
|
59
|
+
def self.get_qrcode(resource_name:, resource_maker:, id:, user: nil, **query)
|
60
|
+
StarkBank::Utils::Request.fetch(
|
61
|
+
method: 'GET',
|
62
|
+
path: "#{StarkBank::Utils::API.endpoint(resource_name)}/#{id}/qrcode",
|
63
|
+
query: StarkBank::Utils::API.cast_json_to_api_format(query),
|
64
|
+
user: user
|
65
|
+
).content
|
66
|
+
end
|
67
|
+
|
59
68
|
def self.post(resource_name:, resource_maker:, entities:, user: nil)
|
60
69
|
jsons = []
|
61
70
|
entities.each do |entity|
|
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: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- starkbank
|
@@ -75,10 +75,20 @@ 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
|
82
|
+
- lib/brcode_payment/brcode_payment.rb
|
83
|
+
- lib/brcode_payment/log.rb
|
84
|
+
- lib/brcode_preview/brcode_preview.rb
|
85
|
+
- lib/deposit/deposit.rb
|
86
|
+
- lib/deposit/log.rb
|
87
|
+
- lib/dict_key/dict_key.rb
|
80
88
|
- lib/error.rb
|
81
89
|
- lib/event/event.rb
|
90
|
+
- lib/invoice/invoice.rb
|
91
|
+
- lib/invoice/log.rb
|
82
92
|
- lib/key.rb
|
83
93
|
- lib/payment_request/payment_request.rb
|
84
94
|
- lib/starkbank.rb
|