starkbank 2.5.0 → 2.7.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/balance/balance.rb +8 -8
  3. data/lib/boleto/boleto.rb +22 -19
  4. data/lib/boleto/log.rb +10 -10
  5. data/lib/boleto_holmes/boleto_holmes.rb +14 -14
  6. data/lib/boleto_holmes/log.rb +16 -13
  7. data/lib/boleto_payment/boleto_payment.rb +21 -18
  8. data/lib/boleto_payment/log.rb +10 -10
  9. data/lib/brcode_payment/brcode_payment.rb +23 -20
  10. data/lib/brcode_payment/log.rb +10 -10
  11. data/lib/brcode_payment/rule.rb +49 -0
  12. data/lib/darf_payment/darf_payment.rb +23 -21
  13. data/lib/darf_payment/log.rb +10 -10
  14. data/lib/deposit/deposit.rb +9 -9
  15. data/lib/deposit/log.rb +10 -10
  16. data/lib/dict_key/dict_key.rb +26 -27
  17. data/lib/dynamic_brcode/dynamic_brcode.rb +155 -0
  18. data/lib/error.rb +7 -40
  19. data/lib/event/attempt.rb +9 -9
  20. data/lib/event/event.rb +30 -56
  21. data/lib/institution/institution.rb +2 -3
  22. data/lib/invoice/invoice.rb +33 -23
  23. data/lib/invoice/log.rb +10 -10
  24. data/lib/invoice/payment.rb +1 -2
  25. data/lib/payment_preview/boleto_preview.rb +74 -0
  26. data/lib/payment_preview/brcode_preview.rb +74 -0
  27. data/lib/payment_preview/payment_preview.rb +71 -0
  28. data/lib/payment_preview/tax_preview.rb +44 -0
  29. data/lib/payment_preview/utility_preview.rb +44 -0
  30. data/lib/payment_request/payment_request.rb +22 -16
  31. data/lib/starkbank.rb +21 -5
  32. data/lib/tax_payment/log.rb +10 -10
  33. data/lib/tax_payment/tax_payment.rb +22 -19
  34. data/lib/transaction/transaction.rb +13 -13
  35. data/lib/transfer/log.rb +10 -10
  36. data/lib/transfer/rule.rb +49 -0
  37. data/lib/transfer/transfer.rb +27 -24
  38. data/lib/utility_payment/log.rb +10 -10
  39. data/lib/utility_payment/utility_payment.rb +26 -17
  40. data/lib/utils/parse.rb +35 -0
  41. data/lib/utils/rest.rb +132 -109
  42. data/lib/webhook/webhook.rb +5 -5
  43. data/lib/workspace/workspace.rb +38 -10
  44. metadata +20 -25
  45. data/lib/brcode_preview/brcode_preview.rb +0 -77
  46. data/lib/key.rb +0 -33
  47. data/lib/user/organization.rb +0 -54
  48. data/lib/user/project.rb +0 -37
  49. data/lib/user/user.rb +0 -20
  50. data/lib/utils/api.rb +0 -79
  51. data/lib/utils/cache.rb +0 -10
  52. data/lib/utils/case.rb +0 -21
  53. data/lib/utils/checks.rb +0 -101
  54. data/lib/utils/environment.rb +0 -13
  55. data/lib/utils/request.rb +0 -79
  56. data/lib/utils/resource.rb +0 -13
  57. data/lib/utils/sub_resource.rb +0 -28
  58. data/lib/utils/url.rb +0 -28
data/lib/error.rb CHANGED
@@ -1,52 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require('json')
3
+ require('starkcore')
4
4
 
5
5
  module StarkBank
6
6
  module Error
7
- class StarkBankError < StandardError
8
- attr_reader :message
9
- def initialize(message)
10
- @message = message
11
- super(message)
12
- end
13
- end
7
+ StarkBankError = StarkCore::Error::StarkCoreError
14
8
 
15
- class Error < StarkBankError
16
- attr_reader :code, :message
17
- def initialize(code, message)
18
- @code = code
19
- @message = message
20
- super("#{code}: #{message}")
21
- end
22
- end
9
+ Error = StarkCore::Error::Error
23
10
 
24
- class InputErrors < StarkBankError
25
- attr_reader :errors
26
- def initialize(content)
27
- errors = []
28
- content.each do |error|
29
- errors << Error.new(error['code'], error['message'])
30
- end
31
- @errors = errors
11
+ InputErrors = StarkCore::Error::InputErrors
32
12
 
33
- super(content.to_json)
34
- end
35
- end
13
+ InternalServerError = StarkCore::Error::InternalServerError
36
14
 
37
- class InternalServerError < StarkBankError
38
- def initialize(message = 'Houston, we have a problem.')
39
- super(message)
40
- end
41
- end
15
+ UnknownError = StarkCore::Error::UnknownError
42
16
 
43
- class UnknownError < StarkBankError
44
- def initialize(message)
45
- super("Unknown exception encountered: #{message}")
46
- end
47
- end
48
-
49
- class InvalidSignatureError < StarkBankError
50
- end
17
+ InvalidSignatureError = StarkCore::Error::InvalidSignatureError
51
18
  end
52
19
  end
data/lib/event/attempt.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require('starkcore')
4
4
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
6
5
  require_relative('event')
7
6
 
7
+
8
8
  module StarkBank
9
9
  class Event
10
10
  # # Event::Attempt object
@@ -12,14 +12,14 @@ module StarkBank
12
12
  # When an Event delivery fails, an event attempt will be registered.
13
13
  # It carries information meant to help you debug event reception issues.
14
14
  #
15
- # ## Attributes:
15
+ # ## Attributes (return-only):
16
16
  # - id [string]: unique id that identifies the delivery attempt. ex: "5656565656565656"
17
17
  # - code [string]: delivery error code. ex: badHttpStatus, badConnection, timeout
18
18
  # - message [string]: delivery error full description. ex: "HTTP POST request returned status 404"
19
19
  # - event_id [string]: ID of the Event whose delivery failed. ex: "4848484848484848"
20
20
  # - webhook_id [string]: ID of the Webhook that triggered this event. ex: "5656565656565656"
21
21
  # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
- class Attempt < StarkBank::Utils::Resource
22
+ class Attempt < StarkCore::Utils::Resource
23
23
  attr_reader :id, :code, :message, :event_id, :webhook_id, :created
24
24
  def initialize(id:, code:, message:, event_id:, webhook_id:, created:)
25
25
  super(id)
@@ -27,7 +27,7 @@ module StarkBank
27
27
  @message = message
28
28
  @event_id = event_id
29
29
  @webhook_id = webhook_id
30
- @created = StarkBank::Utils::Checks.check_datetime(created)
30
+ @created = StarkCore::Utils::Checks.check_datetime(created)
31
31
  end
32
32
 
33
33
  # # Retrieve a specific Event::Attempt
@@ -61,8 +61,8 @@ module StarkBank
61
61
  # ## Return:
62
62
  # - generator of Event::Attempt objects with updated attributes
63
63
  def self.query(limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
64
- after = StarkBank::Utils::Checks.check_date(after)
65
- before = StarkBank::Utils::Checks.check_date(before)
64
+ after = StarkCore::Utils::Checks.check_date(after)
65
+ before = StarkCore::Utils::Checks.check_date(before)
66
66
  StarkBank::Utils::Rest.get_stream(
67
67
  limit: limit,
68
68
  after: after,
@@ -91,8 +91,8 @@ module StarkBank
91
91
  # ## Return:
92
92
  # - list of Attempt objects with updated attributes and cursor to retrieve the next page of Attempt objects
93
93
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, event_ids: nil, webhook_ids: nil, user: nil)
94
- after = StarkBank::Utils::Checks.check_date(after)
95
- before = StarkBank::Utils::Checks.check_date(before)
94
+ after = StarkCore::Utils::Checks.check_date(after)
95
+ before = StarkCore::Utils::Checks.check_date(before)
96
96
  return StarkBank::Utils::Rest.get_page(
97
97
  cursor: cursor,
98
98
  limit: limit,
data/lib/event/event.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require('json')
4
- require('starkbank-ecdsa')
5
- require_relative('../utils/resource')
4
+ require('starkcore')
6
5
  require_relative('../utils/rest')
7
- require_relative('../utils/checks')
8
- require_relative('../utils/cache')
6
+ require_relative('../utils/parse')
9
7
  require_relative('../error')
10
8
  require_relative('../boleto/log')
11
9
  require_relative('../boleto_holmes/log')
@@ -25,18 +23,18 @@ module StarkBank
25
23
  # Events cannot be created, but may be retrieved from the Stark Bank API to
26
24
  # list all generated updates on entities.
27
25
  #
28
- # ## Attributes:
26
+ # ## Attributes (return-only):
29
27
  # - id [string]: unique id returned when the event is created. ex: '5656565656565656'
30
28
  # - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
31
29
  # - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
30
  # - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
33
31
  # - workspace_id [string]: ID of the Workspace that generated this event. Mostly used when multiple Workspaces have Webhooks registered to the same endpoint. ex: '4545454545454545'
34
32
  # - subscription [string]: service that triggered this event. ex: 'transfer', 'utility-payment'
35
- class Event < StarkBank::Utils::Resource
33
+ class Event < StarkCore::Utils::Resource
36
34
  attr_reader :id, :log, :created, :is_delivered, :workspace_id, :subscription
37
35
  def initialize(id:, log:, created:, is_delivered:, workspace_id:, subscription:)
38
36
  super(id)
39
- @created = StarkBank::Utils::Checks.check_datetime(created)
37
+ @created = StarkCore::Utils::Checks.check_datetime(created)
40
38
  @is_delivered = is_delivered
41
39
  @workspace_id = workspace_id
42
40
  @subscription = subscription
@@ -55,7 +53,7 @@ module StarkBank
55
53
  }[subscription.to_sym]
56
54
 
57
55
  @log = log
58
- @log = StarkBank::Utils::API.from_api_json(resource[:resource_maker], log) unless resource.nil?
56
+ @log = StarkCore::Utils::API.from_api_json(resource[:resource_maker], log) unless resource.nil?
59
57
  end
60
58
 
61
59
  # # Retrieve a specific notification Event
@@ -88,8 +86,8 @@ module StarkBank
88
86
  # ## Return:
89
87
  # - generator of Event objects with updated attributes
90
88
  def self.query(limit: nil, after: nil, before: nil, is_delivered: nil, user: nil)
91
- after = StarkBank::Utils::Checks.check_date(after)
92
- before = StarkBank::Utils::Checks.check_date(before)
89
+ after = StarkCore::Utils::Checks.check_date(after)
90
+ before = StarkCore::Utils::Checks.check_date(before)
93
91
  StarkBank::Utils::Rest.get_stream(
94
92
  user: user,
95
93
  limit: limit,
@@ -116,8 +114,8 @@ module StarkBank
116
114
  # ## Return:
117
115
  # - list of Event objects with updated attributes and cursor to retrieve the next page of Event objects
118
116
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, is_delivered: nil, user: nil)
119
- after = StarkBank::Utils::Checks.check_date(after)
120
- before = StarkBank::Utils::Checks.check_date(before)
117
+ after = StarkCore::Utils::Checks.check_date(after)
118
+ before = StarkCore::Utils::Checks.check_date(before)
121
119
  return StarkBank::Utils::Rest.get_page(
122
120
  cursor: cursor,
123
121
  limit: limit,
@@ -179,53 +177,29 @@ module StarkBank
179
177
  # ## Return:
180
178
  # - Parsed Event object
181
179
  def self.parse(content:, signature:, user: nil)
182
- event = StarkBank::Utils::API.from_api_json(resource[:resource_maker], JSON.parse(content)['event'])
183
-
184
- begin
185
- signature = EllipticCurve::Signature.fromBase64(signature)
186
- rescue
187
- raise(StarkBank::Error::InvalidSignatureError, 'The provided signature is not valid')
188
- end
189
-
190
- return event if verify_signature(content: content, signature: signature, user: user)
191
-
192
- return event if verify_signature(content: content, signature: signature, user: user, refresh: true)
193
-
194
- raise(StarkBank::Error::InvalidSignatureError, 'The provided signature and content do not match the Stark Bank public key')
180
+ StarkBank::Utils::Parse.parse_and_verify(
181
+ content: content,
182
+ signature: signature,
183
+ user: user,
184
+ resource: resource,
185
+ key: 'event'
186
+ )
195
187
  end
196
188
 
197
- class << self
198
- private
199
-
200
- def verify_signature(content:, signature:, user:, refresh: false)
201
- public_key = StarkBank::Utils::Cache.starkbank_public_key
202
- if public_key.nil? || refresh
203
- pem = get_public_key_pem(user)
204
- public_key = EllipticCurve::PublicKey.fromPem(pem)
205
- StarkBank::Utils::Cache.starkbank_public_key = public_key
206
- end
207
- EllipticCurve::Ecdsa.verify(content, signature, public_key)
208
- end
209
-
210
- def get_public_key_pem(user)
211
- StarkBank::Utils::Request.fetch(method: 'GET', path: 'public-key', query: { limit: 1 }, user: user).json['publicKeys'][0]['content']
212
- end
213
-
214
- def resource
215
- {
216
- resource_name: 'Event',
217
- resource_maker: proc { |json|
218
- Event.new(
219
- id: json['id'],
220
- log: json['log'],
221
- created: json['created'],
222
- is_delivered: json['is_delivered'],
223
- workspace_id: json['workspace_id'],
224
- subscription: json['subscription']
225
- )
226
- }
189
+ def self.resource
190
+ {
191
+ resource_name: 'Event',
192
+ resource_maker: proc { |json|
193
+ Event.new(
194
+ id: json['id'],
195
+ log: json['log'],
196
+ created: json['created'],
197
+ is_delivered: json['is_delivered'],
198
+ workspace_id: json['workspace_id'],
199
+ subscription: json['subscription']
200
+ )
227
201
  }
228
- end
202
+ }
229
203
  end
230
204
  end
231
205
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/sub_resource')
4
3
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
4
+
6
5
 
7
6
  module StarkBank
8
7
  # # Institution object
@@ -17,7 +16,7 @@ module StarkBank
17
16
  # - name [string]: full version of the institution name. ex: 'Stark Bank S.A.'
18
17
  # - spi_code [string]: SPI code used to identify the institution on Pix transactions. ex: '20018183'
19
18
  # - str_code [string]: STR code used to identify the institution on TED transactions. ex: '123'
20
- class Institution < StarkBank::Utils::SubResource
19
+ class Institution < StarkCore::Utils::SubResource
21
20
  attr_reader :display_name, :name, :spi_code, :str_code
22
21
  def initialize(display_name: nil, name: nil, spi_code: nil, str_code: nil)
23
22
  @display_name = display_name
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require('starkcore')
4
4
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
5
+
6
6
 
7
7
  module StarkBank
8
8
  # # Invoice object
@@ -10,6 +10,8 @@ module StarkBank
10
10
  # When you initialize an Invoice, the entity will not be automatically
11
11
  # sent to the Stark Bank API. The 'create' function sends the objects
12
12
  # to the Stark Bank API and returns the list of created objects.
13
+ # To create scheduled Invoices, which will display the discount, interest, etc. on the final users banking interface,
14
+ # use dates instead of datetimes on the "due" and "discounts" fields.
13
15
  #
14
16
  # ## Parameters (required):
15
17
  # - amount [integer]: Invoice value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34)
@@ -26,19 +28,20 @@ module StarkBank
26
28
  # - tags [list of strings, default nil]: list of strings for tagging
27
29
  #
28
30
  # ## Attributes (return-only):
29
- # - pdf [string, default nil]: public Invoice PDF URL. ex: 'https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8'
30
- # - link [string, default nil]: public Invoice webpage URL. ex: 'https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8'
31
- # - id [string, default nil]: unique id returned when Invoice is created. ex: '5656565656565656'
32
- # - nominal_amount [integer, default nil]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
33
- # - fine_amount [integer, default nil]: Invoice fine value calculated over nominal_amount. ex: 20000
34
- # - interest_amount [integer, default nil]: Invoice interest value calculated over nominal_amount. ex: 10000
35
- # - discount_amount [integer, default nil]: Invoice discount value calculated over nominal_amount. ex: 3000
36
- # - brcode [string, default nil]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
37
- # - fee [integer, default nil]: fee charged by the Invoice. ex: 65 (= R$ 0.65)
38
- # - status [string, default nil]: current Invoice status. ex: 'registered' or 'paid'
39
- # - created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
40
- # - updated [DateTime, default nil]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
41
- class Invoice < StarkBank::Utils::Resource
31
+ # - pdf [string]: public Invoice PDF URL. ex: 'https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8'
32
+ # - link [string]: public Invoice webpage URL. ex: 'https://my-workspace.sandbox.starkbank.com/invoicelink/d454fa4e524441c1b0c1a729457ed9d8'
33
+ # - id [string]: unique id returned when Invoice is created. ex: '5656565656565656'
34
+ # - nominal_amount [integer]: Invoice emission value in cents (will change if invoice is updated, but not if it's paid). ex: 400000
35
+ # - fine_amount [integer]: Invoice fine value calculated over nominal_amount. ex: 20000
36
+ # - interest_amount [integer]: Invoice interest value calculated over nominal_amount. ex: 10000
37
+ # - discount_amount [integer]: Invoice discount value calculated over nominal_amount. ex: 3000
38
+ # - brcode [string]: BR Code for the Invoice payment. ex: '00020101021226800014br.gov.bcb.pix2558invoice.starkbank.com/f5333103-3279-4db2-8389-5efe335ba93d5204000053039865802BR5913Arya Stark6009Sao Paulo6220051656565656565656566304A9A0'
39
+ # - fee [integer]: fee charged by the Invoice. ex: 65 (= R$ 0.65)
40
+ # - transaction_ids [list of strings]: ledger transaction ids linked to this Invoice (if there are more than one, all but the first are reversals or failed reversal chargebacks). ex: ["19827356981273"]
41
+ # - status [string]: current Invoice status. ex: 'registered' or 'paid'
42
+ # - created [DateTime]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
43
+ # - updated [DateTime]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
44
+ class Invoice < StarkCore::Utils::Resource
42
45
  attr_reader :amount, :tax_id, :name, :due, :expiration, :fine, :interest, :discounts, :tags, :pdf, :link, :descriptions, :nominal_amount, :fine_amount, :interest_amount, :discount_amount, :id, :brcode, :fee, :status, :transaction_ids, :created, :updated
43
46
  def initialize(
44
47
  amount:, tax_id:, name:, due: nil, expiration: nil, fine: nil, interest: nil, discounts: nil,
@@ -47,13 +50,12 @@ module StarkBank
47
50
  )
48
51
  super(id)
49
52
  @amount = amount
50
- @due = StarkBank::Utils::Checks.check_datetime(due)
53
+ @due = StarkCore::Utils::Checks.check_date_or_datetime(due)
51
54
  @tax_id = tax_id
52
55
  @name = name
53
56
  @expiration = expiration
54
57
  @fine = fine
55
58
  @interest = interest
56
- @discounts = discounts
57
59
  @tags = tags
58
60
  @pdf = pdf
59
61
  @link = link
@@ -66,8 +68,16 @@ module StarkBank
66
68
  @fee = fee
67
69
  @status = status
68
70
  @transaction_ids = transaction_ids
69
- @updated = StarkBank::Utils::Checks.check_datetime(updated)
70
- @created = StarkBank::Utils::Checks.check_datetime(created)
71
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
72
+ @created = StarkCore::Utils::Checks.check_datetime(created)
73
+ if !discounts.nil?
74
+ checked_discounts = []
75
+ discounts.each do |discount|
76
+ discount["due"] = StarkCore::Utils::Checks.check_date_or_datetime(discount["due"])
77
+ checked_discounts.push(discount)
78
+ end
79
+ @discounts = checked_discounts
80
+ end
71
81
  end
72
82
 
73
83
  # # Create Invoices
@@ -150,8 +160,8 @@ module StarkBank
150
160
  # ## Return:
151
161
  # - generator of Invoice objects with updated attributes
152
162
  def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
153
- after = StarkBank::Utils::Checks.check_date(after)
154
- before = StarkBank::Utils::Checks.check_date(before)
163
+ after = StarkCore::Utils::Checks.check_date(after)
164
+ before = StarkCore::Utils::Checks.check_date(before)
155
165
  StarkBank::Utils::Rest.get_stream(
156
166
  limit: limit,
157
167
  after: after,
@@ -182,8 +192,8 @@ module StarkBank
182
192
  # ## Return:
183
193
  # - list of Invoice objects with updated attributes and cursor to retrieve the next page of Invoice objects
184
194
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
185
- after = StarkBank::Utils::Checks.check_date(after)
186
- before = StarkBank::Utils::Checks.check_date(before)
195
+ after = StarkCore::Utils::Checks.check_date(after)
196
+ before = StarkCore::Utils::Checks.check_date(before)
187
197
  return StarkBank::Utils::Rest.get_page(
188
198
  cursor: cursor,
189
199
  limit: limit,
data/lib/invoice/log.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
3
+ require('starkcore')
4
4
  require_relative('../utils/rest')
5
- require_relative('../utils/checks')
6
5
  require_relative('invoice')
7
6
 
7
+
8
8
  module StarkBank
9
9
  class Invoice
10
10
  # # Invoice::Log object
@@ -14,20 +14,20 @@ module StarkBank
14
14
  # user, but it can be retrieved to check additional information
15
15
  # on the Invoice.
16
16
  #
17
- # ## Attributes:
17
+ # ## Attributes (return-only):
18
18
  # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
19
19
  # - invoice [Invoice]: Invoice entity to which the log refers to.
20
20
  # - errors [list of strings]: list of errors linked to this Invoice event
21
21
  # - type [string]: type of the Invoice event which triggered the log creation. ex: 'canceled' or 'paid'
22
22
  # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
23
- class Log < StarkBank::Utils::Resource
23
+ class Log < StarkCore::Utils::Resource
24
24
  attr_reader :id, :created, :type, :errors, :invoice
25
25
  def initialize(id:, created:, type:, errors:, invoice:)
26
26
  super(id)
27
27
  @type = type
28
28
  @errors = errors
29
29
  @invoice = invoice
30
- @created = StarkBank::Utils::Checks.check_datetime(created)
30
+ @created = StarkCore::Utils::Checks.check_datetime(created)
31
31
  end
32
32
 
33
33
  # # Retrieve a specific Log
@@ -61,8 +61,8 @@ module StarkBank
61
61
  # ## Return:
62
62
  # - list of Log objects with updated attributes
63
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)
64
+ after = StarkCore::Utils::Checks.check_date(after)
65
+ before = StarkCore::Utils::Checks.check_date(before)
66
66
  StarkBank::Utils::Rest.get_stream(
67
67
  limit: limit,
68
68
  after: after,
@@ -91,8 +91,8 @@ module StarkBank
91
91
  # ## Return:
92
92
  # - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
93
93
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, invoice_ids: nil, user: nil)
94
- after = StarkBank::Utils::Checks.check_date(after)
95
- before = StarkBank::Utils::Checks.check_date(before)
94
+ after = StarkCore::Utils::Checks.check_date(after)
95
+ before = StarkCore::Utils::Checks.check_date(before)
96
96
  return StarkBank::Utils::Rest.get_page(
97
97
  cursor: cursor,
98
98
  limit: limit,
@@ -131,7 +131,7 @@ module StarkBank
131
131
  created: json['created'],
132
132
  type: json['type'],
133
133
  errors: json['errors'],
134
- invoice: StarkBank::Utils::API.from_api_json(invoice_maker, json['invoice'])
134
+ invoice: StarkCore::Utils::API.from_api_json(invoice_maker, json['invoice'])
135
135
  )
136
136
  }
137
137
  }
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/sub_resource')
4
3
  require_relative('invoice')
5
4
 
6
5
  module StarkBank
@@ -20,7 +19,7 @@ module StarkBank
20
19
  # - account_type [string]: payer bank account type. ex: 'checking', 'savings', 'salary' or 'payment'
21
20
  # - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
22
21
  # - method [string]: payment method that was used. ex: 'pix'
23
- class Payment < StarkBank::Utils::SubResource
22
+ class Payment < StarkCore::Utils::SubResource
24
23
  attr_reader :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :amount, :end_to_end_id, :method
25
24
  def initialize(name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, amount:, end_to_end_id:, method:)
26
25
  @name = name
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+
5
+
6
+ module StarkBank
7
+ class PaymentPreview
8
+ # # BoletoPreview object
9
+ #
10
+ # A BoletoPreview is used to get information from a Boleto payment you received before confirming the payment.
11
+ #
12
+ # ## Attributes (return-only):
13
+ # - status [string]: current boleto status. ex: 'active', 'expired' or 'inactive'
14
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
15
+ # - discount_amount [int]: discount amount to be paid. ex: 23456 (= R$ 234.56)
16
+ # - fine_amount [int]: fine amount to be paid. ex: 23456 (= R$ 234.56)
17
+ # - interest_amount [int]: interest amount to be paid. ex: 23456 (= R$ 234.56)
18
+ # - due [DateTime or string]: Boleto due date. ex: '2020-04-30'
19
+ # - expiration [DateTime or string]: Boleto expiration date. ex: '2020-04-30'
20
+ # - name [string]: beneficiary full name. ex: 'Anthony Edward Stark'
21
+ # - tax_id [string]: beneficiary tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
22
+ # - receiver_name [string]: receiver (Sacador Avalista) full name. ex: 'Anthony Edward Stark'
23
+ # - receiver_tax_id [string]: receiver (Sacador Avalista) tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
24
+ # - payer_name [string]: payer full name. ex: 'Anthony Edward Stark'
25
+ # - payer_tax_id [string]: payer tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
26
+ # - line [string]: Number sequence that identifies the payment. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062'
27
+ # - bar_code [string]: Bar code number that identifies the payment. ex: '34195819600000000621090063571277307144464000'
28
+ class BoletoPreview < StarkCore::Utils::SubResource
29
+ attr_reader :status, :amount, :discount_amount, :fine_amount, :interest_amount, :due, :expiration, :name, :tax_id, :receiver_name, :receiver_tax_id, :payer_name, :payer_tax_id, :line, :bar_code
30
+ def initialize(status:, amount:, discount_amount:, fine_amount:, interest_amount:, due:, expiration:, name:, tax_id:, receiver_name:, receiver_tax_id:, payer_name:, payer_tax_id:, line:, bar_code:)
31
+ @status = status
32
+ @amount = amount
33
+ @discount_amount = discount_amount
34
+ @fine_amount = fine_amount
35
+ @interest_amount = interest_amount
36
+ @due = StarkCore::Utils::Checks.check_datetime(due)
37
+ @expiration = StarkCore::Utils::Checks.check_datetime(expiration)
38
+ @name = name
39
+ @tax_id = tax_id
40
+ @receiver_name = receiver_name
41
+ @receiver_tax_id = receiver_tax_id
42
+ @payer_name = payer_name
43
+ @payer_tax_id = payer_tax_id
44
+ @line = line
45
+ @bar_code = bar_code
46
+ end
47
+
48
+ def self.resource
49
+ {
50
+ resource_name: 'BoletoPreview',
51
+ resource_maker: proc { |json|
52
+ BoletoPreview.new(
53
+ status: json['status'],
54
+ amount: json['amount'],
55
+ discount_amount: json['discount_amount'],
56
+ fine_amount: json['fine_amount'],
57
+ interest_amount: json['interest_amount'],
58
+ due: json['due'],
59
+ expiration: json['expiration'],
60
+ name: json['name'],
61
+ tax_id: json['tax_id'],
62
+ receiver_name: json['receiver_name'],
63
+ receiver_tax_id: json['receiver_tax_id'],
64
+ payer_name: json['payer_name'],
65
+ payer_tax_id: json['payer_tax_id'],
66
+ line: json['line'],
67
+ bar_code: json['bar_code'],
68
+ )
69
+ }
70
+ }
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+
5
+
6
+ module StarkBank
7
+ class PaymentPreview
8
+ # # BrcodePreview object
9
+ #
10
+ # A BrcodePreview is used to get information from a BR Code you received before confirming the payment.
11
+ #
12
+ # ## Attributes (return-only):
13
+ # - status [string]: Payment status. ex: 'active', 'paid', 'canceled' or 'unknown'
14
+ # - name [string]: Payment receiver name. ex: 'Tony Stark'
15
+ # - tax_id [string]: Payment receiver tax ID. ex: '012.345.678-90'
16
+ # - bank_code [string]: Payment receiver bank code. ex: '20018183'
17
+ # - branch_code [string]: Payment receiver branch code. ex: '0001'
18
+ # - account_number [string]: Payment receiver account number. ex: '1234567'
19
+ # - account_type [string]: Payment receiver account type. ex: 'checking'
20
+ # - allow_change [bool]: If True, the payment is able to receive amounts that are different from the nominal one. ex: True or False
21
+ # - amount [integer]: Value in cents that this payment is expecting to receive. If 0, any value is accepted. ex: 123 (= R$1,23)
22
+ # - nominal_amount [integer]: Original value in cents that this payment was expecting to receive without the discounts, fines, etc.. If 0, any value is accepted. ex: 123 (= R$1,23)
23
+ # - interest_amount [integer]: Current interest value in cents that this payment is charging. If 0, any value is accepted. ex: 123 (= R$1,23)
24
+ # - fine_amount [integer]: Current fine value in cents that this payment is charging. ex: 123 (= R$1,23)
25
+ # - reduction_amount [integer]: Current value reduction value in cents that this payment is expecting. ex: 123 (= R$1,23)
26
+ # - discount_amount [integer]: Current discount value in cents that this payment is expecting. ex: 123 (= R$1,23)
27
+ # - reconciliation_id [string]: Reconciliation ID linked to this payment. ex: 'txId', 'payment-123'
28
+ class BrcodePreview < StarkCore::Utils::SubResource
29
+ attr_reader :status, :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :allow_change, :amount, :nominal_amount, :interest_amount, :fine_amount, :reduction_amount, :discount_amount, :reconciliation_id
30
+ def initialize(status:, name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, allow_change:, amount:, nominal_amount:, interest_amount:, fine_amount:, reduction_amount:, discount_amount:, reconciliation_id:)
31
+ @status = status
32
+ @name = name
33
+ @tax_id = tax_id
34
+ @bank_code = bank_code
35
+ @branch_code = branch_code
36
+ @account_number = account_number
37
+ @account_type = account_type
38
+ @allow_change = allow_change
39
+ @amount = amount
40
+ @nominal_amount = nominal_amount
41
+ @interest_amount = interest_amount
42
+ @fine_amount = fine_amount
43
+ @reduction_amount = reduction_amount
44
+ @discount_amount = discount_amount
45
+ @reconciliation_id = reconciliation_id
46
+ end
47
+
48
+ def self.resource
49
+ {
50
+ resource_name: 'BrcodePreview',
51
+ resource_maker: proc { |json|
52
+ BrcodePreview.new(
53
+ status: json['status'],
54
+ name: json['name'],
55
+ tax_id: json['tax_id'],
56
+ bank_code: json['bank_code'],
57
+ branch_code: json['branch_code'],
58
+ account_number: json['account_number'],
59
+ account_type: json['account_type'],
60
+ allow_change: json['allow_change'],
61
+ amount: json['amount'],
62
+ nominal_amount: json['nominal_amount'],
63
+ interest_amount: json['interest_amount'],
64
+ fine_amount: json['fine_amount'],
65
+ reduction_amount: json['reduction_amount'],
66
+ discount_amount: json['discount_amount'],
67
+ reconciliation_id: json['reconciliation_id']
68
+ )
69
+ }
70
+ }
71
+ end
72
+ end
73
+ end
74
+ end