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

# Your infrastructure

> Onboard customers with your Meta integration and use Kapso for managed billing

Use this path after [setting up MPS](/docs/platform/tech-providers/multi-partner-solutions) with **Messages processed by: Your infrastructure**.

You own registration, messaging, and message webhooks; Kapso provides managed billing.

## At a glance

1. [Prepare your Meta app](#prepare-your-meta-app) and copy your MPS Solution ID.
2. [Launch Embedded Signup](#launch-embedded-signup) so the customer can authorize your app.
3. [Complete onboarding on your backend](#complete-onboarding-on-your-backend), including registration and webhook setup.
4. [Confirm Kapso detected and funded the account](#confirm-managed-funding-in-kapso) before paid traffic.
5. [Start messaging and monitor usage](#monitor-usage) in Kapso.

This path uses Meta's JavaScript SDK, not `@kapso/sdk`, a Kapso setup link, or Kapso's onboarding endpoints.

## Prepare your Meta app

* Activate a Multi-partner Solution with **Messages processed by: Your infrastructure** and **App with messaging permission: Your Meta app**.
* Copy the **Meta solution ID** from **Tenants > Multi-partner solution**. This is not the Meta App ID or a Kapso UUID.
* Create a Facebook Login for Business configuration for your Tech Provider app, using WhatsApp Embedded Signup v4 and the products you need.
* Add your HTTPS domain and OAuth redirect URIs in [Meta's login settings](/docs/platform/onboard-customers-own-meta-app#add-domains-for-embedded-signup). Kapso setup-link `allowed_origins` does not apply to this path.
* Configure your webhook endpoint and subscribe your Meta app to `account_update` and `messages`.

Use your own app's IDs below. Never include your app secret or access tokens in browser code. See [Meta's implementation guide](https://developers.facebook.com/documentation/business-messaging/whatsapp/embedded-signup/implementation) for the app configuration.

## Launch Embedded Signup

If you already have Embedded Signup, add `extras.setup.solutionID` to your existing `FB.login` options. Keep the SDK initialization and flow options appropriate for your configuration.

For a new v4 integration, this example initializes Meta once and enables the button only after `FB.init` completes:

```html theme={null}
<button id="connect-whatsapp" disabled>Connect WhatsApp</button>
<p id="whatsapp-status" role="status"></p>

<script>
  const connectButton = document.getElementById('connect-whatsapp');
  const signupStatus = document.getElementById('whatsapp-status');

  window.fbAsyncInit = function () {
    FB.init({
      appId: 'YOUR_TECH_PROVIDER_APP_ID',
      version: 'v25.0',
      autoLogAppEvents: false,
      xfbml: false
    });
    connectButton.disabled = false;
  };

  connectButton.onclick = function () {
    connectButton.disabled = true;
    signupStatus.textContent = 'Opening Meta…';

    FB.login((response) => {
      const code = response.authResponse?.code;
      if (!code) {
        signupStatus.textContent = 'Setup was not completed.';
        connectButton.disabled = false;
        return;
      }

      void completeOnboarding(code);
    }, {
      config_id: 'YOUR_EMBEDDED_SIGNUP_CONFIG_ID',
      response_type: 'code',
      override_default_response_type: true,
      extras: {
        setup: {
          solutionID: 'YOUR_META_SOLUTION_ID'
        }
      }
    });
  };

  async function completeOnboarding(code) {
    signupStatus.textContent = 'Completing setup…';

    try {
      // Your endpoint, not a Kapso API. Implement the backend steps below.
      const response = await fetch('/api/whatsapp/onboarding/complete', {
        method: 'POST',
        credentials: 'same-origin',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ code })
      });
      if (!response.ok) throw new Error('Onboarding failed');

      signupStatus.textContent = 'Connected. Check managed funding in Kapso before sending paid messages.';
    } catch {
      signupStatus.textContent = 'Could not complete setup. Check your backend before retrying.';
    } finally {
      connectButton.disabled = false;
    }
  }
</script>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js"></script>
```

`solutionID` is case-sensitive and belongs inside `extras.setup`, not at the top level. Keep it as a string. The Solution ID links the customer's authorization to both partners. See [Meta's Multi-partner Solution instructions](https://developers.facebook.com/documentation/business-messaging/whatsapp/solution-providers/multi-partner-solutions#step-5-configure-embedded-signup).

If you offer multiple solutions, select the correct App ID, configuration ID, and Solution ID for the customer before enabling the button. Store that expected context with the onboarding attempt on your backend.

## Complete onboarding on your backend

The example's `/api/whatsapp/onboarding/complete` is an endpoint in **your application**. Protect it with your normal authentication and CSRF controls; adapt the request headers to your framework. Bind the attempt to the signed-in customer.

1. Exchange `code` through Meta's `GET /oauth/access_token`, using your App ID and app secret. Store the returned business token securely on your server; do not log it or return it to the browser.
2. Resolve the authorized WABA and phone number using that token. If multiple assets are available, confirm the customer's selection rather than choosing the first result. You can also collect IDs through Meta's `WA_EMBEDDED_SIGNUP` browser event: validate the event origin and verify asset access server-side. Browser-supplied IDs are not proof of ownership or funding.
3. Subscribe **your app** to the customer's WABA with `POST /{WABA_ID}/subscribed_apps` so your backend receives message webhooks.
4. Register the phone number with `POST /{PHONE_NUMBER_ID}/register` when required by the selected flow. The example targets the standard Cloud API flow; follow Meta's separate requirements for coexistence, migrations, or WABA-only signup.
5. Persist the connection in your system. Return success only after the required backend setup completes.

Use [Meta's Tech Provider onboarding guide](https://developers.facebook.com/documentation/business-messaging/whatsapp/embedded-signup/onboarding-customers-as-a-tech-provider) for the requests. For Kapso-managed billing, use the funding confirmation below instead of asking the customer to add a Meta payment method.

## Confirm managed funding in Kapso

Meta notifies Kapso through `account_update` when the customer joins the solution. Kapso detects the WABA and attempts to fund it automatically, subject to eligibility and your project's prepaid balance. You do not need to send Kapso the customer's authorization code or business token.

Open **Tenants > Multi-partner solution**, find the WABA, and confirm that managed funding is **verified** before sending paid messages. A successful signup callback or a detected WABA alone does not confirm funding. If the account shows **Needs attention**, resolve the displayed issue first.

External onboarding does not create a Kapso WhatsApp configuration or emit the hosted path's `whatsapp.phone_number.created` event. Your own backend tracks connection completion; the Kapso account table tracks funding and aggregate usage.

If the WABA does not appear, check that signup used the exact active Solution ID and the correct Meta app. If those match, contact Kapso with the Solution ID, WABA ID, and signup time. Do not send secrets or access tokens.

## Monitor usage

Once funded, keep sending through your own Meta integration. View each WABA's funding and aggregate usage in **Tenants > Multi-partner solution**.

Kapso checks Pricing Analytics about every five minutes; usage can arrive later. Kapso cannot block sends made through your infrastructure, so keep enough balance for usage between checks. See [managed billing and beta limitations](/docs/platform/tech-providers/multi-partner-solutions#managed-billing).
