starkbank 2.1.0.beta1 → 2.2.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.
@@ -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
@@ -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')
@@ -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]: 1 to 3 digits of the receiver bank institution in Brazil. ex: '200' or '341'
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, 0, 0, 0)
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.check_datetime(scheduled)
43
+ @scheduled = StarkBank::Utils::Checks.check_date_or_datetime(scheduled)
44
44
  @transaction_ids = transaction_ids
45
45
  @fee = fee
46
46
  @tags = tags
@@ -36,7 +36,7 @@ module StarkBank
36
36
  @line = line
37
37
  @bar_code = bar_code
38
38
  @tags = tags
39
- @scheduled = StarkBank::Utils::Checks.check_datetime(scheduled)
39
+ @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
40
40
  @amount = amount
41
41
  @fee = fee
42
42
  @status = status
@@ -28,21 +28,22 @@ module StarkBank
28
28
  hash.each do |key, value|
29
29
  next if value.nil?
30
30
 
31
- value = value.is_a?(Date) || value.is_a?(DateTime) || value.is_a?(Time) ? value.strftime('%Y-%m-%d') : value
31
+ entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = parse_value(value)
32
+ end
33
+ entity_hash
34
+ end
32
35
 
33
- if value.is_a?(Array)
34
- list = []
35
- value.each do |v|
36
- list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
37
- end
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
- entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = value
42
+ list = []
43
+ value.each do |v|
44
+ list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
44
45
  end
45
- entity_hash
46
+ list
46
47
  end
47
48
 
48
49
  def self.from_api_json(resource_maker, json)
@@ -63,6 +64,7 @@ module StarkBank
63
64
  base = last_name(resource_name)
64
65
 
65
66
  return base if base[-1].eql?('s')
67
+ return "#{base}s" if base[-2..-1].eql?('ey')
66
68
  return "#{base[0...-1]}ies" if base[-1].eql?('y')
67
69
 
68
70
  "#{base}s"
@@ -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
@@ -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.0.0"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.2.1"
65
65
  req['Accept-Language'] = language
66
66
 
67
67
  request = Net::HTTP.start(uri.hostname, use_ssl: true) { |http| http.request(req) }
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starkbank
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta1
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - starkbank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-19 00:00:00.000000000 Z
11
+ date: 2020-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: starkbank-ecdsa
@@ -79,8 +79,16 @@ files:
79
79
  - lib/boleto_holmes/log.rb
80
80
  - lib/boleto_payment/boleto_payment.rb
81
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
82
88
  - lib/error.rb
83
89
  - lib/event/event.rb
90
+ - lib/invoice/invoice.rb
91
+ - lib/invoice/log.rb
84
92
  - lib/key.rb
85
93
  - lib/payment_request/payment_request.rb
86
94
  - lib/starkbank.rb
@@ -101,7 +109,7 @@ files:
101
109
  - lib/utils/rest.rb
102
110
  - lib/utils/url.rb
103
111
  - lib/webhook/webhook.rb
104
- homepage: https://github.com/starkbank/sdk-ruby/tree/feature/boleto-holmes
112
+ homepage: https://github.com/starkbank/sdk-ruby
105
113
  licenses:
106
114
  - MIT
107
115
  metadata: {}
@@ -116,9 +124,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
124
  version: '2.3'
117
125
  required_rubygems_version: !ruby/object:Gem::Requirement
118
126
  requirements:
119
- - - ">"
127
+ - - ">="
120
128
  - !ruby/object:Gem::Version
121
- version: 1.3.1
129
+ version: '0'
122
130
  requirements: []
123
131
  rubygems_version: 3.1.4
124
132
  signing_key: