Skip to content

Commit a68aeb1

Browse files
committed
CR fixes
1 parent 58b7188 commit a68aeb1

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
## [0.3.6] - TBA
55

6+
### Added
7+
8+
- Added support for billing-api.
9+
610
### Bugfixes
711
- Fix `customer_monitoring_level` parameter in `login` method in agent-api v3.3/v3.4/v3.5 classes.
812

livechat/billing/api/v1.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def create_direct_charge(self,
3434
price (int): Price of the charge defined in cents.
3535
quantity (int): Number of the accounts within the organization.
3636
return_url (str): Redirection url for the client.
37-
per_account (bool): Whether or not the app is sold in ppa account model.
38-
test (str): Whether or not the direct charge is for test.
37+
per_account (bool): Whether or not the app is sold in ppa account model. Default: False.
38+
test (str): Whether or not the direct charge is for test. Default: False.
3939
payload (dict): Custom payload to be used as request's data.
4040
It overrides all other parameters provided for the method.
4141
headers (dict): Custom headers to be used with session headers.
@@ -82,7 +82,7 @@ def list_direct_charges(self,
8282
headers: dict = None) -> httpx.Response:
8383
''' Lists all direct charges.
8484
Args:
85-
page (int): Navigate to page number.
85+
page (int): Navigate to page number. Default: 1.
8686
status (str): Filter charges by status. One of pending, accepted, active, declined, processed, failed or success.
8787
order_client_id (str): Filter by specific `order_client_id`.
8888
params (dict): Custom params to be used in request's query string.
@@ -119,17 +119,20 @@ def activate_direct_charge(self,
119119
if payload is None:
120120
payload = prepare_payload(locals())
121121
del payload['charge_id']
122-
return self.session.put(f'{self.api_url}/direct_charge/{charge_id}',
123-
json=payload,
124-
headers=headers)
122+
return self.session.put(
123+
f'{self.api_url}/direct_charge/{charge_id}/activate',
124+
json=payload,
125+
headers=headers)
125126

126127
# ledger
127128

128129
def get_ledger(self,
130+
page: int = None,
129131
params: dict = None,
130132
headers: dict = None) -> httpx.Response:
131133
''' Returns current ledger.
132134
Args:
135+
page (int): Navigate to page number. Default: 1.
133136
params (dict): Custom params to be used in request's query string.
134137
It overrides all other parameters provided for the method.
135138
headers (dict): Custom headers to be used with session headers.
@@ -148,7 +151,7 @@ def get_ledger(self,
148151
def get_ledger_balance(self,
149152
params: dict = None,
150153
headers: dict = None) -> httpx.Response:
151-
''' Returns current ledger balance.
154+
''' Returns current ledger balance in cents.
152155
Args:
153156
params (dict): Custom params to be used in request's query string.
154157
It overrides all other parameters provided for the method.
@@ -178,15 +181,15 @@ def create_recurrent_charge(self,
178181
test: bool = True,
179182
payload: dict = None,
180183
headers: dict = None) -> httpx.Response:
181-
''' Creates a new reccurent charge for the user (periodic payment).
184+
''' Creates a new recurrent charge for the user (periodic payment).
182185
Args:
183-
name (str): Name of the reccurent charge.
186+
name (str): Name of the recurrent charge.
184187
price (int): Price of the charge defined in cents.
185188
return_url (str): Redirection url for the client.
186-
per_account (bool): Whether or not the app is sold in ppa account model.
187-
trial_days (int): Number of granted trial days.
188-
months (int): Charge frequency expressed in months.
189-
test (str): Whether or not the direct charge is for test.
189+
per_account (bool): Whether or not the app is sold in ppa account model. Default: False.
190+
trial_days (int): Number of granted trial days. Default: 0.
191+
months (int): Charge frequency expressed in months. Default: 1.
192+
test (str): Whether or not the direct charge is for test. Default: False.
190193
payload (dict): Custom payload to be used as request's data.
191194
It overrides all other parameters provided for the method.
192195
headers (dict): Custom headers to be used with session headers.
@@ -206,7 +209,7 @@ def get_recurrent_charge(self,
206209
charge_id: str,
207210
params: dict = None,
208211
headers: dict = None) -> httpx.Response:
209-
''' Gets specific reccurent charge.
212+
''' Gets specific recurrent charge.
210213
Args:
211214
charge_id (str): ID of the recurrent charge.
212215
params (dict): Custom params to be used in request's query string.
@@ -233,7 +236,7 @@ def list_recurrent_charges(self,
233236
headers: dict = None) -> httpx.Response:
234237
''' Lists all recurrent charges.
235238
Args:
236-
page (int): Navigate to specific page number.
239+
page (int): Navigate to specific page number. Default: 1.
237240
status (str): Filter charges by status. One of pending, accepted, active, declined, processed, failed or success.
238241
order_client_id (str): Filter by specific `order_client_id`.
239242
params (dict): Custom params to be used in request's query string.
@@ -255,7 +258,7 @@ def accept_recurrent_charge(self,
255258
charge_id: str,
256259
payload: dict = None,
257260
headers: dict = None) -> httpx.Response:
258-
''' Accpets specific reccurent charge.
261+
''' Accepets specific recurrent charge.
259262
Args:
260263
charge_id (str): ID of the recurrent charge.
261264
payload (dict): Custom payload to be used as request's data.
@@ -279,7 +282,7 @@ def decline_recurrent_charge(self,
279282
charge_id: str,
280283
payload: dict = None,
281284
headers: dict = None) -> httpx.Response:
282-
''' Declines specific reccurent charge.
285+
''' Declines specific recurrent charge.
283286
Args:
284287
charge_id (str): ID of the recurrent charge.
285288
payload (dict): Custom payload to be used as request's data.
@@ -303,7 +306,7 @@ def activate_recurrent_charge(self,
303306
charge_id: str,
304307
payload: dict = None,
305308
headers: dict = None) -> httpx.Response:
306-
''' Activates specific reccurent charge.
309+
''' Activates specific recurrent charge.
307310
Args:
308311
charge_id (str): ID of the recurrent charge.
309312
payload (dict): Custom payload to be used as request's data.
@@ -327,7 +330,7 @@ def cancel_recurrent_charge(self,
327330
charge_id: str,
328331
payload: dict = None,
329332
headers: dict = None) -> httpx.Response:
330-
''' Cancels specific reccurent charge.
333+
''' Cancels specific recurrent charge.
331334
Args:
332335
charge_id (str): ID of the recurrent charge.
333336
payload (dict): Custom payload to be used as request's data.

livechat/billing/base.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55

66
from __future__ import annotations
77

8+
from livechat.config import CONFIG
9+
810
from .api import BillingApiV1
911

12+
billing_url = CONFIG.get('billing_url')
13+
billing_version = CONFIG.get('billing_version')
14+
1015

1116
class BillingApi:
1217
''' Base class that allows retrieval of client for specific
1318
Billing API version. '''
1419
@staticmethod
1520
def get_client(token: str,
16-
version: str = 'v1',
17-
base_url: str = 'billing.livechatinc.com',
21+
version: str = billing_version,
22+
base_url: str = billing_url,
1823
http2: bool = False,
1924
proxies: dict = None,
2025
verify: bool = True) -> BillingApiV1:
@@ -23,7 +28,7 @@ def get_client(token: str,
2328
Args:
2429
token (str): Full token with type Bearer that will be
2530
used as `Authorization` header in requests to API.
26-
version (str): API's version. Defaults to the v2 version of API.
31+
version (str): Billing API's version. Defaults to the v1 version of Billing.
2732
base_url (str): API's base url. Defaults to API's production URL.
2833
http2 (bool): A boolean indicating if HTTP/2 support should be
2934
enabled. Defaults to `False`.
@@ -40,7 +45,7 @@ def get_client(token: str,
4045
ValueError: If the specified version does not exist.
4146
'''
4247
client = {
43-
'v1': BillingApiV1(token, base_url, http2, proxies, verify),
48+
'1': BillingApiV1(token, base_url, http2, proxies, verify),
4449
}.get(version)
4550
if not client:
4651
raise ValueError('Provided version does not exist.')

livechat/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
CONFIG = {
44
'url': 'api.livechatinc.com',
5+
'billing_url': 'billing.livechatinc.com',
56
'stable': '3.5',
67
'dev': '3.6',
8+
'billing_version': '1'
79
}

livechat/tests/test_billing_api_client.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import pytest
66

77
from livechat.billing.base import BillingApi
8+
from livechat.config import CONFIG
9+
10+
billing_url = CONFIG.get('billing_url')
11+
billing_version = CONFIG.get('billing_version')
812

913

1014
@pytest.fixture
@@ -40,7 +44,7 @@ def test_get_client_with_non_existing_version():
4044

4145
def test_get_client_with_valid_args(billing_api_client):
4246
''' Test if production API URL is used and token is added to headers for valid args. '''
43-
assert billing_api_client.api_url == 'https://billing.livechatinc.com/v1'
47+
assert billing_api_client.api_url == f'https://{billing_url}/v{billing_version}'
4448
assert billing_api_client.session.headers.get('Authorization') == 'test'
4549

4650

@@ -83,10 +87,3 @@ def test_client_supports_http_1():
8387
''' Test if client supports HTTP/1.1 protocol. '''
8488
client = BillingApi.get_client(token='test')
8589
assert client.create_direct_charge().http_version == 'HTTP/1.1'
86-
87-
88-
# At this point billing-api v1 support http2 but will always negotiate to use 'HTTP/1.1'
89-
# def test_client_supports_http_2():
90-
# ''' Test if client supports HTTP/2 protocol. '''
91-
# client = BillingApi.get_client(token='test', http2=True)
92-
# assert client.create_direct_charge().http_version == 'HTTP/2'

0 commit comments

Comments
 (0)