inter_api 1.2.0 → 1.2.2
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 +16 -3
- data/lib/inter_api/payment.rb +10 -3
- data/lib/inter_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a2555a22b99f4a0e9a14bcbb073f041b4ac7c0eaa4e9ef84a0a00991c27ca37
|
4
|
+
data.tar.gz: 6151582d3b22e91d83a20ce821490b7b93d4e8b69b9079d6d694330a70df270e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f01af849e0129792c48c37b76cc775e6dda0b40dde454ced0ffa4cbdfdf1cfb4499729911e4b6360dc2299dd14bddcb6ebed59ed312a4f8661bd833a2e6b60bb
|
7
|
+
data.tar.gz: 7fb2300d3b7dfc5f63042e60664e44c924fab5a595b72e5367eb9555bbc1b88b55a4cb11e93b463a7160eb3568adc7770ad3f974ef99246317eb66008124ea6e
|
@@ -5,7 +5,7 @@ module InterApi
|
|
5
5
|
|
6
6
|
attr_reader :crt, :key, :client_id, :client_secret, :chave_pix, :conta_corrente, :scopes
|
7
7
|
attr_accessor :token, :token_expires_at
|
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", 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", token: nil, token_expires_at: nil)
|
9
9
|
@crt = crt
|
10
10
|
@key = key
|
11
11
|
@client_id = client_id
|
@@ -61,12 +61,11 @@ module InterApi
|
|
61
61
|
post_request("/pix/v2/cob", headers: build_headers, sslcert: @crt, sslkey: @key, body: JSON.dump(body))
|
62
62
|
end
|
63
63
|
|
64
|
-
def create_payment(amount:, payer_tax_id
|
64
|
+
def create_payment(amount:, payer_tax_id: nil, payer_name: nil, expiration: 3600, solicitacao_pagador: nil, info_adicionais: [])
|
65
65
|
body = {
|
66
66
|
calendario: {
|
67
67
|
expiracao: expiration
|
68
68
|
},
|
69
|
-
devedor: build_devedor(payer_tax_id, payer_name),
|
70
69
|
valor: {
|
71
70
|
original: format("%.2f", amount),
|
72
71
|
modalidadeAlteracao: 0
|
@@ -75,6 +74,8 @@ module InterApi
|
|
75
74
|
solicitacaoPagador: solicitacao_pagador,
|
76
75
|
infoAdicionais: info_adicionais
|
77
76
|
}
|
77
|
+
body[:devedor] = build_devedor(payer_tax_id, payer_name) if payer_tax_id && payer_name
|
78
|
+
|
78
79
|
response = post("/pix/v2/cob", headers: build_headers, sslcert: @crt, sslkey: @key, body: JSON.dump(body)) { |response| validate_response(response, "txid") }
|
79
80
|
InterApi::Payment.new(response.json, self)
|
80
81
|
end
|
@@ -104,6 +105,18 @@ module InterApi
|
|
104
105
|
response.json
|
105
106
|
end
|
106
107
|
|
108
|
+
def update_webhook(url)
|
109
|
+
body = {
|
110
|
+
webhookUrl: url
|
111
|
+
}
|
112
|
+
put("/pix/v2/webhook/#{@chave_pix}", headers: build_headers, sslcert: @crt, sslkey: @key, body: JSON.dump(body)) { |response| response.success? }
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_webhook
|
116
|
+
response = get("/pix/v2/webhook/#{@chave_pix}", headers: build_headers, sslcert: @crt, sslkey: @key) { |response| validate_response(response, "webhookUrl") }
|
117
|
+
response.json
|
118
|
+
end
|
119
|
+
|
107
120
|
private
|
108
121
|
|
109
122
|
def build_devedor(payer_tax_id, payer_name)
|
data/lib/inter_api/payment.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
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, :devedor_nome, :devedor_tax_id, :internal_error
|
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, :internal_error
|
4
4
|
def initialize(response, client)
|
5
5
|
@client = client
|
6
6
|
@response = response
|
@@ -15,13 +15,15 @@ module InterApi
|
|
15
15
|
@valor_pago = response.dig("pix", 0, "valor")
|
16
16
|
@criacao = creation_date
|
17
17
|
@expiracao = expiration_date
|
18
|
+
@pago_em = paid_date
|
18
19
|
@devedor_nome = response.dig("devedor", "nome")
|
19
20
|
@devedor_tax_id = response.dig("devedor", "cpf") || response.dig("devedor", "cnpj")
|
20
21
|
@internal_error = PaymentError.new(response).internal_error
|
21
22
|
end
|
22
23
|
|
23
|
-
def paid?
|
24
|
-
|
24
|
+
def paid? external_value = nil
|
25
|
+
external_value = @valor_original if external_value.nil?
|
26
|
+
@status == "CONCLUIDA" && @valor_original.to_d == @valor_pago.to_d && external_value.to_d == @valor_pago.to_d
|
25
27
|
end
|
26
28
|
|
27
29
|
def valid?
|
@@ -68,5 +70,10 @@ module InterApi
|
|
68
70
|
return nil unless @response.dig("calendario", "criacao")
|
69
71
|
Time.new(@response.dig("calendario", "criacao")) + @response.dig("calendario", "expiracao")
|
70
72
|
end
|
73
|
+
|
74
|
+
def paid_date
|
75
|
+
return nil unless @response.dig("pix", 0, "horario")
|
76
|
+
Time.new(@response.dig("pix", 0, "horario"))
|
77
|
+
end
|
71
78
|
end
|
72
79
|
end
|
data/lib/inter_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inter_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todas Essas Coisas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ac
|