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

# TypeScript SDK

> The core SDK for the StellarTools API

The `@stellartools/core` package is the main way to talk to the StellarTools API from TypeScript or JavaScript. It covers customers, checkouts, products, subscriptions, payments, refunds, and credits.

## Install

```bash theme={null}
npm install @stellartools/core
```

## Initialize

```ts theme={null}
import { StellarTools } from "@stellartools/core";

const st = new StellarTools({
  api_key: process.env.STELLAR_TOOLS_API_KEY!,
});
```

The API key determines whether requests go to testnet or mainnet. No other configuration is needed.

## Customers

```ts theme={null}
const customer = await st.customers.create({
  email: "jane@example.com",
  name: "Jane Smith",
  phone: "+12345678901",
});

// customer.id — use this as customerId everywhere else
```

## Checkouts

```ts theme={null}
const checkout = await st.checkout.create({
  customer_id: customer.id,
  product_id: "prod_xxx",
  redirect_url: "https://yourapp.com/success",
});

// Send the customer to checkout.paymentUrl
redirect(checkout.payment_url);
```

For a direct amount checkout without a product:

```ts theme={null}
const checkout = await st.checkout.create({
  customer_d: customer.id,
  amount: 10,
  asset_code: "XLM",
  redirect_url: "https://yourapp.com/success",
});
```

## Products

```ts theme={null}
const product = await st.products.create({
  name: "Pro Plan",
  type: "subscription",
  asset_code: "XLM",
  price_amount: 10,
  recurring_period: "monthly",
});
```

Product types: `one_time`, `subscription`, `metered`.

## Subscriptions

```ts theme={null}
// Create
const subscription = await st.subscriptions.create({
  customer_id: "cust_xxx",
  product_id: "prod_xxx",
});

// Pause, resume, cancel
await st.subscriptions.pause(subscription.id);
await st.subscriptions.resume(subscription.id);
await st.subscriptions.cancel(subscription.id);
```

## Webhooks

```ts theme={null}
const event = st.webhooks.constructEvent(
  rawBody,
  req.headers.get("X-StellarTools-Signature")!,
  process.env.STELLAR_TOOLS_WEBHOOK_SECRET!
);
```

See the [Webhooks](/webhooks) page for all event types and a full handler example.
