[Python-modules-commits] [chargebee-python] 01/05: import charbee-python_1.6.3.orig.tar.gz
Scott Kitterman
kitterman at moszumanska.debian.org
Wed Nov 23 18:10:29 UTC 2016
This is an automated email from the git hooks/post-receive script.
kitterman pushed a commit to branch master
in repository chargebee-python.
commit 4688b850cf6802baa57289c08e950a72e6d176b9
Author: Scott Kitterman <scott at kitterman.com>
Date: Wed Nov 23 11:29:56 2016 -0500
import charbee-python_1.6.3.orig.tar.gz
---
MANIFEST.in | 1 +
PKG-INFO | 10 +
chargebee.egg-info/PKG-INFO | 10 +
chargebee.egg-info/SOURCES.txt | 41 +
chargebee.egg-info/dependency_links.txt | 1 +
chargebee.egg-info/top_level.txt | 2 +
chargebee/__init__.py | 10 +
chargebee/api_error.py | 28 +
chargebee/compat.py | 129 ++
chargebee/environment.py | 17 +
chargebee/http_request.py | 78 +
chargebee/list_result.py | 13 +
chargebee/main.py | 15 +
chargebee/model.py | 47 +
chargebee/models/__init__.py | 19 +
chargebee/models/addon.py | 31 +
chargebee/models/address.py | 18 +
chargebee/models/card.py | 27 +
chargebee/models/comment.py | 25 +
chargebee/models/content.py | 5 +
chargebee/models/coupon.py | 24 +
chargebee/models/coupon_code.py | 17 +
chargebee/models/customer.py | 73 +
chargebee/models/download.py | 9 +
chargebee/models/estimate.py | 32 +
chargebee/models/event.py | 40 +
chargebee/models/hosted_page.py | 44 +
chargebee/models/invoice.py | 105 +
chargebee/models/order.py | 30 +
chargebee/models/plan.py | 32 +
chargebee/models/portal_session.py | 29 +
chargebee/models/shipping_address.py | 18 +
chargebee/models/subscription.py | 82 +
chargebee/models/transaction.py | 42 +
chargebee/request.py | 32 +
chargebee/result.py | 102 +
chargebee/ssl/ca-certs.crt | 3385 +++++++++++++++++++++++++++++++
chargebee/util.py | 41 +
chargebee/version.py | 1 +
setup.cfg | 5 +
setup.py | 30 +
tests/__init__.py | 0
tests/util.py | 45 +
43 files changed, 4745 insertions(+)
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..f5e82a6
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1 @@
+include chargebee/ssl/ca-certs.crt
\ No newline at end of file
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..512b8d8
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: chargebee
+Version: 1.6.3
+Summary: Python wrapper for the ChargeBee Subscription Billing API
+Home-page: https://apidocs.chargebee.com/docs/api?lang=python
+Author: ChargeBee
+Author-email: support at chargebee.com
+License: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN
diff --git a/chargebee.egg-info/PKG-INFO b/chargebee.egg-info/PKG-INFO
new file mode 100644
index 0000000..512b8d8
--- /dev/null
+++ b/chargebee.egg-info/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: chargebee
+Version: 1.6.3
+Summary: Python wrapper for the ChargeBee Subscription Billing API
+Home-page: https://apidocs.chargebee.com/docs/api?lang=python
+Author: ChargeBee
+Author-email: support at chargebee.com
+License: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN
diff --git a/chargebee.egg-info/SOURCES.txt b/chargebee.egg-info/SOURCES.txt
new file mode 100644
index 0000000..06c309d
--- /dev/null
+++ b/chargebee.egg-info/SOURCES.txt
@@ -0,0 +1,41 @@
+MANIFEST.in
+setup.py
+chargebee/__init__.py
+chargebee/api_error.py
+chargebee/compat.py
+chargebee/environment.py
+chargebee/http_request.py
+chargebee/list_result.py
+chargebee/main.py
+chargebee/model.py
+chargebee/request.py
+chargebee/result.py
+chargebee/util.py
+chargebee/version.py
+chargebee.egg-info/PKG-INFO
+chargebee.egg-info/SOURCES.txt
+chargebee.egg-info/dependency_links.txt
+chargebee.egg-info/top_level.txt
+chargebee/models/__init__.py
+chargebee/models/addon.py
+chargebee/models/address.py
+chargebee/models/card.py
+chargebee/models/comment.py
+chargebee/models/content.py
+chargebee/models/coupon.py
+chargebee/models/coupon_code.py
+chargebee/models/customer.py
+chargebee/models/download.py
+chargebee/models/estimate.py
+chargebee/models/event.py
+chargebee/models/hosted_page.py
+chargebee/models/invoice.py
+chargebee/models/order.py
+chargebee/models/plan.py
+chargebee/models/portal_session.py
+chargebee/models/shipping_address.py
+chargebee/models/subscription.py
+chargebee/models/transaction.py
+chargebee/ssl/ca-certs.crt
+tests/__init__.py
+tests/util.py
\ No newline at end of file
diff --git a/chargebee.egg-info/dependency_links.txt b/chargebee.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/chargebee.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/chargebee.egg-info/top_level.txt b/chargebee.egg-info/top_level.txt
new file mode 100644
index 0000000..57a87cc
--- /dev/null
+++ b/chargebee.egg-info/top_level.txt
@@ -0,0 +1,2 @@
+chargebee
+tests
diff --git a/chargebee/__init__.py b/chargebee/__init__.py
new file mode 100644
index 0000000..ac2deef
--- /dev/null
+++ b/chargebee/__init__.py
@@ -0,0 +1,10 @@
+from chargebee.api_error import APIError,PaymentError,InvalidRequestError,OperationFailedError
+from chargebee.models import *
+from chargebee.main import ChargeBee
+
+
+def configure(api_key, site):
+ ChargeBee.configure({
+ 'api_key': api_key,
+ 'site': site,
+ })
diff --git a/chargebee/api_error.py b/chargebee/api_error.py
new file mode 100644
index 0000000..b7c99d6
--- /dev/null
+++ b/chargebee/api_error.py
@@ -0,0 +1,28 @@
+class APIError(Exception):
+
+ def __init__(self, http_code,json_obj):
+ Exception.__init__(self, json_obj.get('message'))
+ self.json_obj = json_obj
+ self.http_status_code = http_code
+ self.type = json_obj.get('type')
+ self.api_error_code = json_obj.get('api_error_code')
+ self.param = json_obj.get('param')
+
+
+ self.error_code = json_obj['error_code']
+ self.http_code = http_code
+ self.http_body = None
+
+class PaymentError(APIError):
+ def __init__(self, http_code,json_obj):
+ APIError.__init__(self, http_code,json_obj)
+
+class InvalidRequestError(APIError):
+ def __init__(self, http_code,json_obj):
+ APIError.__init__(self, http_code,json_obj)
+
+class OperationFailedError(APIError):
+ def __init__(self, http_code,json_obj):
+ APIError.__init__(self, http_code,json_obj)
+
+
diff --git a/chargebee/compat.py b/chargebee/compat.py
new file mode 100644
index 0000000..dd4808f
--- /dev/null
+++ b/chargebee/compat.py
@@ -0,0 +1,129 @@
+
+from chargebee.main import Environment
+
+import re
+import sys
+import socket
+
+try:
+ import simplejson as json
+except ImportError:
+ import json
+
+py_major_v = sys.version_info[0]
+py_minor_v = sys.version_info[1]
+
+if py_major_v < 3:
+ from urllib import urlencode
+ from urlparse import urlparse
+ from urllib2 import urlopen as _urlopen, Request
+elif py_major_v >= 3:
+ from urllib.parse import urlencode, urlparse
+ from urllib.request import urlopen as _urlopen, Request
+
+
+
+try:
+ SSLError = None
+ ssl = None
+
+ if Environment.chargebee_domain is None:
+ HTTPSConnection = object
+ else:
+ HTTPConnection = object
+
+ if py_major_v < 3:
+ from httplib import HTTPConnection, HTTPSConnection, HTTPException
+ else:
+ from http.client import HTTPConnection, HTTPSConnection, HTTPException
+
+ import ssl
+ SSLError = ssl.SSLError
+
+except (ImportError, AttributeError): # Platform-specific: No SSL
+ pass
+
+
+class VerifiedHTTPSConnection(HTTPSConnection):
+ """Based on httplib.HTTPSConnection but wraps socket with SSL certification"""
+
+ def set_cert(self, ca_certs, cert_reqs='CERT_REQUIRED'):
+ ssl_req_scheme = {
+ 'CERT_NONE': ssl.CERT_NONE,
+ 'CERT_OPTIONAL': ssl.CERT_OPTIONAL,
+ 'CERT_REQUIRED': ssl.CERT_REQUIRED
+ }
+
+ self.cert_reqs = ssl_req_scheme.get(cert_reqs) or ssl.CERT_NONE
+ self.ca_certs = ca_certs
+
+ def connect(self):
+ # Add certificate verification
+ sock = socket.create_connection((self.host, self.port), self.timeout)
+
+ # Wrap socket using verification with the root certs in
+ # trusted_root_certs
+ self.sock = ssl.wrap_socket(sock, cert_reqs=self.cert_reqs, ca_certs=self.ca_certs)
+
+ if self.ca_certs:
+ match_hostname(self.sock.getpeercert(), self.host)
+
+
+class CertificateError(ValueError):
+ pass
+
+
+def _dnsname_to_pat(dn):
+ pats = []
+ for frag in dn.split(r'.'):
+ if frag == '*':
+ # When '*' is a fragment by itself, it matches a non-empty dotless
+ # fragment.
+ pats.append('[^.]+')
+ else:
+ # Otherwise, '*' matches any dotless fragment.
+ frag = re.escape(frag)
+ pats.append(frag.replace(r'\*', '[^.]*'))
+ return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
+
+
+def match_hostname(cert, hostname):
+ """Verify that *cert* (in decoded format as returned by
+ SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules
+ are mostly followed, but IP addresses are not accepted for *hostname*.
+
+ CertificateError is raised on failure. On success, the function
+ returns nothing.
+ """
+
+ if not cert:
+ raise ValueError("empty or no certificate")
+ dnsnames = []
+ san = cert.get('subjectAltName', ())
+ for key, value in san:
+ if key == 'DNS':
+ if _dnsname_to_pat(value).match(hostname):
+ return
+ dnsnames.append(value)
+ if not dnsnames:
+ # The subject is only checked when there is no dNSName entry
+ # in subjectAltName
+ for sub in cert.get('subject', ()):
+ for key, value in sub:
+ # XXX according to RFC 2818, the most specific Common Name
+ # must be used.
+ if key == 'commonName':
+ if _dnsname_to_pat(value).match(hostname):
+ return
+ dnsnames.append(value)
+ if len(dnsnames) > 1:
+ raise CertificateError("hostname %r "
+ "doesn't match either of %s"
+ % (hostname, ', '.join(map(repr, dnsnames))))
+ elif len(dnsnames) == 1:
+ raise CertificateError("hostname %r "
+ "doesn't match %r"
+ % (hostname, dnsnames[0]))
+ else:
+ raise CertificateError("no appropriate commonName or "
+ "subjectAltName fields were found")
diff --git a/chargebee/environment.py b/chargebee/environment.py
new file mode 100644
index 0000000..ff43867
--- /dev/null
+++ b/chargebee/environment.py
@@ -0,0 +1,17 @@
+class Environment(object):
+
+ chargebee_domain = None
+ protocol= "https"
+ API_VERSION = "v1"
+
+ def __init__(self, options):
+ self.api_key = options['api_key']
+ self.site = options['site']
+
+ if self.chargebee_domain is None:
+ self.api_endpoint = 'https://%s.chargebee.com/api/%s' % (self.site, self.API_VERSION)
+ else:
+ self.api_endpoint = 'http://%s.%s/api/%s' % (self.site, self.chargebee_domain, self.API_VERSION)
+
+ def api_url(self, url):
+ return self.api_endpoint + url
diff --git a/chargebee/http_request.py b/chargebee/http_request.py
new file mode 100644
index 0000000..aed9498
--- /dev/null
+++ b/chargebee/http_request.py
@@ -0,0 +1,78 @@
+import base64
+
+from chargebee import APIError,PaymentError,InvalidRequestError,OperationFailedError, compat
+from chargebee.main import ChargeBee
+from chargebee.main import Environment
+from chargebee.version import VERSION
+
+def _basic_auth_str(username):
+ return 'Basic ' + base64.b64encode(('%s:' % username).encode('latin1')).strip().decode('latin1')
+
+
+def request(method, url, env, params=None, headers=None):
+ if not env:
+ raise Exception('No environment configured.')
+ if headers is None:
+ headers = {}
+
+ url = env.api_url(url)
+ if method.lower() in ('get', 'head', 'delete'):
+ url = '%s?%s' % (url, compat.urlencode(params))
+ payload = None
+ else:
+ payload = compat.urlencode(params)
+ headers['Content-type'] = 'application/x-www-form-urlencoded'
+
+ headers.update({
+ 'User-Agent': 'ChargeBee-Python-Client v%s' % VERSION,
+ 'Accept': 'application/json',
+ 'Authorization': _basic_auth_str(env.api_key),
+ })
+
+ meta = compat.urlparse(url)
+ if ChargeBee.verify_ca_certs:
+ connection = compat.VerifiedHTTPSConnection(meta.netloc)
+ connection.set_cert(ca_certs=ChargeBee.ca_cert_path)
+ else:
+ if Environment.protocol == "https":
+ connection = compat.HTTPSConnection(meta.netloc)
+ else:
+ connection = compat.HTTPConnection(meta.netloc)
+
+ connection.request(method.upper(), meta.path + '?' + meta.query, payload, headers)
+ try:
+ response = connection.getresponse()
+ data = response.read()
+ if compat.py_major_v >= 3:
+ data = data.decode('utf-8')
+
+ return process_response(url,data, response.status)
+ finally:
+ connection.close()
+
+
+def process_response(url,response, http_code):
+ try:
+ resp_json = compat.json.loads(response)
+ except Exception as ex:
+ raise Exception("Response not in JSON format. Probably not a chargebee error. \n URL is " + url + "\n Content is \n" + response)
+ if http_code < 200 or http_code > 299:
+ handle_api_resp_error(url,http_code, resp_json)
+
+ return resp_json
+
+
+def handle_api_resp_error(url,http_code, resp_json):
+ if 'api_error_code' not in resp_json:
+ raise Exception("The api_error_code is not present. Probably not a chargebee error. \n URL is " + url + "\nContent is \n " + str(resp_json))
+
+ if 'payment' == resp_json.get('type'):
+ raise PaymentError(http_code, resp_json)
+ elif 'operation_failed' == resp_json.get('type'):
+ raise OperationFailedError(http_code, resp_json)
+ elif 'invalid_request' == resp_json.get('type'):
+ raise InvalidRequestError(http_code, resp_json)
+ else:
+ raise APIError(http_code, resp_json)
+
+
diff --git a/chargebee/list_result.py b/chargebee/list_result.py
new file mode 100644
index 0000000..7760424
--- /dev/null
+++ b/chargebee/list_result.py
@@ -0,0 +1,13 @@
+from chargebee.result import Result
+
+
+class ListResult(list):
+
+ def __init__(self, response, next_offset):
+ self.response = response
+ self.next_offset = next_offset
+ self._init_items()
+
+ def _init_items(self):
+ for item in self.response:
+ self.append(Result(item))
diff --git a/chargebee/main.py b/chargebee/main.py
new file mode 100644
index 0000000..630a8a0
--- /dev/null
+++ b/chargebee/main.py
@@ -0,0 +1,15 @@
+import os.path
+
+from chargebee.environment import Environment
+
+
+class ChargeBee(object):
+
+ default_env = None
+
+ verify_ca_certs = True
+ ca_cert_path = os.path.join(os.path.dirname(__file__), 'ssl', 'ca-certs.crt')
+
+ @classmethod
+ def configure(cls, options):
+ cls.default_env = Environment(options)
diff --git a/chargebee/model.py b/chargebee/model.py
new file mode 100644
index 0000000..3cfb8b4
--- /dev/null
+++ b/chargebee/model.py
@@ -0,0 +1,47 @@
+from chargebee.compat import json
+
+
+class Model(object):
+
+ fields = []
+
+ def __init__(self, values, sub_types=None):
+ if sub_types is None:
+ sub_types = {}
+
+ self.values = values
+ self.sub_types = sub_types
+ for field in self.fields:
+ setattr(self, field, None)
+
+ def __str__(self):
+ return json.dumps(self.values, indent=4)
+
+ def load(self, values):
+ for k, v in list(values.items()):
+ set_val = None
+ if isinstance(v, dict):
+ set_val = self.sub_types[k].construct(v) if k in self.sub_types else v
+ elif isinstance(v, (list, tuple)):
+ if k in self.sub_types:
+ set_val = [self.sub_types[k].construct(x) for x in v]
+ else:
+ set_val = v
+ else:
+ set_val = v
+
+ if k not in ('content',): # Skipping models properties
+ setattr(self, k, set_val)
+
+ # Returns null for any attribute that starts with cf_ to access the custom fields.
+ def __getattr__(self, name):
+ if( name[0:3] == "cf_"):
+ return None
+ raise AttributeError("Attribute %s not found " % name)
+
+ @classmethod
+ def construct(cls, values, sub_types=None):
+ obj = cls(values, sub_types)
+ obj.load(values)
+ return obj
+
diff --git a/chargebee/models/__init__.py b/chargebee/models/__init__.py
new file mode 100644
index 0000000..09b6133
--- /dev/null
+++ b/chargebee/models/__init__.py
@@ -0,0 +1,19 @@
+from chargebee.models.addon import Addon
+from chargebee.models.address import Address
+from chargebee.models.card import Card
+from chargebee.models.coupon import Coupon
+from chargebee.models.coupon_code import CouponCode
+from chargebee.models.customer import Customer
+from chargebee.models.event import Event
+from chargebee.models.hosted_page import HostedPage
+from chargebee.models.invoice import Invoice
+from chargebee.models.order import Order
+from chargebee.models.estimate import Estimate
+from chargebee.models.plan import Plan
+from chargebee.models.subscription import Subscription
+from chargebee.models.transaction import Transaction
+from chargebee.models.comment import Comment
+from chargebee.models.portal_session import PortalSession
+from chargebee.models.download import Download
+from chargebee.models.content import Content
+
diff --git a/chargebee/models/addon.py b/chargebee/models/addon.py
new file mode 100644
index 0000000..71f5836
--- /dev/null
+++ b/chargebee/models/addon.py
@@ -0,0 +1,31 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Addon(Model):
+
+ fields = ["id", "name", "invoice_name", "description", "type", "charge_type", "price", \
+ "period", "period_unit", "unit", "status", "archived_at", "enabled_in_portal", "invoice_notes", \
+ "taxable", "meta_data"]
+
+
+ @staticmethod
+ def create(params, env=None, headers=None):
+ return request.send('post', request.uri_path("addons"), params, env, headers)
+
+ @staticmethod
+ def update(id, params=None, env=None, headers=None):
+ return request.send('post', request.uri_path("addons",id), params, env, headers)
+
+ @staticmethod
+ def list(params=None, env=None, headers=None):
+ return request.send('get', request.uri_path("addons"), params, env, headers)
+
+ @staticmethod
+ def retrieve(id, env=None, headers=None):
+ return request.send('get', request.uri_path("addons",id), None, env, headers)
+
+ @staticmethod
+ def delete(id, env=None, headers=None):
+ return request.send('post', request.uri_path("addons",id,"delete"), None, env, headers)
diff --git a/chargebee/models/address.py b/chargebee/models/address.py
new file mode 100644
index 0000000..ad3f296
--- /dev/null
+++ b/chargebee/models/address.py
@@ -0,0 +1,18 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Address(Model):
+
+ fields = ["label", "first_name", "last_name", "email", "company", "phone", "addr", "extended_addr", \
+ "extended_addr2", "city", "state_code", "state", "country", "zip", "subscription_id"]
+
+
+ @staticmethod
+ def retrieve(params, env=None, headers=None):
+ return request.send('get', request.uri_path("addresses"), params, env, headers)
+
+ @staticmethod
+ def update(params, env=None, headers=None):
+ return request.send('post', request.uri_path("addresses"), params, env, headers)
diff --git a/chargebee/models/card.py b/chargebee/models/card.py
new file mode 100644
index 0000000..494586d
--- /dev/null
+++ b/chargebee/models/card.py
@@ -0,0 +1,27 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Card(Model):
+
+ fields = ["customer_id", "status", "gateway", "first_name", "last_name", "iin", "last4", \
+ "card_type", "expiry_month", "expiry_year", "billing_addr1", "billing_addr2", "billing_city", \
+ "billing_state_code", "billing_state", "billing_country", "billing_zip", "ip_address", "masked_number"]
+
+
+ @staticmethod
+ def retrieve(id, env=None, headers=None):
+ return request.send('get', request.uri_path("cards",id), None, env, headers)
+
+ @staticmethod
+ def update_card_for_customer(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"credit_card"), params, env, headers)
+
+ @staticmethod
+ def switch_gateway_for_customer(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"switch_gateway"), params, env, headers)
+
+ @staticmethod
+ def delete_card_for_customer(id, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"delete_card"), None, env, headers)
diff --git a/chargebee/models/comment.py b/chargebee/models/comment.py
new file mode 100644
index 0000000..13aff80
--- /dev/null
+++ b/chargebee/models/comment.py
@@ -0,0 +1,25 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Comment(Model):
+
+ fields = ["id", "entity_type", "added_by", "notes", "created_at", "type", "entity_id"]
+
+
+ @staticmethod
+ def create(params, env=None, headers=None):
+ return request.send('post', request.uri_path("comments"), params, env, headers)
+
+ @staticmethod
+ def retrieve(id, env=None, headers=None):
+ return request.send('get', request.uri_path("comments",id), None, env, headers)
+
+ @staticmethod
+ def list(params=None, env=None, headers=None):
+ return request.send('get', request.uri_path("comments"), params, env, headers)
+
+ @staticmethod
+ def delete(id, env=None, headers=None):
+ return request.send('post', request.uri_path("comments",id,"delete"), None, env, headers)
diff --git a/chargebee/models/content.py b/chargebee/models/content.py
new file mode 100644
index 0000000..dc7dcc2
--- /dev/null
+++ b/chargebee/models/content.py
@@ -0,0 +1,5 @@
+from chargebee.result import Result
+
+
+class Content(Result):
+ pass
diff --git a/chargebee/models/coupon.py b/chargebee/models/coupon.py
new file mode 100644
index 0000000..c82fa98
--- /dev/null
+++ b/chargebee/models/coupon.py
@@ -0,0 +1,24 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Coupon(Model):
+
+ fields = ["id", "name", "invoice_name", "discount_type", "discount_percentage", "discount_amount", \
+ "discount_quantity", "duration_type", "duration_month", "valid_till", "max_redemptions", "status", \
+ "apply_discount_on", "apply_on", "plan_constraint", "addon_constraint", "created_at", "archived_at", \
+ "plan_ids", "addon_ids", "redemptions", "invoice_notes", "meta_data"]
+
+
+ @staticmethod
+ def create(params, env=None, headers=None):
+ return request.send('post', request.uri_path("coupons"), params, env, headers)
+
+ @staticmethod
+ def list(params=None, env=None, headers=None):
+ return request.send('get', request.uri_path("coupons"), params, env, headers)
+
+ @staticmethod
+ def retrieve(id, env=None, headers=None):
+ return request.send('get', request.uri_path("coupons",id), None, env, headers)
diff --git a/chargebee/models/coupon_code.py b/chargebee/models/coupon_code.py
new file mode 100644
index 0000000..a7236c1
--- /dev/null
+++ b/chargebee/models/coupon_code.py
@@ -0,0 +1,17 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class CouponCode(Model):
+
+ fields = ["code", "coupon_id", "coupon_set_name"]
+
+
+ @staticmethod
+ def create(params, env=None, headers=None):
+ return request.send('post', request.uri_path("coupon_codes"), params, env, headers)
+
+ @staticmethod
+ def retrieve(id, env=None, headers=None):
+ return request.send('get', request.uri_path("coupon_codes",id), None, env, headers)
diff --git a/chargebee/models/customer.py b/chargebee/models/customer.py
new file mode 100644
index 0000000..102e364
--- /dev/null
+++ b/chargebee/models/customer.py
@@ -0,0 +1,73 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Customer(Model):
+ class BillingAddress(Model):
+ fields = ["first_name", "last_name", "email", "company", "phone", "line1", "line2", "line3", "city", "state_code", "state", "country", "zip"]
+ pass
+ class Contact(Model):
+ fields = ["id", "first_name", "last_name", "email", "phone", "label", "enabled", "send_account_email", "send_billing_email"]
+ pass
+ class PaymentMethod(Model):
+ fields = ["type", "gateway", "status", "reference_id"]
+ pass
+
+ fields = ["id", "first_name", "last_name", "email", "phone", "company", "vat_number", "auto_collection", \
+ "allow_direct_debit", "created_at", "created_from_ip", "taxability", "card_status", "billing_address", \
+ "contacts", "payment_method", "invoice_notes", "account_credits", "refundable_credits", "excess_payments", \
+ "meta_data"]
+
+
+ @staticmethod
+ def create(params=None, env=None, headers=None):
+ return request.send('post', request.uri_path("customers"), params, env, headers)
+
+ @staticmethod
+ def list(params=None, env=None, headers=None):
+ return request.send('get', request.uri_path("customers"), params, env, headers)
+
+ @staticmethod
+ def retrieve(id, env=None, headers=None):
+ return request.send('get', request.uri_path("customers",id), None, env, headers)
+
+ @staticmethod
+ def update(id, params=None, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id), params, env, headers)
+
+ @staticmethod
+ def update_payment_method(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"update_payment_method"), params, env, headers)
+
+ @staticmethod
+ def update_billing_info(id, params=None, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"update_billing_info"), params, env, headers)
+
+ @staticmethod
+ def add_contact(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"add_contact"), params, env, headers)
+
+ @staticmethod
+ def update_contact(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"update_contact"), params, env, headers)
+
+ @staticmethod
+ def delete_contact(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"delete_contact"), params, env, headers)
+
+ @staticmethod
+ def add_account_credits(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"add_account_credits"), params, env, headers)
+
+ @staticmethod
+ def deduct_account_credits(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"deduct_account_credits"), params, env, headers)
+
+ @staticmethod
+ def set_account_credits(id, params, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"set_account_credits"), params, env, headers)
+
+ @staticmethod
+ def delete(id, params=None, env=None, headers=None):
+ return request.send('post', request.uri_path("customers",id,"delete"), params, env, headers)
diff --git a/chargebee/models/download.py b/chargebee/models/download.py
new file mode 100644
index 0000000..fc56599
--- /dev/null
+++ b/chargebee/models/download.py
@@ -0,0 +1,9 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Download(Model):
+
+ fields = ["download_url", "valid_till"]
+
diff --git a/chargebee/models/estimate.py b/chargebee/models/estimate.py
new file mode 100644
index 0000000..68718a0
--- /dev/null
+++ b/chargebee/models/estimate.py
@@ -0,0 +1,32 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Estimate(Model):
+ class LineItem(Model):
+ fields = ["date_from", "date_to", "unit_amount", "quantity", "is_taxed", "tax", "tax_rate", "amount", "description", "type", "entity_type", "entity_id"]
+ pass
+ class Discount(Model):
+ fields = ["amount", "description", "type", "entity_id"]
+ pass
+ class Tax(Model):
+ fields = ["amount", "description"]
+ pass
+
+ fields = ["created_at", "recurring", "subscription_id", "subscription_status", "term_ends_at", \
+ "collect_now", "price_type", "amount", "credits_applied", "amount_due", "sub_total", "line_items", \
+ "discounts", "taxes"]
+
+
+ @staticmethod
+ def create_subscription(params, env=None, headers=None):
+ return request.send('post', request.uri_path("estimates","create_subscription"), params, env, headers)
+
+ @staticmethod
+ def update_subscription(params, env=None, headers=None):
+ return request.send('post', request.uri_path("estimates","update_subscription"), params, env, headers)
+
+ @staticmethod
+ def renewal_estimate(id, params=None, env=None, headers=None):
+ return request.send('get', request.uri_path("subscriptions",id,"renewal_estimate"), params, env, headers)
diff --git a/chargebee/models/event.py b/chargebee/models/event.py
new file mode 100644
index 0000000..8235181
--- /dev/null
+++ b/chargebee/models/event.py
@@ -0,0 +1,40 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+from chargebee.main import Environment
+
+class Event(Model):
+ class Webhook(Model):
+ fields = ["id", "webhook_status"]
+ pass
+
+ fields = ["id", "occurred_at", "source", "user", "webhook_status", "webhook_failure_reason", \
+ "webhooks", "event_type", "api_version"]
+
+ @property
+ def content(self):
+ from chargebee import Content
+ return Content(self.values['content'])
+
+ @staticmethod
+ def deserialize(json_data):
+ try:
+ webhook_data = json.loads(json_data)
+ except (TypeError, ValueError) as ex:
+ raise Exception("The passed json_data is not JSON formatted . " + ex.message)
+
+ api_version = webhook_data.get('api_version', None)
+ env_version = Environment.API_VERSION
+ if api_version != None and api_version.upper() != env_version.upper():
+ raise Exception("API version [" + api_version.upper() + "] in response does not match "
+ + "with client library API version [" + env_version.upper() + "]")
+ return Event.construct(webhook_data)
+
+ @staticmethod
+ def list(params=None, env=None, headers=None):
+ return request.send('get', request.uri_path("events"), params, env, headers)
+
+ @staticmethod
+ def retrieve(id, env=None, headers=None):
+ return request.send('get', request.uri_path("events",id), None, env, headers)
diff --git a/chargebee/models/hosted_page.py b/chargebee/models/hosted_page.py
new file mode 100644
index 0000000..0adb3e1
--- /dev/null
+++ b/chargebee/models/hosted_page.py
@@ -0,0 +1,44 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class HostedPage(Model):
+
+ fields = ["id", "type", "url", "state", "failure_reason", "pass_thru_content", "embed", \
+ "created_at", "expires_at"]
+
+ @property
+ def content(self):
+ from chargebee import Content
+ if 'content' in self.values:
+ return Content(self.values['content'])
+ return None
+
+ @staticmethod
+ def checkout_new(params, env=None, headers=None):
+ return request.send('post', request.uri_path("hosted_pages","checkout_new"), params, env, headers)
+
+ @staticmethod
+ def checkout_existing(params, env=None, headers=None):
+ return request.send('post', request.uri_path("hosted_pages","checkout_existing"), params, env, headers)
+
+ @staticmethod
+ def update_card(params, env=None, headers=None):
+ return request.send('post', request.uri_path("hosted_pages","update_card"), params, env, headers)
+
+ @staticmethod
+ def update_payment_method(params, env=None, headers=None):
+ return request.send('post', request.uri_path("hosted_pages","update_payment_method"), params, env, headers)
+
+ @staticmethod
+ def checkout_onetime_charge(params, env=None, headers=None):
+ return request.send('post', request.uri_path("hosted_pages","checkout_onetime_charge"), params, env, headers)
+
+ @staticmethod
+ def checkout_onetime_addons(params, env=None, headers=None):
+ return request.send('post', request.uri_path("hosted_pages","checkout_onetime_addons"), params, env, headers)
+
+ @staticmethod
+ def retrieve(id, env=None, headers=None):
+ return request.send('get', request.uri_path("hosted_pages",id), None, env, headers)
diff --git a/chargebee/models/invoice.py b/chargebee/models/invoice.py
new file mode 100644
index 0000000..0477c34
--- /dev/null
+++ b/chargebee/models/invoice.py
@@ -0,0 +1,105 @@
+import json
+from chargebee.model import Model
+from chargebee import request
+from chargebee import APIError
+
+class Invoice(Model):
+ class LineItem(Model):
+ fields = ["date_from", "date_to", "unit_amount", "quantity", "is_taxed", "tax", "tax_rate", "amount", "description", "type", "entity_type", "entity_id"]
+ pass
+ class Discount(Model):
+ fields = ["amount", "description", "type", "entity_id"]
+ pass
+ class Tax(Model):
... 4053 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/chargebee-python.git
More information about the Python-modules-commits
mailing list