跳转到内容

测试商店

测试商店是一个扮演商店角色的渠道。它的购买和真实商店走同样的流程:记录、事件、带签名的回调、GET /v1/customers 和 GET /v1/events。渠道 id:test_store,平台:test。

它产生的所有数据都带 environment: "test"、platform: "test" 和 data.store: "test_store"。你的后端绝不应把它算作收入。

测试商店默认关闭。关闭期间,所有测试商店调用都返回 403 test_store_disabled,自动续订也会暂停。

终端窗口
npx @kasskeep/cli test-store enable --id app_xxx
npx @kasskeep/cli test-store config --id app_xxx --period-seconds 60 --renewal-success-rate 0.8 --products "demo.*"
设置 默认值 含义
subscription_period_seconds 300 一个测试订阅周期的时长(10 秒到 366 天)
renewal_success_rate 1 自动续订成功的概率(0 到 1)
grace_period_seconds 120 续订失败后的宽限期;设为 0 则直接进入扣费重试
billing_retry_seconds 300 宽限期之后的扣费重试时长;之后订阅到期
products 不限 允许的商品 id;末尾的 * 表示前缀匹配。其他商品以 400 product_not_allowed 失败
prices 0.99 USD {"id or prefix*": {price_micros, currency, title?}};先精确匹配,再取最长前缀

如果 App 已有正式交易或商店凭据,开启时会返回 test_store_on_live_app 警告。这是允许的:一个 App 可以同时承载真实流量和测试流量,用 environment 区分。

在客户端用公钥调用,或在 SDK 里设 testStore: true:

POST /v1/test-store/purchases
X-Kasskeep-Key: pk_...
{"app_user_id": "6f1c...", "product_id": "demo.gems_100", "type": "inapp", "quantity": 1, "outcome": "success"}
  • type:inapp 或 subs。quantity 为 1 到 100,订阅只能是 1。
  • outcome:success(默认)、cancelled、pending 或 failed。只有 success 会记录购买。pending 会保留一笔待处理购买,之后可以批准或拒绝。
  • 可选的 price_micros 和 currency 用来覆盖价格。
  • 交易 id 形如 test_<24 hex>。对同一商品再开一个生效中的订阅,会返回 409 already_subscribed。

GET /v1/test-store/products?ids=a,b&type=inapp 返回允许的商品及价格,SDK 的 getProducts 用的就是它。

终端窗口
npx @kasskeep/cli test-store simulate --id app_xxx --scenario renew_fail --user <app_user_id>
npx @kasskeep/cli test-store simulate --id app_xxx --scenario upgrade --user <app_user_id> --to-product-id pro_yearly
场景 适用于 事件
renew 已开启自动续订的生效订阅 subscription.renewed
renew_fail 生效订阅 subscription.billing_issue
grace_expire 处于宽限期 subscription.grace_period_expired
recover 处于宽限期或扣费重试 带 data.recovered 的 subscription.renewed
cancel / uncancel 自动续订开 / 关 subscription.canceled / subscription.uncanceled
expire 未到期 subscription.expired
upgrade 生效中,需要 to_product_id subscription.product_changed,立即生效
downgrade 生效中,需要 to_product_id subscription.product_changed,下次续订时生效
refund 购买或订阅 refund
refund_reverse 已退款 refund.reversed
revoke 购买或订阅 revoked(家人共享)
pending_approve 待处理 purchase 或 subscription.started
pending_decline 待处理 无

场景与当前状态不符时,返回 409 scenario_not_applicable。

终端窗口
npx @kasskeep/cli test-store advance --id app_xxx --user <app_user_id> [--outcome failure]

它把当前周期、宽限期或重试期的结束时间挪到现在,并立即执行到期的动作:续订、失败、结束宽限期或到期。系统时钟不受影响。

什么都不做的话,也有一个任务每 10 秒运行一次,按设置为到期的测试订阅续订或让它到期。