# Add e-signatures and clickwrap to Symfony

> Add e-signatures and clickwrap to Symfony with one controller and symfony/http-client: POST /v1/sessions, GET /v1/records, retry_failed, the session and Twig.

Source: https://esigncomply.com/symfony

Stack · Symfony

To add e-signatures and clickwrap to Symfony, call the REST API from a controller with `symfony/http-client`: there is no bundle, because the server SDK exists for Node.js only. One action creates the session with the secret key and pins the versions in the Symfony session, and another confirms the record. Esign Comply seals each acceptance as an independent record.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/symfony)

No bundle to install: composer require symfony/http-client symfony/twig-bundle

[Symfony quickstart](https://esigncomply.com/docs/quickstart/symfony)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run in Symfony before publishing

**Session action**

src/Controller/SignupController.php (excerpt)

```php
// Step 4: create the session with the secret key. The browser gets the client token only.
#[Route('/api/ceremony', methods: ['POST'])]
public function ceremony(Request $request): JsonResponse
{
    [$status, $session] = $this->esc('POST', 'sessions', [
        'headers' => ['Idempotency-Key' => 'signup-'.self::SIGNER['external_id'].'-'.bin2hex(random_bytes(16))],
        'json' => [
            'profile' => $this->profile,
            'signer' => self::SIGNER,
            'documents' => [
                ['document' => $this->terms, 'version' => 'current'],
                ['document' => $this->privacy, 'version' => 'current'],
            ],
            // The page that runs the ceremony: the scheme and host Symfony worked out for this request.
            'context' => ['url' => $request->getSchemeAndHttpHost().'/signup', 'locale' => 'en-US', 'purpose' => 'account_signup'],
        ],
    ]);
    if (201 !== $status) {
        return $this->json(['error' => $session['error']['code'] ?? 'unknown'], 502);
    }

    // Server-owned state: Symfony's session. The data stays on the server, and the browser holds only the session ID.
    $request->getSession()->set('esc_signup', [
        'signer_id' => self::SIGNER['external_id'],
        'version_ids' => array_column($session['documents'], 'version_id'),
    ]);

    return $this->json(['clientToken' => $session['client_token'], 'apiUrl' => $session['api_url'], 'documents' => $session['documents']]);
}
```

**Scoped client**

config/packages/framework.yaml (excerpt)

```yaml
http_client:
    scoped_clients:
        # There is no Composer package for the API: this is Symfony's own client, scoped to the API address.
        esigncomply.client:
            base_uri: '%env(ESIGNCOMPLY_API_URL)%/'
            auth_bearer: '%env(ESIGNCOMPLY_API_KEY)%'
            timeout: 10
            # Each attempt may take 10 seconds, the wait before it included.
            max_duration: 10
            # Over the rate limit: Symfony waits for Retry-After and sends the request again, twice at most.
            retry_failed:
                http_codes: { 429: true }
                max_retries: 2
```

**The API call**

src/Controller/SignupController.php (excerpt)

```php
/** One call to the Esign Comply API. Returns [status, decoded JSON]. The path has no leading slash. */
private function esc(string $method, string $path, array $options = []): array
{
    $response = $this->esigncomplyClient->request($method, $path, $options);

    // false: Symfony does not throw on 4xx and 5xx. The status is here, and the error envelope is the body.
    return [$response->getStatusCode(), $response->toArray(false)];
}
```

**Confirm action**

src/Controller/SignupController.php (excerpt)

```php
// Step 6: confirm the record with the secret key before the account exists.
#[Route('/api/signup/confirm', methods: ['POST'])]
public function confirm(Request $request): JsonResponse
{
    // A body that is not JSON never gets here: getPayload() throws, and Symfony answers 400.
    $recordId = $request->getPayload()->getString('recordId', 'missing');
    $session = $request->getSession();
    $pinned = $session->get('esc_signup', []);
    $session->save(); // close the session now: PHP keeps it locked while it is open, and the API call may wait

    [$status, $record] = $this->esc('GET', 'records/'.rawurlencode($recordId));

    $versions = array_column($record['documents'] ?? [], 'version_id');
    $expected = $pinned['version_ids'] ?? [];
    sort($versions);
    sort($expected);
    $confirmed = 200 === $status
        && \in_array($record['status'], self::SEALED, true)
        && $record['livemode'] === $this->live
        && $record['signer']['external_id'] === ($pinned['signer_id'] ?? null)
        && $versions === $expected;

    error_log($confirmed ? "confirmed {$record['id']} ({$record['status']})" : 'refused');
    if (!$confirmed) {
        return $this->json(['confirmed' => false], 409);
    }

    // Only now create the account, and store $record['id'] and $record['receipt'] with it.
    return $this->json(['confirmed' => true, 'recordId' => $record['id']]);
}
```

Integrate with Symfony

## How do you integrate Esign Comply with Symfony?

In Symfony the client is configuration: a scoped client in `framework.yaml` carries the API address, the key from `.env.local` and `retry_failed` for the rate limit. One controller with route attributes holds the four routes, the session holds the versions the server pinned, and a Twig template prints the registered document with the `raw` filter.

Symfony is a powerful PHP framework that empowers developers to build scalable, high-performance web applications with reusable components, comprehensive documentation, and a strong community.

Source: [symfony.com](https://symfony.com/), read on November 26, 2026.

[Symfony quickstart](https://esigncomply.com/docs/quickstart/symfony) · [All stacks](https://esigncomply.com/stacks)

Where each part lives in Symfony

- **Session action** · `src/Controller/SignupController.php`
- **Scoped client** · `config/packages/framework.yaml`
- **The API call** · `src/Controller/SignupController.php`
- **Confirm action** · `src/Controller/SignupController.php`

Run on 2026-11-26 with Symfony 8.1.12 from the official skeleton (symfony/http-client 8.1.12, symfony/twig-bundle 8.1.9, Twig 3.31.1) on PHP 8.5.13 with Composer 2.11.2 (the official Composer container image), under the local web server of the Symfony CLI 5.23.0 with PHP CGI, in the dev environment and with APP_ENV=prod, with the browser SDK script build and the conformance check from esigncomply 1.0.4, against the API in test mode.

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Symfony app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes in Symfony, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at [/rules.md](https://esigncomply.com/rules.md). Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The [prompt generator](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap in Symfony

```
Add Esign Comply clickwrap to my Symfony app: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/symfony.md (the steps and the tested code for Symfony)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Symfony facts
- There is no Esign Comply bundle or Composer package. Do not install or invent one. A controller calls the REST API at https://esigncomply.com/v1 with symfony/http-client, auth_bearer and the secret key.
- The browser SDK is a script tag: https://esigncomply.com/sdk/v1/esigncomply.js. It defines the global EsignComply.
- The secret key is ESIGNCOMPLY_API_KEY in .env.local, which is not committed. Never put it in .env, which is. Never print the key.
- Configure a scoped client in config/packages/framework.yaml with base_uri ending in a slash, and request paths without a leading slash: a leading slash drops the /v1 of the base address.
- Read answers with getStatusCode() and toArray(false). Without false, toArray() throws on 4xx and 5xx.
- For the rate limit use retry_failed with http_codes 429 and max_retries 2, and set max_duration: Symfony waits for Retry-After, however long, max_delay does not cap it, and only max_duration ends that wait.
- Keep the signer ID and the pinned version IDs in the session. Call save() on the session before the API call in the action that only reads it: PHP keeps a session locked while it is open.
- Symfony applies no CSRF check to these routes. Never treat reaching a route as proof of where the request came from.
- Print the registered document HTML with the raw filter. Without it Twig escapes the tags and the page no longer matches the registered version.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Action for POST /api/ceremony: call POST /v1/sessions with an Idempotency-Key, save the signer ID and the pinned version IDs in the session, and return only clientToken, apiUrl and documents.
4. Action for GET /legal/{slug}: render the html from GET /v1/documents/{id}/versions/{version_id}/content inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Action for POST /api/signup/confirm: call GET /v1/records/{id} and require: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the ones in the session. Only then create the account.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:8000/signup --callback http://localhost:8000/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
```

3 things to watch

## What goes wrong when you add e-signatures in Symfony?

These are specific to Symfony. Each one was seen while the quickstart's code was run, or is in Symfony's own documentation.

- **retry_failed waits as long as Retry-After says**

  Symfony's documentation says failed requests are retried with an exponential delay, for `429` among other codes. In the test on Symfony 8.1.12 the header won over that delay, and `max_delay` did not cap it: with `max_delay` at 1 second and `Retry-After: 3`, the calls came 3.00 seconds apart. With `Retry-After: 30` and `max_duration: 10`, the call ended after 10.0 seconds with `Max duration was reached`. The quickstart sets `max_duration` for that reason.

  Source: [Symfony documentation, HTTP Client](https://symfony.com/doc/current/http_client.html), read on November 26, 2026.

- **composer dump-env prod writes the secret key into .env.local.php**

  Symfony's documentation says the command parses all `.env` files and dumps their final values to `.env.local.php`, which Symfony then loads instead. In the test that file held `ESIGNCOMPLY_API_KEY` in plain text with mode `644`, and a later change in `.env.local` was not read until the file was deleted. The skeleton's `.gitignore` lists the file.

  Source: [Symfony documentation, Configuring Symfony](https://symfony.com/doc/current/configuration.html), read on November 26, 2026.

- **Without trusted proxies Symfony ignores X-Forwarded-Proto and X-Forwarded-Host**

  Symfony's documentation says you get incorrect information about HTTPS and the requested host until you tell it which proxies to trust. In the test, `getSchemeAndHttpHost()` stayed on `http` and `localhost` with both headers sent, and the session cookie was not `Secure`. With `SYMFONY_TRUSTED_PROXIES` and `SYMFONY_TRUSTED_HEADERS` set, it returned `https://app.example` and the cookie was `Secure`. The quickstart builds `context.url` from that method.

  Source: [Symfony documentation, Behind a Proxy](https://symfony.com/doc/current/deployment/proxies.html), read on November 26, 2026.

## Where are the Symfony quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[Symfony quickstart](https://esigncomply.com/docs/quickstart/symfony)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature in Symfony?

The same record on every stack and platform. Your Symfony code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on [Evidence and verification](https://esigncomply.com/product/evidence).

- **Observed and asserted fields**

  Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

- **A signed receipt**

  `complete()` returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and `GET /v1/records/{id}/receipt` returns it again.

- **An external timestamp**

  An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

- **An offline verifier**

  Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source `esigncomply-verify`, without an account.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures in Symfony

### Is there an Esign Comply SDK for Symfony?

No. There is no bundle and no Composer package, because the server SDK exists for Node.js only. A Symfony app calls the REST API directly with the secret key, and the quickstart does it with `symfony/http-client` and a scoped client in `framework.yaml`.

### Where do I create the session in Symfony?

In a controller action with `#[Route('/api/ceremony', methods: ['POST'])]`, with a `POST` to `/v1/sessions` that carries the secret key and an `Idempotency-Key`. The action saves the pinned versions in the session and returns only the client token, the API URL and the documents as JSON.

### Does Symfony's HttpClient honour Retry-After on a 429?

Yes, with `retry_failed`. In the test against a stand-in that answered `429` with `Retry-After: 2`, the three calls arrived 2.00 seconds apart with the same `Idempotency-Key`. Four confirmations sent at once all answered `200`: the API's log showed one read refused with `429` and passed on the next attempt.

### Does Symfony apply CSRF protection to the confirm route?

No. Symfony checks a CSRF token in its forms and where you ask for one, and the skeleton does not install `symfony/security-csrf`. In the test a `POST` with the session cookie and `Origin: https://evil.example` was answered `200`. What refuses a forged confirmation is the route's own four checks.

### Does the key belong in .env or in .env.local?

In `.env.local`. Symfony's skeleton lists that file in `.gitignore`, and the header of `.env` says not to define production secrets in a committed file. In the test Symfony read `.env.local` itself, and a real environment variable with the same name won over it.

### Other stacks

- [PHP](https://esigncomply.com/php)
- [Laravel](https://esigncomply.com/laravel)
- [Django](https://esigncomply.com/django)

### Platforms used with Symfony

- [Railway](https://esigncomply.com/railway)
- [Render](https://esigncomply.com/render)
- [Fly.io](https://esigncomply.com/fly-io)

[All stacks](https://esigncomply.com/stacks) · [All platforms](https://esigncomply.com/platforms) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Add one controller to your Symfony app. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/symfony)

Free plan: 10 live signatures a month and a full test mode. No card required.

Symfony is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Symfony is from Symfony's documentation or from a test run, as marked, on November 26, 2026. `/symfony.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
