预览订阅变更报价
- 操作名
previewUpdate- 服务端 SDK
previewUpdate- Python
preview_update- Go
PreviewUpdate- 浏览器 SDK
previewUpdate
POST/api/v1/subscriptions/preview-update
为升级、降级或取消生成固定报价,可选立即、续订或商店时点生效。
API v1更新于
- 凭据
- Server Key(传
customerId)或 Customer Token,权限 billing:read。 - SDK
- JavaScript
createLongplayServer().previewUpdate · JavaScript createLongplay().previewUpdate · Python preview_update · Go PreviewUpdate - 成功状态
- HTTP 200
在 record_only 模式下,商户须先支持商户桥接 v4 的 operation.prepare 准备命令,Longplay 才能冻结报价并生成 merchantTerms;确认报价时提交与之匹配的 merchantConfirmation。
相关:商户准备报价
1curl -X POST "$LONGPLAY_API_URL/api/v1/subscriptions/preview-update" \2 -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \3 -H "X-Indiana-Protocol: 0.10" \4 -H "Content-Type: application/json" \5 -d '{6 "requestId": "0f58d1f8-069f-4288-8ec1-4ed10af55b45",7 "membershipId": "5c22044b-a5dd-49fe-83bf-c52eff327451",8 "timing": "immediate",9 "change": {10 "type": "plan",11 "productVersionId": "8c489a1a-5542-44fe-8e80-da2f6a319d01"12 },13 "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d"14}'
响应为示例数据。
请求体参数#
application/json
requestIduuid必填你的业务请求 UUID;同一次操作重试复用,新的操作生成新值。
offerIduuid可选当前 Customer 已领取的优惠 ID,用于新购买;已有订阅改用 setBillingCoupons。
invoiceModeobject可选开票方式设置(可选)。
展开子字段
enable_plan_immediatelyboolean可选是否立即启用 Product。
default: false
finalizeboolean可选是否立即定稿。
default: true
invoice_template_idstring可选发票模板的 ID。
net_terms_daysinteger可选付款期限(天)。
max: 9007199254740991
membershipIduuid必填会员的 ID。
carryOverBalancesobject可选变更时是否结转余额。
展开子字段
featureIdsarray可选Feature 的 ID 列表。
minItems: 1 · maxItems: 100
carryOverUsagesobject可选变更时是否结转用量。
展开子字段
featureIdsarray可选Feature 的 ID 列表。
minItems: 1 · maxItems: 100
membershipIdsarray可选会员的 ID 列表。
minItems: 1 · maxItems: 20
prorationBehaviorenum可选按比例计费的方式,取值见允许值。
查看允许值
"prorate_immediately""none""bill_difference"
timingenum必填立即变更或在周期末变更;只用于契约允许的套餐变更动作。
查看允许值
"immediate""renewal""store"
changeobject | object | object | object | object | object必填要变更到的目标。
展开子字段
type"plan" | "seats" | "quantity" | "cancel" | "uncancel" | "billing_cycle"必填变更内容:plan 切换到 productVersionId,seats 设置某个许可的 席位总数,quantity 设置某个 Feature 的预付包数,cancel 在续订时或立即结束会员,uncancel 撤销待生效的取消或已排期的变更,billing_cycle 调整计费周期锚点。
productVersionIduuid可选Product Version 的 ID。
featureQuantitiesobject可选按内部 Feature ID 记录的预付 Feature 数量。
licenseKeystring可选要调整的该会员中席位许可的键(购买报价中的 seats.key);quantity 为新的席位总数,含已包含的席位。
minLength: 1 · maxLength: 64 · pattern: ^[a-z][a-z0-9_]*$
quantityinteger | integer可选数量(整数)。
internal_feature_iduuid可选Feature 的 ID。
billingCycleAnchor"now" | integer可选now 表示立即重新开始计费周期(配合 timing: "immediate");未来的 Unix 毫秒时间戳表示在该时刻开始新周期(配合 timing: "renewal")。
customerIduuid可选Customer 的 UUID。
响应字段#
成功响应都包含 requestId(本次请求 ID,排查时提供)和 scope(App 与环境)。
HTTP 200 · application/json
requestIduuid必填服务端为这次 HTTP 请求生成的 UUID,排查时提供;它不是你的业务 requestId。
scopeobject必填响应实际所属的 App 和环境。Header 只能核对,不能切换 Key 范围。
展开子字段
projectIdstring必填凭据绑定的 App ID。
minLength: 1
environmentenum必填独立数据范围:sandbox 或 live。
查看允许值
"sandbox""live"
quoteobject | object必填报价。
展开子字段
merchantTermsobject可选商户已准备好的条款;有它时金额和周期以它为准。
展开子字段
requestobject | object | object必填商户收到的原准备请求,用来证明这些条款属于哪次选择。
展开子字段
subjectobject | object | object必填原准备请求绑定的 App、环境和 Customer。
operationIduuid | uuid | uuid必填业务操作 UUID;订阅执行引用 previewAttach 返回的 operationId,余额退款引用原消费操作。
configurationRevisioninteger | integer | integer必填原准备请求绑定的配置修订号。
connectionRevisioninteger | integer | integer必填发起准备时的商户连接版本;连接变更后需重新准备。
expiresAtdate-time | date-time | date-time必填到期时间(ISO 8601,UTC)。
action"purchase" | "subscription_change" | "refund"必填本次业务动作。不同动作的目标字段和数量要求不同,见请求结构与示例。
modeenum | enum可选模式,取值见允许值。
currencystring | string | string必填已发布价格支持的币种代码。
itemsarray可选列表项。
minItems: 1 · maxItems: 100
offerRefsarray | array可选这次选择带上的商户优惠引用。
merchantSubscriptionIdstring可选要变更的商户订阅引用。
minLength: 1 · maxLength: 200
changeobject | object | object | object | object | object可选要变更到的目标。
timingenum可选立即变更或在周期末变更;只用于契约允许的套餐变更动作。
查看允许值
"immediate""renewal"
prorationenum可选这次计划变更使用的按比例结算方式。
查看允许值
"none""create_prorations""always_invoice"
merchantInvoiceIdstring可选要退款的商户账单引用。
minLength: 1 · maxLength: 200
amountMinorinteger可选金额,以最小货币单位计(如美分)。
max: 200000000
entitlementActionenum可选退款后保留(retain)或撤销(revoke)权益。
查看允许值
"retain""revoke"
requestDigeststring必填原准备请求的规范摘要。
pattern: ^[a-f0-9]{64}$
merchantQuoteIdstring必填商户这次报价的引用。
minLength: 1 · maxLength: 200
quoteTermsDigeststring必填条款规范摘要;确认时绑定它,之后不可更换。
pattern: ^[a-f0-9]{64}$
termsVersionstring必填商户条款版本。
minLength: 1 · maxLength: 200
sourceRevisionsarray必填报价依据的商品目录或订阅版本。
maxItems: 100
展开子字段
referencestring必填报价依据的数据来源引用。
minLength: 1 · maxLength: 200
revisionstring必填特定资源的版本号;Customer 资料更新不使用版本号。
minLength: 1 · maxLength: 200
observedAtdate-time必填时间(ISO 8601)。
expiresAtdate-time必填到期时间(ISO 8601,UTC)。
currencystring必填已发布价格支持的币种代码。
pattern: ^[A-Z]{3}$
automaticTaxboolean必填税额是否由商户按自动税计算;未知税额不会当作 0。
linesarray必填明细行。
maxItems: 100
展开子字段
merchantLineIdstring必填商户原生发票行稳定标识;同一发票内不能重复。
minLength: 1 · maxLength: 200
merchantPriceIdstring | null必填这一行的商户价格引用;无对应价格时为空。
quantitystring必填数量,十进制字符串,避免浮点误差。
pattern: ^(0|[1-9]\d{0,11})(\.\d{1,6})?$
subtotalMinorinteger必填金额,以最小货币单位计(如美分)。
min: -200000000 · max: 200000000
discountMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 200000000
taxMinorinteger | null必填金额,以最小货币单位计(如美分)。
totalMinorinteger | null必填金额,以最小货币单位计(如美分)。
subscriptionTermsobject | null必填后续周期的订阅承诺,独立于本次扣款;非订阅时为空。
展开子字段
itemsarray必填列表项。
minItems: 1 · maxItems: 100
discountobject | null可选折扣。
discountExpiresAtdate-time | null可选时间(ISO 8601)。
initialAmountMinorinteger可选金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
subtotalMinorinteger必填金额,以最小货币单位计(如美分)。
min: -200000000 · max: 200000000
discountMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 200000000
nativeDiscountMinorinteger可选金额,以最小货币单位计(如美分)。
min: 0 · max: 200000000
discountobject | null可选折扣。
展开子字段
couponIduuid必填当前 App 和环境中的优惠券 UUID。
amountMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
applicationPolicyenum可选此优惠与原生价格折扣的组合方式:替换原生折扣,或在原生折扣上叠加。
查看允许值
"replace""stack_native"
applicableProductIdsarray可选当前 App 和环境中,此优惠适用的商户原生 Product 标识。
minItems: 1 · maxItems: 100
termsobject | object必填条款内容。
durationobject | object | object必填持续时长。
taxMinorinteger | null必填金额,以最小货币单位计(如美分)。
totalMinorinteger | null必填金额,以最小货币单位计(如美分)。
effectiveAtdate-time | null必填时间(ISO 8601)。
expectedEffectsarray必填商户承诺的原生结果,用于确认展示,不代表平台余额。
maxItems: 100
展开子字段
referencestring必填这项预期结果的稳定标识。
minLength: 1 · maxLength: 200
kindenum必填类型,取值见允许值。
查看允许值
"grant""revoke""change"
descriptionstring必填描述。
minLength: 1 · maxLength: 1000
quantitystring | null必填数量,十进制字符串,避免浮点误差。
unitstring | null必填数量对应的商户单位;没有数量时为空。
requiredConsentsarray必填确认前用户必须接受的商户条款。
maxItems: 20
展开子字段
referencestring必填这项同意条款的稳定标识。
minLength: 1 · maxLength: 200
versionstring必填版本号。
minLength: 1 · maxLength: 200
summarystring必填向用户展示的条款摘要。
minLength: 1 · maxLength: 1000
carryOverBalancesobject可选变更时是否结转余额。
展开子字段
featureIdsarray可选Feature 的 ID 列表。
minItems: 1 · maxItems: 100
carryOverUsagesobject可选变更时是否结转用量。
展开子字段
featureIdsarray可选Feature 的 ID 列表。
minItems: 1 · maxItems: 100
operationIduuid | uuid必填业务操作 UUID;订阅执行引用 previewAttach 返回的 operationId,余额退款引用原消费操作。
membershipIduuid | uuid必填会员的 ID。
productVersionIduuid | uuid必填Product Version 的 ID。
featureQuantitiesobject可选按内部 Feature ID 记录的预付 Feature 数量。
timingenum | "store"必填立即变更或在周期末变更;只用于契约允许的套餐变更动作。
effectiveAtdate-time | null必填时间(ISO 8601)。
expiresAtdate-time | date-time必填到期时间(ISO 8601,UTC)。
currencyenum | enum必填已发布价格支持的币种代码。
creditMinorinteger | null必填金额,以最小货币单位计(如美分)。
debitMinorinteger | null必填金额,以最小货币单位计(如美分)。
discountMinorinteger | null必填金额,以最小货币单位计(如美分)。
taxMinorinteger | null必填金额,以最小货币单位计(如美分)。
totalMinorinteger | null必填金额,以最小货币单位计(如美分)。
retainedProductVersionIdsarray | array必填保留的 Product Version 的 ID 列表。
executionobject | object可选执行信息。
展开子字段
provider"stripe" | "merchant"必填支付渠道,取值见允许值。
invoiceModeobject可选开票方式设置(可选)。
展开子字段
enable_plan_immediatelyboolean可选是否立即启用 Product。
default: false
finalizeboolean可选是否立即定稿。
default: true
invoice_template_idstring可选发票模板的 ID。
net_terms_daysinteger可选付款期限(天)。
max: 9007199254740991
executorenum | "merchant"必填执行方,取值见允许值。
accountIdstring可选Stripe 账户 ID(acct_…)。
pattern: ^acct_[A-Za-z0-9]+$
subscriptionIdstring | uuid必填Stripe 订阅 ID(sub_…)。
actionenum可选本次业务动作。不同动作的目标字段和数量要求不同,见请求结构与示例。
查看允许值
"update""cancel""schedule""release"
updateobject | null可选action 为 update 时,对 subscriptionId 调用 Stripe subscriptions.update 的参数;否则为 null。
展开子字段
itemsarray必填列表项。
maxItems: 20
removearray必填要移除的项。
maxItems: 20
restoreItemsarray可选恢复的明细项。
minItems: 1 · maxItems: 20
prorationBehaviorenum可选按比例计费的方式,取值见允许值。
查看允许值
"always_invoice""create_prorations""none"
prorationDateinteger可选作为 Stripe proration_date 发送的 Unix 时间(秒),即 Stripe 计算按比例费用的起点;变更不按比例计费时不返回。
max: 9007199254740991
paymentBehavior"error_if_incomplete"可选付款行为,取值见允许值。
cancelAtPeriodEndboolean可选是否在当前周期结束时取消。
clearCancelAttrue可选时间(ISO 8601)。
billingCycleAnchorNowtrue可选是否从现在开始新的计费周期。
cancelobject | null可选action 为 cancel 时:用 prorate: false 和 invoice_now: false 立即取消 Stripe 订阅;否则为 null。
展开子字段
scheduleobject | null可选排期。
展开子字段
currentItemsarray必填当前明细项。
maxItems: 20
nextItemsarray必填变更后的明细项。
minItems: 1 · maxItems: 20
switchAtinteger必填时间(ISO 8601)。
max: 9007199254740991
intervalenum必填周期,取值见允许值。
查看允许值
"week""month""year"
intervalCountinteger必填Stripe Price 的计费间隔数量,最多 52。
min: 1 · max: 52
resetBillingCycleAnchortrue可选是否重设计费周期起点。
releaseobject | null可选action 为 release 时:释放 schedule 指定的 Stripe 订阅计划(sub_sched_…),以撤销其中待生效的变更;否则为 null。
展开子字段
schedulestring必填Stripe 订阅 ID(sub_…)。
pattern: ^sub_sched_[A-Za-z0-9]+$
expiresAtdate-time | date-time必填到期时间(ISO 8601,UTC)。
operationIduuid可选业务操作 UUID;订阅执行引用 previewAttach 返回的 operationId,余额退款引用原消费操作。
customerIduuid可选Customer 的 UUID。
configurationRevisioninteger可选扫描配置的修订号。
min: 0 · max: 9007199254740991
connectionRevisioninteger可选冻结此商业指令时的商户连接修订号;用于核对此操作仍使用同一连接配置。
min: 0 · max: 9007199254740991
currencystring可选已发布价格支持的币种代码。
pattern: ^[A-Z]{3}$
type"subscription_change"可选原商户商业指令的类型:购买、订阅变更或退款。按该类型读取对应的固定商业参数。
merchantSubscriptionIdstring可选此次变更对应的商户原生订阅稳定引用。
minLength: 1 · maxLength: 200
membershipIduuid可选会员的 ID。
subscriptionActionenum可选此指令对原订阅执行的动作:更新、取消、安排未来变更或释放已有安排。
查看允许值
"update""cancel""schedule""release"
supersedesOperationIduuid | null可选此次订阅动作替代的原变更操作 UUID;没有被替代的操作时为 null。
changeobject | object | object | object | object | object可选要变更到的目标。
展开子字段
type"cancel" | "uncancel" | "plan" | "seats" | "quantity" | "billing_cycle"必填变更内容:plan 切换到 productVersionId,seats 设置某个许可的 席位总数,quantity 设置某个 Feature 的预付包数,cancel 在续订时或立即结束会员,uncancel 撤销待生效的取消或已排期的变更,billing_cycle 调整计费周期锚点。
productVersionIduuid可选Product Version 的 ID。
featureQuantitiesobject可选按内部 Feature ID 记录的预付 Feature 数量。
licenseKeystring可选要调整的该会员中席位许可的键(购买报价中的 seats.key);quantity 为新的席位总数,含已包含的席位。
minLength: 1 · maxLength: 200
quantityinteger | integer可选数量(整数)。
internal_feature_iduuid可选Feature 的 ID。
billingCycleAnchor"now" | integer可选now 表示立即重新开始计费周期(配合 timing: "immediate");未来的 Unix 毫秒时间戳表示在该时刻开始新周期(配合 timing: "renewal")。
timingenum可选立即变更或在周期末变更;只用于契约允许的套餐变更动作。
查看允许值
"immediate""renewal"
effectiveAtdate-time可选时间(ISO 8601)。
creditMinorinteger可选金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
debitMinorinteger可选金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
totalMinorinteger可选金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
discountMinorinteger可选金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
discountobject | null可选折扣。
展开子字段
couponIduuid必填当前 App 和环境中的优惠券 UUID。
amountMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
applicationPolicyenum可选此优惠与原生价格折扣的组合方式:替换原生折扣,或在原生折扣上叠加。
查看允许值
"replace""stack_native"
applicableProductIdsarray可选当前 App 和环境中,此优惠适用的商户原生 Product 标识。
minItems: 1 · maxItems: 100
termsobject | object必填条款内容。
durationobject | object | object必填持续时长。
taxMinorinteger可选金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
prorationenum可选原订阅变更固定的按比例计费策略:不按比例处理、创建按比例项目或立即开票。商户按该指令执行。
查看允许值
"none""create_prorations""always_invoice"
lineItemsarray可选明细行。
maxItems: 100
展开子字段
priceIduuid必填该明细行所计费的目录 Price 的 UUID;price 是与之绑定的 Stripe Price。
productVersionIduuid必填Product Version 的 ID。
productIdstring必填Product 的 ID。
minLength: 1 · maxLength: 200
quantityinteger必填数量(整数)。
min: 0 · max: 1000000
unitAmountMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
totalMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
intervalenum必填周期,取值见允许值。
查看允许值
"week""month""year""one_off"
intervalCountinteger必填Stripe Price 的计费间隔数量,最多 52。
min: 1 · max: 52
kindenum必填类型,取值见允许值。
查看允许值
"fixed""prepaid""seat"
tiersobject | null必填阶梯价格档位。
removePriceIdsarray可选原订阅变更要求移除的 Longplay Price UUID 列表。
maxItems: 100
sourceLineItemsarray可选订阅变更前冻结的原生订阅价格明细。历史报价可能省略。
minItems: 1 · maxItems: 100
展开子字段
priceIduuid必填变更前订阅明细对应的 Longplay 价格 ID。
productVersionIduuid必填Product Version 的 ID。
productIdstring必填Product 的 ID。
minLength: 1 · maxLength: 200
quantityinteger必填数量(整数)。
min: 1 · max: 1000000
unitAmountMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
totalMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
intervalenum必填周期,取值见允许值。
查看允许值
"week""month""year""one_off"
intervalCountinteger必填Stripe Price 的计费间隔数量,最多 52。
min: 1 · max: 52
kindenum必填类型,取值见允许值。
查看允许值
"fixed""prepaid""seat"
tiersobject | null必填阶梯价格档位。
storeobject可选App Store 或 Google Play 上的 Product 变更(timing: "store")的商店条款:渠道、新的商店商品、目录价格和替换策略;应付金额以商店付款界面为准。
展开子字段
providerenum必填支付渠道,取值见允许值。
查看允许值
"apple""google"
productIdstring必填Product 的 ID。
minLength: 1 · maxLength: 255
catalogAmountMinorinteger必填金额,以最小货币单位计(如美分)。
min: 0 · max: 100000000
policyenum必填策略。
查看允许值
"apple_store""google_full_price"
失败时返回错误对象,按 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 |
CONFLICT | 409 | 同一个 requestId 用了不同的输入(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 |
可能的错误
INVALID_REQUEST
- HTTP
- 400
- 何时
- 请求不符合本页的参数。缺少或无法解析协议头时分别返回
UNSUPPORTED_PROTOCOL_VERSION 或 INVALID_PROTOCOL_VERSION。 - recovery
fix_request
UNAUTHENTICATED
- HTTP
- 401
- 何时
- 凭据缺失、无效、过期或已撤销。
- recovery
authenticate
FORBIDDEN
- HTTP
- 403
- 何时
- 凭据没有
billing:read 权限。 - recovery
check_permissions
SCOPE_MISMATCH
- HTTP
- 403
- 何时
X-Indiana-Project 或 X-Indiana-Environment 与凭据所属的 App 和环境不一致。- recovery
check_scope
CONFLICT
- HTTP
- 409
- 何时
- 同一个
requestId 用了不同的输入(reason: IDEMPOTENCY_CONFLICT)。 - recovery
resolve_conflict
RATE_LIMITED
- HTTP
- 429
- 何时
- 请求过多;按
Retry-After 等待后用同一请求重试。 - recovery
retry_same_request
SERVICE_UNAVAILABLE
- HTTP
- 503
- 何时
- 服务暂时不可用;用同一请求重试。
- recovery
retry_same_request
INTERNAL_ERROR
- HTTP
- 500
- 何时
- 结果未知;先读取原操作,或用原 ID 和原输入重放。
- recovery
recover_operation
相关:错误码与恢复·请求约定·全部接口