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

# Customer

> Customer profiles, order history, and subscription management

# Customer

The customer module gives you access to customer profiles, order history, and subscriptions. Use it to build account dashboards, order tracking pages, and subscription management UIs.

***

## Get Customer Profile

```typescript theme={null}
const customer = await tagada.customer.getProfile(customerId);
```

### By Email

```typescript theme={null}
const customer = await tagada.customer.getByEmail('jane@example.com');
// Returns Customer or null if not found
```

***

## Update Profile

```typescript theme={null}
const updated = await tagada.customer.updateProfile(customerId, {
  firstName: 'Jane',
  lastName: 'Doe',
  phone: '+33612345678',
});
```

***

## Orders

### List Orders

```typescript theme={null}
const { orders, total } = await tagada.customer.getOrders(customerId, {
  limit: 10,
  offset: 0,
});
```

### Get Single Order

```typescript theme={null}
const order = await tagada.customer.getOrder(orderId);
```

***

## Subscriptions

### List Subscriptions

```typescript theme={null}
const subscriptions = await tagada.customer.getSubscriptions(customerId);
```

### Get Single Subscription

```typescript theme={null}
const subscription = await tagada.customer.getSubscription(subscriptionId);
```

***

## React Hook

```tsx theme={null}
import { useCustomer } from '@tagadapay/headless-sdk/react';

function CustomerDashboard({ customerId }: { customerId: string }) {
  const {
    customer,
    orders,
    subscriptions,
    isLoading,
    error,
    loadCustomer,
    loadOrders,
    loadSubscriptions,
    updateProfile,
  } = useCustomer(customerId); // auto-loads profile when customerId is provided

  useEffect(() => {
    if (customerId) {
      loadOrders(customerId);
      loadSubscriptions(customerId);
    }
  }, [customerId]);

  if (isLoading) return <p>Loading...</p>;
  if (error) return <p>Error: {error.message}</p>;

  return (
    <div>
      <h1>Welcome, {customer?.firstName}</h1>

      <h2>Orders</h2>
      {orders.map((order) => (
        <div key={order.id}>
          Order #{order.orderNumber} — {order.status}
        </div>
      ))}

      <h2>Subscriptions</h2>
      {subscriptions.map((sub) => (
        <div key={sub.id}>
          {sub.name} — {sub.status}
        </div>
      ))}
    </div>
  );
}
```

### Full Hook API

| Property / Method                 | Description                                                                        |
| --------------------------------- | ---------------------------------------------------------------------------------- |
| `customer`                        | Current customer profile (null until loaded)                                       |
| `orders`                          | Array of customer orders                                                           |
| `subscriptions`                   | Array of customer subscriptions                                                    |
| `isLoading`                       | True during any async operation                                                    |
| `error`                           | Last error, if any                                                                 |
| `loadCustomer(customerId)`        | Load customer profile (called automatically if `customerId` is passed to the hook) |
| `loadOrders(customerId, opts?)`   | Fetch orders. Optional: `{ limit?, offset? }`                                      |
| `loadSubscriptions(customerId)`   | Fetch all subscriptions                                                            |
| `updateProfile(customerId, data)` | Update customer name, phone, etc.                                                  |
