feat: add donation support with footer card and navigation
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.
This commit is contained in:
1 parent
b5093cb49a
commit
01e97eb078
16 files changed
+1161
-2
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { abacatePay } from "@/lib/abacatepay";
|
||||
import { DonationData } from "@/types/donation";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body: DonationData = await request.json();
|
||||
|
||||
// Validação básica
|
||||
if (!body.amount || body.amount < 5 || body.amount > 10000) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: "Valor deve estar entre R$ 5,00 e R$ 10.000,00",
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const billing = await abacatePay.createBilling({
|
||||
amount: body.amount,
|
||||
metadata: {
|
||||
donorName: body.donorName,
|
||||
donorEmail: body.donorEmail,
|
||||
message: body.message,
|
||||
},
|
||||
returnUrl: `${process.env.NEXT_PUBLIC_BASE_URL}/apoiar/obrigado`,
|
||||
completionUrl: `${process.env.NEXT_PUBLIC_BASE_URL}/api/donations/verify`,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
billingId: billing.id,
|
||||
pixCode: billing.pixCode,
|
||||
pixQrCode: billing.pixQrCode,
|
||||
expiresAt: billing.expiresAt,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Donation creation error:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error:
|
||||
error instanceof Error ? error.message : "Erro interno do servidor",
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { abacatePay } from "@/lib/abacatepay";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const billingId = searchParams.get("billingId");
|
||||
|
||||
if (!billingId) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: "ID da cobrança é obrigatório" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const billing = await abacatePay.getBillingStatus(billingId);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
status: billing.status,
|
||||
amount: billing.amount,
|
||||
createdAt: billing.createdAt,
|
||||
expiresAt: billing.expiresAt,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Billing verification error:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error:
|
||||
error instanceof Error ? error.message : "Erro ao verificar cobrança",
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user