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

# Checkout review

> Run the standalone checkout-risk app and compare its starter and final versions.

## What you will build

Dangerous orders go to review. This is an illustrative application policy, not a default rule that ShieldLabs applies to every customer.

## Run the starting application

You need Node.js 22 or later. The starter runs without ShieldLabs keys; the final version needs a registered HTTPS hostname and matching keys.

Clone the public [tutorial repository](https://github.com/ShieldLabs-ai/use-case-tutorials), then start this standalone application:

```sh theme={null}
git clone https://github.com/ShieldLabs-ai/use-case-tutorials.git
cd use-case-tutorials
git switch starter
cd checkout-risk
npm ci --omit=dev
cp .env.example .env
npm run dev
```

Open [http://127.0.0.1:3000](http://127.0.0.1:3000). The starter has no ShieldLabs dependency or identification check. Its own SQLite state is separate from every other tutorial.

## Add the integration

Stop the starter server. Follow these changes, then run the complete implementation from the `final` branch.

<Steps>
  <Step title="1. Prepare the keys and HTTPS hostname">
    The `.env` copied from `starter` contains no key entries yet. Add the two lines below with this domain's real values:

    ```dotenv theme={null}
    SHIELDLABS_PUBLIC_KEY=your-public-key
    SHIELDLABS_API_KEY=sec_your_private_api_key
    ```

    Register the app's hostname in **Integration > Domains**. Put its matching Public Key and Private API Key in the private `checkout-risk/.env` as `SHIELDLABS_PUBLIC_KEY` and `SHIELDLABS_API_KEY`. Serve this app through HTTPS on that registered hostname. The Private API Key stays on the server; a customer key does not automatically authorize localhost.
  </Step>

  <Step title="2. Identify the action in the browser">
    The `public/index.html` page loads the locally served JS SDK. In `public/index.js`, each action takes a fresh Request ID and sends it with the action:

    ```js theme={null}
    const requestId = await identification.take();
    const response = await fetch('/api/checkout', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ email: form.elements.email.value, requestId }) });
    ```

    Only the Request ID goes to the server; the browser does not supply the risk result.
  </Step>

  <Step title="3. Verify the identification on the server">
    `server/shieldlabs.js` uses `@shieldlabs-ai/node` and the Private API Key to find that exact Request ID in History. The action route passes it to `server/server.js`, where `verifyIdentification(requestId)` rejects missing, stale, replayed, automated or unusable checks before this scenario's rule is applied.
  </Step>

  <Step title="4. Apply the review checkout rule">
    This excerpt from [`server/server.js`](https://github.com/ShieldLabs-ai/use-case-tutorials/blob/final/checkout-risk/server/server.js) shows the decision's core:

    ```js theme={null}
    const check = await verifyIdentification(requestId, { blockBands: [] });
    if (!check.ok) return { success: false, message: check.message };
    if (band(check.identification.risk_score) === 'Dangerous') outcome = 'review';
    ```

    This example deliberately allows a verified Dangerous result through the shared guard, then marks the synthetic order for review. It does not charge or automatically approve a payment. Missing or invalid identification still fails closed.
  </Step>

  <Step title="5. Run the completed application">
    From the repository root, compare the two versions and start the final app:

    ```sh theme={null}
    cd ..
    git diff starter origin/final -- checkout-risk
    git switch final
    cd checkout-risk
    npm ci --omit=dev
    npm start
    ```

    A fresh clone has the remote `origin/final` ref even before its local `final` branch exists. Open the completed app through the registered HTTPS hostname. The Node server listens on `127.0.0.1:3000` behind your reverse proxy.
  </Step>
</Steps>

## Follow the integration code

The completed source is in the [checkout-risk application](https://github.com/ShieldLabs-ai/use-case-tutorials/tree/final/checkout-risk). Read these files in order:

1. [Browser helper](https://github.com/ShieldLabs-ai/use-case-tutorials/blob/final/checkout-risk/public/shieldlabs.js): loads the installed SDK, serializes checks and returns a request ID.
2. [Server verification](https://github.com/ShieldLabs-ai/use-case-tutorials/blob/final/checkout-risk/server/shieldlabs.js): reads real History, checks the matching ID, rereads delayed results and rejects unusable or replayed checks.
3. [Scenario decision](https://github.com/ShieldLabs-ai/use-case-tutorials/blob/final/checkout-risk/server/server.js): applies this app's rule using the verified identification and stores its sample state.

The [finished application](https://github.com/ShieldLabs-ai/use-case-tutorials/tree/final/checkout-risk) keeps its browser, server and SQLite state inside this folder. The tests use synthetic History responses; the normal server does not manufacture a successful identification.

## Try the completed application

1. Submit a synthetic email through the checkout form with a fresh identification. Inspect the returned `outcome`.
2. Run `npm test` in `checkout-risk` to see the Dangerous fixture produce `review` without generating a live high-risk request.
3. Compare the normal browser result with the test: a real visitor's outcome depends on the actual Risk Score.

Use **Reset demo DB** with `DEMO_ALLOW_RESET=1` to repeat the exercise. These controls are for a disposable demonstration, not production authorization.

## Check your result

In DevTools **Network**, inspect the /api/checkout request and copy its `requestId`. Look up the browser Request ID in History and compare its Risk Score band with the returned outcome. A Trusted or Suspicious check is recorded as `accepted`; Dangerous is `review` in this tutorial. Run `npm run check` and `npm test` from `checkout-risk` to exercise failure cases locally without making more identifications.

For a real run, obtain fresh request IDs in the browser and confirm their Device IDs and signals in History. If identification returns HTTP 429, stop and check your account limits before retrying. A cookie change does not prove that the Device ID changed: compare the History rows.

## Adapt it to your product

This example is a starting point, not a production-ready authorization system. Bind each action to an authenticated session where appropriate, authorize administration screens, persist state and atomically consume request IDs across all server instances. Review legitimate shared-device behavior before applying a device-based restriction. See [Acting on results](/guides/acting-on-risk-score).


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