Dumpster Controls · agent page

This is the agent-optimized version of https://dumpstercontrols.io/help/booking-api/lesson-13-react-next-js-and-ai-builders: the same content as the human page, without scripts, styles, animations or navigation. People should open the full page.

Canonical page
https://dumpstercontrols.io/help/booking-api/lesson-13-react-next-js-and-ai-builders
Last updated
2026-10-05
Tokens
1,450 tokens (cl100k_base), within the 2,500-token budget for a help page
Size
11 KB for this page, against 33 KB for the human page (68% smaller)
Markdown
https://dumpstercontrols.io/help/booking-api/lesson-13-react-next-js-and-ai-builders.md, or send Accept: text/markdown to the canonical URL
Cite as
Lesson 13: React, Next.js and AI builders (Claude, Lovable, Codex). Dumpster Controls. https://dumpstercontrols.io/help/booking-api/lesson-13-react-next-js-and-ai-builders (accessed 2026-11-20).
More for agents
Facts sheet · llms.txt · llms-full.txt · All agent pages · Product manual

Booking API course · updated 2026-10-05

Lesson 13: React, Next.js and AI builders (Claude, Lovable, Codex)

The same calls inside a React component, the rules that keep a server key out of the bundle, and the prompt that makes an AI coding tool build the whole checkout from this course.

Before you start

  • Lesson 12
  1. ## React component outline
    ```
    import { useEffect, useState } from "react";
    import { loadStripe } from "@stripe/stripe-js";
    import { Elements, PaymentElement, useStripe, useElements } from "@stripe/react-stripe-js";
    const API = "https://gcwyoiihrupbfqqlcurh.supabase.co/functions/v1/booking-api/v1";
    const KEY = process.env.NEXT_PUBLIC_DC_BOOKING_KEY; // publishable key only, never the server key
    async function api(path, body) { /* same helper as lesson 12 */ }
    ```
    export default function Book() {
    const [intent, setIntent] = useState(null);
    const start = async (form) => setIntent(await api("/intents", form));
    if (!intent) return <OrderForm onSubmit={start} />;
    const stripePromise = loadStripe(intent.stripe.publishable_key, intent.stripe.account ? { stripeAccount: intent.stripe.account } : undefined);
    return (
    <Elements stripe={stripePromise} options={{ clientSecret: intent.client_secret }}>
    <PayStep intent={intent} />
    </Elements>
    );
    }
    function PayStep({ intent }) {
    const stripe = useStripe(); const elements = useElements();
    const pay = async () => {
    const { error } = await stripe.confirmPayment({ elements, confirmParams: { return_url: window.location.href }, redirect: "if_required" });
    if (error) return alert(error.message);
    const c = await api("/confirm", { session_id: intent.session_id, payment_intent_id: intent.payment_intent_id });
    alert(c.state === "held" ? Received, under review: ${c.order_number} : Booked: ${c.order_number});
    };
    return <><PaymentElement /><button onClick={pay}>Pay ${intent.amount.gross_total}</button></>;
    }
    ```
  2. ## Next.js and server keys
    If you call the API from a Route Handler or a server action, use the server key from a server-only environment variable (DC_BOOKING_SERVER_KEY) and never prefix it with NEXT_PUBLIC_. Browser calls use the publishable key and must come from an allowed domain; add your preview domains too while developing.
  3. ## Builders that generate React (Lovable, v0)
    They can call the API directly from the generated components with the publishable key. Tell them the allowed domain is the published site domain, and to read the API reference first. If they try to build a form that posts a price, say no: prices come from POST /quote and the card from the Payment Element.
  4. ## The prompt for an AI tool
    Build custom online booking screens for my dumpster rental website using the Dumpster Controls Booking API. Read https://dumpstercontrols.io/developers/booking/api.md first and follow it exactly. My publishable key is "{publishable_key}" and my allowed domain is "{domain}". Flow: GET /sizes to show the sizes with live prices; GET /materials first and, when enabled is true, ask what the customer is disposing of before the size, show only the sizes allowed for that material with the material price, send material to POST /quote and POST /intents, show the explanation and require the acknowledgement (material_acknowledged: true) when requires_ack is true, and on 409 material_not_allowed offer details.allowed_sizes; POST /quote whenever the size, material or rental days change and show total and processing_fee; POST /check with the delivery date, ZIP and promo code before payment; POST /intents with the full order and customer to get session_id, payment_intent_id and client_secret; mount the Stripe Payment Element with client_secret using the publishable key from the response (and stripeAccount when stripe.account is set), confirm the card with stripe.confirmPayment and redirect "if_required"; then POST /confirm with session_id and payment_intent_id and show order_number. Never compute prices on the client, never collect card data outside the Stripe Payment Element, and never store the server key in the browser. Handle 409 errors by showing the message from the API. Fire my Google Ads and Meta Pixel conversions after /confirm succeeds. If the company also offers junk removal, use the /junk/* endpoints as documented (GET /junk/config, GET /junk/availability, POST /junk/quote, POST /junk/intents, POST /junk/confirm, POST /junk/photos) with the same keys and the same Stripe flow.

What happens next

  • The same prompt, with your key and domain already filled in, is in Online Booking, Developers (Prompt 3).

Troubleshooting

My bundle contains dc_sk_booking_.

A server key leaked into client code. Revoke it in the Developers tab, create a new one and keep it server-only.

Related guides

© 2026 Dumpster Controls. All rights reserved. Made in the USA.