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
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('starkcore')
4
+ require_relative('../utils/rest')
5
+
6
+
7
+ module StarkBank
8
+ # # PaymentPreview object
9
+ #
10
+ # A PaymentPreview is used to get information from a payment code before confirming the payment.
11
+ # This resource can be used to preview BR Codes and bar codes of boleto, tax and utility payments
12
+ #
13
+ # ## Parameters (required):
14
+ # - id [string]: Main identification of the payment. This should be the BR Code for Pix payments and lines or bar codes for payment slips. ex: '34191.09008 63571.277308 71444.640008 5 81960000000062', '00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A'
15
+ #
16
+ # ## Parameters (optional):
17
+ # - scheduled [DateTime or string]: intended payment date. Right now, this parameter only has effect on BrcodePreviews. ex: '2020-04-30'
18
+ #
19
+ # ## Attributes (return-only):
20
+ # - type [string]: Payment type. ex: 'brcode-payment', 'boleto-payment', 'utility-payment' or 'tax-payment'
21
+ # - payment [BrcodePreview, BoletoPreview, UtilityPreview or TaxPreview]: Information preview of the informed payment.
22
+ class PaymentPreview < StarkCore::Utils::Resource
23
+ attr_reader :id, :scheduled, :type, :payment
24
+ def initialize(id: nil, scheduled: nil, type: nil, payment: nil)
25
+ super(id)
26
+ @scheduled = StarkCore::Utils::Checks.check_date(scheduled)
27
+ @type = type
28
+ @payment = payment
29
+ return if type.nil?
30
+
31
+ resource = {
32
+ 'brcode-payment': StarkBank::PaymentPreview::BrcodePreview.resource,
33
+ 'boleto-payment': StarkBank::PaymentPreview::BoletoPreview.resource,
34
+ 'tax-payment': StarkBank::PaymentPreview::TaxPreview.resource,
35
+ 'utility-payment': StarkBank::PaymentPreview::UtilityPreview.resource
36
+ }[type.to_sym]
37
+
38
+ @payment = StarkCore::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
39
+ end
40
+
41
+ # # Create PaymentPreviews
42
+ #
43
+ # Send a list of PaymentPreviews objects for processing in the Stark Bank API
44
+ #
45
+ # ## Parameters (required):
46
+ # - previews [list of PaymentPreviews objects]: list of PaymentPreviews objects to be created in the API
47
+ #
48
+ # ## Parameters (optional):
49
+ # - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
50
+ #
51
+ # ## Return:
52
+ # - list of PaymentPreviews objects with updated attributes
53
+ def self.create(previews, user: nil)
54
+ StarkBank::Utils::Rest.post(entities: previews, user: user, **resource)
55
+ end
56
+
57
+ def self.resource
58
+ {
59
+ resource_name: 'PaymentPreview',
60
+ resource_maker: proc { |json|
61
+ PaymentPreview.new(
62
+ id: json['id'],
63
+ scheduled: json['scheduled'],
64
+ type: json['type'],
65
+ payment: json['payment']
66
+ )
67
+ }
68
+ }
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+
5
+
6
+ module StarkBank
7
+ class PaymentPreview
8
+ # # TaxPreview object
9
+ #
10
+ # A TaxPreview is used to get information from a Tax Payment you received before confirming the payment.
11
+ #
12
+ # ## Attributes (return-only):
13
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
14
+ # - name [string]: beneficiary full name. ex: "Iron Throne"
15
+ # - description [string]: tax payment description. ex: "ISS Payment - Iron Throne"
16
+ # - line [string]: Number sequence that identifies the payment. ex: "85660000006 6 67940064007 5 41190025511 7 00010601813 8"
17
+ # - bar_code [string]: Bar code number that identifies the payment. ex: "85660000006679400640074119002551100010601813"
18
+ class TaxPreview < StarkCore::Utils::SubResource
19
+ attr_reader :amount, :name, :description, :line, :bar_code
20
+ def initialize(amount:, name:, description:, line:, bar_code:)
21
+ @amount = amount
22
+ @name = name
23
+ @description = description
24
+ @line = line
25
+ @bar_code = bar_code
26
+ end
27
+
28
+ def self.resource
29
+ {
30
+ resource_name: 'TaxPreview',
31
+ resource_maker: proc { |json|
32
+ TaxPreview.new(
33
+ amount: json['amount'],
34
+ name: json['name'],
35
+ description: json['description'],
36
+ line: json['line'],
37
+ bar_code: json['bar_code']
38
+ )
39
+ }
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+
5
+
6
+ module StarkBank
7
+ class PaymentPreview
8
+ # # UtilityPreview object
9
+ #
10
+ # A UtilityPreview is used to get information from a Utility Payment you received before confirming the payment.
11
+ #
12
+ # ## Attributes (return-only):
13
+ # - amount [int]: final amount to be paid. ex: 23456 (= R$ 234.56)
14
+ # - name [string]: beneficiary full name. ex: "Light Company"
15
+ # - description [string]: utility payment description. ex: "Utility Payment - Light Company"
16
+ # - line [string]: Number sequence that identifies the payment. ex: "82660000002 8 44361143007 7 41190025511 7 00010601813 8"
17
+ # - bar_code [string]: Bar code number that identifies the payment. ex: "82660000002443611430074119002551100010601813"
18
+ class UtilityPreview < StarkCore::Utils::SubResource
19
+ attr_reader :amount, :name, :description, :line, :bar_code
20
+ def initialize(amount:, name:, description:, line:, bar_code:)
21
+ @amount = amount
22
+ @name = name
23
+ @description = description
24
+ @line = line
25
+ @bar_code = bar_code
26
+ end
27
+
28
+ def self.resource
29
+ {
30
+ resource_name: 'UtilityPreview',
31
+ resource_maker: proc { |json|
32
+ UtilityPreview.new(
33
+ amount: json['amount'],
34
+ name: json['name'],
35
+ description: json['description'],
36
+ line: json['line'],
37
+ bar_code: json['bar_code']
38
+ )
39
+ }
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,11 +1,12 @@
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
  # # PaymentRequest object
9
+ #
9
10
  # A PaymentRequest is an indirect request to access a specific cash-out service
10
11
  # (such as Transfer, BrcodePayments, etc.) which goes through the cost center
11
12
  # approval flow on our website. To emit a PaymentRequest, you must direct it to
@@ -16,24 +17,27 @@ module StarkBank
16
17
  # - center_id [String]: target cost center ID. ex: '5656565656565656'
17
18
  # - payment [Transfer, BrcodePayment, BoletoPayment, UtilityPayment, Transaction or dictionary]: payment entity that should be approved and executed.
18
19
  #
19
- # ## Parameters (optional):
20
+ # ## Parameters (conditionally required):
20
21
  # - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'brcode-payment'
22
+ #
23
+ # ## Parameters (optional):
21
24
  # - due [Date, DateTime, Time or string]: Payment target date in ISO format. ex: 2020-12-31
22
25
  # - tags [list of strings]: list of strings for tagging
23
26
  #
24
27
  # ## Attributes (return-only):
25
28
  # - id [String]: unique id returned when PaymentRequest is created. ex: '5656565656565656'
26
- # - amount [integer, default nil]: PaymentRequest amount. ex: 100000 = R$1.000,00
27
- # - status [string, default nil]: current PaymentRequest status.ex: 'pending' or 'approved'
28
- # - actions [list of dictionaries, default nil]: list of actions that are affecting this PaymentRequest. ex: [{'type': 'member', 'id': '56565656565656, 'action': 'requested'}]
29
- # - updated [DateTime, default nil]: latest update datetime for the PaymentRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
30
- # - created [DateTime, default nil]: creation datetime for the PaymentRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
29
+ # - amount [integer]: PaymentRequest amount. ex: 100000 = R$1.000,00
30
+ # - description [string]: payment request description. ex: "Tony Stark's Suit"
31
+ # - status [string]: current PaymentRequest status.ex: 'pending' or 'approved'
32
+ # - actions [list of dictionaries]: list of actions that are affecting this PaymentRequest. ex: [{'type': 'member', 'id': '56565656565656, 'action': 'requested'}]
33
+ # - updated [DateTime]: latest update datetime for the PaymentRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ # - created [DateTime]: creation datetime for the PaymentRequest. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
31
35
  #
32
- class PaymentRequest < StarkBank::Utils::Resource
33
- attr_reader :center_id, :payment, :type, :due, :tags, :amount, :status, :actions, :updated, :created
36
+ class PaymentRequest < StarkCore::Utils::Resource
37
+ attr_reader :center_id, :payment, :type, :due, :tags, :amount, :description, :status, :actions, :updated, :created
34
38
  def initialize(
35
39
  payment:, center_id:, id: nil, type: nil, due: nil, tags: nil, amount: nil, status: nil,
36
- actions: nil, updated: nil, created: nil
40
+ description: nil, actions: nil, updated: nil, created: nil
37
41
  )
38
42
  super(id)
39
43
  @center_id = center_id
@@ -42,6 +46,7 @@ module StarkBank
42
46
  @amount = amount
43
47
  @status = status
44
48
  @actions = actions
49
+ @description = description
45
50
  @updated = updated
46
51
  @created = created
47
52
 
@@ -82,8 +87,8 @@ module StarkBank
82
87
  # ## Return:
83
88
  # - generator of PaymentRequest objects with updated attributes
84
89
  def self.query(center_id:, limit: nil, after: nil, before: nil, status: nil, type: nil, sort: nil, tags: nil, ids: nil, user: nil)
85
- after = StarkBank::Utils::Checks.check_date(after)
86
- before = StarkBank::Utils::Checks.check_date(before)
90
+ after = StarkCore::Utils::Checks.check_date(after)
91
+ before = StarkCore::Utils::Checks.check_date(before)
87
92
  StarkBank::Utils::Rest.get_stream(
88
93
  center_id: center_id,
89
94
  limit: limit,
@@ -117,8 +122,8 @@ module StarkBank
117
122
  # ## Return:
118
123
  # - list of PaymentRequest objects with updated attributes and cursor to retrieve the next page of PaymentRequest objects
119
124
  def self.page(cursor: nil, center_id:, limit: nil, after: nil, before: nil, status: nil, type: nil, sort: nil, tags: nil, ids: nil, user: nil)
120
- after = StarkBank::Utils::Checks.check_date(after)
121
- before = StarkBank::Utils::Checks.check_date(before)
125
+ after = StarkCore::Utils::Checks.check_date(after)
126
+ before = StarkCore::Utils::Checks.check_date(before)
122
127
  return StarkBank::Utils::Rest.get_page(
123
128
  cursor: cursor,
124
129
  center_id: center_id,
@@ -156,7 +161,7 @@ module StarkBank
156
161
  'darf-payment': StarkBank::DarfPayment.resource
157
162
  }[type.to_sym]
158
163
 
159
- payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
164
+ payment = StarkCore::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
160
165
 
161
166
  [payment, type]
162
167
  end
@@ -173,6 +178,7 @@ module StarkBank
173
178
  tags: json['tags'],
174
179
  amount: json['amount'],
175
180
  status: json['status'],
181
+ description: json['description'],
176
182
  actions: json['actions'],
177
183
  updated: json['updated'],
178
184
  created: json['created']
data/lib/starkbank.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('key')
4
- require_relative('user/project')
5
- require_relative('user/organization')
6
3
  require_relative('workspace/workspace')
7
4
  require_relative('balance/balance')
8
5
  require_relative('transaction/transaction')
@@ -10,10 +7,11 @@ require_relative('invoice/invoice')
10
7
  require_relative('invoice/log')
11
8
  require_relative('invoice/payment')
12
9
  require_relative('dict_key/dict_key')
10
+ require_relative('dynamic_brcode/dynamic_brcode')
13
11
  require_relative('deposit/deposit')
14
12
  require_relative('deposit/log')
15
- require_relative('brcode_preview/brcode_preview')
16
13
  require_relative('brcode_payment/brcode_payment')
14
+ require_relative('brcode_payment/rule')
17
15
  require_relative('brcode_payment/log')
18
16
  require_relative('boleto/boleto')
19
17
  require_relative('boleto/log')
@@ -21,6 +19,7 @@ require_relative('boleto_holmes/boleto_holmes')
21
19
  require_relative('boleto_holmes/log')
22
20
  require_relative('transfer/transfer')
23
21
  require_relative('transfer/log')
22
+ require_relative('transfer/rule')
24
23
  require_relative('boleto_payment/boleto_payment')
25
24
  require_relative('boleto_payment/log')
26
25
  require_relative('utility_payment/utility_payment')
@@ -33,11 +32,28 @@ require_relative('webhook/webhook')
33
32
  require_relative('event/event')
34
33
  require_relative('event/attempt')
35
34
  require_relative('payment_request/payment_request')
35
+ require_relative('payment_preview/payment_preview')
36
+ require_relative('payment_preview/brcode_preview')
37
+ require_relative('payment_preview/boleto_preview')
38
+ require_relative('payment_preview/tax_preview')
39
+ require_relative('payment_preview/utility_preview')
36
40
  require_relative('institution/institution')
37
41
 
38
42
  # SDK to facilitate Ruby integrations with Stark Bank
39
43
  module StarkBank
44
+
45
+ API_VERSION = 'v2'
46
+ SDK_VERSION = '2.7.0'
47
+ HOST = "bank"
48
+ public_constant :API_VERSION, :SDK_VERSION, :HOST;
49
+
40
50
  @user = nil
41
51
  @language = 'en-US'
42
- class << self; attr_accessor :user, :language; end
52
+ @timeout = 15
53
+ class << self; attr_accessor :user, :language, :timeout; end
54
+
55
+ Project = StarkCore::Project
56
+ Organization = StarkCore::Organization
57
+ Key = StarkCore::Key
58
+
43
59
  end
@@ -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('tax_payment')
7
6
 
7
+
8
8
  module StarkBank
9
9
  class TaxPayment
10
10
  # # TaxPayment::Log object
@@ -14,20 +14,20 @@ module StarkBank
14
14
  # user, but it can be retrieved to check additional information
15
15
  # on the TaxPayment.
16
16
  #
17
- # ## Attributes:
17
+ # ## Attributes (return-only):
18
18
  # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
19
19
  # - payment [TaxPayment]: TaxPayment entity to which the log refers to.
20
20
  # - errors [list of strings]: list of errors linked to this TaxPayment event
21
21
  # - type [string]: type of the TaxPayment 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, :payment
25
25
  def initialize(id:, created:, type:, errors:, payment:)
26
26
  super(id)
27
27
  @type = type
28
28
  @errors = errors
29
29
  @payment = payment
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, payment_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, payment_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,
@@ -115,7 +115,7 @@ module StarkBank
115
115
  created: json['created'],
116
116
  type: json['type'],
117
117
  errors: json['errors'],
118
- payment: StarkBank::Utils::API.from_api_json(tax_payment_maker, json['payment'])
118
+ payment: StarkCore::Utils::API.from_api_json(tax_payment_maker, json['payment'])
119
119
  )
120
120
  }
121
121
  }
@@ -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
  # # TaxPayment object
@@ -23,31 +23,33 @@ module StarkBank
23
23
  # - tags [list of strings, default nil]: list of strings for tagging
24
24
  #
25
25
  # ## Attributes (return-only):
26
- # - id [string, default nil]: unique id returned when payment is created. ex: '5656565656565656'
27
- # - type [string, default nil]: tax type. ex: 'das'
28
- # - status [string, default nil]: current payment status. ex: 'success' or 'failed'
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 tax payment is created. ex: 200 (= R$ 2.00)
31
- # - created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
- # - updated [DateTime, default nil]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
- class TaxPayment < StarkBank::Utils::Resource
34
- attr_reader :id, :line, :bar_code, :description, :tags, :scheduled, :status, :amount, :fee, :type, :updated, :created
26
+ # - id [string]: unique id returned when payment is created. ex: '5656565656565656'
27
+ # - type [string]: tax type. ex: 'das'
28
+ # - status [string]: current payment status. ex: 'success' or 'failed'
29
+ # - amount [int]: amount automatically calculated from line or bar_code. ex: 23456 (= R$ 234.56)
30
+ # - fee [integer]: fee charged when tax payment is created. ex: 200 (= R$ 2.00)
31
+ # - transaction_ids [list of strings]: ledger transaction ids linked to this TaxPayment. ex: ["19827356981273"]
32
+ # - created [DateTime]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
33
+ # - updated [DateTime]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ class TaxPayment < StarkCore::Utils::Resource
35
+ attr_reader :id, :line, :bar_code, :description, :tags, :scheduled, :status, :amount, :fee, :type, :transaction_ids, :updated, :created
35
36
  def initialize(
36
37
  id: nil, line: nil, bar_code: nil, description:, tags: nil, scheduled: nil,
37
- status: nil, amount: nil, fee: nil, type: nil, updated: nil, created: nil
38
+ status: nil, amount: nil, fee: nil, transaction_ids: nil, type: nil, updated: nil, created: nil
38
39
  )
39
40
  super(id)
40
41
  @line = line
41
42
  @bar_code = bar_code
42
43
  @description = description
43
44
  @tags = tags
44
- @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
45
+ @scheduled = StarkCore::Utils::Checks.check_date(scheduled)
45
46
  @status = status
46
47
  @amount = amount
47
48
  @fee = fee
48
49
  @type = type
49
- @updated = StarkBank::Utils::Checks.check_datetime(updated)
50
- @created = StarkBank::Utils::Checks.check_datetime(created)
50
+ @transaction_ids = transaction_ids
51
+ @updated = StarkCore::Utils::Checks.check_datetime(updated)
52
+ @created = StarkCore::Utils::Checks.check_datetime(created)
51
53
  end
52
54
 
53
55
  # # Create TaxPayments
@@ -115,8 +117,8 @@ module StarkBank
115
117
  # ## Return:
116
118
  # - generator of TaxPayment objects with updated attributes
117
119
  def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
118
- after = StarkBank::Utils::Checks.check_date(after)
119
- before = StarkBank::Utils::Checks.check_date(before)
120
+ after = StarkCore::Utils::Checks.check_date(after)
121
+ before = StarkCore::Utils::Checks.check_date(before)
120
122
  StarkBank::Utils::Rest.get_stream(
121
123
  limit: limit,
122
124
  after: after,
@@ -147,8 +149,8 @@ module StarkBank
147
149
  # ## Return:
148
150
  # - list of Tax Payment objects with updated attributes and cursor to retrieve the next page of Tax Payment objects
149
151
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
150
- after = StarkBank::Utils::Checks.check_date(after)
151
- before = StarkBank::Utils::Checks.check_date(before)
152
+ after = StarkCore::Utils::Checks.check_date(after)
153
+ before = StarkCore::Utils::Checks.check_date(before)
152
154
  return StarkBank::Utils::Rest.get_page(
153
155
  cursor: cursor,
154
156
  limit: limit,
@@ -193,6 +195,7 @@ module StarkBank
193
195
  amount: json['amount'],
194
196
  fee: json['fee'],
195
197
  type: json['type'],
198
+ transaction_ids: json['transaction_ids'],
196
199
  updated: json['updated'],
197
200
  created: json['created']
198
201
  )
@@ -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
  # # Transaction object
@@ -26,12 +26,12 @@ module StarkBank
26
26
  #
27
27
  # ## Attributes (return-only):
28
28
  # - sender_id [string]: unique id of the sending workspace. ex: '5656565656565656'
29
- # - source [string, default nil]: locator of the entity that generated the transaction. ex: 'charge/1827351876292', 'transfer/92873912873/chargeback'
30
- # - id [string, default nil]: unique id returned when Transaction is created. ex: '7656565656565656'
31
- # - fee [integer, default nil]: fee charged when transaction is created. ex: 200 (= R$ 2.00)
32
- # - balance [integer, default nil]: account balance after transaction was processed. ex: 100000000 (= R$ 1,000,000.00)
33
- # - created [DateTime, default nil]: creation datetime for the boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
- class Transaction < StarkBank::Utils::Resource
29
+ # - source [string]: locator of the entity that generated the transaction. ex: 'charge/1827351876292', 'transfer/92873912873/chargeback'
30
+ # - id [string]: unique id returned when Transaction is created. ex: '7656565656565656'
31
+ # - fee [integer]: fee charged when transaction is created. ex: 200 (= R$ 2.00)
32
+ # - balance [integer]: account balance after transaction was processed. ex: 100000000 (= R$ 1,000,000.00)
33
+ # - created [DateTime]: creation datetime for the boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
34
+ class Transaction < StarkCore::Utils::Resource
35
35
  attr_reader :amount, :description, :external_id, :receiver_id, :sender_id, :tags, :id, :fee, :created, :source
36
36
  def initialize(amount:, description:, external_id:, receiver_id:, sender_id: nil, tags: nil, id: nil, fee: nil, source: nil, balance: nil, created: nil)
37
37
  super(id)
@@ -44,7 +44,7 @@ module StarkBank
44
44
  @fee = fee
45
45
  @source = source
46
46
  @balance = balance
47
- @created = StarkBank::Utils::Checks.check_datetime(created)
47
+ @created = StarkCore::Utils::Checks.check_datetime(created)
48
48
  end
49
49
 
50
50
  # # Create Transactions
@@ -95,8 +95,8 @@ module StarkBank
95
95
  # ## Return:
96
96
  # - generator of Transaction objects with updated attributes
97
97
  def self.query(limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil)
98
- after = StarkBank::Utils::Checks.check_date(after)
99
- before = StarkBank::Utils::Checks.check_date(before)
98
+ after = StarkCore::Utils::Checks.check_date(after)
99
+ before = StarkCore::Utils::Checks.check_date(before)
100
100
  StarkBank::Utils::Rest.get_stream(
101
101
  limit: limit,
102
102
  after: after,
@@ -127,8 +127,8 @@ module StarkBank
127
127
  # ## Return:
128
128
  # - list of Transaction objects with updated attributes and cursor to retrieve the next page of Transaction objects
129
129
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil)
130
- after = StarkBank::Utils::Checks.check_date(after)
131
- before = StarkBank::Utils::Checks.check_date(before)
130
+ after = StarkCore::Utils::Checks.check_date(after)
131
+ before = StarkCore::Utils::Checks.check_date(before)
132
132
  return StarkBank::Utils::Rest.get_page(
133
133
  cursor: cursor,
134
134
  limit: limit,
data/lib/transfer/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('transfer')
7
6
 
7
+
8
8
  module StarkBank
9
9
  class Transfer
10
10
  # # Transfer::Log object
@@ -13,20 +13,20 @@ module StarkBank
13
13
  # is generated for the entity. This log is never generated by the
14
14
  # user.
15
15
  #
16
- # ## Attributes:
16
+ # ## Attributes (return-only):
17
17
  # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
18
18
  # - transfer [Transfer]: Transfer entity to which the log refers to.
19
19
  # - errors [list of strings]: list of errors linked to this BoletoPayment event.
20
20
  # - type [string]: type of the Transfer event which triggered the log creation. ex: 'processing' or 'success'
21
21
  # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
22
- class Log < StarkBank::Utils::Resource
22
+ class Log < StarkCore::Utils::Resource
23
23
  attr_reader :id, :created, :type, :errors, :transfer
24
24
  def initialize(id:, created:, type:, errors:, transfer:)
25
25
  super(id)
26
26
  @type = type
27
27
  @errors = errors
28
28
  @transfer = transfer
29
- @created = StarkBank::Utils::Checks.check_datetime(created)
29
+ @created = StarkCore::Utils::Checks.check_datetime(created)
30
30
  end
31
31
 
32
32
  # # Retrieve a specific Log
@@ -60,8 +60,8 @@ module StarkBank
60
60
  # ## Return:
61
61
  # - list of Log objects with updated attributes
62
62
  def self.query(limit: nil, after: nil, before: nil, types: nil, transfer_ids: nil, user: nil)
63
- after = StarkBank::Utils::Checks.check_date(after)
64
- before = StarkBank::Utils::Checks.check_date(before)
63
+ after = StarkCore::Utils::Checks.check_date(after)
64
+ before = StarkCore::Utils::Checks.check_date(before)
65
65
  StarkBank::Utils::Rest.get_stream(
66
66
  limit: limit,
67
67
  after: after,
@@ -90,8 +90,8 @@ module StarkBank
90
90
  # ## Return:
91
91
  # - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
92
92
  def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, transfer_ids: nil, user: nil)
93
- after = StarkBank::Utils::Checks.check_date(after)
94
- before = StarkBank::Utils::Checks.check_date(before)
93
+ after = StarkCore::Utils::Checks.check_date(after)
94
+ before = StarkCore::Utils::Checks.check_date(before)
95
95
  return StarkBank::Utils::Rest.get_page(
96
96
  cursor: cursor,
97
97
  limit: limit,
@@ -114,7 +114,7 @@ module StarkBank
114
114
  created: json['created'],
115
115
  type: json['type'],
116
116
  errors: json['errors'],
117
- transfer: StarkBank::Utils::API.from_api_json(transfer_maker, json['transfer'])
117
+ transfer: StarkCore::Utils::API.from_api_json(transfer_maker, json['transfer'])
118
118
  )
119
119
  }
120
120
  }
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+
5
+
6
+ module StarkBank
7
+ class Transfer
8
+ # # Transfer::Rule object
9
+ #
10
+ # The Transfer::Rule object modifies the behavior of Transfer objects when passed as an argument upon their creation.
11
+ #
12
+ # ## Parameters (required):
13
+ # - key [string]: Rule to be customized, describes what Transfer behavior will be altered. ex: "resendingLimit"
14
+ # - value [integer]: Value of the rule. ex: 5
15
+ class Rule < StarkCore::Utils::SubResource
16
+ attr_reader :key, :value
17
+ def initialize(key:, value:)
18
+ @key = key
19
+ @value = value
20
+ end
21
+
22
+ def self.parse_rules(rules)
23
+ resource_maker = StarkBank::Transfer::Rule.resource[:resource_maker]
24
+ return rules if rules.nil?
25
+
26
+ parsed_rules = []
27
+ rules.each do |rule|
28
+ unless rule.is_a? Rule
29
+ rule = StarkCore::Utils::API.from_api_json(resource_maker, rule)
30
+ end
31
+ parsed_rules << rule
32
+ end
33
+ return parsed_rules
34
+ end
35
+
36
+ def self.resource
37
+ {
38
+ resource_name: 'Rule',
39
+ resource_maker: proc { |json|
40
+ Rule.new(
41
+ key: json['key'],
42
+ value: json['value']
43
+ )
44
+ }
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end