Skip to content
Stack guide · Laravel

Clickwrap agreement in Laravel

Eight files put a terms and privacy checkbox on your Laravel registration, call the Esign Comply API with the Http facade, and create the user only after the acceptance is confirmed as a sealed record.

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

8 files · copy and run

The working code: a signup clickwrap in Laravel

A service class, four controllers, one Blade view, a migration with its model, and the routes. There is no Composer package to require: Laravel's own HTTP client does the work.

app/Services/EsignComply.php
<?php
// app/Services/EsignComply.php

namespace App\Services;

use App\Models\Acceptance;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;

// The whole client. There is no Composer package to install: these are plain HTTPS calls with the secret key.
class EsignComply
{
    public const SEALED = ['recorded', 'timestamped', 'anchored'];

    // POST /v1/sessions. The response carries client_token, api_url and the pinned documents.
    public static function createSession(array $signer, string $url): array
    {
        return self::client()
            ->withHeaders(['Idempotency-Key' => 'signup-'.$signer['external_id']])
            ->post('/sessions', [
                'profile' => config('services.esigncomply.profile'),
                'signer' => $signer,
                'documents' => [
                    ['document' => config('services.esigncomply.terms'), 'version' => 'current'],
                    ['document' => config('services.esigncomply.privacy'), 'version' => 'current'],
                ],
                'context' => ['url' => $url, 'locale' => 'en-US', 'purpose' => 'account_signup'],
            ])
            ->throw()
            ->json();
    }

    // GET /v1/records/{id}
    public static function getRecord(string $recordId): array
    {
        return self::client()->get('/records/'.rawurlencode($recordId))->throw()->json();
    }

    // GET /v1/documents/{id}/versions/{version_id}/content
    public static function getDocumentContent(string $documentId, string $versionId): array
    {
        return self::client()
            ->get('/documents/'.$documentId.'/versions/'.rawurlencode($versionId).'/content')
            ->throw()
            ->json();
    }

    // Server confirmation: read the record with the secret key and compare it with
    // what this server saved when it created the session.
    public static function confirmRecord(string $recordId, Acceptance $acceptance): ?array
    {
        try {
            $record = self::getRecord($recordId);
        } catch (RequestException|ConnectionException) {
            return null; // a made-up ID, a record from the other environment, or the API could not be reached
        }

        $actual = array_column($record['documents'], 'version_id');
        $expected = $acceptance->document_version_ids;
        sort($actual);
        sort($expected);

        $confirmed = in_array($record['status'], self::SEALED, true)
            && $record['livemode'] === app()->isProduction()
            && $record['signer']['external_id'] === $acceptance->signer_id
            && $actual === $expected;

        return $confirmed ? $record : null;
    }

    private static function client(): PendingRequest
    {
        return Http::baseUrl(config('services.esigncomply.url'))
            ->withToken(config('services.esigncomply.key')) // Authorization: Bearer <key>
            ->acceptJson()
            ->timeout(10)
            // Rate limited: wait out the one-second window and try again (the Free plan allows 2 requests per second).
            ->retry(3, 1000, fn ($exception) => $exception instanceof RequestException && $exception->response->status() === 429);
    }
}

What each file does

Eight files, four jobs: create the session in a controller, collect the acceptance in your own Blade view, confirm the record before User::create, and keep the receipt next to the user.

01

EsignComply.php: the whole client on the Http facade

app/Services/EsignComply.phpView the file

The server SDK is for Node, so Laravel calls the REST API itself. client() sets the base URL, withToken sends Authorization: Bearer <key>, and createSession adds an Idempotency-Key to its POST /v1/sessions. retry waits a second and tries again on a 429, because the Free plan allows 2 requests per second and one signup makes three calls close together.

confirmRecord guards the registration. It reads GET /v1/records/{id} and returns the record only when the status is recorded, timestamped or anchored, livemode equals app()->isProduction(), and the signer and the exact set of document versions equal what the Acceptance model holds.

02

SignupCeremonyController: create the session, return the client token

app/Http/Controllers/SignupCeremonyController.phpView the file

The form posts the email, country and state here once the email is entered. The controller validates them, makes a signer ID, creates the session and saves an Acceptance with the signer ID and the version IDs the session pinned. That row is the server-owned state the confirmation compares against. The session ID goes into the Laravel session.

The JSON response has three keys: clientToken, apiUrl and documents. The client token is short-lived and scoped to this one session. The secret key and the rest of the session object stay on the server.

03

signup.blade.php: your notice, your checkbox, your button

resources/views/auth/signup.blade.phpView the file

A complete page you can fold into your layout. The notice names the button and both documents, the links are underlined and coloured apart from the text around them, and the checkbox starts unchecked and disabled. The script enables it only after observeAssent is watching, so every tick is one the SDK saw happen.

The script loads the browser SDK from https://esigncomply.com/sdk/v1/esigncomply.js, posts to signup.ceremony with the @csrf token in the X-CSRF-TOKEN header, and calls EsignComply.attach with the client token. presentDocument reports each link, the change event opens the button when the signing act is the only step left, and complete() runs from the real click. The record ID is then posted to RegisterController@store with the rest of the form.

04

RegisterController: confirm first, then User::create

app/Http/Controllers/RegisterController.phpView the file

store validates the email and password, then treats the posted record_id as a claim. It finds the open Acceptance for this Laravel session and asks EsignComply::confirmRecord to check the claim against it. No row, no record or a mismatch returns 409, the page tells the signer the acceptance could not be confirmed, and no account is created.

On a confirmed record it creates the user, writes the user ID, the record ID, the signed receipt and the accepted time onto the row, and signs the user in.

05

The migration and the Acceptance model

database/migrations/2026_11_22_000000_create_acceptances_table.phpView the file

One row per ceremony. signer_id, session_id and document_version_ids are written when the session is created. user_id, record_id, receipt and accepted_at are filled in when the record is confirmed. The model casts the version IDs to an array, so the confirmation compares two plain lists.

The receipt is a compact signed token (ES256) that names the record hash. A row with no record ID is a registration that was started and abandoned: sessions expire after 30 minutes, so open rows older than a day are safe to prune.

06

LegalController: the registered version, unmodified

app/Http/Controllers/LegalController.phpView the file

/legal/terms and /legal/privacy render the version Esign Comply holds, fetched by the version ID in ?v=. The Blade view prints the returned HTML with {!! !!} inside <article data-esc-document> and nothing else. When the form reports a link, the browser SDK reads this page, hashes the article's text and sends the hash, and the API compares it with the registered version (rule CR-08).

07

EsignWebhookController: verify the signature, fill the open row

app/Http/Controllers/EsignWebhookController.phpView the file

record.completed arrives once a record is sealed, including when the browser closed before store ran. The controller takes the raw body from $request->getContent(), rejects a timestamp more than 5 minutes from now and recomputes HMAC-SHA256 over <webhook-id>.<webhook-timestamp>.<raw body>, keyed with the base64-decoded part of the secret after whsec_. hash_equals keeps the comparison constant-time.

Deliveries are at-least-once, and the handler only fills a row that is still open, so a repeat changes nothing.

08

web.php and config/services.php

routes/web.phpView the file

Five routes and one config entry. The webhook route is excluded from CSRF protection in bootstrap/app.php, because the delivery is signed. The services.esigncomply entry reads the key, the webhook secret and the three IDs from .env, so the code never calls env() directly.

Test mode

Run it

From an empty account to a sealed test record on localhost:8000. No domain, no card and no Composer package.

  1. 01

    Create a free account and a test key

    Sign up, then choose Create test key in the dashboard. The key starts with esc_test_ and is shown once. The Free plan needs no card, and test keys work on localhost on any port with no domain.

  2. 02

    Register your two documents and a signup profile

    In the dashboard, add a document named Terms of Service and one named Privacy Notice, publish a version of each, and create a profile with method checkbox and level L1. The names matter: the notice in the form names each document by its title, and rule CR-02 looks for both. Copy the three IDs.

  3. 03

    Set the environment variables

    Add these to .env. The services.esigncomply entry in the last tab maps them into config.

    .env
    ESIGNCOMPLY_API_KEY=esc_test_us_...       # the test key, shown once in the dashboard
    ESIGNCOMPLY_PROFILE_ID=prof_signup_4f1a   # the signup profile: checkbox, L1
    ESIGNCOMPLY_TERMS_ID=doc_8Hq2             # Terms of Service
    ESIGNCOMPLY_PRIVACY_ID=doc_Pv71           # Privacy Notice
    ESIGNCOMPLY_WEBHOOK_SECRET=whsec_...      # only for the webhook
    # An EU key (esc_test_eu_...) also needs:
    # ESIGNCOMPLY_API_URL=https://api.eu.esigncomply.com/v1
  4. 04

    Migrate and start the server

    The migration adds the acceptances table.

    $php artisan migrate && php artisan serve
  5. 05

    Sign up once

    Open http://localhost:8000/signup. Enter an email and move to the next field: the checkbox unlocks when the session is attached. Tick it and click Create account.

  6. 06

    Open the test record

    The dashboard lists one new test record under Records. It shows what Esign Comply observed from the browser (the page attached, both documents presented, the notice captured, the tick, the signing act), the conformance findings and the evidence report, watermarked TEST. Your acceptances row holds the same record ID and its signed receipt.

  7. 07

    Run the conformance check

    The checker is a Node CLI, so it needs Node.js 20.19 or later on your machine, not in your app. The command reads ESIGNCOMPLY_API_KEY from your shell and takes test keys only. It opens your page in headless Chromium at 390 by 844, 768 by 1024 and 1440 by 900, tries to submit without the tick and with a scripted click, then signs up for real at each size, so expect three test users in your development database. Every finding names its rule, the measurement and the fix, and the exit code fails a CI build. A clean run ends with 0 block.

    $npx esigncomply@latest check --url http://localhost:8000/signup
Live mode

Going live

The same code runs in test and live. What changes is .env on the production server.

  1. 01
    Register your domainEnter your production host in the dashboard under Domains. Registering app.example.com covers example.com and every subdomain, and every plan, Free included, covers that one domain.
  2. 02
    Verify it with one TXT recordAdd a TXT record named _esigncomply with the value esc-verify=<token> that the dashboard shows. Esign Comply checks every minute for the first hour. Leave the record in place: it is checked again every day.
  3. 03
    Add your organization detailsEnter your organization's legal name and country in the dashboard. The Free plan covers 10 live signature events a month with no checkout. Starter is $200 per year for 2,000 live signature events, and Unlimited is $1,200 per year. One event is one signer's completed signing act, so the terms and the privacy notice accepted together at signup count once.
  4. 04
    Switch to the live keyCreate a live key (esc_live_...) and put it in the production .env only. Copy your documents and profile to live from the dashboard and set the live IDs beside it. With APP_ENV=production, app()->isProduction() makes the confirmation expect a live record, so a test record cannot open a production account.

In live mode context.url has to be inside your registered domain, browser calls are accepted only from it, and a finding at Block level stops the record from being sealed. Run the conformance check until nothing blocks before you switch keys.

Copy-paste prompt

Have your AI tool do it instead

Paste this into Cursor, Claude Code or any coding agent that is open on your Laravel app. It names the two things a tool gets wrong on this stack: there is no Composer package, and the browser SDK comes from a script tag.

The prompt generator writes the long version: your own document and profile IDs, the rule packs for your regions and the stack you pick, in one prompt.

Generate a prompt
Prompt: clickwrap in Laravel
Add a signup clickwrap to this Laravel app with Esign Comply. A new user accepts our Terms of Service and Privacy Notice before the account is created. We render every screen. Esign Comply observes it and keeps the independent record.

Read these first and follow them exactly:
- https://esigncomply.com/setup.md
- https://esigncomply.com/auth.md
- https://esigncomply.com/llms.txt
- https://esigncomply.com/guides/laravel-clickwrap (working code for this stack: use it as the reference)

Stack
- There is no Esign Comply Composer package. Call the REST API with the Http facade: withToken(config('services.esigncomply.key')), and an Idempotency-Key header on POST requests.
- Load the browser SDK with <script src="https://esigncomply.com/sdk/v1/esigncomply.js"></script>. It defines the global EsignComply.

Build
1. POST /signup/ceremony: create the session with POST /v1/sessions. Return only client_token, api_url and the pinned documents. Save the signer ID and the version IDs on an Acceptance model.
2. The Blade signup view: attach the SDK to our own unchecked checkbox and our Create account button. Present each document link, observe the assent container, and call complete() from the user's real click.
3. POST /signup: before User::create, read GET /v1/records/{id} and require status recorded, timestamped or anchored, livemode equal to app()->isProduction(), and the saved signer ID and version IDs. Store the record ID and the receipt on the acceptance row.

Never
- Never invent API methods, packages or legal wording.
- Never pre-check the box, auto-submit or click for the user.
- Never put the secret key in client code, in a template or in the repository, and never print it.
- Never create the account before the server has confirmed the record.

If anything conflicts with existing code, stop and ask me. Finish with npx esigncomply@latest check --url http://localhost:8000/signup and fix every finding marked "block".

Questions about a clickwrap in Laravel

Is there a Composer package for Esign Comply?

No, and the integration does not need one. The server SDK exists for Node. A Laravel app calls the REST API with the Http facade, and a signup clickwrap uses three calls: POST /v1/sessions, GET /v1/records/{id} and one GET for the registered document text. The service class on this page is the whole client.

How do I add a clickwrap agreement to a Laravel registration form?

Create a session from a controller with your secret key and return only the client token. In the Blade view, load the browser SDK with a script tag and attach it to your own unchecked checkbox and submit button. When the signer clicks, the SDK returns a record ID. Confirm that record on your server with GET /v1/records/{id} before User::create, and store the record ID and receipt in an acceptances table.

Where does the confirmation go if I use a starter kit?

Wherever the kit calls User::create. In Breeze that is RegisteredUserController::store, and in Fortify and Jetstream it is the CreateNewUser action. Run EsignComply::confirmRecord there first and create the user only when it returns a record.

Why is the webhook route excluded from CSRF protection?

Because it is a server-to-server POST, not a form in a browser. Esign Comply signs each delivery with HMAC-SHA256, and the controller verifies that signature on the raw body and rejects timestamps more than 5 minutes from now. The signature is the authentication, so the route is listed under validateCsrfTokens(except: ...) in bootstrap/app.php.

Read the webhook reference

What happens when my Laravel app hits the rate limit?

The API answers 429 with a Retry-After header, and the client on this page waits a second and sends the request again, up to three times. The Free plan allows 2 requests per second per key, Starter 10 and Unlimited 50. Calls made by the signer's browser are limited per session, not per key, so a busy signup page does not use up your key's limit.

See the plans

Add the eight files to your Laravel app. Leave the record to us.

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

Working with an AI tool? This page is also available as Markdown: /guides/laravel-clickwrap.md