This is the Python Library for integrating with Chargebee. Sign up for a Chargebee account here.
Chargebee now supports two API versions - V1 and V2, of which V2 is the latest release and all future developments will happen in V2. This library is for API version V2. If you’re looking for V1, head to chargebee-v1 branch.
Install the latest version 2.x.x of the library with the following commands:
$ pip install 'chargebee>=2,<3'
or
$ easy_install --upgrade 'chargebee>=2,<3'
If you would prefer to install it from source, just checkout the latest version for 2.x.x by git checkout [latest 2.x.x release tag]
and install with the following command:
$ python setup.py install
See our Python API Reference.
import chargebee
import json
chargebee.configure(api_key, site)
result = chargebee.Subscription.create({
"plan_id" : "basic"
})
print result.subscription
Idempotency keys are passed along with request headers to allow a safe retry of POST requests.
import chargebee
import json
chargebee.configure(api_key, site)
result = chargebee.Customer.create({
"first_name" : "John",
"last_name" : "Doe",
"email" : "[email protected]",
"locale" : "fr-CA",
"billing_address" : {
"first_name" : "John",
"last_name" : "Doe",
"line1" : "PO Box 9999",
"city" : "Walnut",
"state" : "California",
"zip" : "91789",
"country" : "US"
}
},
None,
{"chargebee-idempotency-key" : "<<UUID>>"} # Replace <<UUID>> with a unique string
)
customer = result.customer
card = result.card
responseHeaders = result.get_response_headers # Retrieves response headers
print(responseHeaders)
idempotencyReplayedValue = result.is_idempotency_replayed # Retrieves Idempotency replayed header value
print(idempotencyReplayedValue)
isIdempotencyReplayed()
method can be accessed to differentiate between original and replayed requests.
See the LICENSE file.