# Card

> Cards: virtual cards with limits, for agents that buy things.

> [!NOTE]
> Invite-only beta. [Request access](mailto:support@noclick.com?subject=Invite-only%20beta%20access) to use this page's API; without access, a call answers 404, or `not_available`.

```python
card = noclick.Card.create("Office supplies", limit_usd=1500, interval="month",
                           merchants=["office_supplies"], agent=buyer, require_approval_above_usd=200)
details = card.purchase(124.50, "Staples", reason="Toner").wait()   # approved first when above $200
for charge in card.transactions(limit=20):
    print(charge.merchant, charge.amount_usd, charge.status)
card.freeze()
```

Cards are your company's commercial cards, for US businesses, in dollars. They spend
your company's own card balance, held by Stripe Payments Company (`Card.funding()`), which you
fund by bank transfer: what a card pays isn't charged to your NoClick account, which
pays only $0.13 per card number issued. Cards need card issuing, which your company
applies for once in the console (`Card.program()`); until it's active these calls
raise `noclick.NotAvailable`. A card number is shown only on a page where the card
issuer's own element displays it (`reveal()`): it never passes through NoClick,
your code or a model.

## Card (invite-only beta)

```typescript
class Card
```

Invite-only beta. A virtual card with a spending limit.
`Card.fromName("Office supplies", { createIfMissing: true, limitUsd: 1500 })` is lazy;
`await card.purchase(...)` approves and pays one purchase, `await card.reveal()` shows its number
to a person. A card is always your company's, for its business, including buying for one of your
users: one issued for a user is only that user's agents' to pay with, never a card the user owns or
funds. It may be held by one agent, which pays with it at checkouts in its browser.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `name` | `string` |  |
| `last4` | `string | null` |  |
| `brand` | `string | null` | The card network, like `visa`. |
| `expMonth` | `number | null` |  |
| `expYear` | `number | null` |  |
| `status` | `CardStatus` | `active`, `frozen` or `closed`. |
| `statusReason` | `"negative_balance" | null` | Why it's frozen when you didn't freeze it: `negative_balance` while your card balance is below zero (it pays again once funded). Null otherwise. |
| `limitUsd` | `number | null` | The most it spends per `interval` (null: no limit). |
| `interval` | `CardInterval | null` | What `limit_usd` covers: `transaction`, `day`, `month` or `all_time`. |
| `spentUsd` | `number | null` | Spent in the current interval (this calendar month's spend for a per-transaction limit). |
| `resetsAt` | `Date | null` | When `spentUsd` starts over (null for `all_time`). |
| `merchants` | `string[] | null` | The merchant categories it may pay (null: any). |
| `requireApprovalAboveUsd` | `number | null` | Charges above this wait for a person (null: never). |
| `agentId` | `string | null` | The agent that pays with it (null if none). |
| `singleUse` | `boolean` | Whether every checkout gets a fresh number that takes one charge (`last4` is the latest one's). |
| `userId` | `string | null` |  |
| `createdAt` | `Date | null` |  |

Types:

```typescript
type CardStatus = "active" | "frozen" | "closed";

/** What `limitUsd` covers. */
type CardInterval = "transaction" | "day" | "month" | "all_time";
```

### Card.create

```typescript
static create(
  name: string,
  options: CardCreateOptions & AllowExisting,
): Promise<Card>
```

Issue a virtual card called `name` (unique among its user's open cards; a
duplicate throws `Conflict` with `existingId`). With `allowExisting: true` a taken name returns the
open card already there, as it is: nothing about it changes, and no number is issued.

Parameters:

- `name` (`string`, required)
- `options.limitUsd` (`number`, required): The most it spends per `interval`.
- `options.interval` (`CardInterval`): Default `"month"`.
- `options.merchants` (`string | string[]`): Merchant categories it may pay (`"office_supplies"`, `"software"`, `"travel"`, ... or a 4-digit code);
any when omitted, never cash, money transfers, gambling or securities.
- `options.agent` (`Agent | string`): The agent that pays with it.
- `options.requireApprovalAboveUsd` (`number`): A purchase above this is approved by a person before anything is paid (`purchase`); a charge
above it that nobody announced is declined, and the merchant's retry passes once they approve.
- `options.singleUse` (`boolean`): Every checkout (every purchase, every `reveal()`) gets a fresh number that takes one charge and
then closes; together they spend within `limitUsd` per `interval` (UTC days and months).
- `options.allowExisting` (`boolean`): A taken name returns the object already there, as it is: nothing about it changes.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The new card, `active`, with its `last4` and expiry (a single-use card has none until its first
checkout). Its number is only ever shown on `reveal()`'s page. Each number costs $0.13.

Types:

```typescript
/** What `limitUsd` covers. */
type CardInterval = "transaction" | "day" | "month" | "all_time";

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Card.fromName

```typescript
static fromName(
  name: string,
  options?: CardDefinition & { createIfMissing?: boolean },
): Card
```

A lazy reference to the open card called `name` for the current (or given) user. Given fields, it
gets the card and sets the ones you pass, on every run: an existing card whose limit, interval,
merchants, approval threshold or agent differ gets yours. `createIfMissing` issues it when there's
none (`interval` is `"month"` unless you pass one); without it, a missing card throws `NotFound`. A
field left out is never changed; `null` clears `agent` or `requireApprovalAboveUsd`,
as `update` does. Each run with fields is a write: set them at startup or in a setup script, and take
the bare `fromName` in request handlers.

Parameters:

- `name` (`string`, required)
- `options.createIfMissing` (`boolean`)
- `options.limitUsd` (`number`): The most it spends per `interval`.
- `options.interval` (`CardInterval`): Default `"month"`.
- `options.merchants` (`string | string[]`): Merchant categories it may pay (`"office_supplies"`, `"software"`, `"travel"`, ... or a 4-digit code);
any when omitted, never cash, money transfers, gambling or securities.
- `options.agent` (`Agent | string | null`, default: unchanged)
- `options.requireApprovalAboveUsd` (`number | null`, default: unchanged)
- `options.singleUse` (`boolean`): Every checkout (every purchase, every `reveal()`) gets a fresh number that takes one charge and
then closes; together they spend within `limitUsd` per `interval` (UTC days and months).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: A card that loads (or is issued, or has your fields set) the first time it's used.
Nothing is sent yet.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** What `limitUsd` covers. */
type CardInterval = "transaction" | "day" | "month" | "all_time";
```

### Card.fromId

```typescript
static fromId(cardId: string, options?: CallOptions): Card
```

A lazy reference to a card by id.

Parameters:

- `cardId` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.

Returns: A card that loads the first time you read a field. Nothing is sent yet.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Card.get

```typescript
static get(cardId: string, options?: CallOptions): Promise<Card>
```

Load a card by id now; an unknown id raises `noclick.NotFound`.

Parameters:

- `cardId` (`string`, required)
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The card, loaded, with this interval's `spent_usd`.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Card.list

```typescript
static list(
  options?: ReadOptions & {
    status?: CardStatus;
    agent?: Agent | string;
    limit?: number;
  },
): Promise<Card[]>
```

The current user's cards (the account's own outside `asUser`, or those `userFilter` covers).

Parameters:

- `options.status` (`CardStatus`)
- `options.agent` (`Agent | string`)
- `options.limit` (`number`): Return at most this many.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Every matching card, newest first, fetched page by page. Closed cards are listed only with `status="closed"`.

Types:

```typescript
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

type CardStatus = "active" | "frozen" | "closed";
```

### Card.listPage

```typescript
static listPage(
  options?: ReadOptions & PageOptions & {
    status?: CardStatus;
    agent?: Agent | string;
  },
): Promise<Page<Card>>
```

One page of cards; pass `nextCursor` back as `cursor`.

Parameters:

- `options.cursor` (`string | null`): The `next_cursor` of the page before; omit it for the first page.
- `options.limit` (`number`): Return at most this many.
- `options.status` (`CardStatus`)
- `options.agent` (`Agent | string`)
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: A page whose `data` holds the cards and whose `next_cursor` is `None` on the last page.

Types:

```typescript
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

type CardStatus = "active" | "frozen" | "closed";
```

### Card.funding

```typescript
static funding(options?: { client?: NoClick }): Promise<CardFunding>
```

Your company's card balance, which every card (the account's and every user's) spends from, and the bank details that fund it.

Parameters:

- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The `balance_usd`, what pending charges hold (`pending_usd`), what cards can still spend
(`available_usd`), and the `bank_transfer` details that fund it.

### Card.program

```typescript
static program(options?: { client?: NoClick }): Promise<CardProgram>
```

Where your company's card issuing stands. It's applied for once, in the console.

Parameters:

- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The program's `status` (`not_started`, `pending_verification`, `active`, `rejected` or
`restricted`), what it still needs (`requirements_due`) and where to apply (`onboarding_url`).

### Card.merchantCategories

```typescript
static merchantCategories(
  options?: { client?: NoClick },
): Promise<CardMerchantCategory[]>
```

The names `merchants` takes, each with the merchant category codes it covers (a 4-digit code works too).

Parameters:

- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Every category, like `office_supplies`, `software` and `travel`.

### Card.transactions

```typescript
transactions(
  options?: { status?: CardTransactionStatus; limit?: number | null },
): Promise<CardTransaction[]>
```

Its charges and refunds, newest first, each with any dispute: the newest `limit` (20 by default; `null` for every one).

Parameters:

- `options.status` (`CardTransactionStatus`)
- `options.limit` (`number | null`, default `20`): Return at most this many.

Returns: The newest `limit` (20 by default; `None` for every one), each with its amount,
merchant, status, for a decline why, and any dispute.

Types:

```typescript
type CardTransactionStatus = "approved" | "settled" | "reversed" | "declined" | "pending_approval";
```

### Card.reveal

```typescript
reveal(): Promise<CardDetails>
```

A page that shows the card's number to a person: the card issuer's own element displays it there,
for 10 minutes, so the number never passes through NoClick or your code. On a single-use card it's a
fresh number, which closes unused after an hour. Needs a key with the `cards:reveal` scope; every
reveal is recorded with the key that made it.

Returns: The page's `url`, when it stops showing the number, the number's `last4` and expiry, and the
cardholder name and billing address a checkout asks for.

### Card.purchase

```typescript
purchase(
  amountUsd: number,
  merchant: string,
  options?: { reason?: string },
): Promise<Operation<CardDetails>>
```

Approve one purchase before paying it: a number for exactly this purchase, which takes one charge of
at most `amountUsd` (tax and shipping included) and then closes. At or under `requireApprovalAboveUsd`
it's ready at once; above it the card's user (or your account's owner) is asked first. A
`card.purchase` operation: `wait()` resolves to the `CardDetails` to pay with, and throws
`PolicyDenied` (declined) or `Expired` (nobody answered in 30 minutes). Needs `cards:reveal`.

Parameters:

- `amountUsd` (`number`, required)
- `merchant` (`string`, required)
- `options.reason` (`string`)

Returns: A `card.purchase` operation; `wait()` returns the `CardDetails` to pay with once approved, and
raises `noclick.PolicyDenied` (declined) or `noclick.Expired` (nobody answered in 30 minutes).

### Card.dispute

```typescript
dispute(
  transaction: CardTransaction | string,
  options: {
    reason: CardDisputeReason;
    explanation: string;
    amountUsd?: number;
    product?: "merchandise" | "service";
    duplicateOf?: CardTransaction | string;;
  },
): Promise<CardDispute>
```

Dispute a settled charge with the card network: `fraudulent` (nobody here made it), `canceled`,
`duplicate` (name the charge it copies in `duplicateOf`), `not_received`, `not_as_described` (with
`product`) or `incorrect_amount` (with the `amountUsd` in dispute). A wrong purchase your agent made
is a merchant dispute, not fraud.

Parameters:

- `transaction` (`CardTransaction | string`, required)
- `options.reason` (`CardDisputeReason`, required)
- `options.explanation` (`string`, required)
- `options.amountUsd` (`number`)
- `options.product` (`"merchandise" | "service"`)
- `options.duplicateOf` (`CardTransaction | string`)

Returns: The dispute, `submitted`; `card.dispute.updated` events follow it to `won` or `lost`.

Types:

```typescript
type CardDisputeReason =
  | "fraudulent"
  | "canceled"
  | "duplicate"
  | "not_received"
  | "not_as_described"
  | "incorrect_amount";
```

### Card.update

```typescript
update(fields: CardUpdateOptions): Promise<this>
```

Change its limits, merchants, approval threshold, agent or name; `null` clears a field.

Parameters:

- `fields` (`CardUpdateOptions`, required)

Returns: This card, updated. A field you leave out is unchanged, and changes apply from the next charge.

Types:

```typescript
/** `null` clears a field: `merchants: null` allows any merchant, `requireApprovalAboveUsd: null` never asks, `agent: null` takes it from its agent. */
interface CardUpdateOptions {
  name?: string;
  limitUsd?: number;
  interval?: CardInterval;
  merchants?: string | string[] | null;
  agent?: Agent | string | null;
  requireApprovalAboveUsd?: number | null;
  /** From its next checkout. */
  singleUse?: boolean;
}

/** What `limitUsd` covers. */
type CardInterval = "transaction" | "day" | "month" | "all_time";
```

### Card.freeze

```typescript
freeze(): Promise<this>
```

Decline every charge until `unfreeze()`; the card keeps its number and limits.

Returns: This card, `frozen`.

### Card.unfreeze

```typescript
unfreeze(): Promise<this>
```

Let a frozen card pay again. While your card balance is below zero every card stays frozen
(`statusReason` `negative_balance`): this throws `Conflict` until it's funded.

Returns: This card, `active`.

### Card.close

```typescript
close(): Promise<this>
```

Close the card for good: it declines every charge and its number is never reissued.

Returns: This card, `closed`.

## CardTransaction (invite-only beta)

```typescript
interface CardTransaction
```

One charge or refund on a card. A `charge` is `approved` (held until the merchant settles it),
`settled` (`settledAmountUsd`), `reversed`, `declined` or `pending_approval` (held for a person);
a `refund` is settled, its `amountUsd` below zero. A decline says why in `declineReason`
(`over_limit`, `over_budget` (an app's card, past what's left of the app's budget),
`merchant_not_allowed`, `frozen`, `insufficient_funds`, `amount_mismatch`,
`not_approved`, `approval_expired`, `awaiting_approval`, `card_closed`, `card_expired`,
`invalid_cvc`, `invalid_expiry`, `3ds_failed`, `issuer_declined`).

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string | null` |  |
| `cardId` | `string | null` |  |
| `kind` | `"charge" | "refund" | null` |  |
| `amountUsd` | `number | null` |  |
| `settledAmountUsd` | `number | null` |  |
| `merchant` | `string | null` |  |
| `merchantCategory` | `string | null` | The `Card.merchantCategories()` name its `merchantMcc` is in (null: none of them). |
| `merchantMcc` | `string | null` |  |
| `status` | `CardTransactionStatus | null` |  |
| `declineReason` | `string | null` |  |
| `approvalId` | `string | null` | The held charge's approval, an operation: `await Operation.fromId(approvalId).wait()` is `true` once approved. |
| `purchaseId` | `string | null` | The `card.purchase` operation whose number paid it. |
| `last4` | `string | null` | The number it was on. |
| `dispute` | `CardDispute | null` |  |
| `at` | `Date | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type CardTransactionStatus = "approved" | "settled" | "reversed" | "declined" | "pending_approval";

type JsonObject = { [key: string]: unknown };
```

## CardDetails (invite-only beta)

```typescript
class CardDetails
```

Invite-only beta. A card number to pay with, shown only at `url`: a page where the card
issuer's own element displays the number, CVC and expiry to whoever opens it, until `expiresAt`.
The number never passes through NoClick, your code or a model, so send `url` only to the person
who pays. Printing or serializing it leaves `url` out.

| Attribute | Type | Description |
| --- | --- | --- |
| `url` | `string` |  |
| `expiresAt` | `Date | null` |  |
| `last4` | `string | null` |  |
| `brand` | `string | null` |  |
| `expMonth` | `number | null` |  |
| `expYear` | `number | null` |  |
| `singleUse` | `boolean` | A number that takes one charge (every number of a single-use card, every purchase's). |
| `amountUsd` | `number | null` | A purchase's exact amount: the most its one charge may be. |
| `closesAt` | `Date | null` | When a single-use number nobody paid with closes. |
| `cardholder` | `string | null` | The name and billing address a checkout asks for: your company's. |
| `billingAddress` | `JsonObject | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## CardFunding (invite-only beta)

```typescript
interface CardFunding
```

Your company's card balance, held by Stripe Payments Company: every card spends from it. It can drop below zero
when a merchant takes a charge without asking; NoClick then freezes your cards until it's funded again.

| Attribute | Type | Description |
| --- | --- | --- |
| `balanceUsd` | `number | null` |  |
| `pendingUsd` | `number | null` | Held by charges that haven't settled. |
| `availableUsd` | `number | null` | What cards can still spend: the balance less what's pending. |
| `topUpUrl` | `string | null` | The console page with the bank details. |
| `bankTransfer` | `CardBankTransfer | null` |  |
| `frozenSince` | `Date | null` | Since when your cards have been frozen because the balance is below zero (null: they aren't). |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## CardBankTransfer (invite-only beta)

```typescript
interface CardBankTransfer
```

Where your company sends money to fund its card balance: a wire lands the same day, ACH within days.

| Attribute | Type | Description |
| --- | --- | --- |
| `bankName` | `string | null` |  |
| `routingNumber` | `string | null` |  |
| `accountNumber` | `string | null` |  |
| `networks` | `string[]` | `ach` and `wire`. |

## CardDispute (invite-only beta)

```typescript
interface CardDispute
```

A settled charge disputed with the card network: `submitted`, then `won`, `lost` or `expired`.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string | null` |  |
| `transactionId` | `string | null` |  |
| `reason` | `CardDisputeReason | null` | `fraudulent`, `canceled`, `duplicate`, `not_received`, `not_as_described` or `incorrect_amount`. |
| `status` | `"submitted" | "won" | "lost" | "expired" | null` |  |
| `amountUsd` | `number | null` |  |
| `createdAt` | `Date | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type CardDisputeReason =
  | "fraudulent"
  | "canceled"
  | "duplicate"
  | "not_received"
  | "not_as_described"
  | "incorrect_amount";

type JsonObject = { [key: string]: unknown };
```

## CardProgram (invite-only beta)

```typescript
interface CardProgram
```

Card issuing for your company: `not_started`, then `pending_verification` while the card issuer
verifies it (`requirementsDue`), `active`; or `rejected`, or `restricted` (it needs something
again). Your company applies once, in the console at `onboardingUrl`: US businesses, in dollars.

| Attribute | Type | Description |
| --- | --- | --- |
| `status` | `CardProgramStatus` |  |
| `requirementsDue` | `string[]` |  |
| `companyName` | `string | null` |  |
| `country` | `string | null` |  |
| `currency` | `string | null` |  |
| `onboardingUrl` | `string | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type CardProgramStatus = "not_started" | "pending_verification" | "active" | "rejected" | "restricted";

type JsonObject = { [key: string]: unknown };
```

## CardMerchantCategory (invite-only beta)

```typescript
interface CardMerchantCategory
```

A name `merchants` takes, and the merchant category codes it covers.

| Attribute | Type | Description |
| --- | --- | --- |
| `name` | `string` |  |
| `description` | `string | null` |  |
| `mccs` | `string[]` |  |
