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

# Clink CLI

> Use clink-cli to initialize customer wallets, manage card links, pay, refund, and inspect risk rules from the command line.

`clink-cli` is a command-line client for Clink customer wallet APIs. Use it to initialize customer wallet profiles, open card setup or management pages, make payments, create refunds, and inspect risk rule settings.

<Warning>
  **Security Note:** The CLI can store customer credentials in your local profile. Do not commit `~/.clink-cli/config.json` or share values such as `customer-api-key`.
</Warning>

<Card title="NPM Package" icon="npm" href="https://www.npmjs.com/package/@clink-ai/clink-cli">
  View the package on npmjs.com
</Card>

## Requirements

* Node.js `>=20`
* Access to the target Clink API environment

The default base URL is:

```text theme={null}
https://api.clinkbill.com
```

## Installation

Install the CLI globally:

```bash theme={null}
npm install -g @clink-ai/clink-cli
```

Or run it without a global install:

```bash theme={null}
npx clink-cli --help
```

Every command starts with:

```bash theme={null}
clink-cli <command> [subcommand] [options]
```

## Quick Start

### 1. Initialize your wallet

Run this once to create or activate a customer wallet and save credentials locally:

```bash theme={null}
clink-cli wallet init --email user@example.com --name "Alice"
```

Check the saved profile:

```bash theme={null}
clink-cli wallet status --format pretty
```

The local config file is stored at:

```text theme={null}
~/.clink-cli/config.json
```

### 2. Open card pages

Get the raw binding link:

```bash theme={null}
clink-cli card binding-link
```

Open the add-card page:

```bash theme={null}
clink-cli card setup-link --open
```

Open the manage-card page:

```bash theme={null}
clink-cli card modify-link --open
```

### 3. Check saved payment methods

List cached payment methods:

```bash theme={null}
clink-cli card list --format pretty
```

Get one cached payment method:

```bash theme={null}
clink-cli card get --payment-instrument-id pi_xxx
```

Notes:

* Card add, update, and delete actions happen on the web page, not directly in the CLI.
* `card list` and `card get` read local cached data.
* `card binding-link`, `card setup-link`, and `card modify-link` refresh the local payment method cache.

### 4. Make a payment

Pay with merchant mode:

```bash theme={null}
clink-cli pay \
  --merchant-id merchant_xxx \
  --amount 10.00 \
  --currency USD \
  --payment-instrument-id pi_xxx
```

Pay with session mode:

```bash theme={null}
clink-cli pay --session-id sess_xxx --payment-instrument-id pi_xxx
```

If `--payment-instrument-id` is omitted, `pay` uses the default cached payment method.

### 5. Refund an order

Create a full refund:

```bash theme={null}
clink-cli refund create --order-id order_xxx
```

Check refund status:

```bash theme={null}
clink-cli refund get --refund-id rfd_xxx
```

### 6. Check risk rules

Get current risk rule settings:

```bash theme={null}
clink-cli risk-rule get --format pretty
```

Open the risk rule page:

```bash theme={null}
clink-cli risk-rule link --open
```

## Common Usage

Use a named profile:

```bash theme={null}
clink-cli wallet init --profile buyer-2 --email user2@example.com --name "Bob"
clink-cli wallet status --profile buyer-2 --format pretty
```

Override the base URL:

```bash theme={null}
clink-cli wallet status --base-url https://uat-api.clinkbill.com
```

Print requests without executing them:

```bash theme={null}
clink-cli pay \
  --merchant-id merchant_xxx \
  --amount 10.00 \
  --currency USD \
  --payment-instrument-id pi_xxx \
  --dry-run
```

## Commands

Command groups:

* `clink-cli wallet init`
* `clink-cli wallet status`
* `clink-cli card binding-link`
* `clink-cli card setup-link`
* `clink-cli card modify-link`
* `clink-cli card list`
* `clink-cli card get --payment-instrument-id <id>`
* `clink-cli risk-rule get`
* `clink-cli risk-rule link`
* `clink-cli pay --merchant-id <id> --amount <amount> --currency <currency>`
* `clink-cli pay --session-id <id>`
* `clink-cli refund create --order-id <id>`
* `clink-cli refund get --refund-id <id>`
* `clink-cli config set <key> <value>`
* `clink-cli config get`
* `clink-cli config unset <key>`

Show help:

```bash theme={null}
clink-cli --help
clink-cli wallet --help
clink-cli card --help
clink-cli refund --help
```

## Configuration

Useful config commands:

```bash theme={null}
clink-cli config get
clink-cli config set base-url https://uat-api.clinkbill.com
clink-cli config set customer-id cus_xxx --profile buyer-2
clink-cli config set customer-api-key sk_test_xxx --profile buyer-2
clink-cli config unset customer-api-key --profile buyer-2
```

Supported config keys:

* `base-url`
* `customer-id`
* `customer-api-key`
* `default-open-links`
* `email`
* `name`

Resolution order:

1. Command flags
2. Environment variables
3. Saved profile config

Environment variables:

* `CLINK_BASE_URL`
* `CLINK_CUSTOMER_ID`
* `CLINK_CUSTOMER_API_KEY`

## Global Options

* `--format <json|pretty>`
* `--dry-run`
* `--open`
* `--profile <name>`
* `--base-url <url>`
* `--customer-id <id>`
* `--customer-api-key <key>`
* `--timeout <ms>`
* `--help`
