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
data/lib/boleto_payment/log.rb
CHANGED
@@ -38,7 +38,7 @@ module StarkBank
|
|
38
38
|
# - id [string]: object unique id. ex: '5656565656565656'
|
39
39
|
#
|
40
40
|
# ## Parameters (optional):
|
41
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
41
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
42
42
|
#
|
43
43
|
# ## Return:
|
44
44
|
# - Log object with updated attributes
|
@@ -52,18 +52,49 @@ module StarkBank
|
|
52
52
|
#
|
53
53
|
# ## Parameters (optional):
|
54
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)
|
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
57
|
# - types [list of strings, default nil]: filter retrieved objects by event types. ex: 'success' or 'failed'
|
58
58
|
# - payment_ids [list of strings, default nil]: list of BoletoPayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
59
|
-
# - user [Project object
|
59
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
60
60
|
#
|
61
61
|
# ## Return:
|
62
62
|
# - list of Log objects with updated attributes
|
63
63
|
def self.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
|
64
64
|
after = StarkBank::Utils::Checks.check_date(after)
|
65
65
|
before = StarkBank::Utils::Checks.check_date(before)
|
66
|
-
StarkBank::Utils::Rest.
|
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 retrieved objects by event types. ex: 'success' or 'failed'
|
88
|
+
# - payment_ids [list of strings, default nil]: list of BoletoPayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
89
|
+
# - user [Organization/Project object]: 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,
|
67
98
|
limit: limit,
|
68
99
|
after: after,
|
69
100
|
before: before,
|
@@ -12,9 +12,9 @@ module StarkBank
|
|
12
12
|
# to the Stark Bank API and returns the list of created objects.
|
13
13
|
#
|
14
14
|
# ## Parameters (required):
|
15
|
-
# - brcode [string]: String loaded directly from the QRCode or copied from the invoice. ex:
|
16
|
-
# - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex:
|
17
|
-
# - description [string]: Text to be displayed in your statement (min. 10 characters). ex:
|
15
|
+
# - brcode [string]: String loaded directly from the QRCode or copied from the invoice. ex: '00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A'
|
16
|
+
# - tax_id [string]: receiver tax ID (CPF or CNPJ) with or without formatting. ex: '01234567890' or '20.018.183/0001-80'
|
17
|
+
# - description [string]: Text to be displayed in your statement (min. 10 characters). ex: 'payment ABC'
|
18
18
|
#
|
19
19
|
# ## Parameters (conditionally required):
|
20
20
|
# - amount [int, default nil]: If the BRCode does not provide an amount, this parameter is mandatory, else it is optional. ex: 23456 (= R$ 234.56)
|
@@ -24,15 +24,17 @@ module StarkBank
|
|
24
24
|
# - tags [list of strings, default nil]: list of strings for tagging
|
25
25
|
#
|
26
26
|
# ## Attributes (return-only):
|
27
|
-
# - id [string, default nil]: unique id returned when payment is created. ex:
|
28
|
-
# -
|
29
|
-
# -
|
27
|
+
# - id [string, default nil]: unique id returned when payment is created. ex: '5656565656565656'
|
28
|
+
# - name [string, nil]: receiver name. ex: 'Jon Snow'
|
29
|
+
# - status [string, default nil]: current payment status. ex: 'success' or 'failed'
|
30
|
+
# - type [string, default nil]: brcode type. ex: 'static' or 'dynamic'
|
31
|
+
# - transaction_ids [list of strings, default nil]: ledger transaction ids linked to this payment. ex: ['19827356981273']
|
30
32
|
# - fee [integer, default nil]: fee charged when the brcode payment is created. ex: 200 (= R$ 2.00)
|
31
33
|
# - updated [datetime.datetime, default nil]: latest update datetime for the payment. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0)
|
32
34
|
# - created [datetime.datetime, default nil]: creation datetime for the payment. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0)
|
33
35
|
class BrcodePayment < StarkBank::Utils::Resource
|
34
|
-
attr_reader :brcode, :tax_id, :description, :amount, :scheduled, :tags, :id, :status, :type, :fee, :updated, :created
|
35
|
-
def initialize(brcode:, tax_id:, description:, amount: nil, scheduled: nil, tags: nil, id: nil, status: nil, type: nil, fee: nil, updated: nil, created: nil)
|
36
|
+
attr_reader :brcode, :tax_id, :description, :amount, :scheduled, :tags, :id, :name, :status, :type, :transaction_ids, :fee, :updated, :created
|
37
|
+
def initialize(brcode:, tax_id:, description:, amount: nil, scheduled: nil, tags: nil, id: nil, name: nil, status: nil, type: nil, transaction_ids: nil, fee: nil, updated: nil, created: nil)
|
36
38
|
super(id)
|
37
39
|
@brcode = brcode
|
38
40
|
@tax_id = tax_id
|
@@ -40,8 +42,10 @@ module StarkBank
|
|
40
42
|
@amount = amount
|
41
43
|
@scheduled = StarkBank::Utils::Checks.check_date_or_datetime(scheduled)
|
42
44
|
@tags = tags
|
45
|
+
@name = name
|
43
46
|
@status = status
|
44
47
|
@type = type
|
48
|
+
@transaction_ids = transaction_ids
|
45
49
|
@fee = fee
|
46
50
|
@updated = StarkBank::Utils::Checks.check_datetime(updated)
|
47
51
|
@created = StarkBank::Utils::Checks.check_datetime(created)
|
@@ -55,7 +59,7 @@ module StarkBank
|
|
55
59
|
# - payments [list of BrcodePayment objects]: list of BrcodePayment objects to be created in the API
|
56
60
|
#
|
57
61
|
# ## Parameters (optional):
|
58
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
62
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
59
63
|
#
|
60
64
|
# ## Return:
|
61
65
|
# - list of BrcodePayment objects with updated attributes
|
@@ -71,7 +75,7 @@ module StarkBank
|
|
71
75
|
# - id [string]: object unique id. ex: '5656565656565656'
|
72
76
|
#
|
73
77
|
# ## Parameters (optional):
|
74
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
78
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
75
79
|
#
|
76
80
|
# ## Return:
|
77
81
|
# - BrcodePayment object with updated attributes
|
@@ -87,12 +91,12 @@ module StarkBank
|
|
87
91
|
# - id [string]: object unique id. ex: '5656565656565656'
|
88
92
|
#
|
89
93
|
# ## Parameters (optional):
|
90
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
94
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
91
95
|
#
|
92
96
|
# ## Return:
|
93
97
|
# - BrcodePayment pdf file
|
94
98
|
def self.pdf(id, user: nil)
|
95
|
-
StarkBank::Utils::Rest.
|
99
|
+
StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
|
96
100
|
end
|
97
101
|
|
98
102
|
# # Update a BrcodePayment entity
|
@@ -104,7 +108,7 @@ module StarkBank
|
|
104
108
|
# - status [string, nil]: You may cancel the payment by passing 'canceled' in the status
|
105
109
|
#
|
106
110
|
# ## Parameters (optional):
|
107
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
111
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
108
112
|
#
|
109
113
|
# ## Return:
|
110
114
|
# - updated BrcodePayment object
|
@@ -118,26 +122,59 @@ module StarkBank
|
|
118
122
|
#
|
119
123
|
# ## Parameters (optional):
|
120
124
|
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
121
|
-
# - after [Date, DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
122
|
-
# - before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
125
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
126
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
123
127
|
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
124
128
|
# - ids [list of strings, default nil]: list of strings to get specific entities by ids. ex: ['12376517623', '1928367198236']
|
125
129
|
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid'
|
126
|
-
# - user [Project object
|
130
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
127
131
|
#
|
128
132
|
# ## Return:
|
129
133
|
# - generator of BrcodePayment objects with updated attributes
|
130
134
|
def self.query(limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil)
|
131
135
|
after = StarkBank::Utils::Checks.check_date(after)
|
132
136
|
before = StarkBank::Utils::Checks.check_date(before)
|
133
|
-
StarkBank::Utils::Rest.
|
137
|
+
StarkBank::Utils::Rest.get_stream(
|
138
|
+
limit: limit,
|
139
|
+
after: after,
|
140
|
+
before: before,
|
141
|
+
tags: tags,
|
142
|
+
ids: ids,
|
143
|
+
status: status,
|
134
144
|
user: user,
|
145
|
+
**resource
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
# # Retrieve paged BrcodePayments
|
150
|
+
#
|
151
|
+
# Receive a list of up to 100 BrcodePayment objects previously created in the Stark Bank API and the cursor to the next page.
|
152
|
+
# Use this function instead of query if you want to manually page your requests.
|
153
|
+
#
|
154
|
+
# ## Parameters (optional):
|
155
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
156
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
157
|
+
# - after [Date, DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
158
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
159
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
160
|
+
# - ids [list of strings, default nil]: list of strings to get specific entities by ids. ex: ['12376517623', '1928367198236']
|
161
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid'
|
162
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
163
|
+
#
|
164
|
+
# ## Return:
|
165
|
+
# - list of BrcodePayment objects with updated attributes and cursor to retrieve the next page of BrcodePayment objects
|
166
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, tags: nil, ids: nil, status: nil, user: nil)
|
167
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
168
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
169
|
+
return StarkBank::Utils::Rest.get_page(
|
170
|
+
cursor: cursor,
|
135
171
|
limit: limit,
|
136
172
|
after: after,
|
137
173
|
before: before,
|
138
174
|
tags: tags,
|
139
175
|
ids: ids,
|
140
176
|
status: status,
|
177
|
+
user: user,
|
141
178
|
**resource
|
142
179
|
)
|
143
180
|
end
|
@@ -154,8 +191,10 @@ module StarkBank
|
|
154
191
|
scheduled: json['scheduled'],
|
155
192
|
tags: json['tags'],
|
156
193
|
id: json['id'],
|
194
|
+
name: json['name'],
|
157
195
|
status: json['status'],
|
158
196
|
type: json['type'],
|
197
|
+
transaction_ids: json['transaction_ids'],
|
159
198
|
fee: json['fee'],
|
160
199
|
updated: json['updated'],
|
161
200
|
created: json['created']
|
data/lib/brcode_payment/log.rb
CHANGED
@@ -38,7 +38,7 @@ module StarkBank
|
|
38
38
|
# - id [string]: object unique id. ex: '5656565656565656'
|
39
39
|
#
|
40
40
|
# ## Parameters (optional):
|
41
|
-
# - user [Project object]: Project object. Not necessary if StarkBank.user was set before function call
|
41
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
42
42
|
#
|
43
43
|
# ## Return:
|
44
44
|
# - Log object with updated attributes
|
@@ -52,18 +52,49 @@ module StarkBank
|
|
52
52
|
#
|
53
53
|
# ## Parameters (optional):
|
54
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)
|
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
57
|
# - types [list of strings, default nil]: filter retrieved objects by event types. ex: 'success' or 'failed'
|
58
58
|
# - payment_ids [list of strings, default nil]: list of BrcodePayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
59
|
-
# - user [Project object
|
59
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
60
60
|
#
|
61
61
|
# ## Return:
|
62
62
|
# - list of Log objects with updated attributes
|
63
63
|
def self.query(limit: nil, after: nil, before: nil, types: nil, payment_ids: nil, user: nil)
|
64
64
|
after = StarkBank::Utils::Checks.check_date(after)
|
65
65
|
before = StarkBank::Utils::Checks.check_date(before)
|
66
|
-
StarkBank::Utils::Rest.
|
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 retrieved objects by event types. ex: 'success' or 'failed'
|
88
|
+
# - payment_ids [list of strings, default nil]: list of BrcodePayment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
89
|
+
# - user [Organization/Project object]: 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,
|
67
98
|
limit: limit,
|
68
99
|
after: after,
|
69
100
|
before: before,
|
@@ -41,12 +41,12 @@ module StarkBank
|
|
41
41
|
#
|
42
42
|
# ## Parameters (optional):
|
43
43
|
# - brcodes [list of strings]: List of brcodes to preview. ex: %w[00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A]
|
44
|
-
# - user [Project object
|
44
|
+
# - user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
45
45
|
#
|
46
46
|
# ## Return:
|
47
47
|
# - generator of BrcodePreview objects with updated attributes
|
48
48
|
def self.query(limit: nil, brcodes: nil, user: nil)
|
49
|
-
StarkBank::Utils::Rest.
|
49
|
+
StarkBank::Utils::Rest.get_stream(
|
50
50
|
user: user,
|
51
51
|
limit: nil,
|
52
52
|
brcodes: brcodes,
|
@@ -0,0 +1,218 @@
|
|
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
|
+
# # DarfPayment object
|
9
|
+
#
|
10
|
+
# When you initialize a DarfPayment, 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
|
+
# - description [string]: Text to be displayed in your statement (min. 10 characters). ex: 'payment ABC'
|
16
|
+
# - description [string]: Text to be displayed in your statement (min. 10 characters). ex: 'payment ABC'
|
17
|
+
# - revenue_code [string]: 4-digit tax code assigned by Federal Revenue. ex: '5948'
|
18
|
+
# - tax_id [tax_id]: tax id (formatted or unformatted) of the payer. ex: '12.345.678/0001-95'
|
19
|
+
# - competence [Date, DateTime, Time or string, default today]: competence month of the service. ex: Date.new(2020, 3, 10)
|
20
|
+
# - nominal_amount [int]: amount due in cents without fee or interest. ex: 23456 (= R$ 234.56)
|
21
|
+
# - fine_amount [int]: fixed amount due in cents for fines. ex: 234 (= R$ 2.34)
|
22
|
+
# - interest_amount [int]: amount due in cents for interest. ex: 456 (= R$ 4.56)
|
23
|
+
# - due [Date, DateTime, Time or string, default today]: due date for payment. ex: Date.new(2020, 3, 10)
|
24
|
+
#
|
25
|
+
# ## Parameters (optional):
|
26
|
+
# - reference_number [string, default nil]: number assigned to the region of the tax. ex: '08.1.17.00-4'
|
27
|
+
# - scheduled [Date, DateTime, Time or string, default today]: payment scheduled date. ex: Date.new(2020, 3, 10)
|
28
|
+
# - tags [list of strings, default nil]: list of strings for tagging
|
29
|
+
#
|
30
|
+
# ## Attributes (return-only):
|
31
|
+
# - id [string, default nil]: unique id returned when payment is created. ex: '5656565656565656'
|
32
|
+
# - status [string, default nil]: current payment status. ex: 'success' or 'failed'
|
33
|
+
# - amount [int, default nil]: Total amount due calculated from other amounts. ex: 24146 (= R$ 241.46)
|
34
|
+
# - fee [integer, default nil]: fee charged when the DarfPayment is processed. ex: 0 (= R$ 0.00)
|
35
|
+
# - created [DateTime, default nil]: creation datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
36
|
+
# - updated [DateTime, default nil]: latest update datetime for the Invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
|
37
|
+
class DarfPayment < StarkBank::Utils::Resource
|
38
|
+
attr_reader :id, :revenue_code, :tax_id, :competence, :reference_number, :fine_amount, :interest_amount,
|
39
|
+
:due, :description, :tags, :scheduled, :status, :amount, :nominal_amount, :fee, :updated, :created
|
40
|
+
def initialize(
|
41
|
+
id: nil, revenue_code:, tax_id:, competence:, reference_number:, fine_amount:, interest_amount:, due:, description: nil,
|
42
|
+
tags: nil, scheduled: nil, status: nil, amount: nil, nominal_amount: nil, fee: nil, updated: nil, created: nil
|
43
|
+
)
|
44
|
+
super(id)
|
45
|
+
@revenue_code = revenue_code
|
46
|
+
@tax_id = tax_id
|
47
|
+
@competence = StarkBank::Utils::Checks.check_date(competence)
|
48
|
+
@reference_number = reference_number
|
49
|
+
@fine_amount = fine_amount
|
50
|
+
@interest_amount = interest_amount
|
51
|
+
@due = StarkBank::Utils::Checks.check_date(due)
|
52
|
+
@description = description
|
53
|
+
@tags = tags
|
54
|
+
@scheduled = StarkBank::Utils::Checks.check_date(scheduled)
|
55
|
+
@status = status
|
56
|
+
@amount = amount
|
57
|
+
@nominal_amount = nominal_amount
|
58
|
+
@fee = fee
|
59
|
+
@updated = StarkBank::Utils::Checks.check_datetime(updated)
|
60
|
+
@created = StarkBank::Utils::Checks.check_datetime(created)
|
61
|
+
end
|
62
|
+
|
63
|
+
# # Create DarfPayments
|
64
|
+
#
|
65
|
+
# Send a list of DarfPayment objects for creation in the Stark Bank API
|
66
|
+
#
|
67
|
+
# ## Parameters (required):
|
68
|
+
# - payments [list of DarfPayment objects]: list of DarfPayment objects to be created in the API
|
69
|
+
#
|
70
|
+
# ## Parameters (optional):
|
71
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
72
|
+
#
|
73
|
+
# ## Return:
|
74
|
+
# - list of DarfPayment objects with updated attributes
|
75
|
+
def self.create(payments, user: nil)
|
76
|
+
StarkBank::Utils::Rest.post(entities: payments, user: user, **resource)
|
77
|
+
end
|
78
|
+
|
79
|
+
# # Retrieve a specific DarfPayment
|
80
|
+
#
|
81
|
+
# Receive a single DarfPayment object previously created by the Stark Bank API by passing its id
|
82
|
+
#
|
83
|
+
# ## Parameters (required):
|
84
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
85
|
+
#
|
86
|
+
# ## Parameters (optional):
|
87
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
88
|
+
#
|
89
|
+
# ## Return:
|
90
|
+
# - DarfPayment object with updated attributes
|
91
|
+
def self.get(id, user: nil)
|
92
|
+
StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
|
93
|
+
end
|
94
|
+
|
95
|
+
# # Retrieve a specific DarfPayment pdf file
|
96
|
+
#
|
97
|
+
# Receive a single DarfPayment pdf file generated in the Stark Bank API by passing its id.
|
98
|
+
# Only valid for darf payments with 'success' status.
|
99
|
+
#
|
100
|
+
# ## Parameters (required):
|
101
|
+
# - id [string]: object unique id. ex: '5656565656565656'
|
102
|
+
#
|
103
|
+
# ## Parameters (optional):
|
104
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
105
|
+
#
|
106
|
+
# ## Return:
|
107
|
+
# - DarfPayment pdf file
|
108
|
+
def self.pdf(id, user: nil)
|
109
|
+
StarkBank::Utils::Rest.get_content(id: id, user: user, sub_resource_name: 'pdf', **resource)
|
110
|
+
end
|
111
|
+
|
112
|
+
# # Retrieve DarfPayments
|
113
|
+
#
|
114
|
+
# Receive a generator of DarfPayment objects previously created in the Stark Bank API
|
115
|
+
#
|
116
|
+
# ## Parameters (optional):
|
117
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
118
|
+
# - after [Date , DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
119
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
120
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
121
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
122
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
123
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
124
|
+
#
|
125
|
+
# ## Return:
|
126
|
+
# - generator of DarfPayment objects with updated attributes
|
127
|
+
def self.query(limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
128
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
129
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
130
|
+
StarkBank::Utils::Rest.get_stream(
|
131
|
+
limit: limit,
|
132
|
+
after: after,
|
133
|
+
before: before,
|
134
|
+
tags: tags,
|
135
|
+
ids: ids,
|
136
|
+
status: status,
|
137
|
+
user: user,
|
138
|
+
**resource
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
# # Retrieve paged Darf Payments
|
143
|
+
#
|
144
|
+
# Receive a list of up to 100 Darf Payment objects previously created in the Stark Bank API and the cursor to the next page.
|
145
|
+
# Use this function instead of query if you want to manually page your requests.
|
146
|
+
#
|
147
|
+
# ## Parameters (optional):
|
148
|
+
# - cursor [string, default nil]: cursor returned on the previous page function call
|
149
|
+
# - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
|
150
|
+
# - after [Date , DateTime, Time or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
|
151
|
+
# - before [Date, DateTime, Time or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
|
152
|
+
# - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
|
153
|
+
# - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
|
154
|
+
# - status [string, default nil]: filter for status of retrieved objects. ex: 'paid' or 'registered'
|
155
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
156
|
+
#
|
157
|
+
# ## Return:
|
158
|
+
# - list of Darf Payment objects with updated attributes and cursor to retrieve the next page of Darf Payment objects
|
159
|
+
def self.page(cursor: nil, limit: nil, after: nil, before: nil, status: nil, tags: nil, ids: nil, user: nil)
|
160
|
+
after = StarkBank::Utils::Checks.check_date(after)
|
161
|
+
before = StarkBank::Utils::Checks.check_date(before)
|
162
|
+
return StarkBank::Utils::Rest.get_page(
|
163
|
+
cursor: cursor,
|
164
|
+
limit: limit,
|
165
|
+
after: after,
|
166
|
+
before: before,
|
167
|
+
tags: tags,
|
168
|
+
ids: ids,
|
169
|
+
status: status,
|
170
|
+
user: user,
|
171
|
+
**resource
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
# # Delete a DarfPayment entity
|
176
|
+
#
|
177
|
+
# Delete a DarfPayment entity previously created in the Stark Bank API
|
178
|
+
#
|
179
|
+
# ## Parameters (required):
|
180
|
+
# - id [string]: UtilityPayment unique id. ex:'5656565656565656'
|
181
|
+
#
|
182
|
+
# ## Parameters (optional):
|
183
|
+
# - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
|
184
|
+
#
|
185
|
+
# ## Return:
|
186
|
+
# - deleted TaxPayment object
|
187
|
+
def self.delete(id, user: nil)
|
188
|
+
StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource)
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.resource
|
192
|
+
{
|
193
|
+
resource_name: 'DarfPayment',
|
194
|
+
resource_maker: proc { |json|
|
195
|
+
DarfPayment.new(
|
196
|
+
id: json['id'],
|
197
|
+
revenue_code: json['revenue_code'],
|
198
|
+
tax_id: json['tax_id'],
|
199
|
+
competence: json['competence'],
|
200
|
+
reference_number: json['reference_number'],
|
201
|
+
fine_amount: json['fine_amount'],
|
202
|
+
interest_amount: json['interest_amount'],
|
203
|
+
due: json['due'],
|
204
|
+
description: json['description'],
|
205
|
+
tags: json['tags'],
|
206
|
+
scheduled: json['scheduled'],
|
207
|
+
status: json['status'],
|
208
|
+
amount: json['amount'],
|
209
|
+
nominal_amount: json['nominal_amount'],
|
210
|
+
fee: json['fee'],
|
211
|
+
updated: json['updated'],
|
212
|
+
created: json['created'],
|
213
|
+
)
|
214
|
+
}
|
215
|
+
}
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|