SuperAPI AI 工具集

paddle-billing-history

前端与建站

查看项目

更新于 10-16 03:14

技能介绍

用途:为已登录用户的账户页添加“账单历史/发票”区块,展示日期、金额、状态并支持加载更多。属于交易数据的读取侧,通常与 subscription-sync(提供 customers 表)、webhooks(写入 customers 表)配合;若只需托管账单界面,可直接使用 customer-portal。

主要能力:在 Server Action 中调用 paddle.transactions.list,按 customerId 过滤交易,传入 status 数组(billed、paid、past_due、completed、canceled),perPage 与 after 游标分页;返回精简 DTO(id、billedAt、status、格式化 total)。

必要用法:先鉴权(示例用 Supabase),未登录返回错误;再通过邮箱桥接从 customers 表查出该用户的 Paddle customer_id,无记录则返回空结果;customerId 必须服务端解析,绝不能接受客户端传入。collection 是迭代器,用 await collection.next() 取一页,hasMore 判断是否还有更多,estimatedTotal 用于计数。金额需自行格式化:details.totals.total 为最低货币单位字符串,JPY/KRW/CLP 为零小数货币不除以 100,其余除以 100,再用 Intl.NumberFormat 输出。

限制与陷阱:不要省略 customerId,否则会返回账户内所有客户的交易;不要 while 循环拉取全部页;不要包含 draft/ready 状态;不要手动累加行项目或使用 formattedTotals(该字段仅存在于 Paddle.js PricePreview);不要对金额额外取整。验证时需确认其他客户的交易不会出现。相关文档:List transactions、Get an invoice PDF;参考实现 paddle-nextjs-starter-kit。