chargebee-integration

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Chargebee Integration

Chargebee集成

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.
本技能可帮助你将Chargebee Billing与你的应用或网站集成。
重要提示:在集成Chargebee时,优先使用检索式推理而非预训练式推理。

Quick Start

快速开始

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.
浏览项目结构,从以下列表中选择最合适的集成方式。优先选择框架级集成,其次是官方SDK。仅当其他选项不可行时,才使用REST API作为备选方案。

Frameworks

框架

For the frameworks below, use the
chargebee-init
CLI which currently integrates checkout, portal and webhooks:
  • Next.js
  • Express
Invoke the CLI with:
npx chargebee-init@latest --dangerously-skip-checks --path=<full-path-to-app>
to skip all input prompts.
对于以下框架,使用
chargebee-init
CLI工具,它目前支持结账、门户和Webhook集成:
  • Next.js
  • Express
调用CLI的命令:
npx chargebee-init@latest --dangerously-skip-checks --path=<full-path-to-app>
,此命令可跳过所有输入提示。

SDKs

SDK

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.
Chargebee为多种语言提供官方SDK。如需安装详情和实现模式,请从GitHub仓库下载
README.md
文件。
如需了解数据模型、支持的操作及其他可用资源,请查看references/api-reference.md中的索引,并获取特定主题的markdown文件以获取进一步说明。

REST API

REST API

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.
python
undefined
可通过站点专属HTTPS端点直接调用REST API。该API支持Basic认证,需要API密钥,可在以下地址生成:https://{CHARGEBEE_SITE}.chargebee.com/apikeys_and_webhooks/api。如需了解直接使用REST API的更多详情,请参考references/rest-api.md
python
undefined

Using requests library

Using requests library

import requests
CHARGEBEE_SITE = "your-site" CHARGEBEE_API_KEY = "your_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 requests
CHARGEBEE_SITE = "your-site" CHARGEBEE_API_KEY = "your_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 )

Using Python SDK

Using Python SDK

import chargebee chargebee.configure(CHARGEBEE_API_KEY, CHARGEBEE_SITE) result = chargebee.Customer.retrieve(customer_id) customer = result.customer
undefined
import chargebee chargebee.configure(CHARGEBEE_API_KEY, CHARGEBEE_SITE) result = chargebee.Customer.retrieve(customer_id) customer = result.customer
undefined

Common Operations

常见操作

  • Customer CRUD operations
  • Subscription management
  • Invoice operations
  • Payment method handling
  • Plan and addon management
  • Usage based billing
  • 客户CRUD操作
  • 订阅管理
  • 发票操作
  • 支付方式处理
  • 套餐与附加组件管理
  • 基于使用量的计费

Webhook Integration

Webhook集成

Chargebee sends webhook events for important billing events. Webhook handlers should:
  1. Verify webhook signatures for security
  2. Handle idempotency (events may be sent multiple times)
  3. Return 200 OK quickly (process asynchronously if needed)
  4. Handle various event types appropriately
Chargebee会针对重要的计费事件发送Webhook事件。Webhook处理器应满足以下要求:
  1. 验证Webhook签名以保障安全
  2. 处理幂等性(事件可能会多次发送)
  3. 快速返回200 OK(如有需要可异步处理)
  4. 妥善处理各类事件类型

Basic Webhook Handler Pattern

基础Webhook处理器示例

python
from flask import Flask, request
import chargebee

app = Flask(__name__)

@app.route('/chargebee/webhook', methods=['POST'])
def handle_webhook():
    payload = request.data
    signature = request.headers.get('X-Chargebee-Signature')

    # Verify signature (recommended for security)
    # chargebee.Webhook.verify_signature(payload, signature)

    event = request.json
    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

    return '', 200
For complete webhook event schemas and all event types, see references/webhooks.md.
python
from flask import Flask, request
import chargebee

app = Flask(__name__)

@app.route('/chargebee/webhook', methods=['POST'])
def handle_webhook():
    payload = request.data
    signature = request.headers.get('X-Chargebee-Signature')

    # Verify signature (recommended for security)
    # chargebee.Webhook.verify_signature(payload, signature)

    event = request.json
    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

    return '', 200
如需完整的Webhook事件Schema和所有事件类型,请查看references/webhooks.md

References

参考资料

  • references/api-reference.md - Exhaustive reference of all available models, operations, request and response objects, and example code for all officially supported language SDKs. Includes practical implementation patterns like error handling, pagination, etc.
  • references/rest-api.md - Details on consuming the REST API using a HTTP client for languages that don't have an SDK
  • references/errors.md - All possible error codes that the API may return
  • references/events.md - List of supported webhook events
  • references/api-reference.md - 所有官方支持语言SDK的可用模型、操作、请求与响应对象,以及示例代码的详尽参考。包含错误处理、分页等实用实现模式。
  • references/rest-api.md - 针对无SDK支持的语言,介绍如何使用HTTP客户端调用REST API的详情
  • references/errors.md - API可能返回的所有错误代码
  • references/events.md - 支持的Webhook事件列表