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.
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
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 }
|
|
);
|
|
}
|
|
}
|