// Cloudflare Pages Function. // Creates a Stripe Express connected account for a mentor and returns a hosted // onboarding link. Stripe collects identity/bank details on its own page — // we never see or store that information ourselves. import Stripe from 'stripe'; export async function onRequestPost(context) { try { const { request, env } = context; const stripe = new Stripe(env.STRIPE_SECRET_KEY, { httpClient: Stripe.createFetchHttpClient(), }); const { mentorEmail, mentorName, country } = await request.json(); const baseUrl = new URL(request.url).origin; const account = await stripe.accounts.create({ type: 'express', country: country || 'US', email: mentorEmail || undefined, business_type: 'individual', capabilities: { card_payments: { requested: true }, transfers: { requested: true }, }, }); const accountLink = await stripe.accountLinks.create({ account: account.id, refresh_url: baseUrl + '/?stripe_refresh=1', return_url: baseUrl + '/?stripe_connected=' + account.id, type: 'account_onboarding', }); return jsonResponse({ url: accountLink.url, accountId: account.id }); } catch (err) { return jsonResponse({ error: err.message }, 500); } } function jsonResponse(body, status) { return new Response(JSON.stringify(body), { status: status || 200, headers: { 'Content-Type': 'application/json' }, }); }