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

# 沙箱測試

> 在建構整合時,控制能力、任務、錢包與轉帳的結果。

沙箱使用與正式環境相同的 API 主機。沙箱 API 金鑰會選擇測試環境,其中的輔助工具可模擬結果而不移動實際資金。

請將金鑰保存在後端。沙箱輔助工具不會取代正式環境的法遵或入駐流程。

```bash theme={null}
export API_BASE='https://platform.swipelux.com'
export SWIPELUX_SANDBOX_API_KEY='replace-with-your-sandbox-key'
```

## 測試能力就緒

在申請能力之後,使用 [`POST /v3/sandbox/customers/{customerId}/capabilities/{capabilityId}/status`](/api-reference/sandbox/post-v3-sandbox-customers-by-customer-id-capabilities-by-capability-id-status) 設定其沙箱狀態:

```bash theme={null}
curl --request POST \
  "${API_BASE}/v3/sandbox/customers/${CUSTOMER_ID}/capabilities/${CAPABILITY_ID}/status" \
  --header "X-API-Key: ${SWIPELUX_SANDBOX_API_KEY}" \
  --header "Content-Type: application/json" \
  --data '{"status":"ready"}'
```

使用輔助工具後請重新讀取該能力。請將其當前的 `status` 與 `openTaskIds` 視為您的產品必須處理的結果。

## 測試待辦任務

使用 [`POST /v3/sandbox/tasks`](/api-reference/sandbox/post-v3-sandbox-tasks) 建立與能力相關的任務:

```bash theme={null}
curl --request POST \
  "${API_BASE}/v3/sandbox/tasks" \
  --header "X-API-Key: ${SWIPELUX_SANDBOX_API_KEY}" \
  --header "Content-Type: application/json" \
  --data @- <<JSON
{
  "scope": {
    "type": "capability",
    "customerId": "${CUSTOMER_ID}",
    "capabilityId": "${CAPABILITY_ID}"
  },
  "items": [
    {
      "type": "explanation",
      "request": "Explain the source of funds."
    }
  ]
}
JSON
```

將 `data.id` 儲存為 `TASK_ID`、`data.revision` 儲存為 `TASK_REVISION`,並將當前的 `data.requirements[0].id` 儲存為 `REQUIREMENT_ID`。透過 [`POST /v3/customers/{customerId}/tasks/{taskId}/submissions`](/api-reference/task-submissions/create-customer-task-submission) 提交答覆:

```bash theme={null}
curl --request POST \
  "${API_BASE}/v3/customers/${CUSTOMER_ID}/tasks/${TASK_ID}/submissions" \
  --header "X-API-Key: ${SWIPELUX_SANDBOX_API_KEY}" \
  --header "Idempotency-Key: sandbox-task-submission-001" \
  --header "Content-Type: application/json" \
  --data @- <<JSON
{
  "taskRevision": ${TASK_REVISION},
  "answers": [
    {
      "requirementId": "${REQUIREMENT_ID}",
      "answer": {
        "type": "text",
        "value": "Sandbox requirement completed."
      }
    }
  ]
}
JSON
```

然後使用 [`POST /v3/sandbox/tasks/{taskId}/review`](/api-reference/sandbox/post-v3-sandbox-tasks-by-task-id-review) 接受或拒絕當前的提交:

```bash theme={null}
curl --request POST \
  "${API_BASE}/v3/sandbox/tasks/${TASK_ID}/review" \
  --header "X-API-Key: ${SWIPELUX_SANDBOX_API_KEY}" \
  --header "Content-Type: application/json" \
  --data '{"outcome":"accepted"}'
```

正式環境的任務完成模式請參閱[能力與任務](/zh-Hant/integration/onboarding/capabilities-and-requirements)。

## 為沙箱錢包儲值

使用 [`POST /v3/sandbox/accounts/{accountId}/topup`](/api-reference/sandbox/post-v3-sandbox-accounts-by-account-id-topup) 為發行的錢包儲值:

```bash theme={null}
curl --request POST \
  "${API_BASE}/v3/sandbox/accounts/${ACCOUNT_ID}/topup" \
  --header "X-API-Key: ${SWIPELUX_SANDBOX_API_KEY}" \
  --header "Content-Type: application/json" \
  --data '{"amount":"250.00","currency":"USDC"}'
```

當您想檢視模擬的儲值轉帳時,將回傳的 `data.id` 儲存為 `TRANSFER_ID`。

## 完成或失敗轉帳

使用 [`POST /v3/sandbox/transfers/{transferId}/state`](/api-reference/sandbox/post-v3-sandbox-transfers-by-transfer-id-state) 設定結果:

<Tabs>
  <Tab title="完成">
    ```bash theme={null}
    curl --request POST \
      "${API_BASE}/v3/sandbox/transfers/${TRANSFER_ID}/state" \
      --header "X-API-Key: ${SWIPELUX_SANDBOX_API_KEY}" \
      --header "Content-Type: application/json" \
      --data '{"state":"completed"}'
    ```
  </Tab>

  <Tab title="失敗">
    ```bash theme={null}
    curl --request POST \
      "${API_BASE}/v3/sandbox/transfers/${TRANSFER_ID}/state" \
      --header "X-API-Key: ${SWIPELUX_SANDBOX_API_KEY}" \
      --header "Content-Type: application/json" \
      --data @- <<'JSON'
    {
      "state": "failed",
      "stateDetail": {
        "code": "sandbox_review",
        "message": "Sandbox transfer failed."
      }
    }
    JSON
    ```
  </Tab>
</Tabs>

接下來,請在沙箱中執行[入金](/zh-Hant/integration/receive-funds)、[出金](/zh-Hant/integration/send-funds) 或[發行銀行帳戶](/zh-Hant/integration/issue-bank-account) 流程。


## Related topics

- [身分驗證](/zh-Hant/integration/authentication.md)
- [快速入門](/zh-Hant/integration/quickstart.md)
- [上線](/zh-Hant/integration/go-live.md)
- [整合總覽](/zh-Hant/integration/overview.md)
- [API 參考](/zh-Hant/api-reference/introduction.md)
