Chargebee Integration
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.
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.
Frameworks
Laravel Cashier
-
https://github.com/chargebee/cashier-chargebee/blob/main/DOCUMENTATION.md
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 --use-defaults --path=
Using requests library
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 )
Using Python SDK
import chargebee chargebee . configure ( CHARGEBEE_API_KEY , CHARGEBEE_SITE ) result = chargebee . Customer . retrieve ( customer_id ) customer = result . customer Common Operations Customer CRUD operations Subscription management Invoice operations Payment method handling Plan and addon management Usage based billing Webhook Integration Chargebee sends webhook events for important billing events. Webhook handlers should: Verify webhook signatures for security Handle idempotency (events may be sent multiple times) Return 200 OK quickly (process asynchronously if needed) Handle various event types appropriately Basic Webhook Handler Pattern 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 . 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