Add content pages (contact, events, happy tails, sponsors, donate)
All pages use config-driven org info via data.orgConfig — no hardcoded org names, emails, or external URLs. Stripe donate page gracefully falls back to a contact CTA when STRIPE_SECRET_KEY is not configured. RateLimiter applied to contact form and happy tails submission. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { getPageBlocks } from '$lib/server/content';
|
||||
import { createDonationCheckout } from '$lib/server/stripe';
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad, Actions } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ url, parent }) => {
|
||||
const parentData = await parent();
|
||||
const content = await getPageBlocks('donate');
|
||||
const paymentStatus = url.searchParams.get('payment');
|
||||
const stripeEnabled = Boolean(process.env.STRIPE_SECRET_KEY);
|
||||
|
||||
return { ...parentData, content, stripeEnabled, paymentStatus };
|
||||
};
|
||||
|
||||
export const actions: Actions = {
|
||||
donate: async ({ request, url }) => {
|
||||
if (!process.env.STRIPE_SECRET_KEY) {
|
||||
return fail(503, { donateError: 'Online payment is not available at this time.' });
|
||||
}
|
||||
|
||||
const fd = await request.formData();
|
||||
const amountStr = fd.get('amount')?.toString().trim();
|
||||
const email = fd.get('email')?.toString().trim() || undefined;
|
||||
|
||||
if (!amountStr) {
|
||||
return fail(400, { donateError: 'Please enter a donation amount.' });
|
||||
}
|
||||
|
||||
const amount = parseFloat(amountStr);
|
||||
if (isNaN(amount) || amount < 1) {
|
||||
return fail(400, { donateError: 'Please enter a valid amount of at least $1.00.' });
|
||||
}
|
||||
|
||||
if (amount > 99999) {
|
||||
return fail(400, {
|
||||
donateError: 'Please enter a smaller amount or contact us directly.'
|
||||
});
|
||||
}
|
||||
|
||||
const baseUrl = url.origin;
|
||||
const checkoutUrl = await createDonationCheckout({
|
||||
amount: Math.round(amount * 100), // convert to cents
|
||||
donorEmail: email,
|
||||
successUrl: `${baseUrl}/donate?payment=success`,
|
||||
cancelUrl: `${baseUrl}/donate?payment=cancelled`
|
||||
});
|
||||
|
||||
if (!checkoutUrl) {
|
||||
return fail(503, {
|
||||
donateError: 'Unable to create payment session. Please try again later.'
|
||||
});
|
||||
}
|
||||
|
||||
redirect(303, checkoutUrl);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user