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

# Embedded checkout for connected accounts

> Embed Ionic checkout on the website you run for each connected account, with Apple Pay.

Your platform can show [embedded checkout](https://docs.ionicfi.com/guides/embedded-checkout.md) on the
website it runs for a connected account. The payment belongs to that account.
A merchant's checkout loads only on the websites registered for that merchant,
so a site you register for one merchant never runs another merchant's checkout.

## Before you begin

* Use a platform secret key with `sessions:write`, `web_domains:read`, and
  `web_domains:write` for the mode you are working in. In **Connect → API
  keys**, the **Payments integration** preset includes them.
* Each merchant's connection must grant `sessions:write`, and `sessions:read`
  to list domains. Access to create a merchant's checkout sessions also lets you
  register where they run, so merchants approve nothing extra.

Every request below sends the merchant's ID in `Ionic-Account`.

## 1. Register the merchant's website

Register the origin of the page where the merchant's customers pay. Do this
once per merchant and mode, for example right after the merchant connects.

```bash theme={null}
curl https://api.ionicfi.com/v1/web_domains \
  -H "Authorization: Bearer $IONIC_PLATFORM_SECRET_KEY" \
  -H "Ionic-Account: mer_REPLACE_WITH_MERCHANT_ID" \
  -H "Content-Type: application/json" \
  -d '{"domain": "https://clinic-a.your-platform.com"}'
```

```json theme={null}
{
  "object": "web_domain",
  "id": "wd_2Mq8Lr4Tn6Vx0Z",
  "domain": "https://clinic-a.your-platform.com",
  "livemode": false,
  "apple_pay": { "status": "not_registered" },
  "created_at": 1792200859,
  "platform_account_id": "mer_REPLACE_WITH_YOUR_PLATFORM_ID"
}
```

Matching uses the exact origin: scheme, hostname, and port. Register each
subdomain separately. Public sites require HTTPS.

You can register the same site for several merchants. Each of them can then run
checkout on it, so a site per merchant keeps merchants separate.

## 2. Create a checkout session for the merchant

```bash theme={null}
curl https://api.ionicfi.com/v1/checkout/sessions \
  -H "Authorization: Bearer $IONIC_PLATFORM_SECRET_KEY" \
  -H "Ionic-Account: mer_REPLACE_WITH_MERCHANT_ID" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: visit-8241-checkout" \
  -d '{
    "mode": "payment",
    "ui_mode": "embedded",
    "line_items": [
      {"name": "Follow-up visit", "amount": 7500, "currency": "usd", "quantity": 1}
    ]
  }'
```

Return the session's `id`, `client_secret`, and `embed_url` to the merchant's
page and mount it as described in
[embedded checkout](https://docs.ionicfi.com/guides/embedded-checkout.md). The frame loads only on a
website registered for the session's merchant. If your page sends a Content
Security Policy, add the [checkout entries](https://docs.ionicfi.com/guides/embedded-checkout.md#content-security-policy).

## Add Apple Pay

1. Download the verification file from
   `https://app.ionicfi.com/.well-known/apple-developer-merchantid-domain-association`.
   The same file serves every domain.
2. Serve it unchanged on the merchant's site at
   `https://clinic-a.your-platform.com/.well-known/apple-developer-merchantid-domain-association`.
   Return HTTP 200 directly, with no redirect or login.
3. Register the domain for Apple Pay with the merchant's account:

   ```bash theme={null}
   curl -X POST https://api.ionicfi.com/v1/web_domains/wd_2Mq8Lr4Tn6Vx0Z/apple_pay \
     -H "Authorization: Bearer $IONIC_PLATFORM_SECRET_KEY" \
     -H "Ionic-Account: mer_REPLACE_WITH_MERCHANT_ID"
   ```

   Check `apple_pay.status` in the response. A `failed` status comes with an
   `apple_pay.error` that says what to fix.
4. Pass `applePay: true` when you mount checkout, and add the
   [Apple Pay policy entries](https://docs.ionicfi.com/guides/apple-pay.md#content-security-policy) if
   your page sends a Content Security Policy.

## Manage the merchant's domains

* `GET /v1/web_domains` with `Ionic-Account` lists only the domains your
  platform added for that merchant.
* `DELETE /v1/web_domains/{id}` removes one. A domain registered for Apple Pay
  is deregistered first.
* The merchant sees these domains in its dashboard, marked with your platform,
  and can remove them.
* When the connection is suspended or ends, the domains your platform added stop
  working immediately and checkout no longer loads on them. They work again if
  a suspended connection is restored.

Ionic Blocks still uses your platform's own
[payment domains](https://docs.ionicfi.com/guides/platform-payment-domains.md), registered without
`Ionic-Account`.

## Errors

| Status | Code | Meaning |
| - | - | - |
| 403 | `ACCOUNT_ACCESS_DENIED` | No active connection to this merchant in this mode. |
| 403 | `PERMISSION_DENIED` | The connection does not grant checkout session access. |
| 403 | `INSUFFICIENT_PERMISSIONS` | Your key does not hold the permission. |
| 403 | `CONNECT_UNAVAILABLE` | Your Program does not allow this permission in this mode. |
| 403 | `MERCHANT_INACTIVE` | The merchant is not active. Applies to adding a domain and registering Apple Pay. |
| 404 | `NOT_FOUND` | Your platform did not add this domain for the merchant. |
| 409 | `WEB_DOMAIN_CONFLICT` | The merchant, or another platform, already registered this origin. |


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