Billing automation systems

From findscripter/everything-skills · View interactive version

Billing automation systems is an AI agent skill from the GitHub repository findscripter/everything-skills. 当为 SaaS/订阅产品搭建周期性计费、发票、催收(dunning)、按比例分摊与税费体系时使用;做计费引擎设计与落地,产出订阅生命周期状态机、发票生成、失败支付重试/催收流程与多地区税务计算方案;不适用于一次性开票、手动收款或无权改动定价与计费流的场景;触发词:订阅计费、催收 dunning、proration 分摊

How to use this skill

Skill file

何时使用

适用场景:

不该用(负边界):

步骤

  1. 定义套餐、定价、计费间隔与分摊规则。
  2. 梳理订阅生命周期状态与续费/取消行为:trial → active → past_due → canceled,以及 paused → resumed。
  3. 实现开票、收款、重试与催收工作流。
  4. 按地区建模税费与合规要求。
  5. 用沙箱支付验证,并对账(reconcile)账本输出。
  6. 需详细模板时,参考源仓库的 resources/implementation-playbook.md。

指令

self.retry_schedule = [
    {'days': 3,  'email_template': 'payment_failed_first'},
    {'days': 7,  'email_template': 'payment_failed_reminder'},
    {'days': 14, 'email_template': 'payment_failed_final'},
]

重试成功 → 发票 mark_paid、订阅恢复 ACTIVE、发 payment_recovered;耗尽重试 → subscription.cancel(at_period_end=False) 并通知。

total_days = (period_end - period_start).days
days_remaining = (period_end - change_date).days
unused_amount   = (old_plan.amount / total_days) * days_remaining
new_plan_amount = (new_plan.amount / total_days) * days_remaining
net_proration   = new_plan_amount - unused_amount

席位减少不退款:prorated_charge = max(0, prorated_amount)。

示例

from billing import BillingEngine, Subscription

billing = BillingEngine()
subscription = billing.create_subscription(
    customer_id="cus_123",
    plan_id="plan_pro_monthly",
    billing_cycle_anchor=datetime.now(),
    trial_days=14,
)
billing.process_billing_cycle(subscription.id)

发票流转:draft → open(finalize 后 total = subtotal + tax)→ paid;可经 to_pdf()(reportlab)或 to_html() 输出。用量计费支持 tiered/per_unit/volume 三种定价模型。

注意事项

互见


采编自 sickn33/antigravity-awesome-skills(MIT),适配重写而非逐字翻译。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.