> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useroutr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Online store

> Add one pay button that takes any token, opens inside your store and tells your server when the order is paid.

![Shoppers pay for a tote bag with USDC on Ethereum, LINK on Base or XLM.](https://mintcdn.com/thirtn/tEtIKPxuXx_PTNHq/images/illustrations/use-case-store-light.svg?fit=max\&auto=format\&n=tEtIKPxuXx_PTNHq\&q=85\&s=ab0d1af41d66fd69e1e5acbe082cc4ec)

Embedded checkoutBrandingWebhooks

## The idea

Someone wants your tote bag and has LINK on Base. Card forms, exchange accounts and "send to this
address on that network, carefully" are all ways to lose the sale. One **Pay with crypto** button
that opens in your page, speaks their token and tells you when the order is paid keeps it.

## How it plays out

**1. Checkout starts on your server**

Your server totals the cart, creates a funding intent for that amount with the order id as its
reference, and returns only the intent's funding token.

**2. The checkout opens in your store**

The [embedded checkout](https://docs.useroutr.com/payments/embedded-checkout.md) appears as a modal, wearing your logo and
colour. Your API key never reaches the browser.

**3. You ship on the webhook**

`funding.credited` marks the order paid. It arrives even if the shopper closes the tab the
moment they hit send.

## The code

```ts Create the payment theme={null}
"use server";

export async function startPayment(cart: Cart) {
  const orderKey = `${cart.id}-v${cart.version}`;
  const intent = await useroutr.fundingIntents.create(
    { amount: cart.totalUsdc, asset: "asset_usdc_stellar", reference: cart.orderId },
    { idempotencyKey: orderKey },
  );
  const url = intent.hosted_funding_url ?? "";
  return url.slice(url.lastIndexOf("/") + 1);
}
```

```tsx Show the button theme={null}
"use client";

import { UseroutrCheckout } from "@useroutr/checkout-react";

export function PayButton({ cart }: { cart: Cart }) {
  const [token, setToken] = useState<string | null>(null);
  return (
    <>
      <button onClick={async () => setToken(await startPayment(cart))}>Pay with crypto</button>
      {token === null ? null : (
        <UseroutrCheckout
          token={token}
          baseUrl="https://api.useroutr.com/v1/public"
          mode="modal"
          onSuccess={() => showThankYou()}
          onClose={() => setToken(null)}
        />
      )}
    </>
  );
}
```

```ts Ship it theme={null}
// Inside your webhook handler, after verifying the event
if (event.type === "funding.credited") {
  await markOrderPaid(event.data.object.reference); // once per order: deliveries can repeat
}
```

## Make it your own

* **Match the shop.** `appearance` sets the colour, logo, corners and font for this checkout
  only. See [Branding](https://docs.useroutr.com/payments/branding.md).
* **Prefer a page to a modal?** Redirect to `hosted_funding_url` instead. See
  [Hosted checkout](https://docs.useroutr.com/payments/hosted-checkout.md).
* **Another framework?** `@useroutr/checkout-core` gives you the same states to render your way.
  See [Custom checkout](https://docs.useroutr.com/payments/custom-checkout.md).

## Good to know

* Price the cart in a stable asset. Shoppers see their own token's amount in the checkout; you
  always receive the cart total.
* Put the cart's version in the idempotency key. Reusing a key with a different total is refused
  with `IDEMPOTENCY_KEY_REUSED`, so a changed cart needs a new key.
* Use `https://sandbox-api.useroutr.com/v1/public` as `baseUrl` while you test with a `ur_test_`
  key.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.