SuperAPI AI 工具集

stripe-testing

测试与质量

查看项目

更新于 10-16 07:14

技能介绍

用途:端到端测试与调试 Stripe 支付集成。

主要能力与用法: 环境准备:用 stripe --version 确认已安装 Stripe CLI;检查环境变量中是否存在以 sk_test_ 开头的测试 API 密钥;如无则需在 Stripe Dashboard 的 Developers → API keys 中设置;用 stripe listen --forward-to localhost:<port>/webhooks/stripe 将 Webhook 转发到本地。 失败扣款诊断:索要付款意图或扣款 ID(pi_ 或 ch_ 开头);用 stripe payment_intents retrieve <id> --api-key $STRIPE_SECRET_KEY 获取详情;查看 last_payment_error 字段中的拒付原因。常见拒付码及复现用测试卡:card_declined 用 4000000000000002,insufficient_funds 用 4000000000009995,expired_card 用 4000000000000069,incorrect_cvc 用 4000000000000127;用 stripe events list --limit 5 --api-key $STRIPE_SECRET_KEY 查看事件。 Webhook 处理测试:用 stripe webhook_endpoints list --api-key $STRIPE_SECRET_KEY 列出已注册端点;用 stripe trigger <event_type> 触发事件(如 payment_intent.succeeded);确认本地服务正确接收并处理;检查处理代码中的签名验证,查找 stripe.webhooks.constructEvent()。常见测试事件包括 checkout.session.completed、invoice.payment_succeeded、invoice.payment_failed、customer.subscription.updated、customer.subscription.deleted。 订阅生命周期验证:用 stripe customers create --name "Test User" --email test@example.com --api-key $STRIPE_SECRET_KEY 创建测试客户;用 stripe test_clocks create --frozen-time $(date +%s) --api-key $STRIPE_SECRET_KEY 创建测试时钟;用 stripe test_clocks advance <clock_id> --frozen-time <future_timestamp> --api-key $STRIPE_SECRET_KEY 推进时钟模拟计费周期;验证订阅状态转换 trialing → active → past_due → canceled。 服务端日志:在应用日志中检索 stripe、webhook、payment 相关条目;检查 Webhook 投递的 HTTP 4xx/5xx 响应;验证幂等性,重复投递不应产生重复记录。

限制与注意:始终使用测试模式密钥(sk_test_),绝不用实时密钥测试;使用 Stripe 内置测试卡号而非真实卡数据;测试时钟对订阅测试至关重要;需确保正确实现 Webhook 签名验证;注意竞态条件,Webhook 可能先于重定向完成到达;显式使用 --api-key 参数以避免误用错误密钥。资料未提供额外收费或平台细节。