sdk_ruby_apis_efi 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b2911571314341305ceb645c8efc78e10263df2ac2aa88ca7a900e97fa0ead3
4
+ data.tar.gz: 9b9dd80c9afe06309f671603c1d09ec073ad8c90b7e6a786fd664a55e8fb5963
5
+ SHA512:
6
+ metadata.gz: 71a99654131b336c3709381a5cdb0a5458642d35a7094f3001a9ae56eed0b4df173dac778f8bdb7098e30c52a3dc47b79f2771d9896bb731f18e2200209c2cd7
7
+ data.tar.gz: d475b5580aeaf907c62f6ca02482822610d371239735e5315a42c814ecbc95b0e09270ff40520fbc7505bea48153940738c1ba7e4358e975c7f90f8a051c1410
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ Changelog
2
+ =========
3
+
4
+ Version 1.0.0 (2023-07-31)
5
+ --------------------------
6
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "coveralls", require: false
4
+ gem "uri"
5
+ gem "http"
6
+ gem "cgi"
7
+ gem "json"
8
+ gem "base64"
9
+ # require "pry"
10
+ # Pry.start
11
+
12
+ # Specify your gem's dependencies in sdk-ruby-apis-efi.gemspec
13
+ # gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 efipay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # sdk-ruby-apis-efi
2
+
3
+ > A ruby gem for integration of your backend with the payment services
4
+ provided by [Efí](https://sejaefi.com.br/).
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sdk_ruby_apis_efi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```bash
24
+ $ gem install sdk_ruby_apis_efi
25
+ ```
26
+
27
+ ## Tested with
28
+ ```
29
+ ruby 2.7.0
30
+ ruby 3.0.4
31
+ ```
32
+
33
+ ## Basic usage
34
+
35
+ ```ruby
36
+ require 'sdk_ruby_apis_efi'
37
+
38
+ options = {
39
+ client_id: CREDENTIALS::CLIENT_ID,
40
+ client_secret: CREDENTIALS::CLIENT_SECRET,
41
+ sandbox: CREDENTIALS::SANDBOX
42
+ }
43
+
44
+ efipay = SdkRubyApisEfi.new(options)
45
+
46
+ charge = {
47
+ items: [{
48
+ name: "Product A",
49
+ value: 1000,
50
+ amount: 2
51
+ }]
52
+ }
53
+
54
+ response = efipay.create_charge(body: charge)
55
+ puts response
56
+ ```
57
+
58
+ ## Examples
59
+
60
+ You can run the examples inside `examples` with the following command:
61
+
62
+ ```bash
63
+ $ ruby examples/create_charge.rb
64
+ ```
65
+
66
+ Just remember to set the correct credentials inside `examples/credentials.rb` before running.
67
+
68
+
69
+ ## Additional documentation
70
+
71
+ The full documentation with all available endpoints is in https://dev.sejaefi.com.br/.
72
+
73
+ ## Changelog
74
+
75
+ [CHANGELOG](https://github.com/efipay/sdk-ruby-apis-efi/tree/master/CHANGELOG.md)
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/efipay/sdk-ruby-apis-efi. This project is intended to be a safe, welcoming space for collaboration.
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'sdk_ruby_apis_efi'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,477 @@
1
+ module SdkRubyApisEfi
2
+ # Endpoints signatures
3
+ module Constants
4
+ module APIs
5
+ CHARGES = {
6
+ URL: {
7
+ production: "https://cobrancas.api.efipay.com.br",
8
+ sandbox: "https://cobrancas-h.api.efipay.com.br"
9
+ },
10
+ ENDPOINTS: {
11
+ authorize: {
12
+ route: "/v1/authorize",
13
+ method: "post"
14
+ },
15
+ create_charge: {
16
+ route: "/v1/charge",
17
+ method: "post"
18
+ },
19
+ create_one_step_charge: {
20
+ route: "/v1/charge/one-step",
21
+ method: "post"
22
+ },
23
+ create_one_step_charge_partner: {
24
+ route: "/v1/partner/charge/one-step",
25
+ method: "post"
26
+ },
27
+ detail_charge: {
28
+ route: "/v1/charge/:id",
29
+ method: "get"
30
+ },
31
+ update_charge_metadata: {
32
+ route: "/v1/charge/:id/metadata",
33
+ method: "put"
34
+ },
35
+ update_billet: {
36
+ route: "/v1/charge/:id/billet",
37
+ method: "put"
38
+ },
39
+ define_pay_method: {
40
+ route: "/v1/charge/:id/pay",
41
+ method: "post"
42
+ },
43
+ define_pay_method_partner: {
44
+ route: "/v1/partner/charge/:id/pay",
45
+ method: "post"
46
+ },
47
+ cancel_charge: {
48
+ route: "/v1/charge/:id/cancel",
49
+ method: "put"
50
+ },
51
+ create_carnet: {
52
+ route: "/v1/carnet",
53
+ method: "post"
54
+ },
55
+ detail_carnet: {
56
+ route: "/v1/carnet/:id",
57
+ method: "get"
58
+ },
59
+ update_carnet_parcel: {
60
+ route: "/v1/carnet/:id/parcel/:parcel",
61
+ method: "put"
62
+ },
63
+ update_carnet_metadata: {
64
+ route: "/v1/carnet/:id/metadata",
65
+ method: "put"
66
+ },
67
+ get_notification: {
68
+ route: "/v1/notification/:token",
69
+ method: "get"
70
+ },
71
+ list_plans: {
72
+ route: "/v1/plans",
73
+ method: "get"
74
+ },
75
+ create_plan: {
76
+ route: "/v1/plan",
77
+ method: "post"
78
+ },
79
+ delete_plan: {
80
+ route: "/v1/plan/:id",
81
+ method: "delete"
82
+ },
83
+ create_subscription: {
84
+ route: "/v1/plan/:id/subscription",
85
+ method: "post"
86
+ },
87
+ create_one_step_subscription: {
88
+ route: "/v1/plan/:id/subscription/one-step",
89
+ method: "post"
90
+ },
91
+ create_one_step_subscription_link: {
92
+ route: "/v1/plan/:id/subscription/one-step/link",
93
+ method: "post"
94
+ },
95
+ detail_subscription: {
96
+ route: "/v1/subscription/:id",
97
+ method: "get"
98
+ },
99
+ define_subscription_pay_method: {
100
+ route: "/v1/subscription/:id/pay",
101
+ method: "post"
102
+ },
103
+ cancel_subscription: {
104
+ route: "/v1/subscription/:id/cancel",
105
+ method: "put"
106
+ },
107
+ update_subscription_metadata: {
108
+ route: "/v1/subscription/:id/metadata",
109
+ method: "put"
110
+ },
111
+ create_subscription_history: {
112
+ route: "/v1/subscription/:id/history",
113
+ method: "post"
114
+ },
115
+ send_subscription_link_email: {
116
+ route: "/v1/charge/:id/subscription/resend",
117
+ method: "post"
118
+ },
119
+ get_installments: {
120
+ route: "/v1/installments",
121
+ method: "get"
122
+ },
123
+ send_billet_email: {
124
+ route: "/v1/charge/:id/billet/resend",
125
+ method: "post"
126
+ },
127
+ create_charge_history: {
128
+ route: "/v1/charge/:id/history",
129
+ method: "post"
130
+ },
131
+ send_carnet_email: {
132
+ route: "/v1/carnet/:id/resend",
133
+ method: "post"
134
+ },
135
+ send_carnet_parcel_email: {
136
+ route: "/v1/carnet/:id/parcel/:parcel/resend",
137
+ method: "post"
138
+ },
139
+ create_carnet_history: {
140
+ route: "/v1/carnet/:id/history",
141
+ method: "post"
142
+ },
143
+ cancel_carnet: {
144
+ route: "/v1/carnet/:id/cancel",
145
+ method: "put"
146
+ },
147
+ cancel_carnet_parcel: {
148
+ route: "/v1/carnet/:id/parcel/:parcel/cancel",
149
+ method: "put"
150
+ },
151
+ create_one_step_link: {
152
+ route: "/v1/charge/one-step/link",
153
+ method: "post"
154
+ },
155
+ define_link_pay_method: {
156
+ route: "/v1/charge/:id/link",
157
+ method: "post"
158
+ },
159
+ update_charge_link: {
160
+ route: "/v1/charge/:id/link",
161
+ method: "put"
162
+ },
163
+ send_link_email: {
164
+ route: "/v1/charge/:id/link/resend",
165
+ method: "post"
166
+ },
167
+ update_plan: {
168
+ route: "/v1/plan/:id",
169
+ method: "put"
170
+ },
171
+ define_balance_sheet_billet: {
172
+ route: "/v1/charge/:id/balance-sheet",
173
+ method: "post"
174
+ },
175
+ settle_charge: {
176
+ route: "/v1/charge/:id/settle",
177
+ method: "put"
178
+ },
179
+ settle_carnet: {
180
+ route: "/v1/carnet/:id/settle",
181
+ method: "put"
182
+ },
183
+ settle_carnet_parcel: {
184
+ route: "/v1/carnet/:id/parcel/:parcel/settle",
185
+ method: "put"
186
+ }
187
+ }
188
+ }
189
+
190
+ PIX = {
191
+ URL: {
192
+ production: "https://pix.api.efipay.com.br",
193
+ sandbox: "https://pix-h.api.efipay.com.br"
194
+ },
195
+ ENDPOINTS: {
196
+ authorize: {
197
+ route: "/oauth/token",
198
+ method: "post"
199
+ },
200
+ pix_config_webhook: {
201
+ route: "/v2/webhook/:chave",
202
+ method: "put"
203
+ },
204
+ pix_detail_webhook: {
205
+ route: "/v2/webhook/:chave",
206
+ method: "get"
207
+ },
208
+ pix_list_webhook: {
209
+ route: "/v2/webhook",
210
+ method: "get"
211
+ },
212
+ pix_delete_webhook: {
213
+ route: "/v2/webhook/:chave",
214
+ method: "delete"
215
+ },
216
+ pix_create_charge: {
217
+ route: "/v2/cob/:txid",
218
+ method: "put"
219
+ },
220
+ pix_create_immediate_charge: {
221
+ route: "/v2/cob",
222
+ method: "post"
223
+ },
224
+ pix_detail_charge: {
225
+ route: "/v2/cob/:txid",
226
+ method: "get"
227
+ },
228
+ pix_update_charge: {
229
+ route: "/v2/cob/:txid",
230
+ method: "patch"
231
+ },
232
+ pix_list_charges: {
233
+ route: "/v2/cob",
234
+ method: "get"
235
+ },
236
+ pix_devolution: {
237
+ route: "/v2/pix/:e2eId/devolucao/:id",
238
+ method: "put"
239
+ },
240
+ pix_detail_devolution: {
241
+ route: "/v2/pix/:e2eId/devolucao/:id",
242
+ method: "get"
243
+ },
244
+ pix_send: {
245
+ route: "/v2/gn/pix/:idEnvio",
246
+ method: "put"
247
+ },
248
+ pix_send_detail: {
249
+ route: "/v2/gn/pix/enviados/:e2eId",
250
+ method: "get"
251
+ },
252
+ pix_send_list: {
253
+ route: "/v2/gn/pix/enviados",
254
+ method: "get"
255
+ },
256
+ pix_detail_received: {
257
+ route: "/v2/pix/:e2eId",
258
+ method: "get"
259
+ },
260
+ pix_received_list: {
261
+ route: "/v2/pix",
262
+ method: "get"
263
+ },
264
+ pix_generate_qrcode: {
265
+ route: "/v2/loc/:id/qrcode",
266
+ method: "get"
267
+ },
268
+ pix_create_location: {
269
+ route: "/v2/loc",
270
+ method: "post"
271
+ },
272
+ pix_location_list: {
273
+ route: "/v2/loc",
274
+ method: "get"
275
+ },
276
+ pix_detail_location: {
277
+ route: "/v2/loc/:id",
278
+ method: "get"
279
+ },
280
+ pix_unlink_txid_location: {
281
+ route: "/v2/loc/:id/txid",
282
+ method: "delete"
283
+ },
284
+ pix_create_evp: {
285
+ route: "/v2/gn/evp",
286
+ method: "post"
287
+ },
288
+ pix_list_evp: {
289
+ route: "/v2/gn/evp",
290
+ method: "get"
291
+ },
292
+ pix_delete_evp: {
293
+ route: "/v2/gn/evp/:chave",
294
+ method: "delete"
295
+ },
296
+ pix_split_detail_charge: {
297
+ route: "/v2/gn/split/cob/:txid",
298
+ method: "get"
299
+ },
300
+ pix_split_link_charge: {
301
+ route: "/v2/gn/split/cob/:txid/vinculo/:splitConfigId",
302
+ method: "put"
303
+ },
304
+ pix_split_unlink_charge: {
305
+ route: "/v2/gn/split/cob/:txid/vinculo/:splitConfigId",
306
+ method: "delete"
307
+ },
308
+ pix_split_detail_due_charge: {
309
+ route: "/v2/gn/split/cobv/:txid",
310
+ method: "get"
311
+ },
312
+ pix_split_link_due_charge: {
313
+ route: "/v2/gn/split/cobv/:txid/vinculo/:splitConfigId",
314
+ method: "put"
315
+ },
316
+ pix_split_unlink_due_charge: {
317
+ route: "/v2/gn/split/cobv/:txid/vinculo/:splitConfigId",
318
+ method: "delete"
319
+ },
320
+ pix_split_config: {
321
+ route: "/v2/gn/split/config",
322
+ method: "post"
323
+ },
324
+ pix_split_config_id: {
325
+ route: "/v2/gn/split/config/:id",
326
+ method: "put"
327
+ },
328
+ pix_split_detail_config: {
329
+ route: "/v2/gn/split/config/:id",
330
+ method: "get"
331
+ },
332
+ get_account_balance: {
333
+ route: "/v2/gn/saldo",
334
+ method: "get"
335
+ },
336
+ update_account_config: {
337
+ route: "/v2/gn/config",
338
+ method: "put"
339
+ },
340
+ list_account_config: {
341
+ route: "/v2/gn/config",
342
+ method: "get"
343
+ },
344
+ pix_create_due_charge: {
345
+ route: "/v2/cobv/:txid",
346
+ method: "put"
347
+ },
348
+ pix_update_due_charge: {
349
+ route: "/v2/cobv/:txid",
350
+ method: "patch"
351
+ },
352
+ pix_detail_due_charge: {
353
+ route: "/v2/cobv/:txid",
354
+ method: "get"
355
+ },
356
+ pix_list_due_charges: {
357
+ route: "/v2/cobv/",
358
+ method: "get"
359
+ },
360
+ create_report: {
361
+ route: "/v2/gn/relatorios/extrato-conciliacao",
362
+ method: "post"
363
+ },
364
+ detail_report: {
365
+ route: "/v2/gn/relatorios/:id",
366
+ method: "get"
367
+ }
368
+ }
369
+ }
370
+
371
+ OPEN_FINANCE = {
372
+ URL: {
373
+ production: "https://openfinance.api.efipay.com.br",
374
+ sandbox: "https://openfinance-h.api.efipay.com.br"
375
+ },
376
+ ENDPOINTS: {
377
+ authorize: {
378
+ route: "/open-finance/oauth/token",
379
+ method: "post"
380
+ },
381
+ of_config_update: {
382
+ route: "/open-finance/config",
383
+ method: "put"
384
+ },
385
+ of_config_detail: {
386
+ route: "/open-finance/config",
387
+ method: "get"
388
+ },
389
+ of_list_participants: {
390
+ route: "/open-finance/participantes",
391
+ method: "get"
392
+ },
393
+ of_start_pix_payment: {
394
+ route: "/open-finance/pagamentos/pix",
395
+ method: "post"
396
+ },
397
+ of_list_pix_payment: {
398
+ route: "/open-finance/pagamentos/pix",
399
+ method: "get"
400
+ },
401
+ of_devolution_pix: {
402
+ route: "/open-finance/devolucao/pagamento/pix",
403
+ method: "post"
404
+ }
405
+ }
406
+ }
407
+ PAYMENTS = {
408
+ URL: {
409
+ production: "https://pagarcontas.api.efipay.com.br",
410
+ sandbox: "https://pagarcontas.api.efipay.com.br"
411
+ },
412
+ ENDPOINTS: {
413
+ authorize: {
414
+ route: "/oauth/token",
415
+ method: "post"
416
+ },
417
+ pay_detail_barcode: {
418
+ route: "/pagamento/codBarras/:codBarras",
419
+ method: "get"
420
+ },
421
+ pay_request_barcode: {
422
+ route: "/pagamento/codBarras/:codBarras",
423
+ method: "post"
424
+ },
425
+ pay_detail_payment: {
426
+ route: "/pagamento/:idPagamento",
427
+ method: "get"
428
+ },
429
+ pay_list_payments: {
430
+ route: "/pagamento/resumo",
431
+ method: "get"
432
+ }
433
+ }
434
+ }
435
+ ACCOUNTS_OPENING = {
436
+ URL: {
437
+ production: "https://abrircontas.api.efipay.com.br",
438
+ sandbox: "https://abrircontas.api.efipay.com.br"
439
+ },
440
+ ENDPOINTS: {
441
+ authorize: {
442
+ route: "/oauth/token",
443
+ method: "post"
444
+ },
445
+ create_account: {
446
+ route: "/cadastro/conta-simplificada",
447
+ method: "post"
448
+ },
449
+ get_account_credentials: {
450
+ route: "/cadastro/conta-simplificada/:idContaSimplificada/credenciais",
451
+ method: "get"
452
+ },
453
+ get_account_certificate: {
454
+ route: "/cadastro/conta-simplificada/:idContaSimplificada/certificado",
455
+ method: "get"
456
+ },
457
+ account_config_webhook: {
458
+ route: "/cadastro/webhook",
459
+ method: "post"
460
+ },
461
+ account_list_webhook: {
462
+ route: "/cadastro/webhooks",
463
+ method: "get"
464
+ },
465
+ account_detail_webhook: {
466
+ route: "/cadastro/webhook/:identificadorWebhook",
467
+ method: "get"
468
+ },
469
+ account_delete_webhook: {
470
+ route: "/cadastro/webhook/:identificadorWebhook",
471
+ method: "delete"
472
+ }
473
+ }
474
+ }
475
+ end
476
+ end
477
+ end
@@ -0,0 +1,227 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require "http"
4
+ require "cgi"
5
+ require "json"
6
+ require 'base64'
7
+ require_relative "constants"
8
+ require_relative "status"
9
+ require_relative "version"
10
+
11
+ module SdkRubyApisEfi
12
+ class Endpoints
13
+
14
+ def initialize(options)
15
+ super()
16
+ @token = nil
17
+ @options = options
18
+ @charges = Constants::APIs::CHARGES
19
+ @pix = Constants::APIs::PIX
20
+ @open_finance = Constants::APIs::OPEN_FINANCE
21
+ @payments = Constants::APIs::PAYMENTS
22
+ @accounts_opening = Constants::APIs::ACCOUNTS_OPENING
23
+ end
24
+
25
+ def method_missing(name, **kwargs)
26
+ if @charges[:ENDPOINTS].include?(name)
27
+ @endpoints = @charges[:ENDPOINTS]
28
+ @urls = @charges[:URL]
29
+ request(@charges[:ENDPOINTS][name], **kwargs)
30
+
31
+ elsif @pix[:ENDPOINTS].include?(name)
32
+ @endpoints = @pix[:ENDPOINTS]
33
+ @urls = @pix[:URL]
34
+ request(@pix[:ENDPOINTS][name], **kwargs)
35
+
36
+ elsif @open_finance[:ENDPOINTS].include?(name)
37
+ @endpoints = @open_finance[:ENDPOINTS]
38
+ @urls = @open_finance[:URL]
39
+ request(@open_finance[:ENDPOINTS][name], **kwargs)
40
+
41
+ elsif @payments[:ENDPOINTS].include?(name)
42
+ @endpoints = @payments[:ENDPOINTS]
43
+ @urls = @payments[:URL]
44
+ request(@payments[:ENDPOINTS][name], **kwargs)
45
+
46
+ elsif @accounts_opening[:ENDPOINTS].include?(name)
47
+ @endpoints = @accounts_opening[:ENDPOINTS]
48
+ @urls = @accounts_opening[:URL]
49
+ request(@accounts_opening[:ENDPOINTS][name], **kwargs)
50
+
51
+ else
52
+ raise "Method not found"
53
+ end
54
+
55
+ end
56
+
57
+ def request(settings, **kwargs)
58
+
59
+ params = kwargs[:params] || {}
60
+ body = kwargs[:body] || {}
61
+ headers = kwargs[:headers] || {}
62
+
63
+ get_url
64
+
65
+ if @token.nil?
66
+ authenticate
67
+ end
68
+
69
+
70
+ response = send(settings, params, body, headers)
71
+
72
+ begin
73
+ JSON.parse(response.body)
74
+ rescue JSON::ParserError
75
+ "{'code': #{response.code}}"
76
+ else
77
+ JSON.parse(response.body)
78
+ end
79
+
80
+ end
81
+
82
+ def send(settings, params, body, headersComplement)
83
+ url = build_url(settings[:route], params)
84
+ if body == {}
85
+ body = nil
86
+ end
87
+ headers = {
88
+ "accept" => "application/json",
89
+ "api-sdk" => "ruby-#{SdkRubyApisEfi::VERSION}"
90
+ }
91
+
92
+ if headersComplement.any?
93
+ headersComplement.each do |key, value|
94
+ headers[key] = value
95
+ end
96
+ end
97
+
98
+ if @options.has_key?(:partner_token)
99
+ headers['partner-token'] = @options[:partner_token]
100
+ end
101
+
102
+
103
+ if @options[:"x-skip-mtls-checking"]
104
+ headers["x-skip-mtls-checking"] = @options[:"x-skip-mtls-checking"]
105
+ end
106
+
107
+ @token = @token.parse
108
+
109
+ if @options.has_key?(:certificate)
110
+
111
+ HTTP
112
+ .headers(headers)
113
+ .auth("Bearer #{@token['access_token']}")
114
+ .method(settings[:method])
115
+ .call(url, json: body, ssl_context: OpenSSL::SSL::SSLContext.new.tap do |ctx|
116
+ ctx.set_params(
117
+ cert: OpenSSL::X509::Certificate.new(File.read(@options[:certificate])),
118
+ key: OpenSSL::PKey::RSA.new(File.read(@options[:certificate]))
119
+ )
120
+ end)
121
+ else
122
+
123
+ HTTP
124
+ .headers(headers)
125
+ .auth("Bearer #{@token['access_token']}")
126
+ .method(settings[:method])
127
+ .call(url, json: body)
128
+ end
129
+
130
+
131
+ end
132
+
133
+ def authenticate
134
+
135
+ url = build_url(@endpoints[:authorize][:route], {})
136
+
137
+ headers = {
138
+ "accept" => "application/json",
139
+ "api-sdk" => "ruby-#{SdkRubyApisEfi::VERSION}"
140
+ }
141
+
142
+ auth_headers = {
143
+ user: @options[:client_id],
144
+ pass: @options[:client_secret]
145
+ }
146
+
147
+ auth_body = {grant_type: :client_credentials}
148
+
149
+ if (@options.has_key?(:certificate))
150
+
151
+ response =
152
+ HTTP
153
+ .headers(headers)
154
+ .basic_auth(auth_headers)
155
+ .post(url, json: auth_body, ssl_context: OpenSSL::SSL::SSLContext.new.tap do |ctx|
156
+ ctx.set_params(
157
+ cert: OpenSSL::X509::Certificate.new(File.read(@options[:certificate])),
158
+ key: OpenSSL::PKey::RSA.new(File.read(@options[:certificate]))
159
+ )
160
+ end)
161
+
162
+ else
163
+ response =
164
+ HTTP
165
+ .headers(headers)
166
+ .basic_auth(auth_headers)
167
+ .post(url, json: auth_body)
168
+ end
169
+
170
+ if response.status.to_s == STATUS::UNAUTHORIZED
171
+ fail "unable to authenticate"
172
+ else
173
+ @token = response
174
+ end
175
+ end
176
+
177
+
178
+ def get_url
179
+ @base_url = @urls[:sandbox]
180
+ if @options.has_key?(:sandbox)
181
+ @base_url = @options[:sandbox] ? @urls[:sandbox] : @urls[:production]
182
+ end
183
+
184
+ end
185
+
186
+ def build_url(route, params)
187
+ params = {} if params.nil?
188
+ route = remove_placeholders(route, params)
189
+ complete_url = complete_url(route, params)
190
+
191
+ end
192
+
193
+ def remove_placeholders(route, params)
194
+ regex = /\:(\w+)/
195
+ route.scan(regex).each do |key|
196
+ key = key[0]
197
+ value = params[key.to_sym].to_s
198
+ route = route.gsub(":#{key}", value)
199
+ params.delete(key.to_sym)
200
+ end
201
+
202
+ return route
203
+ end
204
+
205
+ def query_string(params)
206
+ mapped = params.map { |p, value| "#{p}=#{value}" }
207
+ mapped.join('&')
208
+ end
209
+
210
+ def map_params(params)
211
+ params.map do |key|
212
+ "#{key[0]}=#{CGI.escape(key[1].to_s)}"
213
+ end.join("&")
214
+ end
215
+
216
+ def complete_url(route, params)
217
+ mapped = map_params(params)
218
+ if !mapped.empty?
219
+ "#{@base_url}#{route}?#{mapped}"
220
+ else
221
+ "#{@base_url}#{route}"
222
+ end
223
+ end
224
+
225
+ end
226
+ end
227
+
@@ -0,0 +1,11 @@
1
+ module SdkRubyApisEfi
2
+ # HTTP response statuses
3
+ module STATUS
4
+ OK = "200 OK"
5
+ CREATED = "201 Created"
6
+ ACCEPTED = "202 Accepted"
7
+ NO_CONTENT = "204 No Content"
8
+ UNAUTHORIZED = "401 Unauthorized"
9
+ FORBIDDEN = "403 Forbidden"
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ # :nodoc:
2
+ module SdkRubyApisEfi
3
+ VERSION = "1.0.0"
4
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sdk_ruby_apis_efi/version"
4
+ require_relative "sdk_ruby_apis_efi/endpoints"
5
+
6
+ # Module that just returns an Endpoints instance
7
+
8
+ module SdkRubyApisEfi
9
+ def self.new(options)
10
+ Endpoints.new(options)
11
+ end
12
+ end
13
+
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sdk_ruby_apis_efi
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - João Muniz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cgi
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: base64
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: uri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ description: |-
112
+ A ruby gem for integration of your backend with the
113
+ payment services provided by Efí Pay
114
+ email:
115
+ - consultoria@sejaefi.com.br
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".rubocop.yml"
121
+ - CHANGELOG.md
122
+ - Gemfile
123
+ - LICENSE
124
+ - README.md
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/sdk_ruby_apis_efi.rb
128
+ - lib/sdk_ruby_apis_efi/constants.rb
129
+ - lib/sdk_ruby_apis_efi/endpoints.rb
130
+ - lib/sdk_ruby_apis_efi/status.rb
131
+ - lib/sdk_ruby_apis_efi/version.rb
132
+ homepage: https://github.com/efipay/sdk-ruby-apis-efi
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.6.0
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.2.33
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Efí Pay API Ruby Gem
155
+ test_files: []