From 14a13cf2893001ba5ebf0ede775bb7051bab4bc8 Mon Sep 17 00:00:00 2001 From: Federico Torresan Date: Tue, 30 Jan 2018 11:05:46 +0100 Subject: [PATCH 01/38] Fix Resource rep method --- killbill/resource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/killbill/resource.py b/killbill/resource.py index 53f37a2..d49af5a 100644 --- a/killbill/resource.py +++ b/killbill/resource.py @@ -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()) def build_options(self, **options): default = { From 115a10e31df03bd9f2bf91a68c67a1aa917980f2 Mon Sep 17 00:00:00 2001 From: Federico Torresan Date: Tue, 30 Jan 2018 13:33:36 +0100 Subject: [PATCH 02/38] Add payment method resource --- killbill/__init__.py | 1 + killbill/payment_method.py | 58 ++++++++++++++++++++++++++++++++++++++ killbill/resource.py | 10 ++++++- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 killbill/payment_method.py diff --git a/killbill/__init__.py b/killbill/__init__.py index c0804a4..c2107ca 100644 --- a/killbill/__init__.py +++ b/killbill/__init__.py @@ -39,4 +39,5 @@ from killbill.resource import Resource from killbill.account import Account +from killbill.payment_method import PaymentMethod from killbill.subscription import Subscription diff --git a/killbill/payment_method.py b/killbill/payment_method.py new file mode 100644 index 0000000..d9b5c64 --- /dev/null +++ b/killbill/payment_method.py @@ -0,0 +1,58 @@ +# +# Copyright 2018 Federico Torresan +# +# 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) + + def create(self, is_default, 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, reason=None, comment=None, **options): + set_default = 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.refresh(set_default, **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)) diff --git a/killbill/resource.py b/killbill/resource.py index d49af5a..1cc931e 100644 --- a/killbill/resource.py +++ b/killbill/resource.py @@ -47,7 +47,8 @@ def __init__(self, d): def __repr__(self): return '%s %s' % (self.__class__, self.to_json()) - def build_options(self, **options): + @staticmethod + def build_options(**options): default = { 'contentType': 'application/json', 'baseUri': killbill.base_uri, @@ -88,6 +89,13 @@ def post(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 = {} From 7d41f82f484d767d635b38945ff21da2cb2d4e60 Mon Sep 17 00:00:00 2001 From: Federico Torresan Date: Tue, 30 Jan 2018 14:25:58 +0100 Subject: [PATCH 03/38] Added default value for user header --- killbill/__init__.py | 1 + killbill/account.py | 2 +- killbill/payment_method.py | 4 ++-- killbill/subscription.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/killbill/__init__.py b/killbill/__init__.py index c2107ca..6a2f76f 100644 --- a/killbill/__init__.py +++ b/killbill/__init__.py @@ -16,6 +16,7 @@ # under the License. # +user = 'KillBill Python Client' base_uri = 'http://localhost:8080' username = 'admin' password = 'password' diff --git a/killbill/account.py b/killbill/account.py index bdd2fd7..3a1eb86 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -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(), {}, diff --git a/killbill/payment_method.py b/killbill/payment_method.py index d9b5c64..822cef7 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -22,7 +22,7 @@ class PaymentMethod(killbill.Resource): def __init__(self, **d): super(PaymentMethod, self).__init__(d) - def create(self, is_default, user, reason=None, comment=None, **options): + 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(), @@ -35,7 +35,7 @@ def create(self, is_default, user, reason=None, comment=None, **options): )) return self.refresh(created_payment_method, **options) - def set_default(self, user, reason=None, comment=None, **options): + def set_default(self, user=killbill.user, reason=None, comment=None, **options): set_default = self.put("%s/%s/paymentMethods/%s/setDefault" % (killbill.Account.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId, self.paymentMethodId), diff --git a/killbill/subscription.py b/killbill/subscription.py index e89e41a..6fb29a9 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -23,7 +23,7 @@ class Subscription(killbill.Resource): def __init__(self, **d): super(Subscription, self).__init__(d) - def create(self, user, reason=None, comment=None, requested_date=None, call_completion=False, **options): + def create(self, user=killbill.user, reason=None, comment=None, requested_date=None, call_completion=False, **options): query_params = {} if call_completion: From f785e94b6b2a2a27824cf9b91e8ea567b7b26445 Mon Sep 17 00:00:00 2001 From: Federico Torresan Date: Tue, 30 Jan 2018 14:58:30 +0100 Subject: [PATCH 04/38] Added finder method for account --- killbill/account.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/killbill/account.py b/killbill/account.py index 3a1eb86..72a798a 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -40,3 +40,13 @@ def bundles(self, **options): return self.get("%s/%s/bundles" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), {}, self.build_options(**options)) + + @classmethod + def find_by_id(cls, account_id, **options): + relative_url = "%s/%s" % (cls.KILLBILL_API_ACCOUNTS_PREFIX, account_id) + query_params = { + 'accountWithBalance': False, + 'accountWithBalanceAndCBA': False, + 'audit': 'NONE' + } + return cls.get(relative_url, query_params, cls.build_options(**options)) From e7cd7e3a992129ca903efcbf778c4f8b1bef56c0 Mon Sep 17 00:00:00 2001 From: Federico Torresan Date: Tue, 30 Jan 2018 15:58:30 +0100 Subject: [PATCH 05/38] Added update method for account api --- killbill/account.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/killbill/account.py b/killbill/account.py index 72a798a..721b150 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -36,11 +36,18 @@ def create(self, user=killbill.user, reason=None, comment=None, **options): )) return self.refresh(created_account, **options) + def update(self, **options): + return self.put("%s/%s" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), + self.to_json(), + {}, + self.build_options(**options)) + def bundles(self, **options): return self.get("%s/%s/bundles" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), {}, self.build_options(**options)) + @classmethod def find_by_id(cls, account_id, **options): relative_url = "%s/%s" % (cls.KILLBILL_API_ACCOUNTS_PREFIX, account_id) From 1082ae82f183204358c8bb8f252bd1c9fde646da Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 1 Feb 2018 10:16:41 +0100 Subject: [PATCH 06/38] Modification required by Pierre --- killbill/account.py | 8 ++++---- killbill/payment_method.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/killbill/account.py b/killbill/account.py index 721b150..c8e58bb 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -49,11 +49,11 @@ def bundles(self, **options): @classmethod - def find_by_id(cls, account_id, **options): + 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': False, - 'accountWithBalanceAndCBA': False, - 'audit': 'NONE' + 'accountWithBalance': account_with_balance, + 'accountWithBalanceAndCBA': account_with_balance_and_cba, + 'audit': audit } return cls.get(relative_url, query_params, cls.build_options(**options)) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index 822cef7..574eb6b 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -1,5 +1,6 @@ # -# Copyright 2018 Federico Torresan +# Copyright 2018 Quentral S.r.l. +# 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 From 2117a49cfc0fbdae36f6ac0d90fda4d96ec1d121 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 1 Feb 2018 11:58:44 +0100 Subject: [PATCH 07/38] Fix put request. --- killbill/resource.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/killbill/resource.py b/killbill/resource.py index a3cbae3..1068bdc 100644 --- a/killbill/resource.py +++ b/killbill/resource.py @@ -101,7 +101,8 @@ 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) + raw_get_response = cls.send_request(relative_uri, options) + return cls.fromJson(raw_get_response['body']) @classmethod def send_request(cls, relative_uri, options): From b118b84601197e16bce1af79065b3e4b0a88e601 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Mon, 5 Feb 2018 12:26:14 +0100 Subject: [PATCH 08/38] Added destroy call for payment method. --- killbill/payment_method.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index 574eb6b..4b5a833 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -50,6 +50,17 @@ def set_default(self, user=killbill.user, reason=None, comment=None, **options): )) return self.refresh(set_default, **options) + def destroy(self, user=killbill.user, reason=None, comment=None, **options): + return self.delete("%s/%s" % (self.KILLBILL_API_PAYMENT_METHODS_PREFIX, self.paymentMethodId), + {}, + {}, + 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) From e3719aa785ed14f8b7211901754dde923e6441d4 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Mon, 5 Feb 2018 12:44:15 +0100 Subject: [PATCH 09/38] Added destroy call for payment method. --- killbill/payment_method.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index 4b5a833..50f8f82 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -52,7 +52,7 @@ def set_default(self, user=killbill.user, reason=None, comment=None, **options): def destroy(self, user=killbill.user, reason=None, comment=None, **options): return self.delete("%s/%s" % (self.KILLBILL_API_PAYMENT_METHODS_PREFIX, self.paymentMethodId), - {}, + "{}", {}, self.build_options( user=user, From 7370e562f2c8b295d73139363d6cef272604cbec Mon Sep 17 00:00:00 2001 From: ftorresan Date: Mon, 5 Feb 2018 12:49:01 +0100 Subject: [PATCH 10/38] Added destroy call for payment method. --- killbill/payment_method.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index 50f8f82..aac5d21 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -50,10 +50,12 @@ def set_default(self, user=killbill.user, reason=None, comment=None, **options): )) return self.refresh(set_default, **options) - def destroy(self, user=killbill.user, reason=None, comment=None, **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, From d5d0f45e7ce640f3c56eeba5a71b0289e97d9581 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Mon, 5 Feb 2018 14:24:44 +0100 Subject: [PATCH 11/38] Fix payment method set_default. --- killbill/payment_method.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index aac5d21..b6da8c1 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -40,7 +40,7 @@ def set_default(self, user=killbill.user, reason=None, comment=None, **options): set_default = self.put("%s/%s/paymentMethods/%s/setDefault" % (killbill.Account.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId, self.paymentMethodId), - {}, + "{}", {}, self.build_options( user=user, From ba8e5a3d608434706a0e0f509dbb565a2187434f Mon Sep 17 00:00:00 2001 From: ftorresan Date: Mon, 5 Feb 2018 14:27:05 +0100 Subject: [PATCH 12/38] Fix put method in resource --- killbill/resource.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/killbill/resource.py b/killbill/resource.py index 1068bdc..a3cbae3 100644 --- a/killbill/resource.py +++ b/killbill/resource.py @@ -101,8 +101,7 @@ def put(cls, relative_uri, body, query_params, options): options['method'] = 'PUT' options['body'] = body options['queryParams'] = query_params - raw_get_response = cls.send_request(relative_uri, options) - return cls.fromJson(raw_get_response['body']) + return cls.send_request(relative_uri, options) @classmethod def send_request(cls, relative_uri, options): From 20655deb87ad6a1a63a2fce406b9cc9cc2078e5e Mon Sep 17 00:00:00 2001 From: ftorresan Date: Mon, 5 Feb 2018 14:35:13 +0100 Subject: [PATCH 13/38] Fix set_default method in payment method --- killbill/payment_method.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index b6da8c1..47952d2 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -48,7 +48,7 @@ def set_default(self, user=killbill.user, reason=None, comment=None, **options): comment=comment, **options )) - return self.refresh(set_default, **options) + return self.find_by_id(self.paymentMethodId) def destroy(self, delete_default_pm_with_auto_pay_off=False, force_default_pm_deletion=False, user=killbill.user, reason=None, comment=None, **options): @@ -70,3 +70,14 @@ def find_all_by_account_id(cls, account_id, with_plugin_info=False, **options): '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)) From 95b7cdb42103c454a437c7160baf8fa772137d5d Mon Sep 17 00:00:00 2001 From: ftorresan Date: Mon, 5 Feb 2018 14:35:27 +0100 Subject: [PATCH 14/38] pep8 --- killbill/account.py | 1 - 1 file changed, 1 deletion(-) diff --git a/killbill/account.py b/killbill/account.py index 3add62e..9c6a02a 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -69,7 +69,6 @@ def find_by_external_key(cls, external_key, **options): } 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) From 833f53e9a973bc330a3a9f9d0e05c581482eed66 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Mon, 5 Feb 2018 14:36:40 +0100 Subject: [PATCH 15/38] Fix set_default method in payment method --- killbill/payment_method.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index 47952d2..cf7ffeb 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -37,7 +37,7 @@ def create(self, is_default=True, user=killbill.user, reason=None, comment=None, return self.refresh(created_payment_method, **options) def set_default(self, user=killbill.user, reason=None, comment=None, **options): - set_default = self.put("%s/%s/paymentMethods/%s/setDefault" % + self.put("%s/%s/paymentMethods/%s/setDefault" % (killbill.Account.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId, self.paymentMethodId), "{}", @@ -48,7 +48,7 @@ def set_default(self, user=killbill.user, reason=None, comment=None, **options): comment=comment, **options )) - return self.find_by_id(self.paymentMethodId) + 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): From 2992dce02515252854519156b479d564cf74981b Mon Sep 17 00:00:00 2001 From: ftorresan Date: Tue, 6 Feb 2018 09:40:42 +0100 Subject: [PATCH 16/38] Removed copyright of Quentral. --- killbill/payment_method.py | 1 - 1 file changed, 1 deletion(-) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index cf7ffeb..abbedfd 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -1,5 +1,4 @@ # -# Copyright 2018 Quentral S.r.l. # Copyright 2014-2018 The Billing Project, LLC # # The Billing Project, LLC licenses this file to you under the Apache License, version 2.0 From 135710cf4ac163693652cb73ae68bc51bf3f2311 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Tue, 6 Feb 2018 11:38:02 +0100 Subject: [PATCH 17/38] Added endpoint for catalog and plan details --- killbill/catalog.py | 38 ++++++++++++++++++++++++++++++++++++++ killbill/plan_detail.py | 22 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 killbill/catalog.py create mode 100644 killbill/plan_detail.py diff --git a/killbill/catalog.py b/killbill/catalog.py new file mode 100644 index 0000000..1a7fe9b --- /dev/null +++ b/killbill/catalog.py @@ -0,0 +1,38 @@ +# +# 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 +from killbill.plan_detail import PlanDetail + + +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 PlanDetail.get(relative_url, query_params, PlanDetail.build_options(**options)) + + @classmethod + def available_base_plans(cls, **options): + relative_url = "%s/availableBasePlans" % cls.KILLBILL_API_CATALOG_PREFIX + query_params = {} + return PlanDetail.get(relative_url, query_params, PlanDetail.build_options(**options)) diff --git a/killbill/plan_detail.py b/killbill/plan_detail.py new file mode 100644 index 0000000..ecbb2b1 --- /dev/null +++ b/killbill/plan_detail.py @@ -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 PlanDetail(killbill.Resource): + + def __init__(self, **d): + super(PlanDetail, self).__init__(d) From 26bb45e7925c26bd6c9677d2f6a451e96b3798f2 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Tue, 6 Feb 2018 11:40:20 +0100 Subject: [PATCH 18/38] Added endpoint for catalog and plan details --- killbill/__init__.py | 2 ++ killbill/catalog.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/killbill/__init__.py b/killbill/__init__.py index 6a2f76f..2ed86f3 100644 --- a/killbill/__init__.py +++ b/killbill/__init__.py @@ -40,5 +40,7 @@ from killbill.resource import Resource from killbill.account import Account +from killbill.catalog import Catalog from killbill.payment_method import PaymentMethod +from killbill.plan_detail import PlanDetail from killbill.subscription import Subscription diff --git a/killbill/catalog.py b/killbill/catalog.py index 1a7fe9b..d5e3797 100644 --- a/killbill/catalog.py +++ b/killbill/catalog.py @@ -14,7 +14,6 @@ # under the License. # import killbill -from killbill.plan_detail import PlanDetail class Catalog(killbill.Resource): @@ -29,10 +28,10 @@ def available_addons(cls, base_product_name, **options): query_params = { 'baseProductName': base_product_name } - return PlanDetail.get(relative_url, query_params, PlanDetail.build_options(**options)) + 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 PlanDetail.get(relative_url, query_params, PlanDetail.build_options(**options)) + return killbill.PlanDetail.get(relative_url, query_params, killbill.PlanDetail.build_options(**options)) From 83ab80f11baa1209345a63068d3df34143f43f5f Mon Sep 17 00:00:00 2001 From: ftorresan Date: Tue, 6 Feb 2018 12:03:52 +0100 Subject: [PATCH 19/38] Added bundle --- killbill/__init__.py | 1 + killbill/bundle.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 killbill/bundle.py diff --git a/killbill/__init__.py b/killbill/__init__.py index 2ed86f3..84ef6c0 100644 --- a/killbill/__init__.py +++ b/killbill/__init__.py @@ -40,6 +40,7 @@ from killbill.resource import Resource from killbill.account import Account +from killbill.bundle import Bundle from killbill.catalog import Catalog from killbill.payment_method import PaymentMethod from killbill.plan_detail import PlanDetail diff --git a/killbill/bundle.py b/killbill/bundle.py new file mode 100644 index 0000000..aa7a770 --- /dev/null +++ b/killbill/bundle.py @@ -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)) From 95cfc79be6407ff08404832442137afcb081da56 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Tue, 6 Feb 2018 12:48:56 +0100 Subject: [PATCH 20/38] Fix plan detail serialization --- killbill/plan_detail.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/killbill/plan_detail.py b/killbill/plan_detail.py index ecbb2b1..e164fb8 100644 --- a/killbill/plan_detail.py +++ b/killbill/plan_detail.py @@ -20,3 +20,9 @@ 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 \ No newline at end of file From 1b7793786aa44d631473e5e7e9fa73fecd29fb07 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 8 Feb 2018 12:34:01 +0100 Subject: [PATCH 21/38] Fix account update method. --- killbill/account.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/killbill/account.py b/killbill/account.py index 9c6a02a..4a9ae23 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -37,17 +37,19 @@ def create(self, user=killbill.user, reason=None, comment=None, **options): return self.refresh(created_account, **options) def update(self, **options): - return self.put("%s/%s" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), - self.to_json(), - {}, - self.build_options(**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)) - 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), "{}", { @@ -70,7 +72,8 @@ def find_by_external_key(cls, external_key, **options): 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): + 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, From a298e5364f97f29d556e8996abfb57966420b756 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Fri, 9 Feb 2018 18:04:22 +0100 Subject: [PATCH 22/38] Added change_plan method for subscription --- killbill/subscription.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/killbill/subscription.py b/killbill/subscription.py index 6fb29a9..43d4726 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -43,3 +43,28 @@ def create(self, user=killbill.user, reason=None, comment=None, requested_date=N **options )) return self.refresh(created_subscription, **options) + + def change_plan(self, update, user=killbill.user, reason=None, comment=None, requested_date=None, billing_policy=None, call_completion=False, **options): + query_params = {} + + if call_completion: + query_params['callCompletion'] = call_completion + + if requested_date: + query_params['entitlementDate'] = requested_date + query_params['billingDate'] = requested_date + + for key, value in update.items(): + setattr(self, key, value) + + updated_subscription = self.put("%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), + self.to_json(), + query_params, + self.build_options( + user=user, + reason=reason, + comment=comment, + **options + )) + + return self.fromJson(updated_subscription['body']) \ No newline at end of file From dfedd45be00dc7c5d0936beda1460e0958a837b9 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Fri, 9 Feb 2018 18:16:37 +0100 Subject: [PATCH 23/38] Add subscription finder method. --- killbill/subscription.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/killbill/subscription.py b/killbill/subscription.py index 43d4726..3dedf96 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -67,4 +67,12 @@ def change_plan(self, update, user=killbill.user, reason=None, comment=None, req **options )) - return self.fromJson(updated_subscription['body']) \ No newline at end of file + return self.fromJson(updated_subscription['body']) + + @classmethod + def find_by_id(cls, subscription_id, audit='NONE', **options): + relative_url = "%s/%s" % (cls.KILLBILL_API_ENTITLEMENT_PREFIX, subscription_id) + query_params = { + 'audit': audit + } + return cls.get(relative_url, query_params, cls.build_options(**options)) From 6cad122033df2a633ef24924a17bfc2cb4895025 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Wed, 14 Feb 2018 09:42:57 +0100 Subject: [PATCH 24/38] Added list invoices for account API endpoint --- killbill/account.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/killbill/account.py b/killbill/account.py index 4a9ae23..656247c 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -64,6 +64,17 @@ 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 self.get("%s/%s/invoices" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), + { + 'withItems': with_items, + 'withMigrationInvoices': with_migration_invoices, + 'unpaidInvoicesOnly': unpaid_invoices_only, + 'audit': audit + }, + self.build_options(**options)) + @classmethod def find_by_external_key(cls, external_key, **options): query_params = { From 5a582f7a20ae4b3351f3a1a96d5e7f228fc2ac07 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Wed, 14 Feb 2018 12:10:56 +0100 Subject: [PATCH 25/38] Added invoice class --- killbill/__init__.py | 1 + killbill/account.py | 9 +++++---- killbill/invoice.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 killbill/invoice.py diff --git a/killbill/__init__.py b/killbill/__init__.py index 84ef6c0..6d078a9 100644 --- a/killbill/__init__.py +++ b/killbill/__init__.py @@ -42,6 +42,7 @@ from killbill.account import Account from killbill.bundle import Bundle from killbill.catalog import Catalog +from killbill.invoice import Invoice from killbill.payment_method import PaymentMethod from killbill.plan_detail import PlanDetail from killbill.subscription import Subscription diff --git a/killbill/account.py b/killbill/account.py index 656247c..20b69f1 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -16,6 +16,7 @@ # under the License. # import killbill +from killbill import Bundle, Invoice class Account(killbill.Resource): @@ -44,9 +45,9 @@ def update(self, **options): return self.fromJson(updated_account['body']) def bundles(self, **options): - return self.get("%s/%s/bundles" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), + return Bundle.get("%s/%s/bundles" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), {}, - self.build_options(**options)) + Bundle.build_options(**options)) def close(self, cancel_all_subscriptions, write_off_unpaid_invoices, item_adjust_unpaid_invoices, user, reason=None, comment=None, **options): @@ -66,14 +67,14 @@ def close(self, cancel_all_subscriptions, write_off_unpaid_invoices, item_adjust def invoices(self, with_items=False, with_migration_invoices=False, unpaid_invoices_only=False, audit='NONE', **options): - return self.get("%s/%s/invoices" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), + return 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 }, - self.build_options(**options)) + Invoice.build_options(**options)) @classmethod def find_by_external_key(cls, external_key, **options): diff --git a/killbill/invoice.py b/killbill/invoice.py new file mode 100644 index 0000000..570c493 --- /dev/null +++ b/killbill/invoice.py @@ -0,0 +1,37 @@ +# +# 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) + return cls.get(relative_url, {}, cls.build_options(accept='text/html', **options)) From 84b28be40f09bb0478dc34007f07a29a1994d0f6 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Wed, 14 Feb 2018 12:13:02 +0100 Subject: [PATCH 26/38] Added invoice class --- killbill/account.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/killbill/account.py b/killbill/account.py index 20b69f1..030b7b1 100644 --- a/killbill/account.py +++ b/killbill/account.py @@ -16,7 +16,6 @@ # under the License. # import killbill -from killbill import Bundle, Invoice class Account(killbill.Resource): @@ -45,9 +44,9 @@ def update(self, **options): return self.fromJson(updated_account['body']) def bundles(self, **options): - return Bundle.get("%s/%s/bundles" % (self.KILLBILL_API_ACCOUNTS_PREFIX, self.accountId), - {}, - Bundle.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): @@ -67,14 +66,14 @@ def close(self, cancel_all_subscriptions, write_off_unpaid_invoices, item_adjust def invoices(self, with_items=False, with_migration_invoices=False, unpaid_invoices_only=False, audit='NONE', **options): - return 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 - }, - Invoice.build_options(**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): From 7464aa62426a01d456e912ffa4d69025c06b6747 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Wed, 14 Feb 2018 13:17:30 +0100 Subject: [PATCH 27/38] Fix options --- killbill/invoice.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/killbill/invoice.py b/killbill/invoice.py index 570c493..e561965 100644 --- a/killbill/invoice.py +++ b/killbill/invoice.py @@ -34,4 +34,5 @@ def find_by_id_or_number(cls, id_or_number, with_items=True, audit="NONE", **opt @classmethod def as_html(cls, invoice_id, **options): relative_url = "%s/%s/html" % (cls.KILLBILL_API_INVOICE_PREFIX, invoice_id) - return cls.get(relative_url, {}, cls.build_options(accept='text/html', **options)) + options['accept'] = 'text/html' + return cls.get(relative_url, {}, cls.build_options(**options)) From eac99a60003452383cc1fa78612dc0ad21b3e4e9 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Wed, 14 Feb 2018 13:24:47 +0100 Subject: [PATCH 28/38] Fix invoice pdf response --- killbill/invoice.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/killbill/invoice.py b/killbill/invoice.py index e561965..f6520d5 100644 --- a/killbill/invoice.py +++ b/killbill/invoice.py @@ -35,4 +35,8 @@ def find_by_id_or_number(cls, id_or_number, with_items=True, audit="NONE", **opt def as_html(cls, invoice_id, **options): relative_url = "%s/%s/html" % (cls.KILLBILL_API_INVOICE_PREFIX, invoice_id) options['accept'] = 'text/html' - return cls.get(relative_url, {}, cls.build_options(**options)) + options = cls.build_options(**options) + options['method'] = 'GET' + options['queryParams'] = {} + raw_get_response = cls.send_request(relative_url, options) + return raw_get_response['body'] From 32af48d9db37baddca8bcf1f6bc4c08d3fa87b15 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 22 Mar 2018 12:36:34 +0100 Subject: [PATCH 29/38] Added full catalog endpoint --- killbill/catalog.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/killbill/catalog.py b/killbill/catalog.py index d5e3797..4ddd82d 100644 --- a/killbill/catalog.py +++ b/killbill/catalog.py @@ -35,3 +35,11 @@ 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 + query_params = { + 'requestedDate': requested_date + } + return cls.get(relative_url, query_params, cls.build_options(**options)) From aff77fe3381354e4722e6b69e63bcdb68789afe4 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Wed, 28 Mar 2018 16:47:10 +0200 Subject: [PATCH 30/38] Added refresh query parameter to payment method resource --- killbill/payment_method.py | 4 ++++ killbill/resource.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/killbill/payment_method.py b/killbill/payment_method.py index abbedfd..aaf7e2f 100644 --- a/killbill/payment_method.py +++ b/killbill/payment_method.py @@ -22,6 +22,10 @@ class PaymentMethod(killbill.Resource): 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), diff --git a/killbill/resource.py b/killbill/resource.py index a3cbae3..a246c0a 100644 --- a/killbill/resource.py +++ b/killbill/resource.py @@ -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): From af62e05daad9627b0a31e30cb985ea45569dbb9b Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 29 Mar 2018 15:11:20 +0200 Subject: [PATCH 31/38] Add custom fields for subscription --- killbill/__init__.py | 1 + killbill/custom_field.py | 22 ++++++++++++++++++++ killbill/subscription.py | 43 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 killbill/custom_field.py diff --git a/killbill/__init__.py b/killbill/__init__.py index 6d078a9..a93370a 100644 --- a/killbill/__init__.py +++ b/killbill/__init__.py @@ -42,6 +42,7 @@ 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 diff --git a/killbill/custom_field.py b/killbill/custom_field.py new file mode 100644 index 0000000..b03aa11 --- /dev/null +++ b/killbill/custom_field.py @@ -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) \ No newline at end of file diff --git a/killbill/subscription.py b/killbill/subscription.py index 3dedf96..384a2c0 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -23,7 +23,8 @@ class Subscription(killbill.Resource): def __init__(self, **d): super(Subscription, self).__init__(d) - def create(self, user=killbill.user, reason=None, comment=None, requested_date=None, call_completion=False, **options): + def create(self, user=killbill.user, reason=None, comment=None, requested_date=None, call_completion=False, + **options): query_params = {} if call_completion: @@ -44,7 +45,8 @@ def create(self, user=killbill.user, reason=None, comment=None, requested_date=N )) return self.refresh(created_subscription, **options) - def change_plan(self, update, user=killbill.user, reason=None, comment=None, requested_date=None, billing_policy=None, call_completion=False, **options): + def change_plan(self, update, user=killbill.user, reason=None, comment=None, requested_date=None, + billing_policy=None, call_completion=False, **options): query_params = {} if call_completion: @@ -69,6 +71,43 @@ def change_plan(self, update, user=killbill.user, reason=None, comment=None, req return self.fromJson(updated_subscription['body']) + def add_custom_fields(self, custom_fields, user=killbill.user, reason=None, comment=None, **options): + query_params = {} + custom_fields_response = killbill.CustomField.post( + "%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), + killbill.json.dumps(custom_fields), + query_params, + self.build_options( + user=user, + reason=reason, + comment=comment, + **options + )) + return killbill.CustomField.fromJson(custom_fields_response['body']) + + def remove_custom_fields(self, custom_fields=[], user=killbill.user, reason=None, comment=None, **options): + query_params = {} + killbill.CustomField.delete("%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), + killbill.json.dumps(custom_fields), + query_params, + self.build_options( + user=user, + reason=reason, + comment=comment, + **options + )) + + def custom_fields(self, user=killbill.user, reason=None, comment=None, **options): + query_params = {} + return killbill.CustomField.get("%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), + query_params, + self.build_options( + user=user, + reason=reason, + comment=comment, + **options + )) + @classmethod def find_by_id(cls, subscription_id, audit='NONE', **options): relative_url = "%s/%s" % (cls.KILLBILL_API_ENTITLEMENT_PREFIX, subscription_id) From f8267fb64e37de46c0ae64de8dd1d413a2981792 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 29 Mar 2018 15:35:06 +0200 Subject: [PATCH 32/38] Add custom fields for subscription --- killbill/subscription.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/killbill/subscription.py b/killbill/subscription.py index 384a2c0..f9a6ef5 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -85,10 +85,13 @@ def add_custom_fields(self, custom_fields, user=killbill.user, reason=None, comm )) return killbill.CustomField.fromJson(custom_fields_response['body']) - def remove_custom_fields(self, custom_fields=[], user=killbill.user, reason=None, comment=None, **options): + def remove_custom_fields(self, custom_field_list=None, user=killbill.user, reason=None, comment=None, **options): query_params = {} + if custom_field_list or len(custom_field_list) > 0: + query_params['customFieldList'] = ','.join(custom_field_list) + killbill.CustomField.delete("%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), - killbill.json.dumps(custom_fields), + "{}", query_params, self.build_options( user=user, From 68a97daedf319401e2c834bc9f587b4a31538fc0 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 29 Mar 2018 15:52:01 +0200 Subject: [PATCH 33/38] Add custom fields for subscription --- killbill/subscription.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/killbill/subscription.py b/killbill/subscription.py index f9a6ef5..43f57b6 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -74,7 +74,7 @@ def change_plan(self, update, user=killbill.user, reason=None, comment=None, req def add_custom_fields(self, custom_fields, user=killbill.user, reason=None, comment=None, **options): query_params = {} custom_fields_response = killbill.CustomField.post( - "%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), + "%s/%s/customFields" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), killbill.json.dumps(custom_fields), query_params, self.build_options( @@ -90,7 +90,7 @@ def remove_custom_fields(self, custom_field_list=None, user=killbill.user, reaso if custom_field_list or len(custom_field_list) > 0: query_params['customFieldList'] = ','.join(custom_field_list) - killbill.CustomField.delete("%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), + killbill.CustomField.delete("%s/%s/customFields" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), "{}", query_params, self.build_options( @@ -102,7 +102,7 @@ def remove_custom_fields(self, custom_field_list=None, user=killbill.user, reaso def custom_fields(self, user=killbill.user, reason=None, comment=None, **options): query_params = {} - return killbill.CustomField.get("%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), + return killbill.CustomField.get("%s/%s/customFields" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), query_params, self.build_options( user=user, From 30595b29e68d576aa9f9718ba6a9ad23531f5c94 Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 29 Mar 2018 16:20:57 +0200 Subject: [PATCH 34/38] Add custom fields for subscription --- killbill/subscription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/killbill/subscription.py b/killbill/subscription.py index 43f57b6..9f7a369 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -87,7 +87,7 @@ def add_custom_fields(self, custom_fields, user=killbill.user, reason=None, comm def remove_custom_fields(self, custom_field_list=None, user=killbill.user, reason=None, comment=None, **options): query_params = {} - if custom_field_list or len(custom_field_list) > 0: + if custom_field_list and len(custom_field_list) > 0: query_params['customFieldList'] = ','.join(custom_field_list) killbill.CustomField.delete("%s/%s/customFields" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), From ba98694260a03b2271308b278265386563f0fe7c Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 29 Mar 2018 16:26:02 +0200 Subject: [PATCH 35/38] Add custom fields for subscription --- killbill/subscription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/killbill/subscription.py b/killbill/subscription.py index 9f7a369..b1b03a0 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -83,7 +83,7 @@ def add_custom_fields(self, custom_fields, user=killbill.user, reason=None, comm comment=comment, **options )) - return killbill.CustomField.fromJson(custom_fields_response['body']) + return killbill.CustomField().refresh(custom_fields_response) def remove_custom_fields(self, custom_field_list=None, user=killbill.user, reason=None, comment=None, **options): query_params = {} From 1dd16d8d12281b032d952f42238c4ea59d83221f Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 29 Mar 2018 16:27:51 +0200 Subject: [PATCH 36/38] Add custom fields for subscription --- killbill/subscription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/killbill/subscription.py b/killbill/subscription.py index b1b03a0..72be7e2 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -83,7 +83,7 @@ def add_custom_fields(self, custom_fields, user=killbill.user, reason=None, comm comment=comment, **options )) - return killbill.CustomField().refresh(custom_fields_response) + return killbill.CustomField().refresh(custom_fields_response, **options) def remove_custom_fields(self, custom_field_list=None, user=killbill.user, reason=None, comment=None, **options): query_params = {} From 946e94e4a34258cb29bfc4b8164d1531b4487a9c Mon Sep 17 00:00:00 2001 From: ftorresan Date: Thu, 29 Mar 2018 17:08:59 +0200 Subject: [PATCH 37/38] Add custom fields for subscription --- killbill/subscription.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/killbill/subscription.py b/killbill/subscription.py index 72be7e2..5e36336 100644 --- a/killbill/subscription.py +++ b/killbill/subscription.py @@ -71,6 +71,37 @@ def change_plan(self, update, user=killbill.user, reason=None, comment=None, req return self.fromJson(updated_subscription['body']) + def cancel(self, requested_date=None, call_completion=False, call_timeout_sec=5, entitlement_policy=None, + billing_policy=None, use_requested_date_for_billing=False, plugin_property=None, + user=killbill.user, reason=None, comment=None, **options): + + query_params = {} + + if requested_date: + query_params['requestedDate'] = requested_date + if call_completion: + query_params['callCompletion'] = call_completion + if call_timeout_sec: + query_params['callTimeoutSec'] = call_timeout_sec + if entitlement_policy: + query_params['entitlementPolicy'] = entitlement_policy + if billing_policy: + query_params['billingPolicy'] = billing_policy + if use_requested_date_for_billing: + query_params['useRequestedDateForBilling'] = use_requested_date_for_billing + if plugin_property: + query_params['pluginProperty'] = plugin_property + + return self.delete("%s/%s" % (self.KILLBILL_API_ENTITLEMENT_PREFIX, self.subscriptionId), + "{}", + query_params, + self.build_options( + user=user, + reason=reason, + comment=comment, + **options + )) + def add_custom_fields(self, custom_fields, user=killbill.user, reason=None, comment=None, **options): query_params = {} custom_fields_response = killbill.CustomField.post( From 099666f4fd7f513da702f82cc8947aeaf124602e Mon Sep 17 00:00:00 2001 From: ftorresan Date: Wed, 6 Jun 2018 16:02:06 +0200 Subject: [PATCH 38/38] Fix catalog json format --- killbill/catalog.py | 1 + 1 file changed, 1 insertion(+) diff --git a/killbill/catalog.py b/killbill/catalog.py index 4ddd82d..fd93a60 100644 --- a/killbill/catalog.py +++ b/killbill/catalog.py @@ -39,6 +39,7 @@ def available_base_plans(cls, **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 }