# 查询付款方式设置结果

Operation / SDK: `readPaymentSetup` · `read_payment_setup` · `ReadPaymentSetup`

读取付款方式设置的结果。

更新于 2026-11-06

[网页版本](https://www.longplayai.com/zh-hans/docs/api/read-payment-setup)

<a id="request"></a>

## 请求

- **凭据**: Server Key（传 `customerId`）或 Customer Token，权限 `billing:read`。
- **SDK**: JavaScript `createLongplayServer().readPaymentSetup` · JavaScript `createLongplay().readPaymentSetup` · Python `read_payment_setup` · Go `ReadPaymentSetup`
- **成功状态**: HTTP 200

响应为示例数据。

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/billing/payment-setup" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
  "setupId": "b0e225bc-7b55-4218-8e41-516dea9c4dbd"
}'
```

**TypeScript: readPaymentSetup.ts**

```ts
import { createLongplayServer } from "@tinkerlandai/longplay-sdk/server";

const longplay = createLongplayServer({
  baseUrl: process.env.LONGPLAY_API_URL!,
  apiKey: process.env.LONGPLAY_SERVER_KEY!,
  scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox" },
});

export async function readPaymentSetup() {
  return longplay.readPaymentSetup({
    customerId: "8b258f8b-4228-40fa-8d24-5b16428e686d",
    setupId: "b0e225bc-7b55-4218-8e41-516dea9c4dbd",
  });
}
```

**请求体: request.json**

```json
{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
  "setupId": "b0e225bc-7b55-4218-8e41-516dea9c4dbd"
}
```

**响应示例: response.json**

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "setup": {
    "id": "b0e225bc-7b55-4218-8e41-516dea9c4dbd",
    "provider": "stripe",
    "status": "prepared",
    "currency": "USD",
    "makeDefault": true,
    "url": "https://example.com/url",
    "createdAt": "2026-10-03T12:00:00.000Z",
    "expiresAt": "2099-01-01T00:00:00.000Z",
    "completedAt": "2026-10-03T12:00:00.000Z",
    "execution": {
      "provider": "stripe",
      "executor": "merchant",
      "accountId": "acct_1Example",
      "mode": "setup",
      "currency": "usd",
      "customer": "cus_1Example",
      "clientReferenceId": "7264d609-1bee-49f2-8d21-b4fad49607b5",
      "metadata": {
        "grooveProjectId": "87d7fba2-5f94-4ea8-8471-1e8f05c2f741",
        "grooveEnvironmentId": "a1a7948e-159d-4578-878a-2e6b2309d5b1",
        "grooveCustomerId": "f6ec000d-bef1-4872-826f-c1b83539799d",
        "groovePaymentSetupId": "eb4715da-7cb4-4f7a-84c3-e08786a5b285"
      },
      "setDefaultPaymentMethod": true,
      "expiresAt": "2099-01-01T00:00:00.000Z"
    }
  }
}
```

<a id="parameters"></a>

## 请求体参数

**application/json**

- `setupId` (uuid, required): 付款方式设置的 ID。
- `customerId` (uuid, optional): Customer 的 UUID。

<a id="response"></a>

## 响应字段

成功响应都包含 `requestId`（本次请求 ID，排查时提供）和 `scope`（App 与环境）。

**HTTP 200 · application/json**

- `requestId` (uuid, required): 服务端为这次 HTTP 请求生成的 UUID，排查时提供；它不是你的业务 requestId。
- `scope` (object, required): 响应实际所属的 App 和环境。Header 只能核对，不能切换 Key 范围。
- `scope.projectId` (string, required): 凭据绑定的 App ID。 minLength: 1
- `scope.environment` (enum, required): 独立数据范围：sandbox 或 live。 Values: `"sandbox"`, `"live"`.
- `setup` (object, required): 付款方式设置，字段见下。
- `setup.id` (uuid, required): 付款方式设置 的 ID。
- `setup.provider` ("stripe", required): 支付渠道，取值见允许值。
- `setup.status` (enum, required): 状态，取值见允许值。 Values: `"prepared"`, `"complete"`, `"expired"`.
- `setup.currency` (enum, required): 已发布价格支持的币种代码。 Values: `"USD"`, `"EUR"`, `"CNY"`, `"GBP"`, `"JPY"`, `"CAD"`, `"AUD"`, `"NZD"`, `"CHF"`, `"HKD"`, `"SGD"`, `"KRW"`, `"INR"`, `"BRL"`, `"MXN"`, `"TWD"`, `"THB"`, `"IDR"`, `"MYR"`, `"PHP"`, `"VND"`, `"ZAR"`, `"AED"`, `"SAR"`, `"SEK"`, `"NOK"`, `"DKK"`, `"PLN"`, `"CZK"`, `"HUF"`, `"ILS"`, `"TRY"`, `"RON"`.
- `setup.makeDefault` (boolean, required): 是否设为默认付款方式。
- `setup.url` (uri | null, required): 托管结账地址；支付结果由已验证的 provider 通知确认。
- `setup.createdAt` (date-time, required): 记录创建时的 ISO 8601 UTC 时间。
- `setup.expiresAt` (date-time, required): 到期时间（ISO 8601，UTC）。
- `setup.completedAt` (date-time | null, required): 时间（ISO 8601）。
- `setup.execution` (object | null, required): 执行信息。
- `setup.execution.provider` ("stripe", required): 支付渠道，取值见允许值。
- `setup.execution.executor` ("merchant", required): 执行方，取值见允许值。
- `setup.execution.accountId` (string, required): Stripe 账户 ID（`acct_…`）。 pattern: ^acct_[A-Za-z0-9]+$
- `setup.execution.mode` ("setup", required): 模式，取值见允许值。
- `setup.execution.currency` (string, required): 已发布价格支持的币种代码。 pattern: ^[a-z]{3}$
- `setup.execution.customer` (string | null, required): Stripe Customer ID（`cus_…`）。
- `setup.execution.clientReferenceId` (uuid, required): 用作 Stripe Checkout Session 的 `client_reference_id`，与本次付款方式设置的 `id` 相同。
- `setup.execution.metadata` (object, required): 自定义键值数据。
- `setup.execution.metadata.grooveProjectId` (uuid, required): App 的 UUID。与 `metadata` 中的其他键一起原样复制到 Checkout Session 的 `metadata` 和 `setup_intent_data.metadata`。
- `setup.execution.metadata.grooveEnvironmentId` (uuid, required): App 环境的 UUID。与 `metadata` 中的其他键一起原样复制到 Checkout Session 的 `metadata` 和 `setup_intent_data.metadata`。
- `setup.execution.metadata.grooveCustomerId` (uuid, required): Longplay 写入 Stripe `metadata` 的归因字段，原样复制，不要修改。
- `setup.execution.metadata.groovePaymentSetupId` (uuid, required): 本次付款方式设置的 `id`。与 `metadata` 中的其他键一起原样复制到 Checkout Session 的 `metadata` 和 `setup_intent_data.metadata`。
- `setup.execution.setDefaultPaymentMethod` (boolean, required): 是否设为默认付款方式。
- `setup.execution.expiresAt` (date-time, required): 到期时间（ISO 8601，UTC）。

<a id="errors"></a>

## 错误

失败时返回错误对象，按 `error.code` 与 `error.recovery` 处理。下表是这个接口的凭据、作用域和幂等字段决定的错误；视请求内容还可能返回 `NOT_FOUND`（引用的资源不存在）、`NOT_CONFIGURED`（所需的集成未连接）或 `PAYLOAD_TOO_LARGE`。有些拒绝（如余额不足）不是错误，而是成功响应里的 `reason`。

**可能的错误**

| code | HTTP | 何时 | recovery |
| --- | --- | --- | --- |
| `INVALID_REQUEST` | 400 | 请求不符合本页的参数。缺少或无法解析协议头时分别返回 `UNSUPPORTED_PROTOCOL_VERSION` 或 `INVALID_PROTOCOL_VERSION`。 | `fix_request` |
| `UNAUTHENTICATED` | 401 | 凭据缺失、无效、过期或已撤销。 | `authenticate` |
| `FORBIDDEN` | 403 | 凭据没有 `billing:read` 权限。 | `check_permissions` |
| `SCOPE_MISMATCH` | 403 | `X-Indiana-Project` 或 `X-Indiana-Environment` 与凭据所属的 App 和环境不一致。 | `check_scope` |
| `RATE_LIMITED` | 429 | 请求过多；按 `Retry-After` 等待后用同一请求重试。 | `retry_same_request` |
| `SERVICE_UNAVAILABLE` | 503 | 服务暂时不可用；用同一请求重试。 | `retry_same_request` |
| `INTERNAL_ERROR` | 500 | 结果未知；稍后重试。 | `recover_operation` |

- [错误码与恢复](https://www.longplayai.com/zh-hans/docs/api/errors.md)
- [请求约定](https://www.longplayai.com/zh-hans/docs/api.md)
- [全部接口](https://www.longplayai.com/zh-hans/docs/api/operations.md#commerce)
