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

# Mandate Signing

The `mandate-signing` UI Element lets a payer review and sign a SEPA Direct Debit mandate from an invitation link,
without leaving your application. It presents the mandate form, collects the payer details, and reports the outcome
back to your page through events.

For security and compliance reasons, the mandate data can't leave the Qonto domain and therefore the UI this element
injects into your website is implemented with an iframe. This way, the data is securely handled by Qonto while still
being accessible from your application. The iframe resizes itself to fit its content, so you don't need to set a height
on the container.

> [!NOTE]
>
> The mandate invitation page is public, so this UI Element doesn't need an
> [access
> token](https://docs.qonto.com/api-reference/sdk-libraries/variables/initialize.md#initializeparams) or
> a [proxy
> endpoint](https://docs.qonto.com/partnerships/embed/sdk/proxy-endpoint-implementation.md).
> You only need the ID of the invitation link and the container where the
> element will be rendered.

## How it works

The mandate signing is rendered by calling the [`createUIElement`](https://docs.qonto.com/api-reference/sdk-libraries/variables/ui#createuielement) function with the appropriate
settings:

```ts theme={null}
import { ui } from '@qonto/embed-sdk/ui';

ui.createUIElement({
  uiElementSettings: {
    uiElementName: 'mandate-signing',
    uiElementParams: {
      invitationLinkId: 'your-invitation-link-id',
    },
  },
  operationSettings: {
    uiParentElementId: 'mandate-signing-ui-container',
  },
});
```

When initialized, the element loads the mandate invitation and shows the form. All the data fetching and the signing
itself happen automatically, without requiring additional configuration from your side.

For details about the SDK function to call to display the mandate signing UI, please refer to
the [createUIElement API Reference](https://docs.qonto.com/api-reference/sdk-libraries/variables/ui.md#createuielement).

### Parameters

You pass these parameters in `uiElementSettings.uiElementParams`:

| Parameter | Type | Required | Description |
| - | - | - | - |
| `invitationLinkId` | `string` | Yes | The ID of the mandate invitation link to display. See [Get the invitation link ID](#get-the-invitation-link-id). |

The element honors the `locale` passed in `operationSettings` (or set when initializing the SDK). The supported
values are `en`, `fr`, `de`, `es`, `it` and `pt`.

### Get the invitation link ID

The `invitationLinkId` comes from a blank mandate invitation link generated in the Qonto web app. It is not the
`sign_url` returned when you [create a mandate through the API](https://docs.qonto.com/guides/payments/sepa-direct-debit.md).

1. In the Qonto web app, go to the **Share blank mandate** step of the mandate creation flow
   (`/flows/direct-debit-collections/create-mandate/share-blank-mandate`).
2. Click **Generate mandate link**. The invitation link is copied to your clipboard.
3. The link looks like `https://pay.qonto.com/mandate-invite/<invitation_link_id>`. Pass the last part of the path,
   `<invitation_link_id>`, as `invitationLinkId`.

```ts theme={null}
const invitationLink = 'https://pay.qonto.com/mandate-invite/<invitation_link_id>';
const invitationLinkId = new URL(invitationLink).pathname.split('/').pop();
```

### Validation and errors

`createUIElement` rejects with an `InvalidParametersError` and doesn't render anything in these cases:

* `invitationLinkId` is missing, empty or not a string.
* `locale` is not one of the supported values.

It rejects with an `EmbedOperationError` if the parent element with the given `uiParentElementId` is not found, or if the
element doesn't finish loading within 30 seconds.

> [!NOTE]
>
> If the container already holds a mandate signing element, calling
> `createUIElement` again replaces it instead of adding a second one. The
> previous element is removed before the new one is mounted. Parameters are
> validated first, so if the call is rejected with an `InvalidParametersError`
> (the error is still thrown), the existing element stays in place.

## Emitted events

The mandate signing UI Element emits the following events when users interact with it. You can set up a listener by
passing a function as the `uiElementSettings.uiElementEventListener` parameter when calling `createUIElement`.

### Mandate loaded

This event is emitted when the mandate invitation has loaded and the form is shown. It has no `eventDetail`.

```ts theme={null}
import { ui } from '@qonto/embed-sdk/ui';

ui.createUIElement({
  uiElementSettings: {
    uiElementName: 'mandate-signing',
    uiElementParams: { invitationLinkId: 'your-invitation-link-id' },
    uiElementEventListener: ({ eventName, eventDetail }) => {
      if (eventName === 'mandate-loaded') {
        // React to the mandate being displayed, for example to hide a loading indicator
      }
    },
  },
  operationSettings: {
    uiParentElementId: 'mandate-signing-ui-container',
  },
});
```

### Mandate signed

This event is emitted as soon as the mandate is successfully signed. It is useful in case you want to track the result,
or to automatically move the user to the next step of your flow without waiting for user interaction. It has no
`eventDetail`.

```ts theme={null}
import { ui } from '@qonto/embed-sdk/ui';

ui.createUIElement({
  uiElementSettings: {
    uiElementName: 'mandate-signing',
    uiElementParams: { invitationLinkId: 'your-invitation-link-id' },
    uiElementEventListener: ({ eventName, eventDetail }) => {
      if (eventName === 'mandate-signed') {
        // React to the mandate being signed
      }
    },
  },
  operationSettings: {
    uiParentElementId: 'mandate-signing-ui-container',
  },
});
```

### Mandate error

This event is emitted when the mandate can't be loaded or signed. The `eventDetail` contains a `code` that tells you
what happened:

| Code | Meaning |
| - | - |
| `not_found` | The invitation link doesn't exist. |
| `expired` | The invitation link has expired. |
| `load_failed` | The invitation couldn't be loaded for any other reason. |
| `sign_failed` | The mandate was displayed, but the signing request failed. |

You only need to listen for this event if you want to react to the failure, for example to track it or to take the
user out of the signing step when the invitation can't be used.

```ts theme={null}
import { ui } from '@qonto/embed-sdk/ui';

ui.createUIElement({
  uiElementSettings: {
    uiElementName: 'mandate-signing',
    uiElementParams: { invitationLinkId: 'your-invitation-link-id' },
    uiElementEventListener: ({ eventName, eventDetail }) => {
      if (eventName === 'mandate-error') {
        switch (eventDetail?.code) {
          case 'not_found':
          case 'expired':
          case 'load_failed':
            // The invitation can't be used: take the user out of the signing step
            // (for example, back to the previous page) and tell them what happened
            break;
          case 'sign_failed':
            // The signing request failed: track the failed attempt
            break;
        }
      }
    },
  },
  operationSettings: {
    uiParentElementId: 'mandate-signing-ui-container',
  },
});
```

## Content Security Policy

The mandate signing UI Element is rendered in an iframe hosted by Qonto. If your website sends a
[Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP), allow the Qonto embed host in the
`frame-src` directive (or in `default-src` if you don't set `frame-src`):

```
Content-Security-Policy: frame-src https://embed.qonto.com;
```

If the policy blocks the frame, the browser doesn't load it and reports a violation in the console, such as
`Framing 'https://embed.qonto.com/' violates the following Content Security Policy directive`. The `createUIElement`
call is then rejected with an `EmbedOperationError` after 30 seconds, and the frame is removed from the container. The
error message doesn't mention the policy, so check the browser console if you see this error and your site sets a CSP.

> [!NOTE]
>
> When you test against the staging environment, the host is different. Allow
> the staging embed host as well, for example
> `https://embed-js-master.staging.qonto.co`.

## Customization

Like the rest of the UI Elements, the mandate signing element can be adapted to your branding by defining CSS variables
with the `--qonto-embed-` prefix in your stylesheet. The SDK reads the variables from your stylesheets and passes them to
the element when it mounts.

```css theme={null}
:root {
  --qonto-embed-color-primary: #7e1adb;
  --qonto-embed-button-primary-background-color: #7e1adb;
  --qonto-embed-button-primary-font-color: #ffffff;
  --qonto-embed-button-border-radius: 24px;
}
```

Since the mandate signing element is rendered by Qonto inside an iframe, it only applies a fixed set of variables, and
only when their values are valid. Any other variable, and any value outside the accepted format or range, is ignored.

| Area | Variables |
| - | - |
| Colors | `color-primary`, `background-color`, `content-color-primary`, `content-color-primary-inverted`, `content-color-secondary`, `content-error`, `container-border-color` |
| Inputs | `input-background`, `input-text-color`, `input-placeholder-color`, `input-focus-border-color`, `input-error-border-color`, `input-border`, `input-border-radius` |
| Button | `button-primary-background-color`, `button-primary-background-color-hover`, `button-primary-font-color`, `button-primary-border`, `button-font-size`, `button-font-weight`, `button-height`, `button-border-radius` |
| Typography | `font-family`, `content-font-size`, `content-font-weight`, `content-line-height`, `heading-font-size-1`, `heading-font-size-2`, `heading-font-weight-1`, `heading-font-weight-2`, `heading-line-height` |
| Container | `container-border-radius` |

Accepted values:

* **Colors** must be hexadecimal (`#7e1adb`, `#7e1adbff`), `rgb()`/`rgba()`, `hsl()`/`hsla()` or `transparent`.
* **Lengths** must be in `px` or `rem`, within a reasonable range for the property (for example, `button-border-radius`
  and `container-border-radius` accept `0` to `32px`).
* **Font weights** must be `normal`, `bold` or a number from `100` to `900`.
* **Line heights** must be a unitless number from `1` to `2.5`.
* **Borders** must be `none` or a width of up to `4px`, a style (`solid`, `dashed`, `dotted` or `double`) and a color, for
  example `1px solid #7e1adb`.
* **Font families** must be system fonts, with a maximum of five names (for example, `Arial, Helvetica, sans-serif`).

For guidance on how to define and apply the variables, please refer to the
[customizing UI elements](https://docs.qonto.com/partnerships/embed/sdk/customizing-ui-elements.md)
documentation.
