inter_api 1.2.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/inter_api/client_production.rb +30 -39
- data/lib/inter_api/payment.rb +43 -19
- data/lib/inter_api/version.rb +1 -1
- data/lib/inter_api.rb +1 -3
- metadata +3 -7
- data/lib/inter_api/payment_error.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cffa20a97fdb046b24f8ca8fc61d2b1f49784ce69b9fbb2d7a0a2f2dc7fb69b
|
4
|
+
data.tar.gz: 42786c125f148c254f2900352139b66a0558b6080daf34cfce5a2695998d4c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c5dba5c4a6f064ba16434e4e858e1f473ff8f9a3f0d14515acf1b2f1eb25a4060b1374b86d5a1fcd36ccd8af7db601fc37a215f15c6c1cbe0feca2287f23e3e
|
7
|
+
data.tar.gz: 1a22c4b3025bc13d23b14719fedcbc4bfa25b47da6cac7eee0a2a6302fe1e26a11624f90fa42f1b555a97155c76b88a88d3fdf7504c81dc1ab7de809ea059be9
|
@@ -5,8 +5,7 @@ module InterApi
|
|
5
5
|
SAVE_RESPONSES = true
|
6
6
|
|
7
7
|
attr_reader :crt, :key, :client_id, :client_secret, :chave_pix, :conta_corrente, :scopes
|
8
|
-
|
9
|
-
def initialize(crt:, key:, client_id:, client_secret:, chave_pix:, conta_corrente:, scopes: "cobv.write cobv.read cob.write cob.read pix.write pix.read webhook.read webhook.write", token: nil, token_expires_at: nil)
|
8
|
+
def initialize(crt:, key:, client_id:, client_secret:, chave_pix:, conta_corrente:, scopes: "cobv.write cobv.read cob.write cob.read pix.write pix.read webhook.read webhook.write", access_token: nil, token_expires_at: nil)
|
10
9
|
@crt = crt
|
11
10
|
@key = key
|
12
11
|
@client_id = client_id
|
@@ -14,14 +13,22 @@ module InterApi
|
|
14
13
|
@chave_pix = chave_pix
|
15
14
|
@conta_corrente = conta_corrente
|
16
15
|
@scopes = scopes
|
17
|
-
@
|
16
|
+
@access_token= access_token
|
18
17
|
@token_expires_at = token_expires_at
|
19
|
-
if @token.nil? || @token_expires_at < Time.now
|
20
|
-
authenticate!
|
21
|
-
end
|
22
18
|
end
|
23
19
|
|
24
|
-
def
|
20
|
+
def default_options
|
21
|
+
{
|
22
|
+
sslcert: crt,
|
23
|
+
sslkey: key,
|
24
|
+
headers: {
|
25
|
+
"Content-Type" => "application/json",
|
26
|
+
"x-conta-corrente" => @conta_corrente
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def refresh_token
|
25
32
|
headers = {
|
26
33
|
"Content-Type" => "application/x-www-form-urlencoded"
|
27
34
|
}
|
@@ -31,18 +38,18 @@ module InterApi
|
|
31
38
|
grant_type: "client_credentials",
|
32
39
|
scope: @scopes
|
33
40
|
}
|
34
|
-
response = post("/oauth/v2/token", headers
|
35
|
-
@
|
36
|
-
@token_expires_at = Time.now + response.
|
41
|
+
response = post("/oauth/v2/token", headers:, body:, skip_authentication: true)
|
42
|
+
@access_token = response.access_token
|
43
|
+
@token_expires_at = Time.now + response.expires_in
|
37
44
|
end
|
38
45
|
|
39
46
|
def get_payment_request(payment_id)
|
40
|
-
|
47
|
+
get("/pix/v2/cob/#{payment_id}")
|
41
48
|
end
|
42
49
|
|
43
50
|
def get_payment(payment_id)
|
44
|
-
response = get("/pix/v2/cob/#{payment_id}"
|
45
|
-
InterApi::Payment.new(response
|
51
|
+
response = get("/pix/v2/cob/#{payment_id}")
|
52
|
+
InterApi::Payment.new(response, self)
|
46
53
|
end
|
47
54
|
|
48
55
|
def create_payment_request(**args_body)
|
@@ -59,7 +66,7 @@ module InterApi
|
|
59
66
|
solicitacaoPagador: args_body[:solicitacao_pagador],
|
60
67
|
infoAdicionais: args_body[:info_adicionais]
|
61
68
|
}
|
62
|
-
|
69
|
+
post("/pix/v2/cob", body:)
|
63
70
|
end
|
64
71
|
|
65
72
|
def create_payment(amount:, payer_tax_id: nil, payer_name: nil, expiration: 3600, solicitacao_pagador: nil, info_adicionais: [])
|
@@ -77,22 +84,21 @@ module InterApi
|
|
77
84
|
}
|
78
85
|
body[:devedor] = build_devedor(payer_tax_id, payer_name) if payer_tax_id && payer_name
|
79
86
|
|
80
|
-
response = post("/pix/v2/cob",
|
81
|
-
InterApi::Payment.new(response
|
87
|
+
response = post("/pix/v2/cob", body:)
|
88
|
+
InterApi::Payment.new(response, self)
|
82
89
|
end
|
83
90
|
|
84
91
|
def update_payment_request(payment_id, body)
|
85
|
-
|
92
|
+
patch("/pix/v2/cob/#{payment_id}", body:)
|
86
93
|
end
|
87
94
|
|
88
95
|
def update_payment(payment_id, body)
|
89
|
-
response = patch("/pix/v2/cob/#{payment_id}",
|
90
|
-
InterApi::Payment.new(response
|
96
|
+
response = patch("/pix/v2/cob/#{payment_id}", body:)
|
97
|
+
InterApi::Payment.new(response, self)
|
91
98
|
end
|
92
99
|
|
93
100
|
def get_refund(end_to_end_id, id)
|
94
|
-
|
95
|
-
response.json
|
101
|
+
get("/pix/v2/pix/#{end_to_end_id}/devolucao/#{id}")
|
96
102
|
end
|
97
103
|
|
98
104
|
def refund_payment(end_to_end_id, amount, refund_nature, description)
|
@@ -102,20 +108,18 @@ module InterApi
|
|
102
108
|
natureza: refund_nature,
|
103
109
|
descricao: description
|
104
110
|
}
|
105
|
-
|
106
|
-
response.json
|
111
|
+
put("/pix/v2/pix/#{end_to_end_id}/devolucao/#{id}", body:)
|
107
112
|
end
|
108
113
|
|
109
114
|
def update_webhook(url)
|
110
115
|
body = {
|
111
116
|
webhookUrl: url
|
112
117
|
}
|
113
|
-
put("/pix/v2/webhook/#{@chave_pix}",
|
118
|
+
put("/pix/v2/webhook/#{@chave_pix}", body:)
|
114
119
|
end
|
115
120
|
|
116
121
|
def get_webhook
|
117
|
-
|
118
|
-
response.json
|
122
|
+
get("/pix/v2/webhook/#{@chave_pix}")
|
119
123
|
end
|
120
124
|
|
121
125
|
private
|
@@ -128,18 +132,5 @@ module InterApi
|
|
128
132
|
"nome" => payer_name
|
129
133
|
}
|
130
134
|
end
|
131
|
-
|
132
|
-
def build_headers
|
133
|
-
{
|
134
|
-
"x-conta-corrente" => @conta_corrente,
|
135
|
-
"Authorization" => "Bearer #{@token}",
|
136
|
-
"Content-Type" => "application/json"
|
137
|
-
}
|
138
|
-
end
|
139
|
-
|
140
|
-
def validate_response(response, required_response_key)
|
141
|
-
puts response.json unless response.success?
|
142
|
-
![500, 429].include?(response.code) || response.json.dig(*required_response_key)
|
143
|
-
end
|
144
135
|
end
|
145
136
|
end
|
data/lib/inter_api/payment.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
module InterApi
|
2
2
|
class Payment
|
3
|
-
attr_reader :response, :txid, :end_to_end_id, :devolucoes, :copia_e_cola, :status, :solicitacao, :info_adicionais, :valor_original, :valor_pago, :criacao, :expiracao, :pago_em, :devedor_nome, :devedor_tax_id
|
3
|
+
attr_reader :response, :txid, :end_to_end_id, :devolucoes, :copia_e_cola, :status, :solicitacao, :info_adicionais, :valor_original, :valor_pago, :criacao, :expiracao, :pago_em, :devedor_nome, :devedor_tax_id
|
4
4
|
def initialize(response, client)
|
5
5
|
@client = client
|
6
6
|
@response = response
|
7
|
-
@txid = response.
|
8
|
-
@end_to_end_id =
|
9
|
-
@devolucoes =
|
10
|
-
@copia_e_cola = response.
|
11
|
-
@status = response.
|
12
|
-
@solicitacao = response
|
13
|
-
@info_adicionais = response.
|
14
|
-
@valor_original = response.
|
15
|
-
@valor_pago =
|
7
|
+
@txid = response.txid
|
8
|
+
@end_to_end_id = end_to_end
|
9
|
+
@devolucoes = devolutions
|
10
|
+
@copia_e_cola = response.pixCopiaECola
|
11
|
+
@status = response.status
|
12
|
+
@solicitacao = response["solicitacaoPagador"]
|
13
|
+
@info_adicionais = response.infoAdicionais
|
14
|
+
@valor_original = response.valor.original
|
15
|
+
@valor_pago = total_paid
|
16
16
|
@criacao = creation_date
|
17
17
|
@expiracao = expiration_date
|
18
18
|
@pago_em = paid_date
|
19
|
-
@devedor_nome =
|
20
|
-
@devedor_tax_id =
|
21
|
-
@internal_error = PaymentError.new(response).internal_error
|
19
|
+
@devedor_nome = debtor_name
|
20
|
+
@devedor_tax_id = debtor_tax_id
|
22
21
|
end
|
23
22
|
|
24
23
|
def paid? external_value = nil
|
@@ -62,18 +61,43 @@ module InterApi
|
|
62
61
|
private
|
63
62
|
|
64
63
|
def creation_date
|
65
|
-
return nil unless @response.
|
66
|
-
Time.new(@response.
|
64
|
+
return nil unless @response.calendario.criacao
|
65
|
+
Time.new(@response.calendario.criacao)
|
67
66
|
end
|
68
67
|
|
69
68
|
def expiration_date
|
70
|
-
return nil unless @response.
|
71
|
-
Time.new(@response.
|
69
|
+
return nil unless @response.calendario.criacao
|
70
|
+
Time.new(@response.calendario.criacao) + @response.calendario.expiracao
|
72
71
|
end
|
73
72
|
|
74
73
|
def paid_date
|
75
|
-
return nil unless @response
|
76
|
-
Time.new(@response.
|
74
|
+
return nil unless @response["pix"] && @response.pix.any? && @response.pix[0].horario
|
75
|
+
Time.new(@response.pix[0].horario)
|
76
|
+
end
|
77
|
+
|
78
|
+
def debtor_name
|
79
|
+
return nil unless @response["devedor"]
|
80
|
+
@response.devedor.nome
|
81
|
+
end
|
82
|
+
|
83
|
+
def debtor_tax_id
|
84
|
+
return nil unless @response["devedor"]
|
85
|
+
@response.devedor.cpf || @response.devedor.cnpj
|
86
|
+
end
|
87
|
+
|
88
|
+
def end_to_end
|
89
|
+
return nil unless @response["pix"] && @response.pix.any?
|
90
|
+
@response.pix[0].endToEndId
|
91
|
+
end
|
92
|
+
|
93
|
+
def devolutions
|
94
|
+
return nil unless @response["pix"] && @response.pix.any?
|
95
|
+
@response.pix[0].devolucoes
|
96
|
+
end
|
97
|
+
|
98
|
+
def total_paid
|
99
|
+
return nil unless @response["pix"] && @response.pix.any?
|
100
|
+
@response.pix[0].valor
|
77
101
|
end
|
78
102
|
end
|
79
103
|
end
|
data/lib/inter_api/version.rb
CHANGED
data/lib/inter_api.rb
CHANGED
@@ -9,7 +9,6 @@ require "ac"
|
|
9
9
|
require_relative "inter_api/version"
|
10
10
|
require "inter_api/client_production"
|
11
11
|
require "inter_api/payment"
|
12
|
-
require "inter_api/payment_error"
|
13
12
|
|
14
13
|
module InterApi
|
15
14
|
Typhoeus::Config.timeout = 10
|
@@ -23,8 +22,7 @@ module InterApi
|
|
23
22
|
body = {
|
24
23
|
valor: format("%.2f", amount)
|
25
24
|
}
|
26
|
-
|
27
|
-
response.json
|
25
|
+
post("/pix/v2/cob/pagar/#{payment_id}", body:)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inter_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todas Essas Coisas
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: ac
|
@@ -82,7 +81,6 @@ files:
|
|
82
81
|
- lib/inter_api.rb
|
83
82
|
- lib/inter_api/client_production.rb
|
84
83
|
- lib/inter_api/payment.rb
|
85
|
-
- lib/inter_api/payment_error.rb
|
86
84
|
- lib/inter_api/version.rb
|
87
85
|
- sig/inter_api.rbs
|
88
86
|
homepage: https://github.com/todasessascoisas/inter_api
|
@@ -92,7 +90,6 @@ metadata:
|
|
92
90
|
homepage_uri: https://github.com/todasessascoisas/inter_api
|
93
91
|
source_code_uri: https://github.com/todasessascoisas/inter_api
|
94
92
|
changelog_uri: https://github.com/todasessascoisas/inter_api
|
95
|
-
post_install_message:
|
96
93
|
rdoc_options: []
|
97
94
|
require_paths:
|
98
95
|
- lib
|
@@ -107,8 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
104
|
- !ruby/object:Gem::Version
|
108
105
|
version: '0'
|
109
106
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
111
|
-
signing_key:
|
107
|
+
rubygems_version: 3.6.9
|
112
108
|
specification_version: 4
|
113
109
|
summary: ''
|
114
110
|
test_files: []
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module InterApi
|
2
|
-
class PaymentError
|
3
|
-
STATUS_ERROR = [400, 403, 404, 503]
|
4
|
-
attr_accessor :json_response
|
5
|
-
def initialize json_response
|
6
|
-
@json_response = json_response
|
7
|
-
end
|
8
|
-
|
9
|
-
def internal_error
|
10
|
-
return nil unless json_response["violacoes"] || STATUS_ERROR.include?(json_response["status"])
|
11
|
-
failed_message_error || rejected_message_error || "Pagamento recusado."
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def rejected_message_error
|
17
|
-
"#{json_response["title"]} => #{json_response["detail"]}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def failed_message_error
|
21
|
-
return false unless json_response["violacoes"]
|
22
|
-
"#{json_response["violacoes"][0]["razao"]} => #{json_response["violacoes"][0]["propriedade"]}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|