Skip to content

Commit 20ce506

Browse files
authored
Create fgts.js
1 parent cbe0233 commit 20ce506

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

fgts.js

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// ===============================
2+
// CONFIGURAÇÕES INICIAIS
3+
// ===============================
4+
const AUTH_URL = "https://auth.v8sistema.com/oauth/token";
5+
const API_URL = "https://bff.v8sistema.com";
6+
7+
// 🚨 Preencha com seus dados
8+
const CLIENT_ID = "DHWogdaYmEI8n5bwwxPDzulMlSK7dwIn";
9+
const USER_EMAIL = "SEU_EMAIL_AQUI";
10+
const USER_PASSWORD = "SUA_SENHA_AQUI";
11+
12+
// ===============================
13+
// 1. AUTENTICAÇÃO
14+
// ===============================
15+
async function autenticar() {
16+
const res = await fetch(AUTH_URL, {
17+
method: "POST",
18+
headers: { "Content-Type": "application/json" },
19+
body: JSON.stringify({
20+
client_id: CLIENT_ID,
21+
audience: "https://bff.v8sistema.com",
22+
scope: "offline_access",
23+
username: USER_EMAIL,
24+
password: USER_PASSWORD,
25+
grant_type: "password"
26+
})
27+
});
28+
29+
const data = await res.json();
30+
if (!data.access_token) {
31+
console.log("❌ Erro ao autenticar:", data);
32+
return null;
33+
}
34+
35+
console.log("🔑 Token obtido com sucesso!");
36+
return data.access_token;
37+
}
38+
39+
// ===============================
40+
// 2. CONSULTA DE SALDO FGTS
41+
// ===============================
42+
async function consultarSaldoFGTS(cpf, provider = "bms") {
43+
const token = await autenticar();
44+
if (!token) return;
45+
46+
const res = await fetch(`${API_URL}/fgts/balance`, {
47+
method: "POST",
48+
headers: {
49+
"Authorization": `Bearer ${token}`,
50+
"Content-Type": "application/json"
51+
},
52+
body: JSON.stringify({
53+
documentNumber: cpf,
54+
provider
55+
})
56+
});
57+
58+
const data = await res.json();
59+
console.log("🔍 Consulta iniciada:", data);
60+
61+
return data;
62+
}
63+
64+
// ===============================
65+
// 3. BUSCAR RESULTADO DA CONSULTA
66+
// ===============================
67+
async function buscarResultadoSaldo(cpf) {
68+
const token = await autenticar();
69+
if (!token) return;
70+
71+
const res = await fetch(`${API_URL}/fgts/balance?search=${cpf}`, {
72+
method: "GET",
73+
headers: { "Authorization": `Bearer ${token}` }
74+
});
75+
76+
const data = await res.json();
77+
console.log("📊 Resultado do saldo FGTS:", data);
78+
79+
return data;
80+
}
81+
82+
// ===============================
83+
// 4. CRIAR PROPOSTA FGTS
84+
// ===============================
85+
async function criarPropostaFGTS(payload) {
86+
const token = await autenticar();
87+
if (!token) return;
88+
89+
const res = await fetch(`${API_URL}/fgts/proposal`, {
90+
method: "POST",
91+
headers: {
92+
"Authorization": `Bearer ${token}`,
93+
"Content-Type": "application/json"
94+
},
95+
body: JSON.stringify(payload)
96+
});
97+
98+
const data = await res.json();
99+
console.log("📝 Proposta criada:", data);
100+
101+
return data;
102+
}
103+
104+
// ===============================
105+
// 5. LISTAR PROPOSTAS POR CPF
106+
// ===============================
107+
async function listarPropostas(cpf, status = "") {
108+
const token = await autenticar();
109+
if (!token) return;
110+
111+
const url = `${API_URL}/fgts/proposal?search=${cpf}&status=${status}&page=1&limit=20`;
112+
113+
const res = await fetch(url, {
114+
method: "GET",
115+
headers: { "Authorization": `Bearer ${token}` }
116+
});
117+
118+
const data = await res.json();
119+
console.log("📁 Propostas encontradas:", data);
120+
121+
return data;
122+
}
123+
124+
// ===============================
125+
// 6. DETALHAR PROPOSTA POR ID
126+
// ===============================
127+
async function detalharProposta(id) {
128+
const token = await autenticar();
129+
if (!token) return;
130+
131+
const res = await fetch(`${API_URL}/fgts/proposal/${id}`, {
132+
method: "GET",
133+
headers: { "Authorization": `Bearer ${token}` }
134+
});
135+
136+
const data = await res.json();
137+
console.log("📄 Detalhes da proposta:", data);
138+
139+
return data;
140+
}
141+
142+
// ===============================
143+
// 7. EXEMPLOS DE USO
144+
// ===============================
145+
146+
// Consultar saldo
147+
// consultarSaldoFGTS("12345678900");
148+
149+
// Buscar resultado da consulta
150+
// buscarResultadoSaldo("12345678900");
151+
152+
// Criar proposta (payload de exemplo)
153+
const exemploProposta = {
154+
documentNumber: "12345678900",
155+
name: "Fulano da Silva",
156+
birthDate: "1990-01-01",
157+
phone: "12999999999",
158+
159+
motherName: "Maria da Silva",
160+
161+
pixKey: "12999999999", // pode ser CPF, email ou telefone
162+
pixType: "phone",
163+
164+
address: {
165+
zipCode: "12345000",
166+
street: "Rua A",
167+
number: "123",
168+
district: "Centro",
169+
city: "São Paulo",
170+
state: "SP"
171+
},
172+
173+
periods: [2025, 2026, 2027], // parcelas antecipadas
174+
bank: "bms" // provedor da análise
175+
};
176+
177+
// Criar proposta
178+
// criarPropostaFGTS(exemploProposta);
179+
180+
// Listar propostas
181+
// listarPropostas("12345678900");
182+
183+
// Detalhar proposta
184+
// detalharProposta("ID_DA_PROPOSTA_AQUI");

0 commit comments

Comments
 (0)