O Content-type me parece ser "application/json"... mas se qualquer Content-Type está valendo, aí tá tudo bem. Eu acho que a Efí não manda Authorization no webhook, pq já é enviado com client-certificate no TLS.
O Content-type me parece ser "application/json"... mas se qualquer Content-Type está valendo, aí tá tudo bem. Eu acho que a Efí não manda Authorization no webhook, pq já é enviado com client-certificate no TLS.
# encoding: utf-8
from efipay import EfiPay
import sys
# Configurações de credenciais
credentials = {
'client_id': '',
'client_secret': '',
'sandbox': False, # Altere para True se estiver usando o ambiente de sandbox
'certificate': r''
}
def obter_dados_usuario():
try:
chave_pix = input("Informe a chave PIX do destinatário: ")
valor = input("Informe o valor da transferência: ")
# Verificando se os valores informados são válidos
if not chave_pix:
raise ValueError("A chave PIX não pode ser vazia.")
# Substituir vírgula por ponto e converter para float
valor_float = float(valor.replace(',', '.'))
if valor_float <= 0:
raise ValueError("O valor deve ser um número positivo.")
return chave_pix, "{:.2f}".format(valor_float)
except ValueError as ve:
print(f"Erro de validação: {ve}")
sys.exit(1)
Obrigado @guilherme_efi, mas o retorno foi o mesmo
[Done] exited with code=1 in 1.923 seconds
[Running] node "c:\GERENCIA_NET_EFI\SDK_Node\sdk-node-apis-efi-master\examples\pix\send\pixSend.js"
c:\GERENCIA_NET_EFI\SDK_Node\sdk-node-apis-efi-master\node_modules\sdk-node-apis-efi\lib\endpoints.js:48
throw FALHA AO LER O CERTIFICADO, VERIFIQUE O CAMINHO INFORMADO: ${this.options.certificate}
^
FALHA AO LER O CERTIFICADO, VERIFIQUE O CAMINHO INFORMADO: c:\GERENCIA_NET_EFI\SDK_Node\sdk-node-apis-efi-master\examplesC:GERENCIA_NET_EFIPJCERTIFICADOSproducao-570499-CERT_PRODUCAO_GDB.p12
(Use node --trace-uncaught ... to show where the exception was thrown)
Node.js v21.6.2
[Done] exited with code=1 in 0.729 seconds
Oi, @gil.brandao0067. Bom dia!
Esta mudança que o João mencionou não altera na SDK. Você irá apenas incluir o __dirname junto com as [credenciais](https://github.com/efipay/sdk-node-apis-efi/blob/master/examples/credentials.js#L7) para indicar o caminho absoluto para o certificado.
Exemplo:
om dia consultores!
Estou com aquele típico problema de fácil solução, mas que não se enxerga sem o olhar técnico.
Falha na leitura do certificado. Acreditem, ele está nesse caminho.
Conto com a solidária e preciosa ajuda, pois, estou desde sexta feira tentando concluir essa integração e isso está me consumindo sem necessidade. Gero pix em Homologação, mas preciso botar para moer esse projeto em tempo real de produção.
[Running] node "c:\GERENCIA_NET_EFI\SDK_Node\sdk-node-apis-efi-master\examples\pix\send\pixSend.js"
c:\GERENCIA_NET_EFI\SDK_Node\sdk-node-apis-efi-master\node_modules\sdk-node-apis-efi\lib\endpoints.js:48
throw FALHA AO LER O CERTIFICADO, VERIFIQUE O CAMINHO INFORMADO: ${this.options.certificate}
^
FALHA AO LER O CERTIFICADO, VERIFIQUE O CAMINHO INFORMADO: C:GERENCIA_NET_EFIPJCERTIFICADOSproducao-570499-CERT_PRODUCAO_GDB.p12
(Use node --trace-uncaught ... to show where the exception was thrown)
Node.js v21.6.2
Bom dia consultores!
Estou com aquele típico problema de fácil solução, mas que não se enxerga sem o olhar técnico.
Falha na leitura do certificado. Acreditem, ele está nesse caminho.
Conto com a solidária e preciosa ajuda, pois, estou desde sexta feira tentando concluir essa integração e isso está me consumindo sem necessidade. Gero pix em Homologação, mas preciso botar para moer esse projeto em tempo real de produção.
[Running] node "c:\GERENCIA_NET_EFI\SDK_Node\sdk-node-apis-efi-master\examples\pix\send\pixSend.js"
c:\GERENCIA_NET_EFI\SDK_Node\sdk-node-apis-efi-master\node_modules\sdk-node-apis-efi\lib\endpoints.js:48
throw FALHA AO LER O CERTIFICADO, VERIFIQUE O CAMINHO INFORMADO: ${this.options.certificate}
^
FALHA AO LER O CERTIFICADO, VERIFIQUE O CAMINHO INFORMADO: C:GERENCIA_NET_EFIPJCERTIFICADOSproducao-570499-CERT_PRODUCAO_GDB.p12
(Use node --trace-uncaught ... to show where the exception was thrown)
Node.js v21.6.2
import as EfiPay from 'sdk-node-apis-efi'
import { Injectable } from '@nestjs/common'
import 'dotenv/config'
@Injectable()
export class PixService {
private efiPay = new EfiPay({
sandbox: false,
client_id: process.env.EFIPAY_CLIENT_ID,
client_secret: process.env.EFIPAY_CLIENT_SECRET,
certificate: './certs/producao-453290-LinkZap-v2.p12',
})
constructor() {
//
}
public async getBalance() {
const { saldo } = await this.efiPay.getAccountBalance()
return Number(saldo)
}
public async payPix(pixCode: string, amount: number) {
const balance = await this.getBalance()
if (balance < amount) {
throw new Error('Saldo insuficiente')
}
try {
const response = await this.efiPay.pixSend(
{ idEnvio: '01' },
{
valor: amount,
pagador: {
chave: 'a4c3dcd3-0005-454e-957f-df416a63c4ed',
},
favorecido: {
chave: pixCode,
},
},
)
return response
} catch (error) {
console.log(error)
}
}
}
A API é aberta e descrita nos endpoints, não precisa usar SDK... nós não usamos na nossa integração, apesar deles terem um SDK Golang.
Aonde colocar o certificado é uma questão do seu ambiente local, pq o certificado é usado para estabelecer a conexão... mas sim, se seu ambiente tem uma opção certificate no payload, tem grande cara de ser aí mesmo.
E sim, sem o certificado nem fecha a conexão, então nem vai ter mensagem de erro da Efí, só do seu ambiente local.
Estou tentando gerar o OAuthToken por meio da URL https://api-pix-h.gerencianet.com.br/oauth/token" class="link-msg" >https://api-pix-h.gerencianet.com.br/oauth/token mas sempre retornando um erro: Exception: Address unavailable: https://api-pix-h.gerencianet.com.br/oauth/token.
Acredito que tenha a ver com o certificado, se eu convertesse ele para Bas64, poderia adicioná-lo no payload dentro da chave "certificate"? Ou teria outro lugar?
processing: https://pix.api.efipay.com.br/oauth/token
Trying 52.3.67.197:443...
Connected to pix.api.efipay.com.br (52.3.67.197) port 443
CAfile: none
CApath: none
ALPN: offers http/1.1
NSS: client certificate from file
subject: C=BR,CN=301970
start date: May 19 20:28:50 2021 GMT
expire date: May 19 20:28:50 2024 GMT
common name: 301970
issuer: [email protected],CN=api-pix.gerencianet.com.br,OU=Infraestrutura,O=Gerencianet Pagamentos do Brasil Ltda,ST=Minas Gerais,C=BR
ALPN: server accepted http/1.1
SSL connection using TLS_AES_256_GCM_SHA384
Server certificate:
subject: CN=.api.efipay.com.br,O=EFI S.A. - INSTITUICAO DE PAGAMENTO,L=OURO PRETO,ST=MINAS GERAIS,C=BR
start date: May 17 19:31:27 2023 GMT
expire date: Jun 17 19:31:26 2024 GMT
common name: .api.efipay.com.br
issuer: CN=GlobalSign RSA OV SSL CA 2018,O=GlobalSign nv-sa,C=BE
using HTTP/1.1
> POST /oauth/token HTTP/1.1
Host: pix.api.efipay.com.br
api-sdk: efi-php-1.8.0
User-Agent: GuzzleHttp/7
Content-Type: application/json
Authorization: Basic Q2xpZW50X0lkXzcwMWE0OGU2ZWExMDM0ODk5NjAxNTIzY2VmZjY5ZTZlM2M4OGVjMDA6Q2xpZW50X1NlY3JldF9hMDYyZmU5OWE0NjhmYjViZjIzZmE0YzgwMTUyZDFlM2RhNWIzNjFj
Content-Length: 35
Empty reply from server
Closing connection
Agora estou recebendo a seguinte mensagem:
processing: https://pix.api.efipay.com.br/oauth/token
Trying 35.170.124.249:443...
Connected to pix.api.efipay.com.br (35.170.124.249) port 443
CAfile: none
CApath: none
ALPN: offers http/1.1
NSS: client certificate from file
subject: C=BR,CN=301970
start date: May 02 14:50:05 2024 GMT
expire date: May 02 14:50:05 2027 GMT
common name: 301970
issuer: [email protected],CN=apis.efipay.com.br,OU=Infraestrutura,O=Efi S.A. - Instituicao de Pagamento,ST=Minas Gerais,C=BR
ALPN: server accepted http/1.1
SSL connection using TLS_AES_256_GCM_SHA384
Server certificate:
subject: CN=.api.efipay.com.br,O=EFI S.A. - INSTITUICAO DE PAGAMENTO,L=OURO PRETO,ST=MINAS GERAIS,C=BR
start date: May 17 19:31:27 2023 GMT
expire date: Jun 17 19:31:26 2024 GMT
common name: .api.efipay.com.br
issuer: CN=GlobalSign RSA OV SSL CA 2018,O=GlobalSign nv-sa,C=BE
using HTTP/1.1
> POST /oauth/token HTTP/1.1
Host: pix.api.efipay.com.br
api-sdk: efi-php-1.8.0
User-Agent: GuzzleHttp/7
Content-Type: application/json
Authorization: Basic Q2xpZW50X0lkXzcwMWE0OGU2ZWExMDM0ODk5NjAxNTIzY2VmZjY5ZTZlM2M4OGVjMDA6Q2xpZW50X1NlY3JldF9hMDYyZmU5OWE0NjhmYjViZjIzZmE0YzgwMTUyZDFlM2RhNWIzNjFj
Content-Length: 35
Empty reply from server
Closing connection