# 點數制 (/features/payments/credits)



點數制 [#點數制]

點數制讓顧客預購點數，按使用量扣除，適合 API 服務、AI 工具等用量計費模式。

適用場景 [#適用場景]

* **API 服務** - 按請求次數計費
* **AI 工具** - 按使用量計費
* **設計服務** - 按專案計點
* **諮詢時數** - 按小時計點

功能特點 [#功能特點]

點數包設定 [#點數包設定]

* 多種點數包選項（如 100 點、500 點、1000 點）
* 大量購買折扣
* 點數有效期設定（可選）

自動扣點 [#自動扣點]

* API 呼叫自動扣除對應點數
* 即時餘額查詢
* 扣點記錄追蹤

低餘額提醒 [#低餘額提醒]

* 設定低餘額門檻
* 自動發送提醒通知
* 可選自動儲值

後台設定 [#後台設定]

1. 前往「商品管理」→「新增商品」
2. 選擇「點數制」
3. 設定：
   * 點數包名稱與數量
   * 價格
   * 有效期限（可選）
4. 儲存並發布

技術整合 [#技術整合]

購買點數 [#購買點數]

```typescript
const response = await fetch('https://api.recur.tw/v1/checkout/sessions', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk_test_xxx',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    productId: 'prod_credits_100',
    mode: 'PAYMENT',
    successUrl: 'https://your-site.com/success',
    cancelUrl: 'https://your-site.com/pricing',
  }),
});
```

扣除點數 [#扣除點數]

```typescript
const response = await fetch('https://api.recur.tw/v1/customers/{customerId}/credits/deduct', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk_test_xxx',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    amount: 10,
    description: 'API 呼叫 - 圖片生成',
  }),
});
```

查詢餘額 [#查詢餘額]

```typescript
const response = await fetch('https://api.recur.tw/v1/customers/{customerId}/credits', {
  headers: {
    'Authorization': 'Bearer sk_test_xxx',
  },
});

const { balance } = await response.json();
```

相關 Webhook 事件 [#相關-webhook-事件]

點數操作會透過以下事件通知：

* `order.paid` - 點數購買完成（透過一次性訂單）
* `checkout.completed` - 點數結帳完成

詳細請參考 [Webhook 文件](/guides/webhooks)。
