关于 subscription-billing
面向电商开发与运营团队的订阅计费技能,指导按 Shopify、WooCommerce、BigCommerce 或自定义无头店面选择并配置方案。涵盖周期扣款、失败付款追回及订阅管理,并强调通过 Webhook 同步状态。
主要功能
- 01按平台选择订阅工具
- 02配置周期与订阅计划
- 03设置失败付款重试
- 04支持升级、暂停与取消
- 05通过 Webhook 同步状态
适用场景
- 01为订阅盒或会员项目启用自动扣款
- 02自动处理失败付款以减少流失
- 03让客户自助变更或取消计划
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ finsilabs/ awesome-ecommerce-skills --skill subscription-billing安装后在 Claude Code 中输入/subscription-billing确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
tile.jsonevals/dunning-emails-cancellation-and-webhook-/criteria.jsontask.mdevals/plan-changes-with-proration-preview/criteria.jsontask.mdevals/subscription-creation-with-trial-and-db-/criteria.jsontask.md详细介绍
订阅计费
概述
订阅计费让客户能够按固定周期(每周、每月或每年)自动付款。Shopify、WooCommerce 和 BigCommerce 都有专门的订阅应用和插件,可处理完整的生命周期:初次结账、定期计费、付款失败后的挽回(催缴)、套餐变更、暂停和取消。对于无头店面,Stripe Subscriptions 可通过 API 提供相同功能,无需从头构建计费逻辑。
何时使用此技能
- 构建订阅盒、会员服务或“订阅并省钱”计划时
- 当前的订阅逻辑仍为手动操作,且无法随客户数量增长而扩展时
- 催缴(付款失败挽回)尚未自动化,导致不必要的客户流失时
- 客户需要自助升级或降级套餐、暂停和取消订阅时
核心说明
第 1 步:确定平台并选择合适的订阅工具
| 平台 | 推荐工具 | 说明 |
|---|---|---|
| Shopify | Recharge 或 Seal Subscriptions 或 Bold Subscriptions(Shopify App Store) | Shopify 提供原生 Subscriptions API;Recharge 是使用最广泛的第三方应用;Seal 是较新的低成本选项 |
| Shopify(简单需求) | Shopify Subscriptions(内置,免费) | 适用于基本订阅需求——于 2024 年推出;可处理简单的定期订单 |
| WooCommerce | WooCommerce Subscriptions(每年 $199,WooCommerce 官方扩展) | 官方且功能最完整的 WooCommerce 订阅解决方案;可处理所有计费、催缴和管理工作 |
| BigCommerce | Recurly(通过 BigCommerce App Marketplace)或 Rebilly | BigCommerce 没有原生订阅功能;由第三方应用处理 |
| 自定义 / 无头架构 | Stripe Subscriptions | Stripe Subscriptions 通过 Webhook 处理完整的定期计费生命周期 |
第 2 步:在平台上设置订阅
Shopify(Shopify Subscriptions——内置,免费)
适用于基本的订阅产品:
- 前往 Settings → Apps and sales channels → Shopify Subscriptions(可能需要从 App Store 安装)
- 前往 Products,打开要设为可订阅的任意产品
- 在 Purchase options 下,点击 Add subscription plan
- 配置:
- 计费频率:每周、每月或每 X 个月
- 订阅者折扣(例如,相比一次性购买优惠 10%)
- 免费试用期(可选)
- 产品页面将同时显示“一次性购买”和“订阅并省钱”选项
Shopify Subscriptions 可处理定期计费、付款失败邮件,以及用于管理订阅的客户门户。若需高级催缴、分析和订阅者门户,请使用 Recharge 或 Seal Subscriptions。
Shopify(Recharge——适合规模化运营)
- 从 Shopify App Store 安装 Recharge
- 在 Recharge → Settings → Payment Processors 中连接 Shopify 店铺和 Stripe 账户
- 在 Recharge → Products → Add product 中配置订阅产品:
- 选择哪些 Shopify 产品可作为订阅产品购买
- 设置计费间隔(每周、每月、每 2 个月等)
- 配置订阅者折扣
- 设置客户门户:前往 Recharge → Customer Portal,配置订阅者可以自行管理的事项(暂停、跳过、修改日期、取消、更换产品)
- 配置催缴:前往 Recharge → Settings → Dunning,设置付款失败时的重试计划和邮件序列
Recharge 默认催缴设置:
- 第 0 天:首次付款失败 → 向客户发送邮件
- 第 3 天:重试付款 → 向客户发送邮件
- 第 7 天:重试付款 → 发送最后警告邮件
- 第 14 天:重试付款 → 如果仍然失败,则取消订阅
WooCommerce(WooCommerce Subscriptions)
- 从 woocommerce.com/products/woocommerce-subscriptions 购买并安装 WooCommerce Subscriptions
- 创建订阅产品:前往 Products → Add New,并将产品类型设为 Simple subscription 或 Variable subscription
- 在 Subscription data 下进行配置:
- 计费周期:每日、每周、每月、每年
- 计费间隔:每 1、2、3……个周期
- 订阅期限:持续订阅或有限期限(例如 12 个月)
- 注册费(可选)
- 免费试用期(可选)
- 订阅者折扣(通过比较常规价格和促销价格进行设置)
- 配置支付方式:前往 WooCommerce → Settings → Payments,并确保你的支付网关支持定期付款(通过 WooCommerce Stripe 插件使用 Stripe,通过 WooCommerce PayPal Payments 使用 PayPal)
- 配置催款流程:前往 WooCommerce → Settings → Subscriptions → Failing payments,设置重试规则和电子邮件模板
WooCommerce 客户门户: 客户可在 My Account → Subscriptions 页面管理订阅。WooCommerce Subscriptions 默认提供暂停、取消订阅和更新支付方式的功能。
BigCommerce(Recurly)
- 在 recurly.com 注册并创建一个包含定价的方案(月付、年付等)
- 从 BigCommerce App Marketplace 安装 Recurly 应用,并连接你的商店
- 创建与 Recurly 方案关联的订阅产品
- Recurly 负责处理结账、定期计费、催款、开票和订阅者门户
- 在 Recurly → Configuration → Dunning Campaigns 中配置催款流程:设置重试计划和电子邮件内容
自定义/无头架构
使用 Stripe Subscriptions 管理完整的定期计费生命周期:
创建订阅方案:
在 Stripe Dashboard → Products 中,创建一个包含定期价格的产品(例如“月度方案 — $29/月”)。复制 Price ID(以 price_ 开头)。
订阅客户:
// Create or retrieve the Stripe customer
const customer = await stripe.customers.create({
email: customerEmail,
payment_method: paymentMethodId,
invoice_settings: { default_payment_method: paymentMethodId },
});
// Create the subscription
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: 'price_monthly_pro_29' }], // Price ID from Stripe Dashboard
payment_behavior: 'default_incomplete', // Create subscription, then confirm payment
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.payment_intent'],
trial_period_days: 14, // Optional trial
metadata: { customer_id: customerId },
});
// Return client_secret for 3DS confirmation if needed
const clientSecret = subscription.latest_invoice?.payment_intent?.client_secret;
res.json({ subscriptionId: subscription.id, clientSecret });
通过 Webhook 同步订阅状态:
// Webhook handler for subscription events
async function handleSubscriptionWebhook(event) {
switch (event.type) {
case 'customer.subscription.updated':
await syncSubscriptionStatus(event.data.object);
break;
case 'customer.subscription.deleted':
// Subscription cancelled — revoke access
await db.subscriptions.update({
where: { stripeSubscriptionId: event.data.object.id },
data: { status: 'cancelled', cancelledAt: new Date() },
});
break;
case 'invoice.payment_succeeded':
await recordSuccessfulBillingCycle(event.data.object);
break;
case 'invoice.payment_failed':
// Send dunning email — Stripe retries automatically per your settings
await sendDunningEmail(event.data.object);
break;
case 'customer.subscription.trial_will_end':
// Send trial ending email 3 days before trial ends
await sendTrialEndingEmail(event.data.object);
break;
}
}
在 Stripe Dashboard 中配置催款流程: 前往 Stripe Dashboard → Billing → Settings → Smart Retries。启用 Smart Retries——Stripe 基于 ML 的重试时机选择优于固定计划。还要在 Stripe Dashboard → Billing → Settings → Automatic collection 下配置在所有重试失败后自动取消订阅。
通过按比例计费更改方案:
// Upgrade or downgrade a subscription
const subscription = await stripe.subscriptions.retrieve(stripeSubscriptionId);
await stripe.subscriptions.update(stripeSubscriptionId, {
items: [{ id: subscription.items.data[0].id, price: newPriceId }],
proration_behavior: 'create_prorations', // Charge/credit the difference immediately
});
// Stripe creates a prorated invoice automatically
在周期结束时取消并保留访问权限:
// Cancel at period end — customer retains access until the next billing date
await stripe.subscriptions.update(stripeSubscriptionId, {
cancel_at_period_end: true,
});
// Immediate cancellation
await stripe.subscriptions.cancel(stripeSubscriptionId);
最佳实践
- 使用平台原生订阅工具——WooCommerce Subscriptions、Shopify 上的 Recharge 和 Stripe Subscriptions 均经过生产环境验证,能够正确处理各种边缘情况(付款失败、按比例计费、税费变更)
- 切勿只在 Stripe 中存储订阅状态——始终通过 Webhook 将订阅状态同步到数据库;不要在每次页面加载时都调用 Stripe 检查状态
- 在 Stripe 中配置 Smart Retries——在 Stripe Dashboard → Billing → Settings 下启用;基于 ML 的重试时机选择比固定计划能显著挽回更多失败付款
- 在每次重试时发送催款邮件——逐步提高紧迫程度:“付款失败” → “账户面临风险” → “访问权限即将暂停”;附上可直接更新支付方式的链接
- 让客户自助管理——构建客户门户(或使用 Stripe 托管的客户门户,路径为 Stripe Dashboard → Billing → Customer portal),用于更改方案、暂停和取消订阅;这能减少支持工作量
- 升级立即按比例计费;降级在周期结束时生效——升级应立即收取差额;降级应在下次续订时生效,以避免复杂的部分退款
常见问题
| 问题 | 解决方案 |
|---|---|
| 取消订阅后仍显示为有效 | 通过 Webhook 同步状态——customer.subscription.deleted 必须触发数据库更新;切勿在页面加载时轮询 Stripe 获取状态 |
| WooCommerce Subscriptions 未重试失败的付款 | 确认支付网关支持令牌化定期付款;通过 WooCommerce Stripe 插件接入的 Stripe 支持此功能;基础版 PayPal Standard 不支持 |
| 试用期结束并转为付费时,客户并不知情 | 提前 3 天发送 trial_will_end 邮件(Stripe 会自动触发 Webhook;Recharge 和 WooCommerce Subscriptions 默认会执行此操作) |
| 重试 Webhook 时重复发送催款邮件 | 再次发送前,检查发票尝试次数是否与上次发送催款邮件时的次数一致;使用发票 ID + 尝试次数作为幂等键 |
| 升级时按比例计费,导致客户意外被扣款 | 应用套餐变更前,先显示即将生成的发票预览(Stripe:使用 stripe.invoices.retrieveUpcoming());先向客户显示按比例计费的金额 |
相关技能
- @stripe-integration
- @order-processing-pipeline
- @tax-calculation
- @invoice-generation-automation