Skip to content
Docs
Start free

Take payments with Stripe Checkout

The Stripe checkout task takes a payment with Stripe Checkout. A buy button on your page opens Stripe's payment page for your price, and Stripe tells your site when the payment is done.

On this page

What it doesLink to this section

  • /api/checkout starts a checkout for the price in your keys and answers the address of Stripe's payment page. The page can ask for a quantity from 1 to 10. The price always comes from your keys, never from the page, so nobody can change what they pay.
  • /api/stripe-webhook hears from Stripe when a checkout is paid. It checks Stripe's signature before it trusts anything, then marks the payment as paid in its log. You decide what happens next, like saving the order or emailing yourself.
  • After paying, Stripe sends the buyer back to a page on your site. If they cancel, to another.
Tip:

Do everything in Stripe's test mode first, with test keys. Switch to live keys only when a test payment works from start to end.

Add the taskLink to this section

In Server tasks (top menu), choose Add a ready-made task, pick Stripe checkout and choose Add task. The setup card lists the three keys below, each with Add key.

Keys to addLink to this section

Stripe secret key (STRIPE_SECRET_KEY), a secretLink to this section

  1. Open your API keys

    In the Stripe dashboard, turn on test mode, then open Developers, API keys.

  2. Copy the secret key

    Copy the secret key. It starts with sk_test_ in test mode. Not the publishable key, which starts with pk_.

  3. Add it

    Choose Add key next to Stripe secret key and paste it. Which service is it for? is already api.stripe.com: keep it.

Stripe price (STRIPE_PRICE_ID), a settingLink to this section

  1. Open your product

    In the Stripe dashboard, open Product catalog and the product you sell. Make one first if you have none, with a one-time price.

  2. Copy the price id

    In the product's pricing, open the price and copy its id. It starts with price_. Not the product's own id, which starts with prod_.

  3. Add it

    Choose Add key next to Stripe price, paste the id and save.

Stripe signing secret (STRIPE_WEBHOOK_SECRET), a secretLink to this section

Stripe calls your live site's address when a payment is done, so add this one when your site is live: see Go live below.

  1. Add a webhook in Stripe

    In the Stripe dashboard, open Developers, Webhooks, and add an endpoint. For its address, use your live site's address followed by /api/stripe-webhook:

    Endpoint address
    https://your-site.xodia.site/api/stripe-webhook

    Use your own domain instead if your site has one. For events, pick checkout.session.completed.

  2. Copy the signing secret

    Open the webhook and reveal its signing secret. It starts with whsec_.

  3. Add it

    Choose Add key next to Stripe signing secret and paste it. The code reads this key itself is already on under Advanced: the code checks Stripe's signature with it. Keep it on.

  4. Choose Approve

    A key the code reads itself works only in changes a manager approved. If Server tasks shows Your latest changes need your OK to use your secret keys, or the same line for your live site, choose Approve. See The code reads this key itself.

Finish the codeLink to this section

  • In api/checkout.ts, change DONE_PATH and CANCELLED_PATH to the pages buyers come back to, like a thank you page.
  • In api/stripe-webhook.ts, say what happens after a payment, where it marks the checkout as paid. Stripe can send the same event twice, so make it safe to repeat. The thank you page alone proves nothing: anyone can open it.
  • Your buy button sends a POST to /api/checkout and opens the address it answers.

Connect it with AI in the setup card asks your AI to do all three. Or tell it:

Ask your AI
Make the Buy button on the Pricing page post to /api/checkout and open the url it answers. Send buyers back to /thank-you after paying and to /pricing if they cancel. When the webhook marks a payment paid, email me with the send-email task.

Try it in the previewLink to this section

  1. Turn on server tasks

    In the setup card, choose Turn on server tasks if they are off.

  2. Press your buy button

    Stripe's payment page should open, showing your price, with a test mode badge.

  3. Pay with a test card

    Use Stripe's test card 4242 4242 4242 4242, any date in the future, any three digits for the security code, and any name. Nothing is charged.

After paying in the preview, Stripe sends you back to your site's xodia.site address, not to the preview. That is expected. The webhook doesn't reach the preview: it calls your live site, so try it after you go live.

Go liveLink to this section

  1. Publish, still with test keys

    Publish your site, then add the webhook and its signing secret as above, and Approve if asked.

  2. Make a test payment on the live site

    Pay with the test card on your live site. In Project settings, Server tasks, Recent calls, pick Live site: the call to /api/stripe-webhook shows status 200 and the line paid: checkout with the checkout's id. In Stripe's Webhooks page, the event shows as delivered.

  3. Switch to live keys

    Turn off test mode in Stripe. Replace STRIPE_SECRET_KEY with the live secret key, which starts with sk_live_, and STRIPE_PRICE_ID with your product's live price id. Add a new webhook in live mode with the same address and event, and replace STRIPE_WEBHOOK_SECRET with its signing secret. Test and live mode each have their own keys, prices and webhooks.

Common problemsLink to this section

The buy button gets not_set_upLink to this section

A key is missing or in the wrong place. Check Recent calls: what the task wrote says which one.

  • STRIPE_PRICE_ID holds a product id (prod_...): use the product's price id, which starts with price_.
  • STRIPE_SECRET_KEY holds a publishable key (pk_...) or a signing secret (whsec_...): use the secret key, which starts with sk_.
  • No line at all: STRIPE_SECRET_KEY or STRIPE_PRICE_ID isn't added yet.

Checkout couldn't startLink to this section

Stripe said no. Recent calls shows Stripe's own error code and message:

  • resource_missing No such price: the price id is wrong, or it is a test price with a live key, or a live price with a test key. Use a key and a price from the same mode.
  • 401 or a line about the API key: the secret key is wrong, or it was saved as a setting or with another service. Replace it as a secret for api.stripe.com.
  • A line about the price being recurring: the task takes one-time payments. Use a one-time price, or ask your AI to change the checkout to a subscription.

Stripe's webhook gets Signature not validLink to this section

  • Recent calls says The signing secret can't be read yet: approve this version in Server tasks first. The change isn't approved, so the code got a stand-in instead of the signing secret. Choose Approve in Server tasks, then send a new test payment.
  • The signing secret is from another webhook, or from the other mode. Copy it again from the webhook that points at /api/stripe-webhook.
  • The event was sent again much later: events older than five minutes are refused. Send a new test payment instead of resending an old event.

Stripe's webhook gets not_set_upLink to this section

STRIPE_WEBHOOK_SECRET isn't added, or it holds an API key (sk_...). Use the webhook's signing secret, which starts with whsec_.

Stripe's webhook gets 404 or never arrivesLink to this section

Check the endpoint address is your live address with /api/stripe-webhook at the end, that your site is published with the task in it, and that server tasks are on.

The AI website builder for real code. Made by Zuzo Studio LLC.

Claude, Cursor, Lovable, Bolt, Replit, Webflow, Framer and other product names are trademarks of their owners. Xodia is not affiliated with them.