跳到正文
Indiana
控制台
章节目录 / 浏览器客户端

浏览器客户端

读取当前 Customer 的持有、Offering、Paywall、账本与优惠。

SDK 示例对应当前 API。核对匹配版本与 HTTP 接入方式

API v1更新于

浏览器 SDK

本参考适用于协议 0.5。SDK 发布状态与可直接使用的 HTTP 示例见版本说明。

相关:版本与接入方式

先在宿主完成真实登录,由后端签发当前客户会话。浏览器不传任意 customerId。

当前导出与方法

  • await indiana.features({ attributes? })

    权限features:read

    用现有 Customer 或 Guest Session 加载功能。isOn/getFeatureValue 同步读取本地规则或最近的服务器结果;服务器结果尚未就绪时使用默认值。属性变化会清除旧服务器结果,subscribe 订阅更新,destroy 释放刷新监听。

    返回 FeatureClient

  • indiana.track(name, properties); await indiana.flush()

    权限events:write

    按 100 项和请求体大小分批,后台定时和页面隐藏时发送。失败保留原事件标识;identify/reset 清除旧身份的队列和功能结果。服务器固定 Session 所属 Customer,浏览器不能指定其他客户。0.4 源码候选增加环境级采集控制:请在当前环境的接入设置中开启所需采集;关闭时以 skipped 确认跳过,不删除历史。此协议尚未发布。

    返回 { inserted, duplicates, rejected }

  • resolvePaywall({ selector, locale, commerce, requirement? })

    权限entitlements:read

    读取独立 Paywall、固定 Offering Version 和当前展示能力;不创建 Funnel 或执行购买。

    返回 { paywall }

  • setupPayment({ requestId, currency, makeDefault })

    权限billing:write

    创建独立银行卡设置;不产生订阅、权益或用量扣款授权。

    返回 { setup }

  • readPaymentSetup({ setupId })

    权限billing:read

    核对原设置的实际渠道结果,重试不会重复收费。

    返回 { setup }

  • readBillingInvoice({ invoiceId, after, limit })

    权限billing:read

    读取完整已验证明细,按 nextCursor 分页;不会收费。

    返回 { detail }

  • readCreditStatement({ from, to, entityId?, snapshotAt, after, limit })

    权限credits:read

    范围上限 366 天;首屏 snapshotAt/after 为 null,后续沿用原快照和完整游标。

    返回 { statement }

  • previewUpdate({ requestId, membershipId, timing, change })

    权限billing:read

    为由 Stripe 订阅计费的会员报价一次套餐、席位或取消变更;升级立即按比例计费,降级在周期末生效。

    返回 { quote }

  • update({ operationId })

    权限billing:write

    确认报价:Indiana 执行模式下在 Stripe 执行一次;仅记录模式返回商家要执行的 Stripe 指令。

    返回 { operation }

  • readSubscriptionUpdate({ operationId })

    权限billing:read

    读取变更状态;已排期的降级或取消在生效前显示为 scheduled。

    返回 { operation }

  • previewAttach({ entityId?, requestId, plans, provider, currency, offerId? })

    权限billing:read

    使用已识别客户会话保存最长 24 小时的报价并保留所选优惠;不传 customerId,不触发付款。仅记录模式下,quote.execution 是你的后端用自己的 Stripe Key 创建 Checkout Session 的指令。

    返回 { quote }

  • attach({ operationId, intent? })

    权限billing:write

    客户明确接受报价后执行;intent 为 cancel 时放弃报价并释放所持优惠。待处理时,由 Indiana 执行 Stripe 返回 checkoutUrl,仅记录模式返回同一 execution;记录到已验签的 Stripe 通知后为 complete。响应丢失时重试原 operationId。

    返回 { operation }

  • restoreNativePurchase({ requestId, provider, purchaseIntentId, productId, signedTransaction?, purchaseToken? })

    权限billing:write

    使用已识别客户身份恢复经过商店验证的购买。

    返回 { restore }

  • readSubscriptionOperation({ operationId })

    权限billing:read

    恢复原订单状态和验证后的交付,不重新发起收款。

    返回 { operation }

  • setBillingCoupons({ membershipId, requestId, grantIds })

    权限billing:write

    为当前客户的已启用授权设置有序优惠;只能使用本人持有的券。原 requestId 的重试返回原回执,待结算期间不能更换优惠。

    返回 { coupons }

  • confirmBillingAdjustment({ invoiceId, accepted: true })

    权限billing:write

    仅在客户审阅并同意当前固定追加账单后调用。不能由页面加载或自动重试推断同意。

    返回 { invoice }

  • readBillingControls(input?)

    权限billing:read

    读取已验证客户的授权、限额、窗口和自动充值状态。

    返回 { controls }

  • prepareBillingAuthorization(input)

    权限billing:write

    保留原 requestId,准备固定版本与限额条款;准备不等于客户同意。

    返回 { prepared }

  • confirmBillingAuthorization({ authorizationId, accepted: true })

    权限billing:write

    只在客户明确接受条款后调用;服务端再次验证当前授权和 provider 设置。

    返回 { authorization }

  • revokeBillingAuthorization({ authorizationId, requestId })

    权限billing:write

    撤销当前客户授权;原请求重试不换 UUID。

    返回 { authorization }

  • listBillingInvoices({ after, limit }?)

    权限billing:read

    读取当前客户用量账单;按 nextCursor 分页,limit 最多 100。

    返回 { invoices }

  • readBillingControls(input) / listBillingInvoices({ after, limit })

    权限billing:read

    读取当前已认证客户的自动付款授权、用量窗口、限额与分页账单。读取、刷新和分页不触发扣款。

    返回 { controls } / { invoices }

  • prepareBillingAuthorization(input) / confirmBillingAuthorization({ authorizationId, accepted: true }) / revokeBillingAuthorization({ authorizationId, requestId })

    权限billing:write

    以持久 requestId 准备固定条款与 Sandbox 支付方式;只有支付准备完成且客户明确接受后才能启用付款。撤销会阻止后续自动付款,并保留已有财务事实。

    返回 { prepared } / { authorization }

  • identify(customerToken) / reset()

    Token 只保存在内存;重置或换号会中止旧身份请求。展示中的 Funnel 也必须销毁并丢弃。

    返回 void

  • subscribeIdentity(listener)

    观察 identify/reset,宿主据此清理界面;返回取消订阅函数。

    返回 Unsubscribe function

  • resolveOffering({ selector, commerce, requirement? })

    权限entitlements:read

    使用当前 Customer Token 解析已发布 Offering 层级和 Product availability;浏览器不能覆盖 customerId,此调用不执行购买。

    返回 { offering, candidates, availability, check }

  • checkEntitlement({ requirement, commerce?, paywallId? })

    权限entitlements:read

    npm 0.1.0 beta 提供此方法。匹配服务后,使用当前客户 Token 返回 allowed、拒绝原因和商品推荐;浏览器不能指定客户身份。

    返回 { check }

  • readHoldings()

    权限entitlements:read

    读取当前已认证客户的会员与余额,不接收 customerId。

    返回 { holdings }

  • readLedger(query)

    权限credits:read

    按当前客户分页读取完整历史;游标包含记录类型与精确时间。

    返回 { ledger }

  • quoteBalance(command)

    权限credits:read

    传 operation: quote、internal_feature_id、十进制 quantity 和 properties。只估价,不扣量。

    返回 { quote }

  • listOffers()

    权限offers:resolve

    读取当前客户的有效优惠;实际领取和购买在发布的 Funnel 节点中执行。

    返回 Offer[]

  • redeemCoupon(code, requestId)

    权限offers:resolve

    兑换当前范围中的优惠码,原 requestId 用于响应丢失后的重试。

    返回 { offer, reason }

  • redeemReward(input) / createReferralCode(input)

    权限offers:resolve

    按已配置的奖励与推荐计划执行;创建推荐码另需 offers:resolve。

    返回 Reward / referral code

  • setBillingCoupons(input)

    权限billing:write

    在客户确认的授权上替换后续收款的有序优惠券列表;空列表移除,重试保留 requestId。进行中的收款拒绝修改。

    返回 BillingCoupons

  • claimRewardProduct(input)

    权限offers:resolve

    审阅奖励兑换与后续续费条款后传入 accepted: true;重试保留 redemptionId 和 requestId。新订阅返回 type: checkout 与结账状态;已有相同付费订阅返回 type: subscription 与追加优惠任务状态,保留原优惠和订阅身份。

    返回 RewardProductCheckout

  • formatCouponTerms / formatCouponDiscount / formatCouponMoney

    使用服务端返回的 coupon 条款格式化展示,文案不决定资格或实际收费。

    返回 string