Updated support page to use real data instead of mock values, including monthly costs
52 lines
1.4 KiB
TypeScript
52 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.createDonationBilling({
|
|
amount: body.amount,
|
|
donorEmail: body.donorEmail,
|
|
donorName: body.donorName,
|
|
message: body.message,
|
|
});
|
|
|
|
// AbacatePay pode retornar diferentes formatos
|
|
const pixCode = billing.pixCode || billing.qrCode;
|
|
const pixQrCode = billing.pixQrCode || billing.qrCode;
|
|
const paymentUrl = billing.url || billing.paymentUrl;
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
billingId: billing.id,
|
|
paymentUrl, // URL para redirecionar
|
|
pixCode,
|
|
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 }
|
|
);
|
|
}
|
|
}
|