starkbank 2.2.0 → 2.5.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 +4 -4
- data/lib/balance/balance.rb +2 -2
- data/lib/boleto/boleto.rb +53 -14
- data/lib/boleto/log.rb +36 -5
- data/lib/boleto_holmes/boleto_holmes.rb +41 -6
- data/lib/boleto_holmes/log.rb +36 -5
- data/lib/boleto_payment/boleto_payment.rb +42 -9
- data/lib/boleto_payment/log.rb +36 -5
- data/lib/brcode_payment/brcode_payment.rb +56 -17
- data/lib/brcode_payment/log.rb +36 -5
- data/lib/brcode_preview/brcode_preview.rb +2 -2
- data/lib/darf_payment/darf_payment.rb +218 -0
- data/lib/darf_payment/log.rb +125 -0
- data/lib/deposit/deposit.rb +46 -8
- data/lib/deposit/log.rb +36 -5
- data/lib/dict_key/dict_key.rb +45 -9
- data/lib/error.rb +13 -5
- data/lib/event/attempt.rb +125 -0
- data/lib/event/event.rb +44 -8
- data/lib/institution/institution.rb +67 -0
- data/lib/invoice/invoice.rb +72 -15
- data/lib/invoice/log.rb +52 -5
- data/lib/invoice/payment.rb +57 -0
- data/lib/payment_request/payment_request.rb +53 -11
- data/lib/starkbank.rb +9 -0
- data/lib/tax_payment/log.rb +125 -0
- data/lib/tax_payment/tax_payment.rb +203 -0
- data/lib/transaction/transaction.rb +39 -6
- data/lib/transfer/log.rb +36 -5
- data/lib/transfer/transfer.rb +59 -14
- data/lib/user/organization.rb +54 -0
- data/lib/user/project.rb +11 -6
- data/lib/user/user.rb +0 -4
- data/lib/utility_payment/log.rb +36 -5
- data/lib/utility_payment/utility_payment.rb +42 -9
- data/lib/utils/api.rb +1 -0
- data/lib/utils/request.rb +1 -1
- data/lib/utils/resource.rb +2 -21
- data/lib/utils/rest.rb +29 -14
- data/lib/utils/sub_resource.rb +28 -0
- data/lib/utils/url.rb +3 -1
- data/lib/webhook/webhook.rb +30 -9
- data/lib/workspace/workspace.rb +141 -0
- metadata +17 -7
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/sub_resource')
|
4
|
+
require_relative('invoice')
|
5
|
+
|
6
|
+
module StarkBank
|
7
|
+
class Invoice
|
8
|
+
# # Payment object
|
9
|
+
#
|
10
|
+
# When an Invoice is paid, its InvoicePayment sub-resource will become available.
|
11
|
+
# It carries all the available information about the invoice payment.
|
12
|
+
#
|
13
|
+
# ## Attributes (return-only):
|
14
|
+
# - amount [long]: amount in cents that was paid. ex: 1234 (= R$ 12.34)
|
15
|
+
# - name [string]: payer full name. ex: 'Anthony Edward Stark'
|
16
|
+
# - tax_id [string]: payer tax ID (CPF or CNPJ). ex: '20.018.183/0001-80'
|
17
|
+
# - bank_code [string]: code of the payer bank institution in Brazil. ex: '20018183'
|
18
|
+
# - branch_code [string]: payer bank account branch. ex: '1357-9'
|
19
|
+
# - account_number [string]: payer bank account number. ex: '876543-2'
|
20
|
+
# - account_type [string]: payer bank account type. ex: 'checking', 'savings', 'salary' or 'payment'
|
21
|
+
# - end_to_end_id [string]: central bank's unique transaction ID. ex: 'E79457883202101262140HHX553UPqeq'
|
22
|
+
# - method [string]: payment method that was used. ex: 'pix'
|
23
|
+
class Payment < StarkBank::Utils::SubResource
|
24
|
+
attr_reader :name, :tax_id, :bank_code, :branch_code, :account_number, :account_type, :amount, :end_to_end_id, :method
|
25
|
+
def initialize(name:, tax_id:, bank_code:, branch_code:, account_number:, account_type:, amount:, end_to_end_id:, method:)
|
26
|
+
@name = name
|
27
|
+
@tax_id = tax_id
|
28
|
+
@bank_code = bank_code
|
29
|
+
@branch_code = branch_code
|
30
|
+
@account_number = account_number
|
31
|
+
@account_type = account_type
|
32
|
+
@amount = amount
|
33
|
+
@end_to_end_id = end_to_end_id
|
34
|
+
@method = method
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.resource
|
38
|
+
{
|
39
|
+
sub_resource_name: 'Payment',
|
40
|
+
sub_resource_maker: proc { |json|
|
41
|
+
Payment.new(
|
42
|
+
name: json['name'],
|
43
|
+
tax_id: json['tax_id'],
|
44
|
+
bank_code: json['bank_code'],
|
45
|
+
branch_code: json['branch_code'],
|
46
|
+
account_number: json['account_number'],
|
47
|
+
account_type: json['account_type'],
|
48
|
+
amount: json['amount'],
|
49
|
+
end_to_end_id: json['end_to_end_id'],
|
50
|
+
method: json['method']
|
51
|
+
)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -7,17 +7,17 @@ require_relative('../utils/checks')
|
|
7
7
|
module StarkBank
|
8
8
|
# # PaymentRequest object
|
9
9
|
# A PaymentRequest is an indirect request to access a specific cash-out service
|
10
|
-
# (such as Transfer,
|
10
|
+
# (such as Transfer, BrcodePayments, etc.) which goes through the cost center
|
11
11
|
# approval flow on our website. To emit a PaymentRequest, you must direct it to
|
12
12
|
# a specific cost center by its ID, which can be retrieved on our website at the
|
13
13
|
# cost center page.
|
14
14
|
#
|
15
15
|
# ## Parameters (required):
|
16
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.
|
17
|
+
# - payment [Transfer, BrcodePayment, BoletoPayment, UtilityPayment, Transaction or dictionary]: payment entity that should be approved and executed.
|
18
18
|
#
|
19
19
|
# ## Parameters (optional):
|
20
|
-
# - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', '
|
20
|
+
# - type [String]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'brcode-payment'
|
21
21
|
# - due [Date, DateTime, Time or string]: Payment target date in ISO format. ex: 2020-12-31
|
22
22
|
# - tags [list of strings]: list of strings for tagging
|
23
23
|
#
|
@@ -53,7 +53,7 @@ module StarkBank
|
|
53
53
|
#
|
54
54
|
# ## Parameters
|
55
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.
|
56
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
57
57
|
#
|
58
58
|
# ## Return
|
59
59
|
# - list of PaymentRequest objects with updated attributes
|
@@ -70,21 +70,57 @@ module StarkBank
|
|
70
70
|
# - center_id [string]: target cost center ID. ex: '5656565656565656'
|
71
71
|
# ## Parameters (optional):
|
72
72
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
73
|
-
# - after [Date
|
74
|
-
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
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
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', '
|
76
|
+
# - type [string, default nil]: payment type, inferred from the payment parameter if it is not a dictionary. ex: 'transfer', 'brcode-payment'
|
77
77
|
# - sort [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
78
78
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
79
79
|
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
80
|
-
# - user [Project object
|
80
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
81
81
|
#
|
82
82
|
# ## Return:
|
83
83
|
# - generator of PaymentRequest objects with updated attributes
|
84
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
85
|
after = StarkBank::Utils::Checks.check_date(after)
|
86
86
|
before = StarkBank::Utils::Checks.check_date(before)
|
87
|
-
StarkBank::Utils::Rest.
|
87
|
+
StarkBank::Utils::Rest.get_stream(
|
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
|
+
# # Retrieve paged PaymentRequests
|
103
|
+
#
|
104
|
+
# Receive a list of up to 100 PaymentRequest objects previously created in the Stark Bank API and the cursor to the next page.
|
105
|
+
# Use this function instead of query if you want to manually page your requests.
|
106
|
+
#
|
107
|
+
# ## Parameters (optional):
|
108
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
109
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
110
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
111
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
112
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
113
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
114
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
115
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
116
|
+
#
|
117
|
+
# ## Return:
|
118
|
+
# - list of PaymentRequest objects with updated attributes and cursor to retrieve the next page of PaymentRequest objects
|
119
|
+
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)
|
122
|
+
return StarkBank::Utils::Rest.get_page(
|
123
|
+
cursor: cursor,
|
88
124
|
center_id: center_id,
|
89
125
|
limit: limit,
|
90
126
|
after: after,
|
@@ -102,16 +138,22 @@ module StarkBank
|
|
102
138
|
def parse_payment(payment:, type:)
|
103
139
|
return [payment, 'transfer'] if payment.is_a?(StarkBank::Transfer)
|
104
140
|
return [payment, 'transaction'] if payment.is_a?(StarkBank::Transaction)
|
141
|
+
return [payment, 'brcode-payment'] if payment.is_a?(StarkBank::BrcodePayment)
|
105
142
|
return [payment, 'boleto-payment'] if payment.is_a?(StarkBank::BoletoPayment)
|
106
143
|
return [payment, 'utility-payment'] if payment.is_a?(StarkBank::UtilityPayment)
|
144
|
+
return [payment, 'tax-payment'] if payment.is_a?(StarkBank::TaxPayment)
|
145
|
+
return [payment, 'darf-payment'] if payment.is_a?(StarkBank::DarfPayment)
|
107
146
|
|
108
|
-
raise(Exception('Payment must either be a Transfer, a Transaction, a BoletoPayment, a UtilityPayment or a hash.')) unless payment.is_a?(Hash)
|
147
|
+
raise(Exception('Payment must either be a Transfer, a Transaction, a BrcodePayment, BoletoPayment, a UtilityPayment, a TaxPayment, a DarfPayment or a hash.')) unless payment.is_a?(Hash)
|
109
148
|
|
110
149
|
resource = {
|
111
150
|
'transfer': StarkBank::Transfer.resource,
|
112
151
|
'transaction': StarkBank::Transaction.resource,
|
152
|
+
'brcode-payment': StarkBank::BrcodePayment.resource,
|
113
153
|
'boleto-payment': StarkBank::BoletoPayment.resource,
|
114
|
-
'utility-payment': StarkBank::UtilityPayment.resource
|
154
|
+
'utility-payment': StarkBank::UtilityPayment.resource,
|
155
|
+
'tax-payment': StarkBank::TaxPayment.resource,
|
156
|
+
'darf-payment': StarkBank::DarfPayment.resource
|
115
157
|
}[type.to_sym]
|
116
158
|
|
117
159
|
payment = StarkBank::Utils::API.from_api_json(resource[:resource_maker], payment) unless resource.nil?
|
data/lib/starkbank.rb
CHANGED
@@ -2,10 +2,13 @@
|
|
2
2
|
|
3
3
|
require_relative('key')
|
4
4
|
require_relative('user/project')
|
5
|
+
require_relative('user/organization')
|
6
|
+
require_relative('workspace/workspace')
|
5
7
|
require_relative('balance/balance')
|
6
8
|
require_relative('transaction/transaction')
|
7
9
|
require_relative('invoice/invoice')
|
8
10
|
require_relative('invoice/log')
|
11
|
+
require_relative('invoice/payment')
|
9
12
|
require_relative('dict_key/dict_key')
|
10
13
|
require_relative('deposit/deposit')
|
11
14
|
require_relative('deposit/log')
|
@@ -22,9 +25,15 @@ require_relative('boleto_payment/boleto_payment')
|
|
22
25
|
require_relative('boleto_payment/log')
|
23
26
|
require_relative('utility_payment/utility_payment')
|
24
27
|
require_relative('utility_payment/log')
|
28
|
+
require_relative('tax_payment/tax_payment')
|
29
|
+
require_relative('tax_payment/log')
|
30
|
+
require_relative('darf_payment/darf_payment')
|
31
|
+
require_relative('darf_payment/log')
|
25
32
|
require_relative('webhook/webhook')
|
26
33
|
require_relative('event/event')
|
34
|
+
require_relative('event/attempt')
|
27
35
|
require_relative('payment_request/payment_request')
|
36
|
+
require_relative('institution/institution')
|
28
37
|
|
29
38
|
# SDK to facilitate Ruby integrations with Stark Bank
|
30
39
|
module StarkBank
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative('../utils/resource')
|
4
|
+
require_relative('../utils/rest')
|
5
|
+
require_relative('../utils/checks')
|
6
|
+
require_relative('tax_payment')
|
7
|
+
|
8
|
+
module StarkBank
|
9
|
+
class TaxPayment
|
10
|
+
# # TaxPayment::Log object
|
11
|
+
#
|
12
|
+
# Every time a TaxPayment entity is updated, a corresponding TaxPayment::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 TaxPayment.
|
16
|
+
#
|
17
|
+
# ## Attributes:
|
18
|
+
# - id [string]: unique id returned when the log is created. ex: '5656565656565656'
|
19
|
+
# - payment [TaxPayment]: TaxPayment entity to which the log refers to.
|
20
|
+
# - errors [list of strings]: list of errors linked to this TaxPayment event
|
21
|
+
# - type [string]: type of the TaxPayment 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, :payment
|
25
|
+
def initialize(id:, created:, type:, errors:, payment:)
|
26
|
+
super(id)
|
27
|
+
@type = type
|
28
|
+
@errors = errors
|
29
|
+
@payment = payment
|
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 [Organization/Project object, default nil]: Organization or 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
|
+
# - payment_ids [list of strings, default nil]: list of TaxPayment ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
59
|
+
# - user [Organization/Project object, default nil]: Organization or 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, payment_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_stream(
|
67
|
+
limit: limit,
|
68
|
+
after: after,
|
69
|
+
before: before,
|
70
|
+
types: types,
|
71
|
+
payment_ids: payment_ids,
|
72
|
+
user: user,
|
73
|
+
**resource
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# # Retrieve paged Logs
|
78
|
+
#
|
79
|
+
# Receive a list of up to 100 Log objects previously created in the Stark Bank API and the cursor to the next page.
|
80
|
+
# Use this function instead of query if you want to manually page your requests.
|
81
|
+
#
|
82
|
+
# ## Parameters (optional):
|
83
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
84
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
85
|
+
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
86
|
+
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
87
|
+
# - types [list of strings, default nil]: filter for log event types. ex: 'paid' or 'canceled'
|
88
|
+
# - payment_ids [list of strings, default nil]: list of TaxPayment ids to filter logs. ex: ['5656565656565656', '4545454545454545']
|
89
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if Starkbank.user was set before function call
|
90
|
+
#
|
91
|
+
# ## Return:
|
92
|
+
# - list of Log objects with updated attributes and cursor to retrieve the next page of Log objects
|
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)
|
96
|
+
return StarkBank::Utils::Rest.get_page(
|
97
|
+
cursor: cursor,
|
98
|
+
limit: limit,
|
99
|
+
after: after,
|
100
|
+
before: before,
|
101
|
+
types: types,
|
102
|
+
payment_ids: payment_ids,
|
103
|
+
user: user,
|
104
|
+
**resource
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.resource
|
109
|
+
tax_payment_maker = StarkBank::TaxPayment.resource[:resource_maker]
|
110
|
+
{
|
111
|
+
resource_name: 'TaxPaymentLog',
|
112
|
+
resource_maker: proc { |json|
|
113
|
+
Log.new(
|
114
|
+
id: json['id'],
|
115
|
+
created: json['created'],
|
116
|
+
type: json['type'],
|
117
|
+
errors: json['errors'],
|
118
|
+
payment: StarkBank::Utils::API.from_api_json(tax_payment_maker, json['payment'])
|
119
|
+
)
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,203 @@
|
|
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
|
+
# # TaxPayment object
|
9
|
+
#
|
10
|
+
# When you initialize a TaxPayment, 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 (conditionally required):
|
15
|
+
# - line [string, default nil]: Number sequence that describes the payment. Either 'line' or 'bar_code' parameters are required. If both are sent, they must match. ex: '85800000003 0 28960328203 1 56072020190 5 22109674804 0'
|
16
|
+
# - bar_code [string, default nil]: Bar code number that describes the payment. Either 'line' or 'barCode' parameters are required. If both are sent, they must match. ex: '83660000001084301380074119002551100010601813'
|
17
|
+
#
|
18
|
+
# ## Parameters (required):
|
19
|
+
# - description [string]: Text to be displayed in your statement (min. 10 characters). ex: 'payment ABC'
|
20
|
+
#
|
21
|
+
# ## Parameters (optional):
|
22
|
+
# - scheduled [Date, DateTime, Time or string, default today]: payment scheduled date. ex: Date.new(2020, 3, 10)
|
23
|
+
# - tags [list of strings, default nil]: list of strings for tagging
|
24
|
+
#
|
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
|
35
|
+
def initialize(
|
36
|
+
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
|
+
)
|
39
|
+
super(id)
|
40
|
+
@line = line
|
41
|
+
@bar_code = bar_code
|
42
|
+
@description = description
|
43
|
+
@tags = tags
|
44
|
+
@scheduled = StarkBank::Utils::Checks.check_date(scheduled)
|
45
|
+
@status = status
|
46
|
+
@amount = amount
|
47
|
+
@fee = fee
|
48
|
+
@type = type
|
49
|
+
@updated = StarkBank::Utils::Checks.check_datetime(updated)
|
50
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
51
|
+
end
|
52
|
+
|
53
|
+
# # Create TaxPayments
|
54
|
+
#
|
55
|
+
# Send a list of TaxPayment objects for creation in the Stark Bank API
|
56
|
+
#
|
57
|
+
# ## Parameters (required):
|
58
|
+
# - payments [list of TaxPayment objects]: list of TaxPayment objects to be created in the API
|
59
|
+
#
|
60
|
+
# ## Parameters (optional):
|
61
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
62
|
+
#
|
63
|
+
# ## Return:
|
64
|
+
# - list of TaxPayment objects with updated attributes
|
65
|
+
def self.create(payments, user: nil)
|
66
|
+
StarkBank::Utils::Rest.post(entities: payments, user: user, **resource)
|
67
|
+
end
|
68
|
+
|
69
|
+
# # Retrieve a specific TaxPayment
|
70
|
+
#
|
71
|
+
# Receive a single TaxPayment object previously created by the Stark Bank API by passing its id
|
72
|
+
#
|
73
|
+
# ## Parameters (required):
|
74
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
75
|
+
#
|
76
|
+
# ## Parameters (optional):
|
77
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
78
|
+
#
|
79
|
+
# ## Return:
|
80
|
+
# - TaxPayment object with updated attributes
|
81
|
+
def self.get(id, user: nil)
|
82
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
83
|
+
end
|
84
|
+
|
85
|
+
# # Retrieve a specific TaxPayment pdf file
|
86
|
+
#
|
87
|
+
# Receive a single TaxPayment pdf file generated in the Stark Bank API by passing its id.
|
88
|
+
# Only valid for tax payments with 'success' status.
|
89
|
+
#
|
90
|
+
# ## Parameters (required):
|
91
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
92
|
+
#
|
93
|
+
# ## Parameters (optional):
|
94
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
95
|
+
#
|
96
|
+
# ## Return:
|
97
|
+
# - TaxPayment pdf file
|
98
|
+
def self.pdf(id, user: nil)
|
99
|
+
StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
|
100
|
+
end
|
101
|
+
|
102
|
+
# # Retrieve TaxPayments
|
103
|
+
#
|
104
|
+
# Receive a generator of TaxPayment objects previously created in the Stark Bank API
|
105
|
+
#
|
106
|
+
# ## Parameters (optional):
|
107
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
108
|
+
# - after [Date , DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
109
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
110
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
111
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
112
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
113
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
114
|
+
#
|
115
|
+
# ## Return:
|
116
|
+
# - generator of TaxPayment objects with updated attributes
|
117
|
+
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
|
+
StarkBank::Utils::Rest.get_stream(
|
121
|
+
limit: limit,
|
122
|
+
after: after,
|
123
|
+
before: before,
|
124
|
+
tags: tags,
|
125
|
+
ids: ids,
|
126
|
+
status: status,
|
127
|
+
user: user,
|
128
|
+
**resource
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
# # Retrieve paged Tax Payments
|
133
|
+
#
|
134
|
+
# Receive a list of up to 100 Tax Payment objects previously created in the Stark Bank API and the cursor to the next page.
|
135
|
+
# Use this function instead of query if you want to manually page your requests.
|
136
|
+
#
|
137
|
+
# ## Parameters (optional):
|
138
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
139
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
140
|
+
# - after [Date , DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
141
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
142
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
143
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
144
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
145
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
146
|
+
#
|
147
|
+
# ## Return:
|
148
|
+
# - list of Tax Payment objects with updated attributes and cursor to retrieve the next page of Tax Payment objects
|
149
|
+
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
|
+
return StarkBank::Utils::Rest.get_page(
|
153
|
+
cursor: cursor,
|
154
|
+
limit: limit,
|
155
|
+
after: after,
|
156
|
+
before: before,
|
157
|
+
tags: tags,
|
158
|
+
ids: ids,
|
159
|
+
status: status,
|
160
|
+
user: user,
|
161
|
+
**resource
|
162
|
+
)
|
163
|
+
end
|
164
|
+
|
165
|
+
# # Delete a TaxPayment entity
|
166
|
+
#
|
167
|
+
# Delete a TaxPayment entity previously created in the Stark Bank API
|
168
|
+
#
|
169
|
+
# ## Parameters (required):
|
170
|
+
# - id [string]: UtilityPayment unique id. ex:'5656565656565656'
|
171
|
+
#
|
172
|
+
# ## Parameters (optional):
|
173
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
174
|
+
#
|
175
|
+
# ## Return:
|
176
|
+
# - deleted TaxPayment object
|
177
|
+
def self.delete(id, user: nil)
|
178
|
+
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.resource
|
182
|
+
{
|
183
|
+
resource_name: 'TaxPayment',
|
184
|
+
resource_maker: proc { |json|
|
185
|
+
TaxPayment.new(
|
186
|
+
id: json['id'],
|
187
|
+
line: json['line'],
|
188
|
+
bar_code: json['bar_code'],
|
189
|
+
description: json['description'],
|
190
|
+
tags: json['tags'],
|
191
|
+
scheduled: json['scheduled'],
|
192
|
+
status: json['status'],
|
193
|
+
amount: json['amount'],
|
194
|
+
fee: json['fee'],
|
195
|
+
type: json['type'],
|
196
|
+
updated: json['updated'],
|
197
|
+
created: json['created']
|
198
|
+
)
|
199
|
+
}
|
200
|
+
}
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|