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

# Customer

> Reference for the Customer interface providing payment and item management capabilities.

The `Customer` interface provides payment and item management functionality that is shared between users and teams. Both [`CurrentUser`](https://docs.hexclave.com/sdk/types/user#currentuser) and [`Team`](https://docs.hexclave.com/sdk/types/team#team) types extend this interface, allowing them to create checkout URLs and manage items.This interface is automatically available on:- [`CurrentUser`](https://docs.hexclave.com/sdk/types/user#currentuser) objects
- [`Team`](https://docs.hexclave.com/sdk/types/team#team) objects
- [`ServerUser`](https://docs.hexclave.com/sdk/types/user#serveruser) objects (with additional server-side capabilities)
- [`ServerTeam`](https://docs.hexclave.com/sdk/types/team#serverteam) objects (with additional server-side capabilities)## Table of ContentsCustomer Table of Contents<pre />## Properties

\<details>

\<summary>`customer.id`
          
            
            customer</summary>

      

Unique identifier - the user ID for individual accounts or team ID for organizations.

Type Definition

\`typescript declare const id: string; `

\</details>

## Methods

\<details>

\<summary>`customer.createCheckoutUrl(options)`
          
            
            customer</summary>

      

Creates a secure checkout URL for purchasing a product. This method integrates with Stripe to generate a payment link that handles the entire purchase flow.

Parameters

\**options.productId** `string` *required*

The ID of the product to purchase, as configured in your Hexclave project settings.

\**options.returnUrl** `string`

The URL to redirect the user to after they complete (or cancel) the checkout. If not provided, the user is redirected to the current page.

Returns

\`Promise<string>`

A secure URL that redirects to the Stripe checkout page.

Signature

\```typescript theme={null}
declare function createCheckoutUrl(options: {
  productId: string;
  returnUrl?: string;
}): Promise<string>;
\```

Examples

\```typescript theme={null}
const user = useUser({ or: "redirect" });

const handleUpgrade = async () => {
  const checkoutUrl = await user.createCheckoutUrl({
    productId: "prod_premium_monthly",
    returnUrl: "https://myapp.com/billing",
  });
  window.location.href = checkoutUrl;
};
\```

\```typescript theme={null}
const team = await user.getTeam("team_123");

const purchaseSeats = async () => {
  const checkoutUrl = await team.createCheckoutUrl({
    productId: "prod_additional_seats",
  });
  window.open(checkoutUrl, "_blank");
};
\```

\</details>



\<details>

\<summary>`customer.createPaymentMethodSetupIntent`
          
            
            customer</summary>

      

Creates a Stripe SetupIntent for adding a new payment method. The returned `clientSecret` and `stripeAccountId` can be used with Stripe.js to collect payment details.

Returns

\`Promise<CustomerPaymentMethodSetupIntent>`

Signature

\```typescript theme={null}
declare function createPaymentMethodSetupIntent(): Promise<{
  clientSecret: string;
  stripeAccountId: string;
}>;
\```

Examples

\```typescript theme={null}
const setupIntent = await user.createPaymentMethodSetupIntent();
// Use setupIntent.clientSecret with Stripe.js
\```

\</details>



\<details>

\<summary>`customer.setDefaultPaymentMethodFromSetupIntent(setupIntentId)`
          
            
            customer</summary>

      

Sets the default payment method from a completed SetupIntent. Call this after the user has successfully added a payment method through Stripe.js.

Parameters

\**setupIntentId** `string` *required*

The ID of the completed SetupIntent.

Returns

\`Promise<CustomerDefaultPaymentMethod>`

Signature

\```typescript theme={null}
declare function setDefaultPaymentMethodFromSetupIntent(
  setupIntentId: string
): Promise<CustomerDefaultPaymentMethod>;
\```

Examples

\```typescript theme={null}
const paymentMethod = await user.setDefaultPaymentMethodFromSetupIntent(
  "seti_1abc123"
);
console.log(`Set default card ending in ${paymentMethod?.last4}`);
\```

\</details>



\<details>

\<summary>`customer.switchSubscription(options)`
          
            
            customer</summary>

      

Switches an existing subscription from one product to another. Useful for upgrading or downgrading plans.

Parameters

\**options.fromProductId** `string` *required*

The product ID of the current subscription to switch from.

\**options.toProductId** `string` *required*

The product ID to switch to.

\**options.priceId** `string`

The specific price ID to use for the new product.

\**options.quantity** `number`

The quantity for the new subscription.

Returns

\`Promise<void>`

Signature

\```typescript theme={null}
declare function switchSubscription(options: {
  fromProductId: string;
  toProductId: string;
  priceId?: string;
  quantity?: number;
}): Promise<void>;
\```

Examples

\```typescript theme={null}
await user.switchSubscription({
  fromProductId: "prod_basic_monthly",
  toProductId: "prod_premium_monthly",
});
\```

\</details>



\<details>

\<summary>`customer.getBilling`
          
            
            customer</summary>

      

Retrieves the customer's billing information, including whether they have a Stripe customer record and their default payment method.

Returns

\`Promise<CustomerBilling>`

Signature

\```typescript theme={null}
declare function getBilling(): Promise<CustomerBilling>;
\```

Examples

\```typescript theme={null}
const billing = await user.getBilling();
if (billing.defaultPaymentMethod) {
  console.log(`Card ending in ${billing.defaultPaymentMethod.last4}`);
}
\```

\</details>



\<details>

\<summary>`customer.useBilling`
          
            
            customer</summary>

      

React hook version of `getBilling`. Returns the customer's billing information reactively.

Returns

\`CustomerBilling`

Signature

\```typescript theme={null}
declare function useBilling(): CustomerBilling;
\```

Examples

\```tsx theme={null}
function BillingInfo() {
  const user = useUser({ or: "redirect" });
  const billing = user.useBilling();

  return (
    \<div>
      \{billing.defaultPaymentMethod
        ? `Card ending in ${billing.defaultPaymentMethod.last4}`
        : "No payment method on file"}
    \</div>
  );
}
\```

\</details>



\<details>

\<summary>`customer.getItem(itemId)`
          
            
            customer</summary>

      

Retrieves information about a specific item associated with this customer.

Parameters

\**itemId** `string` *required*

The ID of the item to retrieve.

Returns

\`Promise<Item>`

An [`Item`](https://docs.hexclave.com/sdk/types/item#item) object containing the display name, current quantity, and other details.

Signature

\```typescript theme={null}
declare function getItem(itemId: string): Promise<Item>;
\```

Examples

\```typescript theme={null}
const credits = await user.getItem("credits");
console.log(`Available credits: ${credits.nonNegativeQuantity}`);
console.log(`Actual balance: ${credits.quantity}`);
\```

\</details>



\<details>

\<summary>`customer.useItem(itemId)`
          
            
            customer</summary>

      

React hook version of `getItem`. Provides real-time updates when the item quantity changes.

Parameters

\**itemId** `string` *required*

The ID of the item to retrieve.

Returns

\`Item`

Signature

\```typescript theme={null}
declare function useItem(itemId: string): Item;
\```

Examples

\```tsx theme={null}
function CreditsWidget() {
  const user = useUser({ or: "redirect" });
  const credits = user.useItem("credits");

  return (
    \<div className="credits-widget">
      \<h3>Available Credits</h3>
      \<div className="credits-count">
        \{credits.nonNegativeQuantity}
      \</div>
      \<small>{credits.displayName}</small>
    \</div>
  );
}
\```

\</details>



\<details>

\<summary>`customer.listProducts([options])`
          
            
            customer</summary>

      

Lists the products owned by this customer, including subscription status and quantities.

Parameters

\**options.cursor** `string`

Pagination cursor from a previous response's `nextCursor`.

\**options.limit** `number`

Maximum number of products to return.

Returns

\`Promise<CustomerProductsList>`

Signature

\```typescript theme={null}
declare function listProducts(options?: {
  cursor?: string;
  limit?: number;
}): Promise<CustomerProductsList>;
\```

Examples

\```typescript theme={null}
const products = await user.listProducts();
for (const product of products) {
  console.log(`${product.displayName}: ${product.quantity}`);
}
\```

\</details>



\<details>

\<summary>`customer.useProducts([options])`
          
            
            customer</summary>

      

React hook version of `listProducts`. Returns the customer's products reactively.

Parameters

\**options.cursor** `string`

Pagination cursor from a previous response's `nextCursor`.

\**options.limit** `number`

Maximum number of products to return.

Returns

\`CustomerProductsList`

Signature

\```typescript theme={null}
declare function useProducts(options?: {
  cursor?: string;
  limit?: number;
}): CustomerProductsList;
\```

\</details>



\<details>

\<summary>`customer.listInvoices([options])`
          
            
            customer</summary>

      

Lists the invoices for this customer.

Parameters

\**options.cursor** `string`

Pagination cursor from a previous response's `nextCursor`.

\**options.limit** `number`

Maximum number of invoices to return.

Returns

\`Promise<CustomerInvoicesList>`

Signature

\```typescript theme={null}
declare function listInvoices(options?: {
  cursor?: string;
  limit?: number;
}): Promise<CustomerInvoicesList>;
\```

Examples

\```typescript theme={null}
const invoices = await user.listInvoices();
for (const invoice of invoices) {
  console.log(`${invoice.status}: $${invoice.amountTotal / 100}`);
}
\```

\</details>



\<details>

\<summary>`customer.useInvoices([options])`
          
            
            customer</summary>

      

React hook version of `listInvoices`. Returns the customer's invoices reactively.

Parameters

\**options.cursor** `string`

Pagination cursor from a previous response's `nextCursor`.

\**options.limit** `number`

Maximum number of invoices to return.

Returns

\`CustomerInvoicesList`

Signature

\```typescript theme={null}
declare function useInvoices(options?: {
  cursor?: string;
  limit?: number;
}): CustomerInvoicesList;
\```

\</details>

***# Related TypesThese types are returned by the methods above. You'll encounter them when working with billing, products, and invoices.## `CustomerBilling`Returned by [`getBilling()`](#customergetbilling) / [`useBilling()`](#customerusebilling).

\<details>

\<summary>`customer.hasCustomer`
          
            
            customer</summary>

      

Whether the customer has a Stripe customer record.

Type Definition

\`typescript declare const hasCustomer: boolean; `

\</details>



\<details>

\<summary>`customer.defaultPaymentMethod`
          
            
            customer</summary>

      

The customer's default payment method, or `null` if none is set.

When present, contains `id`, `brand`, `last4`, `exp_month`, and `exp_year`.

Type Definition

\```typescript theme={null}
declare const defaultPaymentMethod: {
  id: string;
  brand: string | null;
  last4: string | null;
  exp_month: number | null;
  exp_year: number | null;
} | null;
\```

\</details>

## `CustomerProduct`Returned by [`listProducts()`](#customerlistproducts) / [`useProducts()`](#customeruseproducts). The return value is an array of `CustomerProduct` with a `nextCursor: string | null` property for pagination.

\<details>

\<summary>`customer.id`
          
            
            customer</summary>

      

The product ID, or `null` for inline products.

Type Definition

\`typescript declare const id: string | null; `

\</details>



\<details>

\<summary>`customer.displayName`
          
            
            customer</summary>

      

The human-readable name of the product.

Type Definition

\`typescript declare const displayName: string; `

\</details>



\<details>

\<summary>`customer.quantity`
          
            
            customer</summary>

      

How many of this product the customer owns.

Type Definition

\`typescript declare const quantity: number; `

\</details>



\<details>

\<summary>`customer.type`
          
            
            customer</summary>

      

Whether this is a one-time purchase or a recurring subscription.

Type Definition

\`typescript declare const type: "one_time" | "subscription"; `

\</details>



\<details>

\<summary>`customer.subscription`
          
            
            customer</summary>

      

Subscription details, or `null` for one-time purchases. Includes the subscription ID, current period end date, and cancellation status.

Type Definition

\```typescript theme={null}
declare const subscription: null | {
  subscriptionId: string | null;
  currentPeriodEnd: Date | null;
  cancelAtPeriodEnd: boolean;
  isCancelable: boolean;
};
\```

\</details>



\<details>

\<summary>`customer.customerType`
          
            
            customer</summary>

      

The type of customer that owns this product.

Type Definition

\`typescript declare const customerType: "user" | "team" | "custom"; `

\</details>



\<details>

\<summary>`customer.isServerOnly`
          
            
            customer</summary>

      

Whether this product can only be granted server-side.

Type Definition

\`typescript declare const isServerOnly: boolean; `

\</details>



\<details>

\<summary>`customer.stackable`
          
            
            customer</summary>

      

Whether multiple quantities of this product can be stacked.

Type Definition

\`typescript declare const stackable: boolean; `

\</details>



\<details>

\<summary>`customer.switchOptions`
          
            
            customer</summary>

      

Available products to switch this subscription to. Only present for subscription products.

Type Definition

\```typescript theme={null}
declare const switchOptions: Array<{
  productId: string;
  displayName: string;
  prices: InlineProduct["prices"];
}> | undefined;
\```

\</details>

## `CustomerInvoice`Returned by [`listInvoices()`](#customerlistinvoices) / [`useInvoices()`](#customeruseinvoices). The return value is an array of `CustomerInvoice` with a `nextCursor: string | null` property for pagination.

\<details>

\<summary>`customer.createdAt`
          
            
            customer</summary>

      

When the invoice was created.

Type Definition

\`typescript declare const createdAt: Date; `

\</details>



\<details>

\<summary>`customer.status`
          
            
            customer</summary>

      

The invoice status.

Type Definition

\`typescript declare const status: "draft" | "open" | "paid" | "uncollectible" | "void" | null; `

\</details>



\<details>

\<summary>`customer.amountTotal`
          
            
            customer</summary>

      

The total amount of the invoice in the smallest currency unit (e.g. cents).

Type Definition

\`typescript declare const amountTotal: number; `

\</details>



\<details>

\<summary>`customer.hostedInvoiceUrl`
          
            
            customer</summary>

      

A URL to the hosted invoice page on Stripe, or `null` if not available.

Type Definition

\`typescript declare const hostedInvoiceUrl: string | null; `

\</details>

***## Payment Workflow**1. Create checkout URL**Call `createCheckoutUrl()` with the desired product ID.**2. Redirect to Stripe**Direct the user to the returned URL.**3. User completes payment**Stripe handles the payment process on their hosted page.**4. Webhook processing**Hexclave receives webhook notifications from Stripe.**5. Item allocation**Purchased items are automatically added to the customer's account.**6. User returns**The user is redirected back to your application.## Usage Notes- **Purchases**: When a user completes a purchase, associated items are automatically added
- **Subscriptions**: Recurring subscriptions automatically replenish items at the specified intervals
- **Manual allocation**: Server-side code can manually adjust item quantities using [`ServerItem`](https://docs.hexclave.com/sdk/types/item#serveritem) methods
- **Race conditions**: Use [`tryDecreaseQuantity()`](https://docs.hexclave.com/sdk/types/item#serveritemtrydecreasequantity) for atomic, race-condition-free item consumption
