npm package: @plasmacheckout/sdk
Description: Official Node.js/TypeScript SDK for the Plasma Checkout API
Latest version: 0.2.0

# @plasmacheckout/sdk

Official Node.js/TypeScript SDK for the [Plasma Checkout](https://plasmacheckout.com) API.

## Installation

```bash
npm install @plasmacheckout/sdk
# or
pnpm add @plasmacheckout/sdk
```

## Quick Start

```typescript
import { PlasmaSDK } from '@plasmacheckout/sdk';

const plasma = new PlasmaSDK({
  apiKey: 'pk_live_xxx',
  secretKey: 'sk_live_xxx',
});
```

## Products

```typescript
// List products
const { data, pagination } = await plasma.products.list({ limit: 10 });

// Get a product
const { data: product } = await plasma.products.get('product_id');

// Create a product
const { data: newProduct } = await plasma.products.create({
  title: 'T-Shirt',
  price: 9990,
  status: 'active',
});

// Update a product
const { data: updated } = await plasma.products.update('product_id', {
  title: 'Updated T-Shirt',
  price: 12990,
});

// Delete a product
await plasma.products.delete('product_id');
```

## Orders

```typescript
// List orders
const { data: orders } = await plasma.orders.list({ status: 'pending' });

// Get an order
const { data: order } = await plasma.orders.get('order_id');

// Create an order
const { data: newOrder } = await plasma.orders.create({
  customer: { email: 'customer@example.com', name: 'John Doe' },
  items: [{ title: 'T-Shirt', price: 9990, quantity: 2 }],
});

// Update order status
const { data: updatedOrder } = await plasma.orders.update('order_id', {
  status: 'completed',
  paymentStatus: 'paid',
});
```

## Checkout

```typescript
// Create a checkout link
const { data: session } = await plasma.checkout.createLink({
  items: [{ title: 'T-Shirt', price: 9990, quantity: 1 }],
  successUrl: 'https://mystore.com/success',
  cancelUrl: 'https://mystore.com/cancel',
});

console.log(session.checkoutUrl); // https://checkout.plasmacheckout.com/ck_xxx

// Get session details
const { data: details } = await plasma.checkout.getSession('ck_xxx');
```

## Customers

```typescript
// List customers
const { data: customers } = await plasma.customers.list();

// Get customer by email
const { data: customer } = await plasma.customers.get('customer@example.com', {
  includeOrders: true,
  ordersLimit: 5,
});
```

## Webhooks

```typescript
// List deliveries
const { data: deliveries } = await plasma.webhooks.list();

// Get stats
const { data: stats } = await plasma.webhooks.stats();

// Verify webhook signature
import { verifyWebhookSignature } from '@plasmacheckout/sdk';

app.post('/webhooks', (req, res) => {
  const signature = req.headers['x-plasma-signature'];
  const isValid = verifyWebhookSignature(req.body, signature, WEBHOOK_SECRET);

  if (!isValid) return res.status(401).send('Invalid signature');
  // Process webhook event...
});
```

## Error Handling

```typescript
import { PlasmaError } from '@plasmacheckout/sdk';

try {
  await plasma.products.get('nonexistent');
} catch (error) {
  if (error instanceof PlasmaError) {
    console.log(error.code);       // 'NOT_FOUND'
    console.log(error.statusCode); // 404
    console.log(error.message);    // 'Product not found'
  }
}
```

## Configuration

```typescript
const plasma = new PlasmaSDK({
  apiKey: 'pk_live_xxx',
  secretKey: 'sk_live_xxx',
  baseUrl: 'https://api.plasmacheckout.com', // optional
  timeout: 30000,                             // optional, in ms
});
```

## License

MIT