跳到正文
Indiana
控制台
文档
章节目录 / 客户状态与历史

客户状态与历史

构建账户页:精确余额、套餐资格、状态订阅和分页历史。

SDK 0.0.1更新于

读取当前客户持有与账本

先在宿主完成真实登录并取得当前用户 Token,再 grow.identify。浏览器请求不传客户 ID。当前读接口与屏幕组件读取同一份会员、余额和验证交易;数据保持私有,不缓存成公开设计。

数量、余额和费率使用十进制字符串。过滤作用于全历史,再使用带微秒和记录类型的游标分页。报价不扣款;消费、预扣、确认、释放和原价退款只能由可信后端执行。

后端消费需要 credits:consume;退款另外需要 credits:manage。报价、账本与持有分别需要 credits:read、credits:read 和 entitlements:read。当前余额执行只开放明确的 Sandbox 范围。

app/account.tsTypeScript
const { holdings } = await grow.readHoldings();const { ledger } = await grow.readLedger({  type: null, from: null, to: null, after: null, limit: 50,});// Read the next page with ledger.nextCursor; preserve the entire cursor.const { quote } = await grow.quoteBalance({  operation: "quote", entitlementId, quantity: "1", properties: {},});
server/usage.tsTypeScript
const { receipt } = await groove.mutateBalance({  customerId: verifiedCustomer.id,  command: {    operation: "consume", entitlementId, quantity: "1", properties: {},    idempotencyKey: `job:${job.id}`,  },});// Retry the same job with its original idempotencyKey and input.