starkbank 2.1.0 → 2.2.0.beta2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21f296f6ce46e6451eb4650fcc5bd8f77b657184b10662daae70c79c4df26cc3
4
- data.tar.gz: 2a0355e608aa51c1302ea55c8491741981afbfefd2bb86f56fb606fc4ab38c76
3
+ metadata.gz: 766b123365232a3f071a9a12072eaf8fc2f30021a72ed0f4a41b54726fca81c5
4
+ data.tar.gz: 5c8349015b1ee06624223bdeb28ca9f3765e92bba3d62ebe04e76656a0ec14e8
5
5
  SHA512:
6
- metadata.gz: cce7c99b52dc834e4110caa9861a89dbb039d02d080d17631995666298798f6c1ca7024796958cc170d7f08d5a594a8f8ee4bb98078f8897e75a8455dad55987
7
- data.tar.gz: 2e5c9d0a3d0f33b050f08b29e35453db3011190760145aec59a87a993a1086c038e9d430004cd8bdf7fe1ef657d08554d4eea4fec14d5e9d2692f57df71808c5
6
+ metadata.gz: b397a9af3581435b2398b7d0e19ff6e252c73024b7bad74d1f49e909f1eda18c95b89b4a95741340e6519aab69d7c1247bfcdb5b05dca5ecf589bb2c404ce743
7
+ data.tar.gz: 1bf497cdc47b95a04bba1b3dc199ffda07cff053c9b4aeced2feb82538ad2d0183b8d5049b677068a4cc2bdbdc63d6f5f4d1ec64f615d602be27678f41b77514
@@ -58,7 +58,7 @@ module StarkBank
58
58
  @city = city
59
59
  @state_code = state_code
60
60
  @zip_code = zip_code
61
- @due = due
61
+ @due = StarkBank::Utils::Checks.check_date(due)
62
62
  @fine = fine
63
63
  @interest = interest
64
64
  @overdue_limit = overdue_limit
@@ -37,7 +37,7 @@ module StarkBank
37
37
  @description = description
38
38
  @line = line
39
39
  @bar_code = bar_code
40
- @scheduled = StarkBank::Utils::Checks.check_datetime(scheduled)
40
+ @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
41
41
  @tags = tags
42
42
  @status = status
43
43
  @amount = amount
@@ -9,6 +9,7 @@ require_relative('../utils/cache')
9
9
  require_relative('../error')
10
10
  require_relative('../boleto/log')
11
11
  require_relative('../boleto_holmes/log')
12
+ require_relative('../invoice/log')
12
13
  require_relative('../transfer/log')
13
14
  require_relative('../boleto_payment/log')
14
15
  require_relative('../utility_payment/log')
@@ -22,7 +23,7 @@ module StarkBank
22
23
  #
23
24
  # ## Attributes:
24
25
  # - id [string]: unique id returned when the event is created. ex: '5656565656565656'
25
- # - log [Log]: a Log object from one the subscription services (TransferLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
26
+ # - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
26
27
  # - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
27
28
  # - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
28
29
  # - subscription [string]: service that triggered this event. ex: 'transfer', 'utility-payment'
@@ -36,6 +37,7 @@ module StarkBank
36
37
 
37
38
  resource = {
38
39
  'transfer': StarkBank::Transfer::Log.resource,
40
+ 'invoice': StarkBank::Invoice::Log.resource,
39
41
  'boleto': StarkBank::Boleto::Log.resource,
40
42
  'boleto-payment': StarkBank::BoletoPayment::Log.resource,
41
43
  'utility-payment': StarkBank::UtilityPayment::Log.resource,
@@ -0,0 +1,173 @@
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
+ # # Invoice object
9
+ #
10
+ # When you initialize an Invoice, 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]: Invoice value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34)
16
+ # - tax_id [string]: payer tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
17
+ # - name [string]: payer name. ex: 'Iron Bank S.A.'
18
+ #
19
+ # ## Parameters (optional):
20
+ # - due [DateTime or string, default today + 2 days]: Invoice due date in UTC ISO format. ex: '2020-10-28T17:59:26.249976+00:00'
21
+ # - expiration [integer, default 5097600 (59 days)]: time interval in seconds between due date and expiration date. ex 123456789
22
+ # - fine [float, default 0.0]: Invoice fine for overdue payment in %. ex: 2.5
23
+ # - interest [float, default 0.0]: Invoice monthly interest for overdue payment in %. ex: 5.2
24
+ # - discounts [list of hashes, default nil]: list of hashes with 'percentage':float and 'due':DateTime or string pairs
25
+ # - descriptions [list of hashes, default nil]: list of hashes with 'key':string and 'value':string pairs
26
+ # - tags [list of strings, default nil]: list of strings for tagging
27
+ #
28
+ # ## Attributes (return-only):
29
+ # - id [string, default nil]: unique id returned when Invoice is created. ex: '5656565656565656'
30
+ # - nominal_amount [integer, default nil]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
31
+ # - fine_amount [integer, default nil]: Invoice fine value calculated over nominal_amount. ex: 20000
32
+ # - interest_amount [integer, default nil]: Invoice interest value calculated over nominal_amount. ex: 10000
33
+ # - discount_amount [integer, default nil]: Invoice discount value calculated over nominal_amount. ex: 3000
34
+ # - brcode [string, default nil]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
35
+ # - status [string, default nil]: current Invoice status. ex: 'registered' or 'paid'
36
+ # - created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
37
+ # - updated [DateTime, default nil]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
38
+ class Invoice < StarkBank::Utils::Resource
39
+ attr_reader :amount, :due, :tax_id, :name, :expiration, :fine, :interest, :discounts, :tags, :descriptions, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :id, :brcode, :status, :created, :updated
40
+ def initialize(
41
+ amount:, due:, tax_id:, name:, expiration: nil, fine: nil, interest: nil, discounts: nil,
42
+ tags: nil, descriptions: nil, nominal_amount: nil, fine_amount: nil, interest_amount: nil,
43
+ discount_amount: nil, id: nil, brcode: nil, status: nil, created: nil, updated: nil
44
+ )
45
+ super(id)
46
+ @amount = amount
47
+ @due = StarkBank::Utils::Checks.check_datetime(due)
48
+ @tax_id = tax_id
49
+ @name = name
50
+ @expiration = expiration
51
+ @fine = fine
52
+ @interest = interest
53
+ @discounts = discounts
54
+ @tags = tags
55
+ @descriptions = descriptions
56
+ @nominal_amount = nominal_amount
57
+ @fine_amount = fine_amount
58
+ @interest_amount = interest_amount
59
+ @discount_amount = discount_amount
60
+ @brcode = brcode
61
+ @status = status
62
+ @updated = StarkBank::Utils::Checks.check_datetime(updated)
63
+ @created = StarkBank::Utils::Checks.check_datetime(created)
64
+ end
65
+
66
+ # # Create Invoices
67
+ #
68
+ # Send a list of Invoice objects for creation in the Stark Bank API
69
+ #
70
+ # ## Parameters (required):
71
+ # - invoices [list of Invoice objects]: list of Invoice objects to be created in the API
72
+ #
73
+ # ## Parameters (optional):
74
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
75
+ #
76
+ # ## Return:
77
+ # - list of Invoice objects with updated attributes
78
+ def self.create(invoices, user: nil)
79
+ StarkBank::Utils::Rest.post(entities: invoices, user: user, **resource)
80
+ end
81
+
82
+ # # Retrieve a specific Invoice
83
+ #
84
+ # Receive a single Invoice object previously created in the Stark Bank API by passing its id
85
+ #
86
+ # ## Parameters (required):
87
+ # - id [string]: object unique id. ex: '5656565656565656'
88
+ #
89
+ # ## Parameters (optional):
90
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
91
+ #
92
+ # ## Return:
93
+ # - Invoice object with updated attributes
94
+ def self.get(id, user: nil)
95
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
96
+ end
97
+
98
+ # # Retrieve Invoices
99
+ #
100
+ # Receive a generator of Invoice objects previously created in the Stark Bank API
101
+ #
102
+ # ## Parameters (optional):
103
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
104
+ # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
105
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
106
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
107
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
108
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
109
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
110
+ #
111
+ # ## Return:
112
+ # - generator of Invoice objects with updated attributes
113
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
114
+ after = StarkBank::Utils::Checks.check_date(after)
115
+ before = StarkBank::Utils::Checks.check_date(before)
116
+ StarkBank::Utils::Rest.get_list(
117
+ limit: limit,
118
+ after: after,
119
+ before: before,
120
+ status: status,
121
+ tags: tags,
122
+ ids: ids,
123
+ user: user,
124
+ **resource
125
+ )
126
+ end
127
+
128
+ # # Update an Invoice entity
129
+ #
130
+ # Update an Invoice entity previously created in the Stark Bank API
131
+ #
132
+ # ## Parameters (required):
133
+ # - id [string]: Invoice unique id. ex: '5656565656565656'
134
+ #
135
+ # ## Parameters (optional):
136
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
137
+ #
138
+ # ## Return:
139
+ # - deleted Invoice object
140
+ def self.update(id, status: nil, amount: nil, due: nil, expiration: nil, user: nil)
141
+ StarkBank::Utils::Rest.patch_id(id: id, status: status, amount: amount, due: due, expiration: expiration, user: user, **resource)
142
+ end
143
+
144
+ def self.resource
145
+ {
146
+ resource_name: 'Invoice',
147
+ resource_maker: proc { |json|
148
+ Invoice.new(
149
+ id: json['id'],
150
+ amount: json['amount'],
151
+ due: json['due'],
152
+ tax_id: json['tax_id'],
153
+ name: json['name'],
154
+ expiration: json['expiration'],
155
+ fine: json['fine'],
156
+ interest: json['interest'],
157
+ discounts: json['discounts'],
158
+ tags: json['tags'],
159
+ descriptions: json['descriptions'],
160
+ nominal_amount: json['nominal_amount'],
161
+ fine_amount: json['fine_amount'],
162
+ interest_amount: json['interest_amount'],
163
+ discount_amount: json['discount_amount'],
164
+ brcode: json['brcode'],
165
+ status: json['status'],
166
+ updated: json['updated'],
167
+ created: json['created'],
168
+ )
169
+ }
170
+ }
171
+ end
172
+ end
173
+ end
@@ -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 a 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,6 +4,8 @@ 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')
7
9
  require_relative('boleto/boleto')
8
10
  require_relative('boleto/log')
9
11
  require_relative('boleto_holmes/boleto_holmes')
@@ -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(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)
@@ -46,7 +46,8 @@ module StarkBank
46
46
 
47
47
  return Time.new(data.year, data.month, data.day) if data.is_a?(Date)
48
48
 
49
- check_datetime_string(data)
49
+ data, _type = check_datetime_string(data)
50
+ data
50
51
  end
51
52
 
52
53
  def self.check_date(data)
@@ -56,9 +57,9 @@ module StarkBank
56
57
 
57
58
  return data if data.is_a?(Date)
58
59
 
59
- data = check_datetime_string(data)
60
+ data, type = check_datetime_string(data)
60
61
 
61
- Date.new(data.year, data.month, data.day)
62
+ type == 'date' ? Date.new(data.year, data.month, data.day) : data
62
63
  end
63
64
 
64
65
  class << self
@@ -68,17 +69,17 @@ module StarkBank
68
69
  data = data.to_s
69
70
 
70
71
  begin
71
- return DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00')
72
+ return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00'), 'datetime']
72
73
  rescue ArgumentError
73
74
  end
74
75
 
75
76
  begin
76
- return DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00')
77
+ return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00'), 'datetime']
77
78
  rescue ArgumentError
78
79
  end
79
80
 
80
81
  begin
81
- return DateTime.strptime(data, '%Y-%m-%d')
82
+ return [DateTime.strptime(data, '%Y-%m-%d'), 'date']
82
83
  rescue ArgumentError
83
84
  raise(ArgumentError, 'invalid datetime string ' + data)
84
85
  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.1.0"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.2.0.beta2"
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: 2.1.0
4
+ version: 2.2.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - starkbank
@@ -81,6 +81,8 @@ files:
81
81
  - lib/boleto_payment/log.rb
82
82
  - lib/error.rb
83
83
  - lib/event/event.rb
84
+ - lib/invoice/invoice.rb
85
+ - lib/invoice/log.rb
84
86
  - lib/key.rb
85
87
  - lib/payment_request/payment_request.rb
86
88
  - lib/starkbank.rb
@@ -116,9 +118,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
118
  version: '2.3'
117
119
  required_rubygems_version: !ruby/object:Gem::Requirement
118
120
  requirements:
119
- - - ">="
121
+ - - ">"
120
122
  - !ruby/object:Gem::Version
121
- version: '0'
123
+ version: 1.3.1
122
124
  requirements: []
123
125
  rubygems_version: 3.1.4
124
126
  signing_key: