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

# Quickstart

> Embed Playto Pay checkout in three steps.

The entire integration is a script tag and one function call.

## 1. Add the SDK

Include `playto.js` on the page where you want to sell.

```html
<script src="https://app.playto.so/pay/playto.js"></script>
```

## 2. Open the checkout

Wire it to your buy button. Pass the id of the product (payment link) you
want to charge for, and a full `returnUrl` to send the customer back to after
payment.

```html
<button id="buy">Buy now</button>

<script>
  document.getElementById("buy").addEventListener("click", function () {
    Playto.checkout({
      productId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890", // your product id
      returnUrl: window.location.href                    // where to send the customer back
    });
  });
</script>
```

> [!NOTE]
>
> `productId` is the `id` of a product (payment link). To charge an invoice, pass
> the invoice's `id` as `paymentLinkId` instead.

## 3. Handle the return

When payment ends, the modal closes and the customer's window goes to your
`returnUrl` with the result appended to the URL. Call `Playto.handleReturn()` on
that page (often the same page, which reloads) to detect it and fire your
callback.

```html
<script>
  Playto.handleReturn({
    onSuccess: function (result) {
      // result.sessionId is available — show success UI
    },
    onError: function (result) {
      // show a "payment not completed" message
    }
  });
</script>
```

That's it. Here's the whole thing on one page:

```html
<!doctype html>
<html>
  <body>
    <button id="buy">Buy now</button>

    <script src="https://app.playto.so/pay/playto.js"></script>
    <script>
      // Fire success/error if we just came back from checkout.
      Playto.handleReturn({
        onSuccess: (r) => alert("Thanks! Payment " + r.sessionId),
      });

      document.getElementById("buy").addEventListener("click", () => {
        Playto.checkout({
          productId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          returnUrl: window.location.href,
        });
      });
    </script>
  </body>
</html>
```

> [!TIP]
>
> Testing? Pass `env: "sandbox"` and a sandbox product id to run against the test
> environment with no real money. Test mode needs no domain approval, so `localhost`
> and ngrok URLs work. Without `env: "sandbox"`, a sandbox id shows "Link Not
> Found". See [Going live](/guides/embedded-checkout/going-live.md).

> [!NOTE]
>
> In **Live**, your site's domain must be approved first. See
> [Going live](/guides/embedded-checkout/going-live.md#approve-your-domains).

## React

There's no separate React package — the SDK is framework-agnostic. Load the
script once and call the global from an event handler:

```jsx
function BuyButton({ productId }) {
  const buy = () =>
    window.Playto.checkout({
      productId,
      returnUrl: window.location.href,
    });
  return <button onClick={buy}>Buy now</button>;
}

// On the page you return to:
useEffect(() => {
  window.Playto?.handleReturn({ onSuccess: (r) => {/* … */} });
}, []);
```

> [!NOTE]
>
> Load `playto.js` via Next.js `<Script>`, a `<script>` in your document `<head>`,
> or by injecting it once on mount — then call `window.Playto`.

Next: [How it works](/guides/embedded-checkout/how-it-works.md) or the full
[SDK reference](/guides/embedded-checkout/sdk-reference.md).
