Add donation functionality to encourage community support, including a footer card on the home page, a highlighted "Apoiar" link in the header, and comprehensive English messages for the donation section to promote transparency and user engagement.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { abacatePay } from "@/lib/abacatepay";
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const payload = await request.text();
|
|
const signature = request.headers.get("x-abacatepay-signature");
|
|
|
|
if (!signature || !abacatePay.verifyWebhookSignature(payload, signature)) {
|
|
return NextResponse.json(
|
|
{ error: "Assinatura inválida" },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
const event = JSON.parse(payload);
|
|
|
|
if (event.type === "billing.paid") {
|
|
// Processar doação confirmada
|
|
console.log("Donation confirmed:", event.data.id);
|
|
|
|
// Aqui você pode:
|
|
// 1. Salvar no banco de dados
|
|
// 2. Enviar email de agradecimento
|
|
// 3. Atualizar estatísticas
|
|
// 4. Notificar a equipe
|
|
|
|
// Por enquanto, apenas log
|
|
console.log("Donation details:", {
|
|
id: event.data.id,
|
|
amount: event.data.amount,
|
|
metadata: event.data.metadata,
|
|
paidAt: event.data.paidAt,
|
|
});
|
|
}
|
|
|
|
return NextResponse.json({ success: true });
|
|
} catch (error) {
|
|
console.error("Webhook error:", error);
|
|
return NextResponse.json(
|
|
{ error: "Erro ao processar webhook" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|