Front-end
Copiar
<form id="payment-form">
<div id="card-element"></div>
<button id="submit-btn" type="submit">Pagar</button>
</form>
Back-end
Copiar
app.post("/api/pay", async (req, res) => {
const { token, amount, installments } = req.body;
const response = await fetch("https://api-sandbox.pagou.ai/v2/transactions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.PAGOU_TOKEN}`,
},
body: JSON.stringify({
external_ref: "order_2001",
amount,
currency: "BRL",
method: "credit_card",
token,
installments,
buyer: {
name: "Ada Lovelace",
email: "ada@example.com",
document: {
type: "CPF",
number: "12345678901",
},
},
products: [{ name: "Atualização de plano", price: amount, quantity: 1 }],
}),
});
res.json(await response.json());
});

