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

# 測試

> 上線前測試你的 Kyren Pay 整合

使用本頁測試你的整合，不要假設未公開支援的環境或密鑰類型。

## 目前環境模型

| 項目          | 目前行為                        |
| ----------- | --------------------------- |
| 生產 API      | `https://api.kyren.top`     |
| 生產 API 密鑰前綴 | `kyren_live_`               |
| 自助測試密鑰      | 商戶控制台目前不提供                  |
| Staging 存取  | 僅在 Kyren 提供 Base URL 和憑證後可用 |

<Warning>
  除非 Kyren 已向你提供對應環境的憑證，否則不要向任意 Staging URL 傳送測試流量。
</Warning>

## 測試 API 密鑰

使用目標環境實際簽發的 API 密鑰：

```bash theme={null}
curl https://api.kyren.top/v1/products \
  -H "x-api-key: kyren_live_xxxxxxxxxxxxxxxxxxxx"
```

## 測試卡號

只有在 Kyren 已向你提供 Staging 或可測試環境，或為你的商戶啟用可測試支付閘道時，才應使用以下卡號。不要假設這些卡號會在生產收銀台中產生確定性的測試結果。

| 卡號                    | 行為   |
| --------------------- | ---- |
| `4242 4242 4242 4242` | 支付成功 |
| `4000 0000 0000 0002` | 卡被拒絕 |
| `4000 0000 0000 9995` | 餘額不足 |

對於所有測試卡：

* 使用任意未來的到期日期（如 `12/28`）
* 使用任意 3 位 CVV（如 `123`）
* 使用任意持卡人姓名
* 使用任意帳單地址

## 測試微信支付 / 支付寶

二維碼支付行為取決於商戶綁定的閘道配置。驗證非同步狀態更新時，請使用 Kyren 為目標環境提供的憑證，或配合回調模擬。

## 測試 Webhook

在本地測試 Webhook 時，可以使用 [ngrok](https://ngrok.com) 等隧道工具暴露本地伺服器：

```bash theme={null}
# 啟動本地 Webhook 處理服務
node server.js  # 監聽 3000 埠

# 在另一個終端建立隧道
ngrok http 3000
```

然後在控制台中將 ngrok URL 配置為你的 Webhook 端點：

```
https://abc123.ngrok.io/webhooks/kyren
```

<Tip>
  正式上線前，記得將 Webhook URL 更新為你的生產環境端點。
</Tip>

## 上線檢查清單

切換到生產環境前，請確保你已經完成以下步驟：

<Steps>
  <Step title="替換 API 密鑰">
    使用 `api.kyren.top` 對應的生產密鑰
  </Step>

  <Step title="更新介面位址">
    如果 Kyren 向你提供了 Staging Base URL，請從該位址切換到 `api.kyren.top`
  </Step>

  <Step title="更新 Webhook URL">
    在控制台中設定生產環境的 Webhook 端點
  </Step>

  <Step title="驗證 Webhook 簽名">
    確保你的伺服器正確驗證 `X-Kyren-Signature` 請求標頭
  </Step>

  <Step title="優雅處理錯誤">
    測試各種錯誤場景，確保你的應用能正確處理
  </Step>
</Steps>
