Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
14a13cf
Fix Resource rep method
Jan 30, 2018
115a10e
Add payment method resource
Jan 30, 2018
7d41f82
Added default value for user header
Jan 30, 2018
f785e94
Added finder method for account
Jan 30, 2018
e7cd7e3
Added update method for account api
Jan 30, 2018
1082ae8
Modification required by Pierre
Feb 1, 2018
38c0dd7
Merge remote-tracking branch 'upstream/master'
Feb 1, 2018
2117a49
Fix put request.
Feb 1, 2018
b118b84
Added destroy call for payment method.
Feb 5, 2018
e3719aa
Added destroy call for payment method.
Feb 5, 2018
7370e56
Added destroy call for payment method.
Feb 5, 2018
d5d0f45
Fix payment method set_default.
Feb 5, 2018
ba8e5a3
Fix put method in resource
Feb 5, 2018
20655de
Fix set_default method in payment method
Feb 5, 2018
95b7cdb
pep8
Feb 5, 2018
833f53e
Fix set_default method in payment method
Feb 5, 2018
2992dce
Removed copyright of Quentral.
Feb 6, 2018
135710c
Added endpoint for catalog and plan details
Feb 6, 2018
26bb45e
Added endpoint for catalog and plan details
Feb 6, 2018
83ab80f
Added bundle
Feb 6, 2018
95cfc79
Fix plan detail serialization
Feb 6, 2018
1b77937
Fix account update method.
Feb 8, 2018
a298e53
Added change_plan method for subscription
Feb 9, 2018
dfedd45
Add subscription finder method.
Feb 9, 2018
6cad122
Added list invoices for account API endpoint
Feb 14, 2018
5a582f7
Added invoice class
Feb 14, 2018
84b28be
Added invoice class
Feb 14, 2018
7464aa6
Fix options
Feb 14, 2018
eac99a6
Fix invoice pdf response
Feb 14, 2018
32af48d
Added full catalog endpoint
Mar 22, 2018
aff77fe
Added refresh query parameter to payment method resource
Mar 28, 2018
af62e05
Add custom fields for subscription
Mar 29, 2018
f8267fb
Add custom fields for subscription
Mar 29, 2018
68a97da
Add custom fields for subscription
Mar 29, 2018
30595b2
Add custom fields for subscription
Mar 29, 2018
ba98694
Add custom fields for subscription
Mar 29, 2018
1dd16d8
Add custom fields for subscription
Mar 29, 2018
946e94e
Add custom fields for subscription
Mar 29, 2018
099666f
Fix catalog json format
Jun 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions killbill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
#

user = 'KillBill Python Client'
base_uri = 'http://localhost:8080'
username = 'admin'
password = 'password'
Expand All @@ -39,4 +40,10 @@

from killbill.resource import Resource
from killbill.account import Account
from killbill.bundle import Bundle
from killbill.catalog import Catalog
from killbill.custom_field import CustomField
from killbill.invoice import Invoice
from killbill.payment_method import PaymentMethod
from killbill.plan_detail import PlanDetail
from killbill.subscription import Subscription
40 changes: 35 additions & 5 deletions killbill/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Account(killbill.Resource):
def __init__(self, **d):
super(Account, self).__init__(d)

def create(self, user, reason=None, comment=None, **options):
def create(self, user=killbill.user, reason=None, comment=None, **options):
created_account = self.post(self.KILLBILL_API_ACCOUNTS_PREFIX,
self.to_json(),
{},
Expand All @@ -36,12 +36,20 @@ def create(self, user, reason=None, comment=None, **options):
))
return self.refresh(created_account, **options)

def update(self, **options):
updated_account = self.put("%s/%s" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId),
self.to_json(),
{},
self.build_options(**options))
return self.fromJson(updated_account['body'])

def bundles(self, **options):
return self.get("%s/%s/bundles" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId),
{},
self.build_options(**options))
return killbill.Bundle.get("%s/%s/bundles" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId),
{},
killbill.Bundle.build_options(**options))

def close(self, cancel_all_subscriptions, write_off_unpaid_invoices, item_adjust_unpaid_invoices, user, reason=None, comment=None, **options):
def close(self, cancel_all_subscriptions, write_off_unpaid_invoices, item_adjust_unpaid_invoices, user, reason=None,
comment=None, **options):
return self.delete("%s/%s" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId),
"{}",
{
Expand All @@ -56,9 +64,31 @@ def close(self, cancel_all_subscriptions, write_off_unpaid_invoices, item_adjust
**options
))

def invoices(self, with_items=False, with_migration_invoices=False, unpaid_invoices_only=False, audit='NONE',
**options):
return killbill.Invoice.get("%s/%s/invoices" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId),
{
'withItems': with_items,
'withMigrationInvoices': with_migration_invoices,
'unpaidInvoicesOnly': unpaid_invoices_only,
'audit': audit
},
killbill.Invoice.build_options(**options))

@classmethod
def find_by_external_key(cls, external_key, **options):
query_params = {
'externalKey': external_key
}
return cls.get(cls.KILLBILL_API_ACCOUNTS_PREFIX, query_params, cls.build_options(**options))

@classmethod
def find_by_id(cls, account_id, account_with_balance=False, account_with_balance_and_cba=False, audit='NONE',
**options):
relative_url = "%s/%s" % (cls.KILLBILL_API_ACCOUNTS_PREFIX, account_id)
query_params = {
'accountWithBalance': account_with_balance,
'accountWithBalanceAndCBA': account_with_balance_and_cba,
'audit': audit
}
return cls.get(relative_url, query_params, cls.build_options(**options))
31 changes: 31 additions & 0 deletions killbill/bundle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright 2014-2017 The Billing Project, LLC
#
# The Billing Project, LLC licenses this file to you under the Apache License, version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import killbill


class Bundle(killbill.Resource):
KILLBILL_API_BUNDLE_PREFIX = killbill.Resource.KILLBILL_API_PREFIX + '/bundles'

def __init__(self, **d):
super(Bundle, self).__init__(d)

@classmethod
def find_all_by_account_id_and_external_key(cls, account_id, external_key=None, **options):
relative_url = "%s/%s/bundles" % (killbill.Account.KILLBILL_API_ACCOUNTS_PREFIX, account_id)
query_params = {
'externalKey': external_key
}
return cls.get(relative_url, query_params, cls.build_options(**options))
46 changes: 46 additions & 0 deletions killbill/catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright 2014-2017 The Billing Project, LLC
#
# The Billing Project, LLC licenses this file to you under the Apache License, version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import killbill


class Catalog(killbill.Resource):
KILLBILL_API_CATALOG_PREFIX = killbill.Resource.KILLBILL_API_PREFIX + '/catalog'

def __init__(self, **d):
super(Catalog, self).__init__(d)

@classmethod
def available_addons(cls, base_product_name, **options):
relative_url = "%s/availableAddons" % cls.KILLBILL_API_CATALOG_PREFIX
query_params = {
'baseProductName': base_product_name
}
return killbill.PlanDetail.get(relative_url, query_params, killbill.PlanDetail.build_options(**options))

@classmethod
def available_base_plans(cls, **options):
relative_url = "%s/availableBasePlans" % cls.KILLBILL_API_CATALOG_PREFIX
query_params = {}
return killbill.PlanDetail.get(relative_url, query_params, killbill.PlanDetail.build_options(**options))

@classmethod
def catalog(cls, requested_date=None, **options):
relative_url = cls.KILLBILL_API_CATALOG_PREFIX
options['accept'] = 'application/json'
query_params = {
'requestedDate': requested_date
}
return cls.get(relative_url, query_params, cls.build_options(**options))
22 changes: 22 additions & 0 deletions killbill/custom_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright 2014-2017 The Billing Project, LLC
#
# The Billing Project, LLC licenses this file to you under the Apache License, version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import killbill


class CustomField(killbill.Resource):

def __init__(self, **d):
super(CustomField, self).__init__(d)
42 changes: 42 additions & 0 deletions killbill/invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Copyright 2014-2017 The Billing Project, LLC
#
# The Billing Project, LLC licenses this file to you under the Apache License, version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import killbill


class Invoice(killbill.Resource):
KILLBILL_API_INVOICE_PREFIX = killbill.Resource.KILLBILL_API_PREFIX + '/invoices'

def __init__(self, **d):
super(Invoice, self).__init__(d)

@classmethod
def find_by_id_or_number(cls, id_or_number, with_items=True, audit="NONE", **options):
relative_url = "%s/%s" % (cls.KILLBILL_API_INVOICE_PREFIX, id_or_number)
query_params = {
'withItems': with_items,
'audit': audit
}
return cls.get(relative_url, query_params, cls.build_options(**options))

@classmethod
def as_html(cls, invoice_id, **options):
relative_url = "%s/%s/html" % (cls.KILLBILL_API_INVOICE_PREFIX, invoice_id)
options['accept'] = 'text/html'
options = cls.build_options(**options)
options['method'] = 'GET'
options['queryParams'] = {}
raw_get_response = cls.send_request(relative_url, options)
return raw_get_response['body']
86 changes: 86 additions & 0 deletions killbill/payment_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#
# Copyright 2014-2018 The Billing Project, LLC
#
# The Billing Project, LLC licenses this file to you under the Apache License, version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import killbill


class PaymentMethod(killbill.Resource):
KILLBILL_API_PAYMENT_METHODS_PREFIX = killbill.Resource.KILLBILL_API_PREFIX + '/paymentMethods'

def __init__(self, **d):
super(PaymentMethod, self).__init__(d)

@classmethod
def get_refresh_query(cls):
return {'withPluginInfo': True}

def create(self, is_default=True, user=killbill.user, reason=None, comment=None, **options):
created_payment_method = self.post("%s/%s/paymentMethods" %
(killbill.Account.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId),
self.to_json(),
{'isDefault': is_default},
self.build_options(
user=user,
reason=reason,
comment=comment,
**options
))
return self.refresh(created_payment_method, **options)

def set_default(self, user=killbill.user, reason=None, comment=None, **options):
self.put("%s/%s/paymentMethods/%s/setDefault" %
(killbill.Account.KILLBILL_API_ACCOUNTS_PREFIX,
self.accountId, self.paymentMethodId),
"{}",
{},
self.build_options(
user=user,
reason=reason,
comment=comment,
**options
))
return self.find_by_id(self.paymentMethodId, **options)

def destroy(self, delete_default_pm_with_auto_pay_off=False, force_default_pm_deletion=False, user=killbill.user,
reason=None, comment=None, **options):
return self.delete("%s/%s" % (self.KILLBILL_API_PAYMENT_METHODS_PREFIX, self.paymentMethodId),
"{}",
{'deleteDefaultPmWithAutoPayOff': delete_default_pm_with_auto_pay_off,
'forceDefaultPmDeletion': force_default_pm_deletion},
self.build_options(
user=user,
reason=reason,
comment=comment,
**options
))

@classmethod
def find_all_by_account_id(cls, account_id, with_plugin_info=False, **options):
relative_url = "%s/%s/paymentMethods" % (killbill.Account.KILLBILL_API_ACCOUNTS_PREFIX, account_id)
query_params = {
'withPluginInfo': with_plugin_info
}
return cls.get(relative_url, query_params, cls.build_options(**options))

@classmethod
def find_by_id(cls, payment_method_id, plugin_property=None, included_deleted=False, audit='NONE', with_plugin_info=False, **options):
relative_url = "%s/%s" % (cls.KILLBILL_API_PAYMENT_METHODS_PREFIX, payment_method_id)
query_params = {
'pluginProperty': plugin_property,
'includedDeleted': included_deleted,
'audit': audit,
'withPluginInfo': with_plugin_info
}
return cls.get(relative_url, query_params, cls.build_options(**options))
28 changes: 28 additions & 0 deletions killbill/plan_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2014-2017 The Billing Project, LLC
#
# The Billing Project, LLC licenses this file to you under the Apache License, version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import killbill


class PlanDetail(killbill.Resource):

def __init__(self, **d):
super(PlanDetail, self).__init__(d)

@classmethod
def dict_to_object(cls, d):
if 'plan' in d:
return cls(**d)
return d
15 changes: 13 additions & 2 deletions killbill/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, d):
setattr(self, key, value)

def __repr__(self):
return '%s %s' % (self.__class__, self.to_json)
return '%s %s' % (self.__class__, self.to_json())

@staticmethod
def build_options(**options):
Expand All @@ -63,9 +63,13 @@ def build_options(**options):
def to_json(self):
return killbill.json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def get_refresh_query(cls):
return {}

def refresh(self, raw_response, **options):
url = raw_response['response'].headers['Location']
return self.get(url, {}, self.build_options(**options))
return self.get(url, self.get_refresh_query(), self.build_options(**options))

@classmethod
def fromJson(cls, jsonString):
Expand Down Expand Up @@ -96,6 +100,13 @@ def delete(cls, relative_uri, body, query_params, options):
options['queryParams'] = query_params
return cls.send_request(relative_uri, options)

@classmethod
def put(cls, relative_uri, body, query_params, options):
options['method'] = 'PUT'
options['body'] = body
options['queryParams'] = query_params
return cls.send_request(relative_uri, options)

@classmethod
def send_request(cls, relative_uri, options):
headers = {}
Expand Down
Loading