# WP-CLI

> Every TrustOrder admin function as a wp trustorder command.

Every admin function is also available as a `wp trustorder` command, using the same services as the admin screen.

Exit status: `0` means success, `1` means a service or validation error. On an error the message is only the error code or a fixed text, never your buyers' data or the API key.

## Status

```bash
wp trustorder status [--format=table|json]
```

Shows the key (first 12 characters only), the connection test (shop, account status, daily quota, today's checks), the last error, the intl, order storage and checkout type checks, and the backfill progress of both environments. Exits with `1` if the service cannot be reached.

## Settings

```bash
wp trustorder settings get [<key>] [--format=table|json]
```

Shows the settings. Keys: `api-key` (prefix only), `strictness`, `hidden-gateways`, `fallback-gateways`, `pickup-methods`, `enabled`, `share-geo`, `silent`.

```bash
wp trustorder settings set <key> <value>
```

Changes one setting, validated exactly like the admin screen.

- Lists are comma-separated.
- `enabled`, `share-geo` and `silent` take `true`/`false`, `on`/`off`, `yes`/`no` or `1`/`0`.

Examples:

```bash
wp trustorder settings set strictness normal
wp trustorder settings set silent on
wp trustorder settings set share-geo off
```

### Set the API key from STDIN only

The API key is read only from piped STDIN, so it never appears in the command line or the shell history:

```bash
printf '%s' "$KEY" | wp trustorder settings set api-key -
```

- Any other value after `api-key`, `--api-key=...` and WP-CLI's `--prompt` are refused.
- A terminal or no input within 5 seconds is an error.
- An empty STDIN removes the key.
- If the key is set with the `TRUSTORDER_API_KEY` constant, it cannot be changed here.

## Check one buyer

```bash
wp trustorder check --email=<email> [--phone=<phone>] [--country=<ISO2>] [--postcode=<postcode>] [--address=<address>] [--strictness=lenient|normal|strict] [--format=table|json]
```

Asks the service about one buyer and shows the verdict, level, score, reasons and check id. This is an admin tool: it skips the result cache and does not use the checkout limits. The values are hashed locally, only hashes are sent, and nothing is logged.

## Backfill

```bash
wp trustorder backfill start [--env=live|test]
```

Starts or resumes the backfill for the environment of the saved key. Another environment is refused.

```bash
wp trustorder backfill status [--format=table|json]
```

Shows the state of both environments.

```bash
wp trustorder backfill run [--limit=<orders>]
```

Runs the backfill in your terminal with a progress bar instead of in the background. A pending background step is taken over. `--limit` pauses after the 200-order page in which that many orders were processed; `backfill start` resumes. When the service is unavailable, the retry goes back to the background.

## Order reports

```bash
wp trustorder signal send <order-id>... [--format=table|json]
```

Sends the current outcome of the orders now. Nothing is sent if the service already holds it. Exits with `1` if an order is missing or its report failed or waits for a retry.

```bash
wp trustorder signal status <order-id> [--format=table|json]
```

Shows the stored state without a request, including the outcome wanted for the order's current status (`refund` for a refunded order).

## Exceptions

```bash
wp trustorder exceptions list [--limit=<1-100>] [--cursor=<cursor>] [--format=table|json]
wp trustorder exceptions add --kind=email|phone|address --action=allow|deny [--value=<value>] [--country=<ISO2>] [--postcode=<postcode>] [--address=<address>] [--address-2=<address-2>] [--note=<note>]
wp trustorder exceptions remove --kind=email|phone|address [--value=<value>] [--country=<ISO2>] [--postcode=<postcode>] [--address=<address>] [--address-2=<address-2>]
```

The same always-allow and always-deny exceptions as the admin screen.

- Use `--value` for an e-mail or phone number.
- Use `--country`, `--postcode` and `--address` for an address.
- The value is hashed locally; the list never shows values.

## Keep buyer data out of your shell history

`check --email` / `--phone` and `exceptions add` / `remove --value` take the buyer's data as a command-line argument, which a logging shell keeps in its history. Run them in a shell that does not log, or clear the history afterwards.

## API

The TrustOrder API itself is documented here: [TrustOrder API](https://docs.uptools.io/trustorder/api/).
