# 确认批量订阅

Operation / SDK: `confirmSubscriptionBatch` · `confirm_subscription_batch` · `ConfirmSubscriptionBatch`

确认批量订阅。

更新于 2026-11-06

[网页版本](https://www.longplayai.com/zh-hans/docs/api/confirm-subscription-batch)

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

## 请求

- **凭据**: Server Key，权限 `billing:write`。只在后端调用。
- **SDK**: JavaScript `createLongplayServer().confirmSubscriptionBatch` · Python `confirm_subscription_batch` · Go `ConfirmSubscriptionBatch`
- **成功状态**: HTTP 200

> 在 `record_only` 模式下，商户须先支持商户桥接 v4 的 `operation.prepare` 准备命令，Longplay 才能冻结报价并生成 `merchantTerms`；确认报价时提交与之匹配的 `merchantConfirmation`。

- [商户准备报价](https://www.longplayai.com/zh-hans/docs/guides/merchant-execution.md#prepared-terms)

响应为示例数据。

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/subscriptions/batches/confirm" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
  "batchId": "f9bad959-aa86-4e4a-801f-11c26e67bddd"
}'
```

**TypeScript: confirmSubscriptionBatch.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 confirmSubscriptionBatch() {
  return longplay.confirmSubscriptionBatch({
    customerId: "8b258f8b-4228-40fa-8d24-5b16428e686d",
    batchId: "f9bad959-aa86-4e4a-801f-11c26e67bddd",
  });
}
```

**请求体: request.json**

```json
{
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
  "batchId": "f9bad959-aa86-4e4a-801f-11c26e67bddd"
}
```

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

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "batch": {
    "batchId": "f9bad959-aa86-4e4a-801f-11c26e67bddd",
    "ready": true,
    "status": "prepared",
    "createdAt": "2026-10-03T12:00:00.000Z",
    "acceptedAt": null,
    "groups": [
      {
        "operationId": "a8b14e0c-6576-49a4-812c-7a1587e55255",
        "membershipIds": [
          "5c22044b-a5dd-49fe-83bf-c52eff327451"
        ],
        "provider": "stripe",
        "action": "cancel",
        "timing": "immediate",
        "status": "prepared",
        "quote": null,
        "managementUrl": null,
        "failureCode": null
      }
    ]
  }
}
```

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

## 请求体参数

**application/json**

- `batchId` (uuid, required): 批次的 ID。
- `customerId` (uuid, required): 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"`.
- `batch` (object, required): 批次，字段见下。
- `batch.batchId` (uuid, required): 批次的 ID。
- `batch.ready` (boolean, required): 是否就绪。
- `batch.status` (enum, required): 状态，取值见允许值。 Values: `"prepared"`, `"cancelled"`, `"expired"`, `"pending"`, `"partial"`, `"effective"`, `"action_required"`.
- `batch.createdAt` (date-time, required): 记录创建时的 ISO 8601 UTC 时间。
- `batch.acceptedAt` (date-time | null, required): 时间（ISO 8601）。
- `batch.groups` (array, required): 分组。 minItems: 1 · maxItems: 100
- `batch.groups.operationId` (uuid, required): 业务操作 UUID；订阅执行引用 previewAttach 返回的 operationId，余额退款引用原消费操作。
- `batch.groups.membershipIds` (array, required): 会员的 ID 列表。 minItems: 1 · maxItems: 20
- `batch.groups.provider` (enum, required): 支付渠道，取值见允许值。 Values: `"stripe"`, `"apple"`, `"google"`.
- `batch.groups.action` (enum, required): 本次业务动作。不同动作的目标字段和数量要求不同，见请求结构与示例。 Values: `"cancel"`, `"uncancel"`.
- `batch.groups.timing` (enum, required): 立即变更或在周期末变更；只用于契约允许的套餐变更动作。 Values: `"immediate"`, `"renewal"`.
- `batch.groups.status` (enum, required): 状态，取值见允许值。 Values: `"prepared"`, `"confirmed"`, `"pending"`, `"scheduled"`, `"effective"`, `"cancelled"`, `"failed"`, `"store_action_required"`.
- `batch.groups.quote` (object | null, required): 报价。
- `batch.groups.quote.merchantTerms` (object, optional): 商户已准备好的条款；有它时金额和周期以它为准。
- `batch.groups.quote.carryOverBalances` (object, optional): 变更时是否结转余额。
- `batch.groups.quote.carryOverUsages` (object, optional): 变更时是否结转用量。
- `batch.groups.quote.operationId` (uuid, required): 业务操作 UUID；订阅执行引用 previewAttach 返回的 operationId，余额退款引用原消费操作。
- `batch.groups.quote.membershipId` (uuid, required): 会员的 ID。
- `batch.groups.quote.productVersionId` (uuid, required): Product Version 的 ID。
- `batch.groups.quote.featureQuantities` (object, optional): 按内部 Feature ID 记录的预付 Feature 数量。
- `batch.groups.quote.timing` (enum, required): 立即变更或在周期末变更；只用于契约允许的套餐变更动作。 Values: `"immediate"`, `"renewal"`.
- `batch.groups.quote.effectiveAt` (date-time, required): 时间（ISO 8601）。
- `batch.groups.quote.expiresAt` (date-time, required): 到期时间（ISO 8601，UTC）。
- `batch.groups.quote.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"`.
- `batch.groups.quote.creditMinor` (integer, required): 金额，以最小货币单位计（如美分）。 min: 0 · max: 100000000
- `batch.groups.quote.debitMinor` (integer, required): 金额，以最小货币单位计（如美分）。 min: 0 · max: 100000000
- `batch.groups.quote.discountMinor` (integer, required): 金额，以最小货币单位计（如美分）。 min: 0 · max: 100000000
- `batch.groups.quote.taxMinor` (integer, required): 金额，以最小货币单位计（如美分）。 min: 0 · max: 100000000
- `batch.groups.quote.totalMinor` (integer, required): 金额，以最小货币单位计（如美分）。 min: 0 · max: 100000000
- `batch.groups.quote.retainedProductVersionIds` (array, required): 保留的 Product Version 的 ID 列表。 maxItems: 19
- `batch.groups.quote.execution` (object | object, required): 执行信息。
- `batch.groups.managementUrl` (uri | null, required): App Store 或 Google Play 的订阅管理页面，Customer 需在此完成由商店管理的分组；Stripe 分组为 `null`。
- `batch.groups.failureCode` (enum | null, required): 失败代码。

<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:write` 权限。 | `check_permissions` |
| `SCOPE_MISMATCH` | 403 | `X-Indiana-Project` 或 `X-Indiana-Environment` 与凭据所属的 App 和环境不一致。 | `check_scope` |
| `CONFLICT` | 409 | 同一个 `batchId` 用了不同的输入（`reason: IDEMPOTENCY_CONFLICT`）。 | `resolve_conflict` |
| `RATE_LIMITED` | 429 | 请求过多；按 `Retry-After` 等待后用同一请求重试。 | `retry_same_request` |
| `SERVICE_UNAVAILABLE` | 503 | 服务暂时不可用；用同一请求重试。 | `retry_same_request` |
| `INTERNAL_ERROR` | 500 | 结果未知；先读取原操作，或用原 ID 和原输入重放。 | `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)
