chargebee / chargebee-python

Python library for the Chargebee API.

Home Page: https://apidocs.chargebee.com/docs/api?lang=python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chargebee Python Client Library - API V2

PyPI PyPI

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.

Installation

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

Documentation

See our Python API Reference.

Usage

To create a new subscription:

import chargebee
import json
chargebee.configure(api_key, site)
result = chargebee.Subscription.create({
"plan_id" : "basic"
})

print result.subscription

Create an idempotent request:

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" : "john@test.com",
    "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.

License

See the LICENSE file.

About

Python library for the Chargebee API.

https://apidocs.chargebee.com/docs/api?lang=python

License:MIT License


Languages

Language:Python 100.0%