starkbank 2.1.0.beta2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98835d3b25dff96530638da6c2da72f1c8acbe7cb3a5fdb45a25e5506f8cb153
4
- data.tar.gz: b298cf063b7b824658c247122c3135302096924332b311d638089573aea432cc
3
+ metadata.gz: 21f296f6ce46e6451eb4650fcc5bd8f77b657184b10662daae70c79c4df26cc3
4
+ data.tar.gz: 2a0355e608aa51c1302ea55c8491741981afbfefd2bb86f56fb606fc4ab38c76
5
5
  SHA512:
6
- metadata.gz: 778c03a3493122b36fc1f1cd521e96c9a45035f5ff4590fc8189c17da4d3be177e890f8de65978e1c16eda9f4d3362e97e018e3f032186a0fe99a011df45e6d8
7
- data.tar.gz: 8a992c980902e97809cded32d229f72b4ef8e4c1adc6d2d8e8f67c7eb8a0c7efc5bf7bbc6faec265ad5a741ae0219de1f5d2bb507f501cef9e5c55338e34e5e7
6
+ metadata.gz: cce7c99b52dc834e4110caa9861a89dbb039d02d080d17631995666298798f6c1ca7024796958cc170d7f08d5a594a8f8ee4bb98078f8897e75a8455dad55987
7
+ data.tar.gz: 2e5c9d0a3d0f33b050f08b29e35453db3011190760145aec59a87a993a1086c038e9d430004cd8bdf7fe1ef657d08554d4eea4fec14d5e9d2692f57df71808c5
@@ -58,7 +58,7 @@ module StarkBank
58
58
  @city = city
59
59
  @state_code = state_code
60
60
  @zip_code = zip_code
61
- @due = StarkBank::Utils::Checks.check_date(due)
61
+ @due = due
62
62
  @fine = fine
63
63
  @interest = interest
64
64
  @overdue_limit = overdue_limit
@@ -0,0 +1,121 @@
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
+ # # BoletoHolmes object
9
+ #
10
+ # When you initialize a BoletoHolmes, the entity will not be automatically
11
+ # created in 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
+ # - boleto_id [string]: investigated boleto entity ID. ex: '5656565656565656'
16
+ #
17
+ # ## Parameters (optional):
18
+ # - tags [list of strings]: list of strings for tagging
19
+ #
20
+ # ## Attributes (return-only):
21
+ # - id [string, default nil]: unique id returned when holmes is created. ex: '5656565656565656'
22
+ # - status [string, default nil]: current holmes status. ex: 'solving' or 'solved'
23
+ # - result [string, default nil]: result of boleto status investigation. ex: 'paid' or 'cancelled'
24
+ # - created [DateTime, default nil]: creation datetime for the Boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
25
+ # - updated [DateTime, default nil]: latest update datetime for the holmes. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
26
+ class BoletoHolmes < StarkBank::Utils::Resource
27
+ attr_reader :boleto_id, :tags, :id, :status, :result, :created, :updated
28
+ def initialize(
29
+ boleto_id:, tags: nil, id: nil, status: nil, result: nil, created: nil, updated: nil
30
+ )
31
+ super(id)
32
+ @boleto_id = boleto_id
33
+ @tags = tags
34
+ @status = status
35
+ @result = result
36
+ @created = StarkBank::Utils::Checks.check_datetime(created)
37
+ @updated = StarkBank::Utils::Checks.check_datetime(updated)
38
+ end
39
+
40
+ # # Create BoletoHolmes
41
+ #
42
+ # Send a list of BoletoHolmes objects for creation in the Stark Bank API
43
+ #
44
+ # ## Parameters (required):
45
+ # - holmes [list of BoletoHolmes objects]: list of BoletoHolmes objects to be created in the API
46
+ #
47
+ # ## Parameters (optional):
48
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
49
+ #
50
+ # ## Return:
51
+ # - list of BoletoHolmes objects with updated attributes
52
+ def self.create(holmes, user: nil)
53
+ StarkBank::Utils::Rest.post(entities: holmes, user: user, **resource)
54
+ end
55
+
56
+ # # Retrieve a specific BoletoHolmes
57
+ #
58
+ # Receive a single BoletoHolmes object previously created by the Stark Bank API by passing its id
59
+ #
60
+ # ## Parameters (required):
61
+ # - id [string]: object unique id. ex: '5656565656565656'
62
+ #
63
+ # ## Parameters (optional):
64
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
65
+ #
66
+ # ## Return:
67
+ # - BoletoHolmes object with updated attributes
68
+ def self.get(id, user: nil)
69
+ StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
70
+ end
71
+
72
+ # # Retrieve BoletoHolmes
73
+ #
74
+ # Receive a generator of BoletoHolmes objects previously created in the Stark Bank API
75
+ #
76
+ # ## Parameters (optional):
77
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
78
+ # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
79
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
80
+ # - status [string, default nil]: filter for status of retrieved objects. ex: 'solved'
81
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
82
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
83
+ # - boleto_id [string, default nil]: filter for holmes that investigate a specific boleto by its ID. ex: '5656565656565656'
84
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
85
+ #
86
+ # ## Return:
87
+ # - generator of BoletoHolmes objects with updated attributes
88
+ def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, boleto_id: nil, user: nil)
89
+ after = StarkBank::Utils::Checks.check_date(after)
90
+ before = StarkBank::Utils::Checks.check_date(before)
91
+ StarkBank::Utils::Rest.get_list(
92
+ limit: limit,
93
+ after: after,
94
+ before: before,
95
+ status: status,
96
+ tags: tags,
97
+ ids: ids,
98
+ boleto_id: boleto_id,
99
+ user: user,
100
+ **resource
101
+ )
102
+ end
103
+
104
+ def self.resource
105
+ {
106
+ resource_name: 'BoletoHolmes',
107
+ resource_maker: proc { |json|
108
+ BoletoHolmes.new(
109
+ boleto_id: json['boleto_id'],
110
+ tags: json['tags'],
111
+ id: json['id'],
112
+ status: json['status'],
113
+ result: json['result'],
114
+ created: json['created'],
115
+ updated: json['updated']
116
+ )
117
+ }
118
+ }
119
+ end
120
+ end
121
+ end
@@ -3,30 +3,28 @@
3
3
  require_relative('../utils/resource')
4
4
  require_relative('../utils/rest')
5
5
  require_relative('../utils/checks')
6
- require_relative('invoice')
6
+ require_relative('boleto_holmes')
7
7
 
8
8
  module StarkBank
9
- class Invoice
10
- # # Invoice::Log object
9
+ class BoletoHolmes
10
+ # # BoletoHolmes::Log object
11
11
  #
12
- # Every time a Invoice entity is updated, a corresponding Invoice::Log
12
+ # Every time a BoletoHolmes entity is modified, a corresponding BoletoHolmes::Log
13
13
  # is generated for the entity. This log is never generated by the
14
14
  # user, but it can be retrieved to check additional information
15
- # on the Invoice.
15
+ # on the BoletoHolmes.
16
16
  #
17
17
  # ## Attributes:
18
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'
19
+ # - holmes [BoletoHolmes]: BoletoHolmes entity to which the log refers to.
20
+ # - type [string]: type of the Boleto event which triggered the log creation. ex: 'registered' or 'paid'
22
21
  # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
23
22
  class Log < StarkBank::Utils::Resource
24
- attr_reader :id, :created, :type, :errors, :invoice
25
- def initialize(id:, created:, type:, errors:, invoice:)
23
+ attr_reader :id, :holmes, :type, :created
24
+ def initialize(id:, holmes:, type:, created:)
26
25
  super(id)
26
+ @holmes = holmes
27
27
  @type = type
28
- @errors = errors
29
- @invoice = invoice
30
28
  @created = StarkBank::Utils::Checks.check_datetime(created)
31
29
  end
32
30
 
@@ -54,13 +52,13 @@ module StarkBank
54
52
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
53
  # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
54
  # - 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']
55
+ # - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'registered'
56
+ # - holmes_ids [list of strings, default nil]: list of BoletoHolmes ids to filter logs. ex: ['5656565656565656', '4545454545454545']
59
57
  # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
60
58
  #
61
59
  # ## Return:
62
60
  # - list of Log objects with updated attributes
63
- def self.query(limit: nil, after: nil, before: nil, types: nil, invoice_ids: nil, user: nil)
61
+ def self.query(limit: nil, after: nil, before: nil, types: nil, holmes_ids: nil, user: nil)
64
62
  after = StarkBank::Utils::Checks.check_date(after)
65
63
  before = StarkBank::Utils::Checks.check_date(before)
66
64
  StarkBank::Utils::Rest.get_list(
@@ -68,23 +66,22 @@ module StarkBank
68
66
  after: after,
69
67
  before: before,
70
68
  types: types,
71
- invoice_ids: invoice_ids,
69
+ holmes_ids: holmes_ids,
72
70
  user: user,
73
71
  **resource
74
72
  )
75
73
  end
76
74
 
77
75
  def self.resource
78
- invoice_maker = StarkBank::Invoice.resource[:resource_maker]
76
+ holmes_maker = StarkBank::BoletoHolmes.resource[:resource_maker]
79
77
  {
80
- resource_name: 'InvoiceLog',
78
+ resource_name: 'BoletoHolmesLog',
81
79
  resource_maker: proc { |json|
82
80
  Log.new(
83
81
  id: json['id'],
84
- created: json['created'],
82
+ holmes: StarkBank::Utils::API.from_api_json(holmes_maker, json['holmes']),
85
83
  type: json['type'],
86
- errors: json['errors'],
87
- invoice: StarkBank::Utils::API.from_api_json(invoice_maker, json['invoice'])
84
+ created: json['created']
88
85
  )
89
86
  }
90
87
  }
@@ -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_date(scheduled)
40
+ @scheduled = StarkBank::Utils::Checks.check_datetime(scheduled)
41
41
  @tags = tags
42
42
  @status = status
43
43
  @amount = amount
@@ -8,7 +8,7 @@ require_relative('../utils/checks')
8
8
  require_relative('../utils/cache')
9
9
  require_relative('../error')
10
10
  require_relative('../boleto/log')
11
- require_relative('../invoice/log')
11
+ require_relative('../boleto_holmes/log')
12
12
  require_relative('../transfer/log')
13
13
  require_relative('../boleto_payment/log')
14
14
  require_relative('../utility_payment/log')
@@ -22,7 +22,7 @@ module StarkBank
22
22
  #
23
23
  # ## Attributes:
24
24
  # - id [string]: unique id returned when the event is created. ex: '5656565656565656'
25
- # - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
25
+ # - log [Log]: a Log object from one the subscription services (TransferLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
26
26
  # - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
27
27
  # - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
28
28
  # - subscription [string]: service that triggered this event. ex: 'transfer', 'utility-payment'
@@ -36,10 +36,10 @@ module StarkBank
36
36
 
37
37
  resource = {
38
38
  'transfer': StarkBank::Transfer::Log.resource,
39
- 'invoice': StarkBank::Invoice::Log.resource,
40
39
  'boleto': StarkBank::Boleto::Log.resource,
41
40
  'boleto-payment': StarkBank::BoletoPayment::Log.resource,
42
- 'utility-payment': StarkBank::UtilityPayment::Log.resource
41
+ 'utility-payment': StarkBank::UtilityPayment::Log.resource,
42
+ 'boleto-holmes': StarkBank::BoletoHolmes::Log.resource
43
43
  }[subscription.to_sym]
44
44
 
45
45
  @log = log
@@ -6,6 +6,8 @@ require_relative('balance/balance')
6
6
  require_relative('transaction/transaction')
7
7
  require_relative('boleto/boleto')
8
8
  require_relative('boleto/log')
9
+ require_relative('boleto_holmes/boleto_holmes')
10
+ require_relative('boleto_holmes/log')
9
11
  require_relative('transfer/transfer')
10
12
  require_relative('transfer/log')
11
13
  require_relative('boleto_payment/boleto_payment')
@@ -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_date(scheduled)
43
+ @scheduled = StarkBank::Utils::Checks.check_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_date(scheduled)
39
+ @scheduled = StarkBank::Utils::Checks.check_datetime(scheduled)
40
40
  @amount = amount
41
41
  @fee = fee
42
42
  @status = status
@@ -28,22 +28,21 @@ module StarkBank
28
28
  hash.each do |key, value|
29
29
  next if value.nil?
30
30
 
31
- entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = parse_value(value)
32
- end
33
- entity_hash
34
- end
31
+ value = value.is_a?(Date) || value.is_a?(DateTime) || value.is_a?(Time) ? value.strftime('%Y-%m-%d') : value
35
32
 
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)
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
41
42
 
42
- list = []
43
- value.each do |v|
44
- list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
43
+ entity_hash[StarkBank::Utils::Case.snake_to_camel(key)] = value
45
44
  end
46
- list
45
+ entity_hash
47
46
  end
48
47
 
49
48
  def self.from_api_json(resource_maker, json)
@@ -61,7 +60,12 @@ module StarkBank
61
60
  end
62
61
 
63
62
  def self.last_name_plural(resource_name)
64
- "#{last_name(resource_name)}s"
63
+ base = last_name(resource_name)
64
+
65
+ return base if base[-1].eql?('s')
66
+ return "#{base[0...-1]}ies" if base[-1].eql?('y')
67
+
68
+ "#{base}s"
65
69
  end
66
70
 
67
71
  def self.last_name(resource_name)
@@ -46,8 +46,7 @@ module StarkBank
46
46
 
47
47
  return Time.new(data.year, data.month, data.day) if data.is_a?(Date)
48
48
 
49
- data, _type = check_datetime_string(data)
50
- data
49
+ check_datetime_string(data)
51
50
  end
52
51
 
53
52
  def self.check_date(data)
@@ -57,9 +56,9 @@ module StarkBank
57
56
 
58
57
  return data if data.is_a?(Date)
59
58
 
60
- data, type = check_datetime_string(data)
59
+ data = check_datetime_string(data)
61
60
 
62
- type == 'date' ? Date.new(data.year, data.month, data.day) : data
61
+ Date.new(data.year, data.month, data.day)
63
62
  end
64
63
 
65
64
  class << self
@@ -69,17 +68,17 @@ module StarkBank
69
68
  data = data.to_s
70
69
 
71
70
  begin
72
- return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00'), 'datetime']
71
+ return DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S.%L+00:00')
73
72
  rescue ArgumentError
74
73
  end
75
74
 
76
75
  begin
77
- return [DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00'), 'datetime']
76
+ return DateTime.strptime(data, '%Y-%m-%dT%H:%M:%S+00:00')
78
77
  rescue ArgumentError
79
78
  end
80
79
 
81
80
  begin
82
- return [DateTime.strptime(data, '%Y-%m-%d'), 'date']
81
+ return DateTime.strptime(data, '%Y-%m-%d')
83
82
  rescue ArgumentError
84
83
  raise(ArgumentError, 'invalid datetime string ' + data)
85
84
  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.beta2"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.1.0"
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.beta2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - starkbank
@@ -75,12 +75,12 @@ files:
75
75
  - lib/balance/balance.rb
76
76
  - lib/boleto/boleto.rb
77
77
  - lib/boleto/log.rb
78
+ - lib/boleto_holmes/boleto_holmes.rb
79
+ - lib/boleto_holmes/log.rb
78
80
  - lib/boleto_payment/boleto_payment.rb
79
81
  - lib/boleto_payment/log.rb
80
82
  - lib/error.rb
81
83
  - lib/event/event.rb
82
- - lib/invoice/invoice.rb
83
- - lib/invoice/log.rb
84
84
  - lib/key.rb
85
85
  - lib/payment_request/payment_request.rb
86
86
  - lib/starkbank.rb
@@ -116,9 +116,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '2.3'
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - ">"
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
- version: 1.3.1
121
+ version: '0'
122
122
  requirements: []
123
123
  rubygems_version: 3.1.4
124
124
  signing_key:
@@ -1,173 +0,0 @@
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