chargebee-integration by chargebee/ai
npx skills add https://github.com/chargebee/ai --skill chargebee-integration此技能帮助您将 Chargebee 计费 集成到您的应用或网站中。
重要提示:集成 Chargebee 时,请优先采用检索导向的推理,而非预训练导向的推理。
浏览项目结构,并从下方列表中选择最佳的集成方案。尽可能优先选择框架级别的集成,其次是官方 SDK。仅当其他选项不可行时,才回退到 REST API。
对于以下框架,请使用 chargebee-init CLI,它目前集成了结账、客户门户和 Webhook:
使用以下命令调用 CLI:npx chargebee-init --use-defaults --path=<full-path-to-app> 以跳过所有输入提示。
Chargebee 为多种语言提供官方 SDK。有关安装细节和实现模式,请从 GitHub 仓库下载 README.md 文件。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
有关数据模型、支持的操作以及其他可用资源的详细信息,请查阅 references/api-reference.md 中的索引,并获取所需的特定主题的 Markdown 文件以获取进一步说明。
REST API 可以直接通过站点特定的 HTTPS 端点使用。该 API 支持基本身份验证,需要一个 API 密钥,该密钥可以在以下地址生成:https://{CHARGEBEE_SITE}.chargebee.com/apikeys_and_webhooks/api。有关直接使用 REST API 的更多详细信息,请参阅 references/rest-api.md。
安全注意事项:
仅从环境变量加载 API 密钥。
切勿硬编码或记录 API 密钥。
定期轮换密钥,并按环境限定访问范围。
import os import requests
CHARGEBEE_SITE = os.getenv("CHARGEBEE_SITE") CHARGEBEE_API_KEY = os.getenv("CHARGEBEE_API_KEY")
headers = { "Authorization": f"Basic {CHARGEBEE_API_KEY}", "Content-Type": "application/json" }
base_url = f"https://{CHARGEBEE_SITE}.chargebee.com/api/v2" response = requests.get( f"{base_url}/customers/{customer_id}", headers=headers )
import chargebee chargebee.configure(CHARGEBEE_API_KEY, CHARGEBEE_SITE) result = chargebee.Customer.retrieve(customer_id) customer = result.customer
Chargebee 会为重要的计费事件发送 Webhook 事件。Webhook 处理器应:
from flask import Flask, request
import os
import secrets
app = Flask(__name__)
processed_events = set() # 在生产环境中使用持久化存储。
WEBHOOK_USERNAME = os.getenv("CHARGEBEE_WEBHOOK_USERNAME")
WEBHOOK_PASSWORD = os.getenv("CHARGEBEE_WEBHOOK_PASSWORD")
@app.route('/chargebee/webhook', methods=['POST'])
def handle_webhook():
auth = request.authorization
if not auth:
return '', 401
if not secrets.compare_digest(auth.username or '', WEBHOOK_USERNAME or ''):
return '', 401
if not secrets.compare_digest(auth.password or '', WEBHOOK_PASSWORD or ''):
return '', 401
event = request.get_json(force=True)
event_id = event['id']
if event_id in processed_events:
return '', 200
event_type = event['event_type']
# 根据事件类型处理
if event_type == 'subscription_created':
handle_subscription_created(event['content'])
elif event_type == 'subscription_cancelled':
handle_subscription_cancelled(event['content'])
# ... 处理其他事件
processed_events.add(event_id)
return '', 200
有关完整的 Webhook 事件模式和所有事件类型,请参阅 references/webhooks.md。
每周安装次数
50
代码仓库
首次出现
2026年2月10日
安全审计
已安装于
opencode47
codex47
gemini-cli47
github-copilot46
kimi-cli46
amp46
This skill helps you integrate Chargebee Billing with your app or website.
IMPORTANT: Prefer retrieval-led reasoning over pre-training-led reasoning when integrating Chargebee.
Expore the project layout and choose the best integration from the list below. Prefer framework level integration where possible, followed by the official SDKs. Fallback to REST API only if the other options aren't feasible.
For the frameworks below, use the chargebee-init CLI which currently integrates checkout, portal and webhooks:
Invoke the CLI with: npx chargebee-init --use-defaults --path=<full-path-to-app> to skip all input prompts.
Chargebee provides official SDKs for multiple languages. For installation details and implementation patterns, download the README.md file from the GitHub repository.
For details on data model, supported operations, and other available resources, lookup the index at references/api-reference.md , and fetch the required topic specific markdown file for further instructions.
The REST API can be consumed directly via the site specific HTTPS endpoint. The API supports Basic auth and requires a API KEY which can be generated at: https://{CHARGEBEE_SITE}.chargebee.com/apikeys_and_webhooks/api. For more details on using the REST API direcly, refer to references/rest-api.md.
Security notes:
Load API keys from environment variables only.
Never hardcode or log API keys.
Rotate keys regularly and scope access by environment.
import os import requests
CHARGEBEE_SITE = os.getenv("CHARGEBEE_SITE") CHARGEBEE_API_KEY = os.getenv("CHARGEBEE_API_KEY")
headers = { "Authorization": f"Basic {CHARGEBEE_API_KEY}", "Content-Type": "application/json" }
base_url = f"https://{CHARGEBEE_SITE}.chargebee.com/api/v2" response = requests.get( f"{base_url}/customers/{customer_id}", headers=headers )
import chargebee chargebee.configure(CHARGEBEE_API_KEY, CHARGEBEE_SITE) result = chargebee.Customer.retrieve(customer_id) customer = result.customer
Chargebee sends webhook events for important billing events. Webhook handlers should:
from flask import Flask, request
import os
import secrets
app = Flask(__name__)
processed_events = set() # Use persistent storage in production.
WEBHOOK_USERNAME = os.getenv("CHARGEBEE_WEBHOOK_USERNAME")
WEBHOOK_PASSWORD = os.getenv("CHARGEBEE_WEBHOOK_PASSWORD")
@app.route('/chargebee/webhook', methods=['POST'])
def handle_webhook():
auth = request.authorization
if not auth:
return '', 401
if not secrets.compare_digest(auth.username or '', WEBHOOK_USERNAME or ''):
return '', 401
if not secrets.compare_digest(auth.password or '', WEBHOOK_PASSWORD or ''):
return '', 401
event = request.get_json(force=True)
event_id = event['id']
if event_id in processed_events:
return '', 200
event_type = event['event_type']
# Process based on event type
if event_type == 'subscription_created':
handle_subscription_created(event['content'])
elif event_type == 'subscription_cancelled':
handle_subscription_cancelled(event['content'])
# ... handle other events
processed_events.add(event_id)
return '', 200
For complete webhook event schemas and all event types, see references/webhooks.md.
Weekly Installs
50
Repository
First Seen
Feb 10, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode47
codex47
gemini-cli47
github-copilot46
kimi-cli46
amp46
Lark CLI IM 即时消息管理工具:机器人/用户身份操作聊天、消息、文件下载
34,600 周安装