> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://docs.navalabs.ai/api/mcp` to find what you need.

# Integrate an existing facilitator \[Developer Preview]

:::warning[Developer Preview]
Nava Gateway is a **Developer Preview**. The real Nava Guardian payments venue,
checks, and final payment field contract
remain incomplete. The wrapper shown here is not a production commitment.
:::

Keep your existing x402 verifier and wrap it with the package's root export:

```js
// [!include ../../../../examples/gateway-facilitator/verify.mjs:gateway-wrap]
```

`withGuardian(theirVerify, config)` first calls `theirVerify`. If that result is
invalid, it returns the base result without contacting Guardian. If it is valid,
the wrapper runs the common `verifyPayment` primitive and returns valid only for
an approved Guardian result.

Configure it with credentials belonging to the facilitator's Nava integration:

```js
const guardianConfig = {
  baseUrl: process.env.NAVA_BASE_URL,
  apiKey: process.env.NAVA_API_KEY,
  appId: process.env.NAVA_APP_ID,
};
```

`NAVA_API_KEY` is a server-only integration API key and `NAVA_APP_ID` is that
integration's public app ID. Nava uses both on
`GET /integrator/policies` and `POST /integrator/verifications`.

`GuardianConfig.timeoutMs` optionally overrides the shared 10-second request
timeout for enrollment, submission, and polling calls.

The complete placeholder pattern is in
[`examples/gateway-facilitator/verify.mjs`](https://github.com/navalabs-dev/docs/blob/main/examples/gateway-facilitator/verify.mjs).
It does not contact any service when imported.

## Common primitive

Use `verifyPayment` directly when you need the normalized result before adapting
it to your facilitator response:

```js
import { verifyPayment } from '@navalabs/x402-guardian';

const result = await verifyPayment(
  { paymentPayload, paymentRequirements },
  guardianConfig,
  { intervalMs: 1_000, maxAttempts: 20 },
);

const outcome = result.verdict?.outcome;
if (outcome === 'approved') {
  // Continue to your existing settlement path.
} else if (outcome === 'rejected') {
  return {
    isValid: false,
    invalidReason: result.verdict.humanReason,
    reasonCode: result.verdict.reasonCode,
  };
} else {
  // Missing verdict, timeout, or error: fail closed.
  return { isValid: false, invalidReason: result.reason ?? 'Guardian unavailable' };
}
```

`outcome` is authoritative. Pass `reasonCode` through as an opaque string; do not
approve or reject using a locally maintained reason-code list. This keeps an
integration fail-closed while preserving new diagnostic codes.

## Enroll payer wallets

A payer does not select a policy in the payment payload. Enroll the wallet by:

1. Linking or creating the payer's agent under the facilitator integration.
2. Registering the payer wallet on that agent for the payment chain.
3. Activating a policy for the agent.

The facilitator resolves enrollment with
`GET /integrator/policies?walletAddress=<payer>&chainId=<chain>`. `status:
active` is enrolled. `wallet_not_found` or `status: initial` is not enrolled.
Ambiguous bindings, chain mismatches, timeouts, 5xx responses, and malformed
responses are lookup failures and always fail closed.

| Mode | Wallet enrolled | Wallet not enrolled | Lookup error |
| --- | --- | --- | --- |
| `off` | Vanilla x402 | Vanilla x402 | Not applicable |
| `optional` | Guardian gates | Vanilla x402 | Invalid/fail; never bypass |
| `required` | Guardian gates | Invalid: `payer wallet not enrolled` | Invalid/fail |

Caller-supplied `policyId`, `agentId`, and `navaApiKey` fields are ignored and
stripped before the payload reaches the base x402 verifier (`toX402Payload`
also drops `arbiterUserPrompt` and a bundled `verification` fee payload). Keep
the facilitator's integration key server-side and redact it from logs and
errors.

Leave `allowPromptOverride` unset or `false`. The default prompt is derived from
the signed payment action. The payer-supplied `arbiterUserPrompt` is descriptive
only and should not be trusted across this unsigned channel.

## Settlement boundary

`verifyPayment` and `withGuardian` never settle. After an approved outcome, your
facilitator remains responsible for its normal exact-payment and one-time
settlement controls. A timeout, malformed response, transport failure, or
rejected outcome must not reach settlement.
