feat(donations): add custom donation tier with flexible amount selection

- Updated support page grid layout to accommodate new custom donation card
- Enhanced API route to validate and process custom donation amounts (min/max limits)
- Modified donation card component to include custom amount input field
- Ensures users can donate any amount within specified range, improving donation flexibility
This commit is contained in:
Evandro Fonseca Junior committed 2025-10-26 22:30:46 -03:00
1 parent 8271d1fa31
commit 5ccc9120c4
4 files changed
+232 -40

No files matched your search

+7 -1
View File
@@ -170,7 +170,7 @@ export default async function SupportPage({
<h2 className="text-3xl font-bold text-center mb-8">
Escolha como apoiar
</h2>
<div className="grid grid-cols-1 md:grid-cols-3 gap-8 max-w-4xl mx-auto">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8 max-w-6xl mx-auto">
<DonationCard
id="coffee"
amount={5}
@@ -196,6 +196,12 @@ export default async function SupportPage({
icon="pizza"
badge={t("tiers.lunch.badge")}
/>
<DonationCard
id="custom"
title="Personalizado"
description="Escolha quanto quer doar"
icon="heart"
/>
</div>
</div>
</BlurFade>
+44 -6
View File
@@ -11,6 +11,7 @@ export async function POST(request: NextRequest) {
"coffee",
"snack",
"lunch",
"custom",
];
if (!body.tier || !validTiers.includes(body.tier)) {
return NextResponse.json(
@@ -22,14 +23,49 @@ export async function POST(request: NextRequest) {
const product =
DONATION_PRODUCTS[body.tier as keyof typeof DONATION_PRODUCTS];
// Se for custom, validar valor enviado
let finalAmount: number;
let finalDescription: string;
if (body.tier === "custom") {
if (!body.customAmount || typeof body.customAmount !== "number") {
return NextResponse.json(
{ success: false, error: "Valor customizado inválido" },
{ status: 400 }
);
}
const minAmount = DONATION_PRODUCTS.custom.minAmount;
const maxAmount = DONATION_PRODUCTS.custom.maxAmount;
if (body.customAmount < minAmount || body.customAmount > maxAmount) {
return NextResponse.json(
{
success: false,
error: `Valor deve estar entre R$ ${minAmount} e R$ ${maxAmount}`,
},
{ status: 400 }
);
}
// Converter para centavos
finalAmount = Math.round(body.customAmount * 100);
finalDescription = `Doação Personalizada - R$ ${body.customAmount.toFixed(
2
)}`;
} else {
finalAmount = product.price;
finalDescription = product.name;
}
let pixData;
// Fluxo: Anônimo ou Identificado
if (body.anonymous === true) {
// Doação anônima - sem customer
pixData = await abacatePay.createPixQrCode({
amount: product.price,
description: product.name,
amount: finalAmount,
description: finalDescription,
expiresIn: 600,
});
@@ -38,8 +74,9 @@ export async function POST(request: NextRequest) {
console.log("📝 Registro de doação anônima:", {
type: "donation_created",
pixId: pixData.id,
amount: product.price,
amount: finalAmount,
tier: body.tier,
customAmount: body.tier === "custom" ? body.customAmount : undefined,
anonymous: true,
createdAt: new Date().toISOString(),
});
@@ -87,8 +124,8 @@ export async function POST(request: NextRequest) {
}
pixData = await abacatePay.createPixQrCode({
amount: product.price,
description: product.name,
amount: finalAmount,
description: finalDescription,
expiresIn: 600,
customer: {
name: body.donorName.trim(),
@@ -103,8 +140,9 @@ export async function POST(request: NextRequest) {
console.log("📝 Registro de doação identificada:", {
type: "donation_created",
pixId: pixData.id,
amount: product.price,
amount: finalAmount,
tier: body.tier,
customAmount: body.tier === "custom" ? body.customAmount : undefined,
anonymous: false,
donor: {
name: body.donorName,