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

> ## Agent Instructions
> Treat these docs and the Whop MCP server as the source of truth for Whop API behavior. Don't infer endpoint behavior from marketing pages.
> MCP server: connect https://mcp.whop.com/mcp (streamable HTTP, browser sign-in, no API key in the client config) to search these docs and read or change live Whop data. Setup: https://docs.whop.com/developer/guides/ai_and_mcp.md
> Whop CLI: install with `curl -fsSL https://whop.com/install.sh | sh` to scaffold, run, and deploy Whop apps and websites. It acts on production, not the sandbox. Overview: https://docs.whop.com/cli/overview.md Agent mode: https://docs.whop.com/cli/agent-mode.md
> Hosting: Whop serves a site or app from the build `whop apps deploy` uploads, with rollbacks, secrets, and server logs. Guide: https://docs.whop.com/developer/websites/hosting.md
> Plugins: in Claude Code, run `/plugin marketplace add whopio/plugins`, then `/plugin install whop@whop`. Guide: https://docs.whop.com/developer/guides/plugins/claude-code.md Every agent tool: https://docs.whop.com/developer/ai/overview.md
> Environments: build and test in the sandbox (API `https://sandbox-api.whop.com/api/v1`, keys at https://sandbox.whop.com/dashboard/developer, SDK environment `Sandbox`; no real money). Production (API `https://api.whop.com/api/v1`, keys at https://whop.com/dashboard/developer, SDK environment `Production`, the SDK default) moves real money, so use it only at launch. The two share no accounts, keys, products, or webhooks, and their keys look identical: never mix them. Sandbox guide: https://docs.whop.com/developer/guides/sandbox.md Comparison: https://docs.whop.com/developer/quickstart.md
> API: send `Authorization: Bearer <API_KEY>` from your server only, and pin a dated version with the `Api-Version-Date` header. OpenAPI spec: https://api.whop.com/api/v1/openapi.json
> Which API: build on the Current API, whose pages live under https://docs.whop.com/api-reference/ (start at https://docs.whop.com/api-reference/overview.md). Pages under /api-reference/legacy/ are the Legacy API. Use one only when https://docs.whop.com/api-reference/stability.md lists the resource as Legacy-only.

# Iframe SDK

> Gebruik de @whop/iframe-SDK om vanuit je ingesloten app met Whop te communiceren, bijvoorbeeld om een link te openen of een in-app-aankoop te starten.

Whop sluit apps in de site in met iframes. Deze SDK biedt een typeveilige manier om met de Whop-applicatie te communiceren via een request-en-response-API die `window.postMessage` gebruikt.

Omdat dit pakket afhankelijk is van `window.postMessage`, werkt het alleen in **Client Components** of client-side JavaScript.

### Relevante pakketten

* `@whop/iframe` - Het hoofdpakket voor de iframe-SDK.
* `@whop/react` - Een React-wrapper voor Whop Apps, inclusief helpers voor de iframe-SDK.

***

## Installatie

De belangrijkste functie die het pakket `@whop/iframe` exporteert, is de functie `createSdk`. Wanneer je deze aanroept, stelt de functie met `window.on('message', ...)` een listener in voor berichten van de hoofdsite van Whop. Ze is ook beschikbaar via de component `WhopIframeSdkProvider` uit `@whop/react`.

### React

Als je React gebruikt, voeg dan de component `WhopIframeSdkProvider` uit `@whop/react` toe om de iframe-SDK aan alle onderliggende componenten beschikbaar te stellen.

**1. Mount de provider in de root-layout**

```javascript theme={null}
// app/layout.tsx
import { WhopIframeSdkProvider } from "@whop/react";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode,
}) {
  return (
    <html lang="en">
      <body>
        <WhopIframeSdkProvider>{children}</WhopIframeSdkProvider>
      </body>
    </html>
  );
}
```

**2. Gebruik de iframe-SDK in een component**

```javascript theme={null}
// components/example.tsx
import { useIframeSdk } from "@whop/react";

export const Example = () => {
  const iframeSdk = useIframeSdk();

  return (
    <button
      onClick={() => iframeSdk.openExternalUrl({ url: "https://example.com" })}
    >
      Open External URL
    </button>
  );
};
```

### Andere frameworks

Voor andere frameworks kun je de functie `createSdk` uit `@whop/iframe` gebruiken om een instantie van de iframe-SDK te maken.

**1. Maak de instantie van de iframe-SDK**

```javascript theme={null}
// lib/iframe-sdk.ts
import { createSdk } from "@whop/iframe";

export const iframeSdk = createSdk({
  appId: process.env.NEXT_PUBLIC_WHOP_APP_ID,
});
```

**2. Gebruik de instantie van de iframe-SDK**

```javascript theme={null}
// index.ts
import { iframeSdk } from "@/lib/iframe-sdk";

const navigationButtonElement = document.querySelector("button");

if (navigationButtonElement) {
  navigationButtonElement.addEventListener("click", () => {
    iframeSdk.openExternalUrl({ url: "https://example.com" });
  });
}
```

> [!TIP]
>
> De SDK en het iframe zijn nu ingesteld.

## Externe links openen

Nadat je de iframe-SDK hebt geïnitialiseerd, kun je deze gebruiken om externe links te openen. Hiermee wordt je app gesloten en navigeer je naar een nieuwe website.

```javascript React theme={null}
"use client";
import { useIframeSdk } from "@whop/react";

export default function Home() {
	const iframeSdk = useIframeSdk();

    function openLink() {
    	iframeSdk.openExternalUrl({ url: "https://google.com" });
    }

    return <button onClick={openLink}>Click me to open Google</button>;

}

```

```javascript Vanilla JS theme={null}
import { iframeSdk } from "@/lib/iframe-sdk";

const navigationButtonElement = document.querySelector("button");

if (navigationButtonElement) {
  navigationButtonElement.addEventListener("click", () => {
    iframeSdk.openExternalUrl({ url: "https://google.com" });
  });
}
```

### Gebruikersprofielen openen

Als je een Whop-gebruikersprofiel wilt tonen, kun je de methode `openExternalUrl` gebruiken en de link naar de profielpagina meegeven, die eruitziet als `https://whop.com/@username`.

De Whop-app onderschept dit en toont een modal met het gebruikersprofiel in plaats van weg te navigeren.

```javascript React theme={null}
"use client";
import { useIframeSdk } from "@whop/react";

export default function Home() {
	const iframeSdk = useIframeSdk();

    function openProfile() {
    	iframeSdk.openExternalUrl({ url: "https://whop.com/@j" });
    }

    return <button onClick={openProfile}>View Profile</button>;

}

```

```javascript Vanilla JS theme={null}
import { iframeSdk } from "@/lib/iframe-sdk";

const profileButtonElement = document.querySelector("button");

if (profileButtonElement) {
  profileButtonElement.addEventListener("click", () => {
    iframeSdk.openExternalUrl({ url: "https://whop.com/@j" });
  });
}
```

> [!NOTE]
>
> Je kunt ook een gebruikers-ID gebruiken in plaats van een gebruikersnaam. De uiteindelijke link
> ziet er dan zo uit: `https://whop.com/@user_XXXXXXXX`

## In-app-aankopen

De iframe-SDK biedt een methode om in-app-aankopen direct binnen je app te starten. Zo kun je met de checkout van Whop betalingen accepteren voor eenmalige aankopen of abonnementen.

Om in-app-aankopen te verwerken, moet je:

1. Een checkoutconfiguratie aanmaken op je server (met variantgegevens in het compatibiliteitsveld `plan` en je metadata)
2. De methode `inAppPurchase` van de iframe-SDK gebruiken om de betalingsmodal te openen
3. Het antwoord afhandelen en de betaling valideren via webhooks

```tsx React theme={null}
"use client";
import { useIframeSdk } from "@whop/react";
import { useState } from "react";

export default function PaymentButton() {
    const iframeSdk = useIframeSdk();
    const [paymentId, setPaymentId] = useState<string>();

    async function handlePurchase() {
        // 1. Create checkout configuration on server
        //    (in this example this is a nextjs server action, but it could also be a plain API route)
        const checkoutConfiguration = await createCheckoutConfiguration(/* can pass options here */);

        // 2. Open payment modal
        const res = await iframeSdk.inAppPurchase({
            planId: checkoutConfiguration.plan.id,
            id: checkoutConfiguration.id
        });

        if (res.status === "ok") {
            setPaymentId(res.data.receipt_id);
        } else {
            // handle errors
        }
    }

    return <button onClick={handlePurchase}>Purchase</button>;

}

```

```javascript Vanilla JS theme={null}
import { iframeSdk } from "@/lib/iframe-sdk";

const paymentButton = document.querySelector("button#payment-button");

paymentButton.addEventListener(
    "click",
    async function onPaymentButtonClick() {
        // 1. Create checkout configuration on server
        const checkoutConfiguration = await createCheckoutConfiguration(/* can pass options here */);

        // 2. Open payment modal
        const res = await iframeSdk.inAppPurchase({
            planId: checkoutConfiguration.plan.id,
            id: checkoutConfiguration.id
        });

        if (res.status === "ok") {
            const paymentId = res.data.receipt_id;
            // Send this id to your backend to validate, or rely on webhooks.
            // User has purchased the item, and it can be unlocked.
        } else {
            // handle errors
        }
    }
);
```

> [!NOTE]
>
> Zie de [documentatie over het accepteren van betalingen](https://docs.whop.com/nl/developer/guides/accept-payments.md) voor een volledige
> gids over het instellen van in-app-aankopen, inclusief het aanmaken van
> checkoutconfiguraties, het afhandelen van webhooks en het valideren van betalingen.


## Related topics

- [Frosted UI](https://docs.whop.com/nl/developer/guides/frosted_ui.md)
- [Authenticatie en API-sleutels](https://docs.whop.com/nl/developer/guides/auth-scoping.md)
- [Gebruikers authenticeren in Whop-apps](https://docs.whop.com/nl/developer/guides/authentication.md)
