Algo assim funcionaria:
js
import axios from "axios";
import https from "https";
const subdomain = process.env.NODE_ENV === "production" ? "pix" : "pix-h";
const clientCreds = clientId + ":" + clientSecret;
const authorization = Basic ${Buffer.from(clientCreds).toString("base64")};
const certificate = Buffer.from(certificateBase64Encoded, "base64");
const httpsAgent = new https.Agent({
pfx: certificate,
passphrase: "",
});
const oAuthResponse = await axios.post(
https://${subdomain}.api.efipay.com.br/oauth/token,
{
grant_type: "client_credentials",
},
{
headers: {
Authorization: authorization,
"Content-Type": "application/json",
},
httpsAgent,
}
);
const token = oAuthResponse.data.access_token;
const efiApi = axios.create({
baseURL: https://${subdomain}.api.efipay.com.br,
headers: {
Authorization: Bearer ${token},
"Content-Type": "application/json",
},
httpsAgent,
});
await efiApi.put(
/v2/webhook/${process.env.PIX_KEY},
{
webhookUrl:
${process.env.WEBHOOK_BASE_URL}/api/webhook/efi?secret=${process.env.WEBHOOK_SECRET}&ignore=.replace(
"//api",
"/api"
),
},
{
headers: {
"x-skip-mtls-checking": "true",
},
}
);
import axios from "axios";
import https from "https";
const subdomain = process.env.NODE_ENV === "production" ? "pix" : "pix-h";
const clientCreds = clientId + ":" + clientSecret;
const authorization = Basic ${Buffer.from(clientCreds).toString("base64")};
const certificate = Buffer.from(certificateBase64Encoded, "base64");
const httpsAgent = new https.Agent({
pfx: certificate,
passphrase: "",
});
const oAuthResponse = await axios.post(
https://${subdomain}.api.efipay.com.br/oauth/token,
{
grant_type: "client_credentials",
},
{
headers: {
Authorization: authorization,
"Content-Type": "application/json",
},
httpsAgent,
}
);
const token = oAuthResponse.data.access_token;
const efiApi = axios.create({
baseURL: https://${subdomain}.api.efipay.com.br,
headers: {
Authorization: Bearer ${token},
"Content-Type": "application/json",
},
httpsAgent,
});
await efiApi.put(
/v2/webhook/${process.env.PIX_KEY},
{
webhookUrl:
${process.env.WEBHOOK_BASE_URL}/api/webhook/efi?secret=${process.env.WEBHOOK_SECRET}&ignore=.replace(
"//api",
"/api"
),
},
{
headers: {
"x-skip-mtls-checking": "true",
},
}
);