starkbank 0.4.1 → 2.1.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: a04698bff84f2740a1ea3febaf6289e293feb7430ea580711ac166108b1633a3
4
- data.tar.gz: 7298985a8eab4f23744f3125ef8b2c891c20fb650606e04ed76f9f05bf0863de
3
+ metadata.gz: 98835d3b25dff96530638da6c2da72f1c8acbe7cb3a5fdb45a25e5506f8cb153
4
+ data.tar.gz: b298cf063b7b824658c247122c3135302096924332b311d638089573aea432cc
5
5
  SHA512:
6
- metadata.gz: 1135e671f73fd00669b2f8b615303196ddd9525b59837fd77ecd35c3639e305591e72dd5023a1538e32abc32bcb5ce3917ea00b662ceeaaaf2ac4e1cd4a21edb
7
- data.tar.gz: a00a59fd6d06dbca0b7a23b23faf050357aeb75e408e8e33ad8d9f392bff3c1b31e443c92b8c767bb2294b6dab7d0f45c774cf6588ae38e0f5406e8c568a7e21
6
+ metadata.gz: 778c03a3493122b36fc1f1cd521e96c9a45035f5ff4590fc8189c17da4d3be177e890f8de65978e1c16eda9f4d3362e97e018e3f032186a0fe99a011df45e6d8
7
+ data.tar.gz: 8a992c980902e97809cded32d229f72b4ef8e4c1adc6d2d8e8f67c7eb8a0c7efc5bf7bbc6faec265ad5a741ae0219de1f5d2bb507f501cef9e5c55338e34e5e7
@@ -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
@@ -164,7 +164,7 @@ module StarkBank
164
164
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
165
165
  #
166
166
  # ## Return:
167
- # - deleted Boleto with updated attributes
167
+ # - deleted Boleto object
168
168
  def self.delete(id, user: nil)
169
169
  StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
170
170
  end
@@ -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
@@ -133,7 +133,7 @@ module StarkBank
133
133
  # Parameters (optional):
134
134
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
135
135
  # Return:
136
- # - deleted BoletoPayment with updated attributes
136
+ # - deleted BoletoPayment object
137
137
  def self.delete(id, user: nil)
138
138
  StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
139
139
  end
@@ -8,6 +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
12
  require_relative('../transfer/log')
12
13
  require_relative('../boleto_payment/log')
13
14
  require_relative('../utility_payment/log')
@@ -21,7 +22,7 @@ module StarkBank
21
22
  #
22
23
  # ## Attributes:
23
24
  # - id [string]: unique id returned when the event is created. ex: '5656565656565656'
24
- # - log [Log]: a Log object from one the subscription services (TransferLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
25
+ # - log [Log]: a Log object from one the subscription services (TransferLog, InvoiceLog, BoletoLog, BoletoPaymentlog or UtilityPaymentLog)
25
26
  # - created [DateTime]: creation datetime for the notification event. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
26
27
  # - is_delivered [bool]: true if the event has been successfully delivered to the user url. ex: False
27
28
  # - subscription [string]: service that triggered this event. ex: 'transfer', 'utility-payment'
@@ -33,14 +34,16 @@ module StarkBank
33
34
  @is_delivered = is_delivered
34
35
  @subscription = subscription
35
36
 
36
- maker = {
37
+ resource = {
37
38
  'transfer': StarkBank::Transfer::Log.resource,
39
+ 'invoice': StarkBank::Invoice::Log.resource,
38
40
  'boleto': StarkBank::Boleto::Log.resource,
39
41
  'boleto-payment': StarkBank::BoletoPayment::Log.resource,
40
42
  'utility-payment': StarkBank::UtilityPayment::Log.resource
41
- }[subscription.to_sym][:resource_maker]
43
+ }[subscription.to_sym]
42
44
 
43
- @log = StarkBank::Utils::API.from_api_json(maker, log)
45
+ @log = log
46
+ @log = StarkBank::Utils::API.from_api_json(resource[:resource_maker], log) unless resource.nil?
44
47
  end
45
48
 
46
49
  # # Retrieve a specific notification Event
@@ -96,7 +99,7 @@ module StarkBank
96
99
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
97
100
  #
98
101
  # ## Return:
99
- # - deleted Event with updated attributes
102
+ # - deleted Event object
100
103
  def self.delete(id, user: nil)
101
104
  StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
102
105
  end
@@ -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
@@ -0,0 +1,142 @@
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
+ # # PaymentRequest object
9
+ # A PaymentRequest is an indirect request to access a specific cash-out service
10
+ # (such as Transfer, BoletoPayments, etc.) which goes through the cost center
11
+ # approval flow on our website. To emit a PaymentRequest, you must direct it to
12
+ # a specific cost center by its ID, which can be retrieved on our website at the
13
+ # cost center page.
14
+ #
15
+ # ## Parameters (required):
16
+ # - center_id [String]: target cost center ID. ex: '5656565656565656'
17
+ # - payment [Transfer, BoletoPayment, UtilityPayment, Transaction or dictionary]: payment entity that should be approved and executed.
18
+ #
19
+ # ## Parameters (optional):
20
+ # - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'boleto-payment'
21
+ # - due [Date, DateTime, Time or string]: Payment target date in ISO format. ex: 2020-12-31
22
+ # - tags [list of strings]: list of strings for tagging
23
+ #
24
+ # ## Attributes (return-only):
25
+ # - 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)
31
+ #
32
+ class PaymentRequest < StarkBank::Utils::Resource
33
+ attr_reader :center_id, :payment, :type, :due, :tags, :amount, :status, :actions, :updated, :created
34
+ def initialize(
35
+ payment:, center_id:, id: nil, type: nil, due: nil, tags: nil, amount: nil, status: nil,
36
+ actions: nil, updated: nil, created: nil
37
+ )
38
+ super(id)
39
+ @center_id = center_id
40
+ @due = due
41
+ @tags = tags
42
+ @amount = amount
43
+ @status = status
44
+ @actions = actions
45
+ @updated = updated
46
+ @created = created
47
+
48
+ @payment, @type = parse_payment(payment: payment, type: type)
49
+ end
50
+
51
+ ## Create PaymentRequests
52
+ # Sends a list of PaymentRequests objects for creating in the Stark Bank API
53
+ #
54
+ # ## Parameters
55
+ # - payment_requests [list of PaymentRequest objects]: list of PaymentRequest objects to be created in the API
56
+ # - user [Project object]: Project object. Not necessary if StarkBank.User.Default was set before function call
57
+ #
58
+ # ## Return
59
+ # - list of PaymentRequest objects with updated attributes
60
+ #
61
+ def self.create(payment_requests, user: nil)
62
+ StarkBank::Utils::Rest.post(entities: payment_requests, user: user, **resource)
63
+ end
64
+
65
+ # # Retrieve PaymentRequests
66
+ #
67
+ # Receive a generator of PaymentRequest objects previously created in the Stark Bank API
68
+ #
69
+ # ## Parameters (required):
70
+ # - center_id [string]: target cost center ID. ex: '5656565656565656'
71
+ # ## Parameters (optional):
72
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
73
+ # - after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
74
+ # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
75
+ # - status [string, default '-created']: sort order considered in response. Valid options are '-created' or '-due'.
76
+ # - type [string, default nil]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'boleto-payment'
77
+ # - sort [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
78
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
79
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
80
+ # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
81
+ #
82
+ # ## Return:
83
+ # - generator of PaymentRequest objects with updated attributes
84
+ 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)
87
+ StarkBank::Utils::Rest.get_list(
88
+ center_id: center_id,
89
+ limit: limit,
90
+ after: after,
91
+ before: before,
92
+ status: status,
93
+ type: type,
94
+ sort: sort,
95
+ tags: tags,
96
+ ids: ids,
97
+ user: user,
98
+ **resource
99
+ )
100
+ end
101
+
102
+ def parse_payment(payment:, type:)
103
+ return [payment, 'transfer'] if payment.is_a?(StarkBank::Transfer)
104
+ return [payment, 'transaction'] if payment.is_a?(StarkBank::Transaction)
105
+ return [payment, 'boleto-payment'] if payment.is_a?(StarkBank::BoletoPayment)
106
+ return [payment, 'utility-payment'] if payment.is_a?(StarkBank::UtilityPayment)
107
+
108
+ raise(Exception('Payment must either be a Transfer, a Transaction, a BoletoPayment, a UtilityPayment or a hash.')) unless payment.is_a?(Hash)
109
+
110
+ resource = {
111
+ 'transfer': StarkBank::Transfer.resource,
112
+ 'transaction': StarkBank::Transaction.resource,
113
+ 'boleto-payment': StarkBank::BoletoPayment.resource,
114
+ 'utility-payment': StarkBank::UtilityPayment.resource
115
+ }[type.to_sym]
116
+
117
+ payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
118
+
119
+ [payment, type]
120
+ end
121
+
122
+ def self.resource
123
+ {
124
+ resource_name: 'PaymentRequest',
125
+ resource_maker: proc { |json|
126
+ PaymentRequest.new(
127
+ id: json['id'],
128
+ payment: json['payment'],
129
+ center_id: json['centerId'],
130
+ type: json['type'],
131
+ tags: json['tags'],
132
+ amount: json['amount'],
133
+ status: json['status'],
134
+ actions: json['actions'],
135
+ updated: json['updated'],
136
+ created: json['created']
137
+ )
138
+ }
139
+ }
140
+ end
141
+ end
142
+ end
@@ -14,6 +14,7 @@ require_relative('utility_payment/utility_payment')
14
14
  require_relative('utility_payment/log')
15
15
  require_relative('webhook/webhook')
16
16
  require_relative('event/event')
17
+ require_relative('payment_request/payment_request')
17
18
 
18
19
  # SDK to facilitate Ruby integrations with Stark Bank
19
20
  module StarkBank
@@ -87,15 +87,26 @@ module StarkBank
87
87
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
88
88
  # - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
89
89
  # - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
90
+ # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
90
91
  # - external_ids [list of strings, default nil]: list of external ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
92
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
91
93
  # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
92
94
  #
93
95
  # ## Return:
94
96
  # - generator of Transaction objects with updated attributes
95
- def self.query(limit: nil, after: nil, before: nil, external_ids: nil, user: nil)
97
+ def self.query(limit: nil, after: nil, before: nil, tags: nil, external_ids: nil, ids: nil, user: nil)
96
98
  after = StarkBank::Utils::Checks.check_date(after)
97
99
  before = StarkBank::Utils::Checks.check_date(before)
98
- StarkBank::Utils::Rest.get_list(user: user, limit: limit, after: after, before: before, external_ids: external_ids, **resource)
100
+ StarkBank::Utils::Rest.get_list(
101
+ limit: limit,
102
+ after: after,
103
+ before: before,
104
+ tags: tags,
105
+ external_ids: external_ids,
106
+ ids: ids,
107
+ user: user,
108
+ **resource
109
+ )
99
110
  end
100
111
 
101
112
  def self.resource
@@ -21,6 +21,7 @@ module StarkBank
21
21
  #
22
22
  # ## Parameters (optional):
23
23
  # - tags [list of strings]: list of strings for reference when searching for transfers. ex: ['employees', 'monthly']
24
+ # - scheduled [string, default now]: datetime when the transfer will be processed. May be pushed to next business day if necessary. ex: DateTime.new(2020, 3, 11, 8, 0, 0, 0)
24
25
  #
25
26
  # ## Attributes (return-only):
26
27
  # - id [string, default nil]: unique id returned when Transfer is created. ex: '5656565656565656'
@@ -30,8 +31,8 @@ module StarkBank
30
31
  # - created [DateTime, default nil]: creation datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
31
32
  # - updated [DateTime, default nil]: latest update datetime for the transfer. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
32
33
  class Transfer < StarkBank::Utils::Resource
33
- attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
34
- def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
34
+ attr_reader :amount, :name, :tax_id, :bank_code, :branch_code, :account_number, :scheduled, :transaction_ids, :fee, :tags, :status, :id, :created, :updated
35
+ def initialize(amount:, name:, tax_id:, bank_code:, branch_code:, account_number:, scheduled: nil, transaction_ids: nil, fee: nil, tags: nil, status: nil, id: nil, created: nil, updated: nil)
35
36
  super(id)
36
37
  @amount = amount
37
38
  @name = name
@@ -39,6 +40,7 @@ module StarkBank
39
40
  @bank_code = bank_code
40
41
  @branch_code = branch_code
41
42
  @account_number = account_number
43
+ @scheduled = StarkBank::Utils::Checks.check_date(scheduled)
42
44
  @transaction_ids = transaction_ids
43
45
  @fee = fee
44
46
  @tags = tags
@@ -79,6 +81,22 @@ module StarkBank
79
81
  StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
80
82
  end
81
83
 
84
+ # # Delete a Transfer entity
85
+ #
86
+ # Delete a Transfer entity previously created in the Stark Bank API
87
+ #
88
+ # ## Parameters (required):
89
+ # - id [string]: Transfer unique id. ex: '5656565656565656'
90
+ #
91
+ # ## Parameters (optional):
92
+ # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
93
+ #
94
+ # ## Return:
95
+ # - deleted Transfer object
96
+ def self.delete(id, user: nil)
97
+ StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
98
+ end
99
+
82
100
  # # Retrieve a specific Transfer pdf file
83
101
  #
84
102
  # Receive a single Transfer pdf receipt file generated in the Stark Bank API by passing its id.
@@ -108,11 +126,12 @@ module StarkBank
108
126
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'success' or 'failed'
109
127
  # - tax_id [string, default nil]: filter for transfers sent to the specified tax ID. ex: "012.345.678-90"
110
128
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
129
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
111
130
  # - user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call
112
131
  #
113
132
  # ## Return:
114
133
  # - generator of Transfer objects with updated attributes
115
- def self.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, user: nil)
134
+ def self.query(limit: nil, after: nil, before: nil, transaction_ids: nil, status: nil, tax_id: nil, sort: nil, tags: nil, ids: nil, user: nil)
116
135
  after = StarkBank::Utils::Checks.check_date(after)
117
136
  before = StarkBank::Utils::Checks.check_date(before)
118
137
  StarkBank::Utils::Rest.get_list(
@@ -124,6 +143,7 @@ module StarkBank
124
143
  tax_id: tax_id,
125
144
  sort: sort,
126
145
  tags: tags,
146
+ ids: ids,
127
147
  user: user,
128
148
  **resource
129
149
  )
@@ -141,6 +161,7 @@ module StarkBank
141
161
  bank_code: json['bank_code'],
142
162
  branch_code: json['branch_code'],
143
163
  account_number: json['account_number'],
164
+ scheduled: json['scheduled'],
144
165
  transaction_ids: json['transaction_ids'],
145
166
  fee: json['fee'],
146
167
  tags: json['tags'],
@@ -2,12 +2,12 @@
2
2
 
3
3
  require('starkbank-ecdsa')
4
4
  require_relative('../utils/resource')
5
- require_relative('../utils/checks')
6
5
 
7
6
  module StarkBank
8
7
  class User < StarkBank::Utils::Resource
9
8
  attr_reader :pem, :environment
10
9
  def initialize(environment, id, private_key)
10
+ require_relative('../utils/checks')
11
11
  super(id)
12
12
  @pem = StarkBank::Utils::Checks.check_private_key(private_key)
13
13
  @environment = StarkBank::Utils::Checks.check_environment(environment)
@@ -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
@@ -133,7 +133,7 @@ module StarkBank
133
133
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
134
134
  #
135
135
  # ## Return:
136
- # - deleted UtilityPayment with updated attributes
136
+ # - deleted UtilityPayment object
137
137
  def self.delete(id, user: nil)
138
138
  StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
139
139
  end
@@ -5,16 +5,22 @@ require_relative('case')
5
5
  module StarkBank
6
6
  module Utils
7
7
  module API
8
- def self.api_json(entity)
8
+ def self.build_entity_hash(entity)
9
9
  if entity.is_a?(Hash)
10
10
  entity_hash = entity
11
11
  else
12
12
  entity_hash = {}
13
13
  entity.instance_variables.each do |key|
14
- entity_hash[key[1..-1]] = entity.instance_variable_get(key)
14
+ variable = entity.instance_variable_get(key)
15
+ entity_hash[key[1..-1]] = variable.is_a?(StarkBank::Utils::Resource) ? build_entity_hash(variable) : entity.instance_variable_get(key)
15
16
  end
16
17
  end
17
- cast_json_to_api_format(entity_hash)
18
+ entity_hash
19
+ end
20
+
21
+ def self.api_json(entity)
22
+ built_hash = build_entity_hash(entity)
23
+ cast_json_to_api_format(built_hash)
18
24
  end
19
25
 
20
26
  def self.cast_json_to_api_format(hash)
@@ -22,19 +28,22 @@ module StarkBank
22
28
  hash.each do |key, value|
23
29
  next if value.nil?
24
30
 
25
- 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
26
35
 
27
- if value.is_a?(Array)
28
- list = []
29
- value.each do |v|
30
- list << (v.is_a?(Hash) ? cast_json_to_api_format(v) : v)
31
- end
32
- value = list
33
- 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)
34
41
 
35
- 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)
36
45
  end
37
- entity_hash
46
+ list
38
47
  end
39
48
 
40
49
  def self.from_api_json(resource_maker, json)
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require('starkbank-ecdsa')
4
3
  require('date')
5
- require_relative('../user/user')
4
+ require('starkbank-ecdsa')
6
5
  require_relative('environment')
6
+ require_relative('../user/user')
7
7
 
8
8
  module StarkBank
9
9
  module Utils
@@ -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-0.4.1"
64
+ req['User-Agent'] = "Ruby-#{RUBY_VERSION}-SDK-2.1.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) }
@@ -83,7 +83,7 @@ module StarkBank
83
83
  # - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
84
84
  #
85
85
  # ## Return:
86
- # - deleted Webhook with updated attributes
86
+ # - deleted Webhook object
87
87
  def self.delete(id, user: nil)
88
88
  StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
89
89
  end
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: 0.4.1
4
+ version: 2.1.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - starkbank
@@ -16,28 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.3
19
+ version: 0.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.3
26
+ version: 0.0.5
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: 5.14.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: 5.14.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.81'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.81'
41
69
  description:
42
70
  email:
43
71
  executables: []
@@ -51,7 +79,10 @@ files:
51
79
  - lib/boleto_payment/log.rb
52
80
  - lib/error.rb
53
81
  - lib/event/event.rb
82
+ - lib/invoice/invoice.rb
83
+ - lib/invoice/log.rb
54
84
  - lib/key.rb
85
+ - lib/payment_request/payment_request.rb
55
86
  - lib/starkbank.rb
56
87
  - lib/transaction/transaction.rb
57
88
  - lib/transfer/log.rb
@@ -85,11 +116,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
116
  version: '2.3'
86
117
  required_rubygems_version: !ruby/object:Gem::Requirement
87
118
  requirements:
88
- - - ">="
119
+ - - ">"
89
120
  - !ruby/object:Gem::Version
90
- version: '0'
121
+ version: 1.3.1
91
122
  requirements: []
92
- rubygems_version: 3.0.6
123
+ rubygems_version: 3.1.4
93
124
  signing_key:
94
125
  specification_version: 4
95
126
  summary: SDK to facilitate Ruby integrations with Stark Bank