/how-to-build-lovable

How to build Donation system with Lovable?

Learn how to build a secure, scalable donation system with Lovable using step by step guidance, best practices, payment integration and analytics.

Book a free  consultation
4.9
Clutch rating 🌟
600+
Happy partners
17+
Countries served
190+
Team members
Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to build Donation system with Lovable?

We’ll build a simple, production-capable donation flow in Lovable: a public Donate page, a server API that creates Stripe Checkout sessions using secrets stored in Lovable Cloud, optional Supabase storage of donation records, and a small admin list to view donations. All changes are done in Lovable Chat Mode (edits/diffs), Preview, and Publish — no terminal required. Use Lovable Secrets for keys, test with Stripe test keys in Preview, and enable Stripe webhooks after Publish.

 

What we’re building / changing (plain English)

 

Public Donate page: amount input, email, Donate button that calls a server API to create a Stripe Checkout session and redirects the user to Checkout.

Server API endpoints: /api/create-checkout to create sessions, /api/webhook to receive Stripe webhook events and record donations in Supabase.

Optional Supabase storage: store donation rows so admins can view donations in an admin page.

 

Lovable-native approach

 

  • Do all coding inside Lovable Chat Mode — ask Lovable to create/modify files (no terminal).
  • Store keys in Lovable Cloud Secrets UI (STRIPE_SECRET_KEY, STRIPE_PUBLIC_KEY, SUPABASE_URL, SUPABASE_ANON\_KEY).
  • Use Preview to test client-side flows with Stripe test keys. Note: Stripe webhooks require a public URL — enable after Publish.
  • Publish to get a stable public URL and wire Stripe webhooks to /api/webhook on your published domain.

 

Meta-prompts to paste into Lovable (paste each labeled prompt into Chat Mode)

 

Prompt 1 — Create Donate UI and client flow

Goal: Add a Donate page and component that posts to API and redirects to Stripe Checkout.

Exact files to create/modify:

  • create src/pages/Donate.tsx
  • create src/components/DonateForm.tsx
  • modify src/App.tsx (or routes file) to add a route to /donate

Acceptance criteria:

  • /donate renders a form with amount and email
  • clicking Donate calls POST /api/create-checkout and redirects to Stripe Checkout URL returned

Secrets/integrations:

  • requires STRIPE_PUBLIC_KEY (client uses only for optional Stripe.js usage; server uses secret)

Prompt text to paste into Lovable Chat Mode (single message):

Please create src/components/DonateForm.tsx and src/pages/Donate.tsx, and register /donate route in src/App.tsx (or next/router routes). DonateForm should:

  • Collect amount (USD integer) and email.
  • POST JSON {amount, email} to /api/create-checkout.
  • On response {checkoutUrl}, redirect window.location = checkoutUrl.
    Ensure minimal styling. Add client-side validation for positive amount. Done when /donate works in Preview and returns a checkoutUrl from the API.

 

Prompt 2 — Add server API to create Checkout sessions

Goal: Create server endpoint to call Stripe and return Checkout url.

Exact files to create/modify:

  • create src/pages/api/create-checkout.ts (Next-style) or functions/api/create-checkout.ts depending on project structure
  • create src/lib/stripe.ts to init Stripe from process.env.STRIPE_SECRET_KEY

Acceptance criteria:

  • POST /api/create-checkout accepts {amount, email} and returns {checkoutUrl}
  • Uses process.env.STRIPE_SECRET_KEY from Lovable Secrets; responds 400 on invalid input

Secrets/integrations:

  • Set STRIPE_SECRET_KEY in Lovable Secrets UI (test key starts with sk_test_)

Prompt text to paste into Lovable Chat Mode:

Create src/pages/api/create-checkout.ts and src/lib/stripe.ts. The API should:

  • Read amount and email from body.
  • Create a Stripe Checkout session in test mode, currency USD, line_items with amount in cents.
  • Success URL should be ${process.env.NEXT_PUBLIC_APP_URL}/donation-success?session_id={CHECKOUT_SESSION_ID} (we will set NEXT_PUBLIC_APP_URL via Secrets or environment)
  • Return JSON {checkoutUrl: session.url}
    Reference process.env.STRIPE_SECRET_KEY. Done when calling the endpoint in Preview returns a valid session URL.

 

Prompt 3 — Optional: Supabase integration and webhook to record donations

Goal: Record completed donations in Supabase using Stripe webhooks.

Exact files to create/modify:

  • create src/pages/api/webhook.ts
  • create src/lib/supabaseClient.ts
  • update src/pages/api/create-checkout.ts to write a pending row with stripe_session_id (optional)

Acceptance criteria:

  • /api/webhook verifies Stripe signature using process.env.STRIPE_WEBHOOK_SECRET and inserts/updates row in Supabase donations table
  • donations table (external step) exists with columns: id (uuid), amount (int), currency (text), email (text), status (text), stripe_session_id (text), created_at (timestamp)

Secrets/integrations:

  • Add SUPABASE_URL, SUPABASE_ANON_KEY, and STRIPE_WEBHOOK_SECRET to Lovable Secrets UI.
  • Create Supabase table via Supabase dashboard (outside Lovable): donations with columns listed above.

Prompt text to paste into Lovable Chat Mode:

Create src/lib/supabaseClient.ts using SUPABASE_URL and SUPABASE_ANON_KEY, create src/pages/api/webhook.ts to:

  • Parse raw Stripe body and verify signature with STRIPE_WEBHOOK_SECRET
  • On event.checkout.session.completed, insert or update donations row in Supabase with amount, currency, email, stripe_session_id, status='completed'
    If raw body handling requires disabling bodyParser, add Next.js config for /api/webhook. Done when webhook handler returns 200 on valid Stripe test events (after Publish + Stripe webhook configured).

 

Prompt 4 — Admin donations list page

Goal: Add a simple admin page to list donations from Supabase.

Exact files to create/modify:

  • create src/pages/admin/donations.tsx

Acceptance criteria:

  • /admin/donations fetches from Supabase (SUPABASE_ANON_KEY) and lists recent donations.
  • Page protected by a simple client-side check if needed (note: for production secure via server-side auth).

Secrets/integrations:

  • Uses SUPABASE_ANON_KEY and SUPABASE_URL from Secrets.

Prompt text to paste into Lovable Chat Mode:

Create src/pages/admin/donations.tsx that lists donations by querying Supabase from src/lib/supabaseClient.ts. Display amount, email, status, created_at. Done when /admin/donations shows rows from the Supabase donations table in Preview (test data).

 

How to verify in Lovable Preview

 

  • Unlock Preview: Use Lovable Preview to open /donate. Fill amount/email and click Donate. The create-checkout API should return a Stripe test checkout URL and your browser should redirect to Stripe Checkout (test cards: 4242...).
  • Limitations: Stripe webhooks won’t reach your Preview URL. To verify webhook-driven Supabase writes, Publish and set Stripe webhook endpoint to your published URL + /api/webhook, then complete a test payment and check admin page or Supabase table.

 

How to Publish / re-publish

 

  • In Lovable: Click Publish. After Publish, copy the public site URL and add it in Stripe Dashboard: Webhooks → Add endpoint → /api/webhook with events checkout.session.completed.
  • Re-publish: Make edits in Chat Mode, Preview to test, then Publish again. Stripe webhook endpoint remains the same unless domain changes.

 

Common pitfalls in Lovable (and how to avoid them)

 

  • Missing Secrets: Add STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET to Lovable Secrets UI before previewing the server endpoints.
  • Webhook testing in Preview: Preview is not public; use Publish for real webhook delivery.
  • Supabase table creation: Create tables in Supabase dashboard (outside Lovable). If migrations are needed, use GitHub export and run migrations locally or via your CI.
  • Body parsing for Stripe webhook: Ensure the webhook endpoint uses raw body parsing (Next.js config) or verification will fail.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

How to add a Stripe webhook with idempotent audit log

This prompt helps an AI assistant understand your setup and guide to build the feature

AI AI Prompt

How to add donation rate-limiting and duplicate detection

This prompt helps an AI assistant understand your setup and guide to build the feature

AI AI Prompt

How to export donations as CSV (admin)

This prompt helps an AI assistant understand your setup and guide to build the feature

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation
Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

Best Practices for Building a Donation system with AI Code Generators

A compact answer: Use a payment processor (Stripe Checkout) so you never handle card data, store secrets (Stripe keys, Supabase service role) in Lovable Secrets UI, validate amounts server-side, record donations in a database (Supabase) via server-side webhooks, and deploy server code as serverless endpoints (created in Lovable files and published or exported to GitHub). In Lovable you must edit files with Chat Mode or file diffs, put secrets in Secrets UI, test in Preview for UI flows, and Publish or export to GitHub for a public endpoint (webhooks require a live URL). Focus on security (no card fields on your servers), idempotent webhook handling, rate limits, and clear UX for donors.

 

Practical Best Practices (step-by-step)

 

  • Use a PCI-compliant processor (Stripe Checkout) so you never touch card data.
  • Keep secrets in Lovable Secrets UI (STRIPE_SECRET, STRIPE_WEBHOOK_SECRET, SUPABASE_SERVICE\_KEY). Never commit keys to Git.
  • Server-side validation: validate donation amounts and donor metadata on the server. Don’t trust client inputs.
  • Use webhooks for final confirmation: record donations only after Stripe confirms payment via a signed webhook.
  • Idempotency and dedupe: use Stripe’s event IDs or session IDs to avoid double-recording.
  • Store minimal donor data: email, name, amount, timestamp, Stripe payment id. Don’t store sensitive card data.
  • Rate limiting and bot protection: throttle create-session endpoints and require simple captchas for open forms.
  • Testing: use Stripe test keys in Lovable Secrets, Preview UI flows locally, then Publish/export to GitHub to get a public URL for webhook testing.
  • Monitoring and retry: log webhook failures, set up alerting, and implement retry/idempotency.

 

Minimal working example (Stripe Checkout + webhook + Supabase save)

 

// server/api/create-checkout-session.js
// Node/Express style serverless handler for creating a Checkout Session
const stripe = require('stripe')(process.env.STRIPE_SECRET);
const SUPABASE_URL = process.env.SUPABASE_URL;
const SUPABASE_KEY = process.env.SUPABASE_SERVICE_KEY;
const fetch = require('node-fetch'); // or use supabase client

module.exports = async (req, res) => {
  // validate method and body
  if (req.method !== 'POST') return res.status(405).end();
  const {amount_cents, email} = req.body;
  // server-side validation of amount
  if (!amount_cents || amount_cents < 100) return res.status(400).json({error:'invalid amount'});
  const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card'],
    line_items: [{price_data:{currency:'usd',product_data:{name:'Donation'},unit_amount: amount_cents},quantity:1}],
    mode: 'payment',
    customer_email: email,
    success_url: process.env.SUCCESS_URL,
    cancel_url: process.env.CANCEL_URL
  });
  return res.json({sessionId: session.id});
};

 

// server/api/webhook.js
// Verify Stripe signature, then write to Supabase (or your DB). Use STRIPE_WEBHOOK_SECRET in Secrets UI.
const stripe = require('stripe')(process.env.STRIPE_SECRET);
const SUPABASE_URL = process.env.SUPABASE_URL;
const SUPABASE_KEY = process.env.SUPABASE_SERVICE_KEY;

module.exports = async (req, res) => {
  const sig = req.headers['stripe-signature'];
  let event;
  try {
    event = stripe.webhooks.constructEvent(req.rawBody, sig, process.env.STRIPE_WEBHOOK_SECRET);
  } catch (err) {
    return res.status(400).send(`Webhook Error: ${err.message}`);
  }
  if (event.type === 'checkout.session.completed') {
    const session = event.data.object;
    // idempotency: use session.id as unique key in DB
    await fetch(`${SUPABASE_URL}/rest/v1/donations`, {
      method: 'POST',
      headers: { 'apikey': SUPABASE_KEY, 'Authorization': `Bearer ${SUPABASE_KEY}`, 'Content-Type': 'application/json' },
      body: JSON.stringify({ session_id: session.id, email: session.customer_email, amount: session.amount_total, currency: session.currency, created_at: new Date().toISOString() })
    });
  }
  res.json({received: true});
};

 

<!-- client/donate.html -->
<!-- include publishable key from environment injected at build time or via config -->
<script src="https://js.stripe.com/v3/"></script>
<form id="donationForm">
  <input id="email" type="email" required/>
  <input id="amount" type="number" min="1" required/>
  <button type="submit">Donate</button>
</form>
<script>
  const stripe = Stripe('pk_test_YOUR_PUBLISHABLE_KEY'); // inject via config/Preview
  document.getElementById('donationForm').addEventListener('submit', async e=>{
    e.preventDefault();
    const amount = Math.round(Number(document.getElementById('amount').value)*100);
    const email = document.getElementById('email').value;
    const r = await fetch('/api/create-checkout-session', {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({amount_cents:amount,email})});
    const {sessionId} = await r.json();
    const {error} = await stripe.redirectToCheckout({sessionId});
    if (error) alert(error.message);
  });
</script>

 

Lovable-specific workflow tips

 

  • Edit code with Chat Mode / file diffs — don’t expect a terminal. Add files and deps via package.json edits in the editor.
  • Store secrets in Secrets UI and reference them as process.env.\* in your code. Preview will let you test UI but webhooks need a public URL after Publish or GitHub export.
  • Use Preview to test client flows, then Publish (or sync to GitHub for Vercel/Netlify) to get a stable URL for Stripe webhook configuration.
  • When you need more control (custom builds, native modules), export to GitHub from Lovable and complete CI steps there.

 


Recognized by the best

Trusted by 600+ businesses globally

From startups to enterprises and everything in between, see for yourself our incredible impact.

RapidDev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with.

They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

Arkady
CPO, Praction
Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost.

He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Donald Muir
Co-Founder, Arc
RapidDev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space.

They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Mat Westergreen-Thorne
Co-CEO, Grantify
RapidDev is an excellent developer for custom-code solutions.

We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Emmanuel Brown
Co-Founder, Church Real Estate Marketplace
Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 

This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Samantha Fekete
Production Manager, Media Production Company
The pSEO strategy executed by RapidDev is clearly driving meaningful results.

Working with RapidDev has delivered measurable, year-over-year growth. Comparing the same period, clicks increased by 129%, impressions grew by 196%, and average position improved by 14.6%. Most importantly, qualified contact form submissions rose 350%, excluding spam.

Appreciation as well to Matt Graham for championing the collaboration!

Michael W. Hammond
Principal Owner, OCD Tech

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.