exsited 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- exsited-1.0.0/LICENSE.txt +21 -0
- exsited-1.0.0/PKG-INFO +294 -0
- exsited-1.0.0/README.md +276 -0
- exsited-1.0.0/exsited/__init__.py +0 -0
- exsited-1.0.0/exsited/common/__init__.py +0 -0
- exsited-1.0.0/exsited/common/ab_exception.py +18 -0
- exsited-1.0.0/exsited/common/sdk_conf.py +3 -0
- exsited-1.0.0/exsited/common/sdk_console.py +6 -0
- exsited-1.0.0/exsited/common/sdk_const.py +3 -0
- exsited-1.0.0/exsited/common/sdk_util.py +28 -0
- exsited-1.0.0/exsited/exsited/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/account/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/account/account.py +83 -0
- exsited-1.0.0/exsited/exsited/account/account_api_url.py +13 -0
- exsited-1.0.0/exsited/exsited/account/dto/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/account/dto/account_dto.py +137 -0
- exsited-1.0.0/exsited/exsited/account/dto/account_nested_dto.py +189 -0
- exsited-1.0.0/exsited/exsited/auth/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/auth/auth_api_url.py +2 -0
- exsited-1.0.0/exsited/exsited/auth/dto/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/auth/dto/token_dto.py +26 -0
- exsited-1.0.0/exsited/exsited/common/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/common/common_api_url.py +2 -0
- exsited-1.0.0/exsited/exsited/common/common_enum.py +6 -0
- exsited-1.0.0/exsited/exsited/common/dto/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/common/dto/common_dto.py +60 -0
- exsited-1.0.0/exsited/exsited/exsited_sdk.py +41 -0
- exsited-1.0.0/exsited/exsited/invoice/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/invoice/dto/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/invoice/dto/invoice_dto.py +60 -0
- exsited-1.0.0/exsited/exsited/invoice/invoice.py +100 -0
- exsited-1.0.0/exsited/exsited/invoice/invoice_api_url.py +4 -0
- exsited-1.0.0/exsited/exsited/order/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/order/dto/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/order/dto/order_dto.py +68 -0
- exsited-1.0.0/exsited/exsited/order/dto/order_nested_dto.py +89 -0
- exsited-1.0.0/exsited/exsited/order/dto/usage_dto.py +17 -0
- exsited-1.0.0/exsited/exsited/order/order.py +34 -0
- exsited-1.0.0/exsited/exsited/order/order_api_url.py +7 -0
- exsited-1.0.0/exsited/exsited/payment/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/payment/dto/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/payment/dto/payment_dto.py +83 -0
- exsited-1.0.0/exsited/exsited/payment/payment.py +20 -0
- exsited-1.0.0/exsited/exsited/payment/payment_api_url.py +4 -0
- exsited-1.0.0/exsited/exsited/purchase_order/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/purchase_order/dto/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/purchase_order/dto/purchase_order_dto.py +101 -0
- exsited-1.0.0/exsited/exsited/purchase_order/purchase_order.py +17 -0
- exsited-1.0.0/exsited/exsited/purchase_order/purchase_order_api_url.py +5 -0
- exsited-1.0.0/exsited/exsited/setting/__init__.py +0 -0
- exsited-1.0.0/exsited/exsited/setting/setting.py +8 -0
- exsited-1.0.0/exsited/exsited/setting/setting_api_url.py +2 -0
- exsited-1.0.0/exsited/http/__init__.py +0 -0
- exsited-1.0.0/exsited/http/ab_rest_processor.py +137 -0
- exsited-1.0.0/exsited/http/http_const.py +16 -0
- exsited-1.0.0/exsited/http/http_requester.py +88 -0
- exsited-1.0.0/exsited/sdlize/__init__.py +0 -0
- exsited-1.0.0/exsited/sdlize/ab_base_dto.py +9 -0
- exsited-1.0.0/exsited/sdlize/dto_base.py +98 -0
- exsited-1.0.0/exsited.egg-info/PKG-INFO +294 -0
- exsited-1.0.0/exsited.egg-info/SOURCES.txt +65 -0
- exsited-1.0.0/exsited.egg-info/dependency_links.txt +1 -0
- exsited-1.0.0/exsited.egg-info/not-zip-safe +1 -0
- exsited-1.0.0/exsited.egg-info/requires.txt +4 -0
- exsited-1.0.0/exsited.egg-info/top_level.txt +1 -0
- exsited-1.0.0/setup.cfg +4 -0
- exsited-1.0.0/setup.py +35 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 exsited
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
exsited-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: exsited
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Exsited SDK Support
|
|
5
|
+
Home-page: https://github.com/exsited/exsited-python
|
|
6
|
+
Author: Ashiq Rahman
|
|
7
|
+
Author-email: ashiq@webalive.com.au
|
|
8
|
+
Platform: any
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE.txt
|
|
14
|
+
Requires-Dist: requests==2.31.0
|
|
15
|
+
Requires-Dist: setuptools
|
|
16
|
+
Requires-Dist: peewee
|
|
17
|
+
Requires-Dist: mysql-connector-python
|
|
18
|
+
|
|
19
|
+
# Exsited Python SDK
|
|
20
|
+
The Exsited Python SDK provides an easy-to-use library for integrating Exsited services into your project. This includes Custom Integration, Onsite Integration and all APIs.
|
|
21
|
+
|
|
22
|
+
***
|
|
23
|
+
## Table of Contents
|
|
24
|
+
- [Requirements](#Requirements)
|
|
25
|
+
- [Installation](#Installation)
|
|
26
|
+
- [Configuration](#Configuration)
|
|
27
|
+
- [Authentication](#Authentication)
|
|
28
|
+
- [Getting Started](#Getting-Started)
|
|
29
|
+
- [Testing](#Testing)
|
|
30
|
+
- [API Documentation](#API-Documentation)
|
|
31
|
+
- [Usage charge_item_uuid Association](#Usage-charge_item_uuid-Association)
|
|
32
|
+
# Requirements
|
|
33
|
+
Python 3.12 and Later
|
|
34
|
+
|
|
35
|
+
# Installation
|
|
36
|
+
```bash
|
|
37
|
+
#Installation
|
|
38
|
+
pip install exsited
|
|
39
|
+
```
|
|
40
|
+
# Configuration
|
|
41
|
+
|
|
42
|
+
To set up the Exsited SDK, you'll require your `Client ID`, `Client Secret`, and `Redirect URL`. If you have not received these details already, please reach out to your designated client contact to obtain them
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Authentication
|
|
47
|
+
1. **Locate `common_data.py`:** Open the SKD project directory on an IDE and navigate to the `common_data.py` file which is located in the following path: `tests/common/common_data.py`.
|
|
48
|
+
2. **Update `get_request_token_dto` function:** Within the `common_data.py` class, locate the method named `get_request_token_dto` and update it with the credentials you were provided.
|
|
49
|
+
<img src="blob:https://webalive.atlassian.net/c058a466-42ce-405e-b3ca-dfbbb81a9939#media-blob-url=true&id=ee9aff06-3e79-4823-b0bf-9ef83f5d3c9a&collection=contentId-558825510&contextId=558825510&mimeType=image%2Fpng&name=image.png&size=435487&width=2049&height=922&alt=image.png" alt="">
|
|
50
|
+
|
|
51
|
+
3. **Provide Credential Values:** Populate the mandatory fields (`clientId`, `clientSecret`, `redirectUri`, and `ExsitedUrl`) within the `RequestTokenDTO` object. However, **replace the placeholder values** in the following code block with your actual credentials:
|
|
52
|
+
|
|
53
|
+
### Code Example:
|
|
54
|
+
```python
|
|
55
|
+
def get_request_token_dto():
|
|
56
|
+
return RequestTokenDTO(
|
|
57
|
+
grantType="client_credentials",
|
|
58
|
+
clientId="[YOUR_CLIENT_ID]", # Replace with your actual Client ID
|
|
59
|
+
clientSecret="[YOUR_CLIENT_SECRET]", # Replace with your actual Client Secret
|
|
60
|
+
redirectUri="[YOUR_REDIRECT_URI]", # Replace with your actual Redirect URL
|
|
61
|
+
ExsitedUrl="[YOUR_EXSITED_SERVER_URL]" # Replace with your Exsited server URL,
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
### Credentials Table
|
|
65
|
+
| Key | value |
|
|
66
|
+
|--------------|---------------------------|
|
|
67
|
+
| clientId | "[YOUR_CLIENT_ID]" |
|
|
68
|
+
| clientSecret | "[YOUR_CLIENT_SECRET]" |
|
|
69
|
+
| redirectUri | "[YOUR_REDIRECT_URI]" |
|
|
70
|
+
| ExsitedUrl | "[YOUR_EXSITED_SERVER_URL]" |
|
|
71
|
+
|
|
72
|
+
# Getting Started
|
|
73
|
+
Follow the common pattern to test the functions on the SDK. All the tests can be done on the test files located in the Tests directory.
|
|
74
|
+
|
|
75
|
+
### Testing SDK Functions
|
|
76
|
+
|
|
77
|
+
### Example Method 1: `test_account_create_basic`
|
|
78
|
+
***
|
|
79
|
+
|
|
80
|
+
### Request Parameters
|
|
81
|
+
|
|
82
|
+
| Parameter | Description | Type | Required |
|
|
83
|
+
|-----------------|---------------------------------------------------------|------------------|----------|
|
|
84
|
+
| account | Contains the account details to be created. | `AccountDataDTO` | Yes |
|
|
85
|
+
| account.name | The name of the account. | `str` | Yes |
|
|
86
|
+
| account.emailAddress | The email address associated with the account. | `str` | Yes |
|
|
87
|
+
|
|
88
|
+
### Example Request Data (JSON Representation)
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"account": {
|
|
93
|
+
"name": "Example Name",
|
|
94
|
+
"emailAddress": "example@example.com"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
### Function Signature
|
|
99
|
+
```Python
|
|
100
|
+
def test_account_create_basic():
|
|
101
|
+
SDKConfig.PRINT_REQUEST_DATA = False
|
|
102
|
+
SDKConfig.PRINT_RAW_RESPONSE = False
|
|
103
|
+
|
|
104
|
+
exsited_sdk: ExsitedSDK = ExsitedSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
# You will edit the following request_data
|
|
108
|
+
request_data = AccountCreateDTO(account=AccountDataDTO(name="Example Name", emailAddress="example@example.com"))
|
|
109
|
+
|
|
110
|
+
response = exsited_sdk.account.create(request_data=request_data)
|
|
111
|
+
print(response)
|
|
112
|
+
except ABException as ab:
|
|
113
|
+
print(ab)
|
|
114
|
+
print(ab.get_errors())
|
|
115
|
+
print(ab.raw_response)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Example Method 2: `test_order_create_basic`
|
|
119
|
+
***
|
|
120
|
+
| Parameter | Description | Type | Required |
|
|
121
|
+
|------------|---------------------------------------------|------|----------|
|
|
122
|
+
| accountId | The ID of the account associated with the order. | str | Yes |
|
|
123
|
+
| item_id | The ID of the item being ordered. | str | Yes |
|
|
124
|
+
| quantity | The quantity of the item being ordered. | str | Yes |
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"order": {
|
|
129
|
+
"accountId": "30PS79",
|
|
130
|
+
"lines": [
|
|
131
|
+
{
|
|
132
|
+
"item_id": "ITEM-0055",
|
|
133
|
+
"quantity": "1"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
### Function Signature
|
|
140
|
+
```Python
|
|
141
|
+
def test_order_create_basic():
|
|
142
|
+
SDKConfig.PRINT_REQUEST_DATA = True
|
|
143
|
+
SDKConfig.PRINT_RAW_RESPONSE = False
|
|
144
|
+
|
|
145
|
+
exsited_sdk: ExsitedSDK = ExsitedSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
|
|
146
|
+
|
|
147
|
+
try:
|
|
148
|
+
# You will edit the following request_data
|
|
149
|
+
request_data = OrderCreateDTO(order=OrderDataDTO(accountId="30PS79").add_line(item_id="ITEM-0055", quantity="1"))
|
|
150
|
+
response = exsited_sdk.order.create(request_data=request_data)
|
|
151
|
+
print(response)
|
|
152
|
+
|
|
153
|
+
except ABException as ab:
|
|
154
|
+
print(ab)
|
|
155
|
+
print(ab.get_errors())
|
|
156
|
+
print(ab.raw_response)
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
***
|
|
160
|
+
### Response
|
|
161
|
+
| Field | Description |
|
|
162
|
+
|----------|-------------------------------------------------------------|
|
|
163
|
+
| response | The response from the the method being called. |
|
|
164
|
+
| errors | Any errors encountered during the account creation process. |
|
|
165
|
+
|
|
166
|
+
### Error Handling
|
|
167
|
+
| Field | Description |
|
|
168
|
+
|-----------------|---------------------------------------------------------|
|
|
169
|
+
| ab | The exception object. |
|
|
170
|
+
| ab.get_errors() | A list of errors that occurred during the account creation process. |
|
|
171
|
+
| ab.raw_response | The raw response data from the API call, useful for debugging. |
|
|
172
|
+
|
|
173
|
+
# Testing
|
|
174
|
+
### Executing Functions
|
|
175
|
+
To test the SDK functions, adhere to the common pattern outlined below. All tests should be conducted using the provided test files located in the "Tests" directory.
|
|
176
|
+
|
|
177
|
+
1. Set up the environment: Ensure that the SDK configuration is appropriately initialized for testing purposes.
|
|
178
|
+
|
|
179
|
+
2. Customize request data: Adjust the `request_data` as needed for the specific function being tested.
|
|
180
|
+
|
|
181
|
+
3. Execute the function: Call the desired function from the SDK, updating the `request_data` inside the function body.
|
|
182
|
+
|
|
183
|
+
### Required Fields
|
|
184
|
+
The following tables contain for the required fields for the test cases
|
|
185
|
+
### Account
|
|
186
|
+
|
|
187
|
+
| Function Name | Required Fields |
|
|
188
|
+
|-----------------------------------|--------------------------------|
|
|
189
|
+
| test_account_create_basic | name, emailAddress |
|
|
190
|
+
| test_account_update_info | id (Account ID) |
|
|
191
|
+
| test_account_list_basic | n/a |
|
|
192
|
+
| test_account_details | id (Account ID) |
|
|
193
|
+
| test_account_delete | id (Account ID) |
|
|
194
|
+
| test_account_payment_methods_add | processorType, default, paymentProcessor, reference |
|
|
195
|
+
| test_account_payment_card_methods_add | processorType, default, paymentProcessor, reference, cardType, token, cardNumber, expiryMonth, expiryYear |
|
|
196
|
+
| test_list_payment_methods | account_id (Account ID) |
|
|
197
|
+
| test_delete_payment_methods | account_id (Account ID), reference |
|
|
198
|
+
| test_payment_method_details | account_id (Account ID), reference |
|
|
199
|
+
|
|
200
|
+
### Order
|
|
201
|
+
| Function | Required Parameters |
|
|
202
|
+
|----------------------------|-----------------------------------|
|
|
203
|
+
| test_order_create_basic | accountId, item_id, quantity (Item Quantity) |
|
|
204
|
+
| test_order_list_basic | n/a |
|
|
205
|
+
| test_order_details | id (Order ID) |
|
|
206
|
+
| test_order_cancel | id (Order ID), effective_date |
|
|
207
|
+
| test_order_usage_add | chargeItemUuid, chargingPeriod, quantity, startTime, endTime, type |
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
### Invoice
|
|
211
|
+
| Function | Required Parameters |
|
|
212
|
+
|-----------------------|----------------------|
|
|
213
|
+
| test_invoice_list | n/a |
|
|
214
|
+
| test_invoice_details | id |
|
|
215
|
+
|
|
216
|
+
# API Documentation
|
|
217
|
+
[API Documentation](https://callservice.atlassian.net/wiki/spaces/Implementa/pages/8159248/API+Documentations)
|
|
218
|
+
|
|
219
|
+
# Usage `charge_item_uuid` Association
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
The `order_usage_db` folder contains the functionality for handling database operations related to orders within the Exsited SDK. This module is responsible for connecting to the database, managing orders, processing order data, and saving the relevant information to the database.
|
|
224
|
+
|
|
225
|
+
### Components of `order_usage_db`
|
|
226
|
+
|
|
227
|
+
1. **`connect_with_db.py`**
|
|
228
|
+
- Manages the database connection setup, including functions for establishing and terminating connections
|
|
229
|
+
|
|
230
|
+
2. **`order_manager.py`**
|
|
231
|
+
- Manages Order data, to create rows for the database where the relevant associations are made in order to create usages easily using **`charge_item_uuid`**
|
|
232
|
+
|
|
233
|
+
3. **`order_model.py`**
|
|
234
|
+
- Contains the structure of the order association table
|
|
235
|
+
|
|
236
|
+
4. **`order_service.py`**
|
|
237
|
+
- Contains the function to create the association records
|
|
238
|
+
|
|
239
|
+
5. **`save_to_db.py`**
|
|
240
|
+
- Implements the logic to persist order association data to the database. It interacts with the `connect_with_db.py` module to perform save operations.
|
|
241
|
+
|
|
242
|
+
### Adding Data To the Association Table
|
|
243
|
+
|
|
244
|
+
After configuring your database connection in `connect_with_db.py`, you can use the other scripts to manage orders and persist data to your database. For example, you can create and process an order using `order_manager.py` and then save it using `save_to_db.py`.
|
|
245
|
+
|
|
246
|
+
#### Example Workflow
|
|
247
|
+
|
|
248
|
+
1. **Adding Database Details:**
|
|
249
|
+
In the SaveToDB class within the order_usage_db module, ensure that you update the OrderManager
|
|
250
|
+
initialization with your specific database connection details, such as the database name, username,
|
|
251
|
+
password, and host address.
|
|
252
|
+
2. ```python
|
|
253
|
+
class SaveToDB:
|
|
254
|
+
def process_order_data(_order_id: str, _account_id: str, _item_id: str, _item_name: str, _charge_item_uuid: str):
|
|
255
|
+
# Add your database details below
|
|
256
|
+
order_manager = OrderManager('your_database_name', 'your_username', 'your_password', 'your_host_address')
|
|
257
|
+
order_manager.connect_to_db()
|
|
258
|
+
order_manager.process_order(
|
|
259
|
+
account_id=_account_id,
|
|
260
|
+
order_id=_order_id,
|
|
261
|
+
item_id=_item_id,
|
|
262
|
+
item_name=_item_name,
|
|
263
|
+
charge_item_uuid=_charge_item_uuid
|
|
264
|
+
)
|
|
265
|
+
order_manager.disconnect_from_db()
|
|
266
|
+
|
|
267
|
+
3. Once the database details and other necessary configurations have been added, you can use the following example to add an order.
|
|
268
|
+
This will automatically update the association tables, allowing you to retrieve the relevant details needed to update usage data.
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
def test_order_create_basic():
|
|
272
|
+
SDKConfig.PRINT_REQUEST_DATA = True
|
|
273
|
+
SDKConfig.PRINT_RAW_RESPONSE = False
|
|
274
|
+
|
|
275
|
+
exsited_sdk: ExsitedSDK = ExsitedSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
|
|
276
|
+
|
|
277
|
+
try:
|
|
278
|
+
request_data = OrderCreateDTO(
|
|
279
|
+
order=OrderDataDTO(accountId="AC01").add_line(item_id="ITEM-001", quantity="1"))
|
|
280
|
+
response = exsited_sdk.order.create(request_data=request_data)
|
|
281
|
+
|
|
282
|
+
if response.order:
|
|
283
|
+
account_id = response.order.accountId
|
|
284
|
+
order_id = response.order.id
|
|
285
|
+
for line in response.order.lines:
|
|
286
|
+
if line.itemChargeType == 'METERED':
|
|
287
|
+
#Note: The item must be of type "Metered" for the association data to be stored.
|
|
288
|
+
SaveToDB.process_order_data(_account_id=account_id, _order_id=order_id, _item_id=line.itemId,
|
|
289
|
+
_item_name=line.itemName, _charge_item_uuid=line.chargeItemUuid)
|
|
290
|
+
except ABException as ab:
|
|
291
|
+
print(ab)
|
|
292
|
+
print(ab.get_errors())
|
|
293
|
+
print(ab.raw_response)
|
|
294
|
+
|
exsited-1.0.0/README.md
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# Exsited Python SDK
|
|
2
|
+
The Exsited Python SDK provides an easy-to-use library for integrating Exsited services into your project. This includes Custom Integration, Onsite Integration and all APIs.
|
|
3
|
+
|
|
4
|
+
***
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- [Requirements](#Requirements)
|
|
7
|
+
- [Installation](#Installation)
|
|
8
|
+
- [Configuration](#Configuration)
|
|
9
|
+
- [Authentication](#Authentication)
|
|
10
|
+
- [Getting Started](#Getting-Started)
|
|
11
|
+
- [Testing](#Testing)
|
|
12
|
+
- [API Documentation](#API-Documentation)
|
|
13
|
+
- [Usage charge_item_uuid Association](#Usage-charge_item_uuid-Association)
|
|
14
|
+
# Requirements
|
|
15
|
+
Python 3.12 and Later
|
|
16
|
+
|
|
17
|
+
# Installation
|
|
18
|
+
```bash
|
|
19
|
+
#Installation
|
|
20
|
+
pip install exsited
|
|
21
|
+
```
|
|
22
|
+
# Configuration
|
|
23
|
+
|
|
24
|
+
To set up the Exsited SDK, you'll require your `Client ID`, `Client Secret`, and `Redirect URL`. If you have not received these details already, please reach out to your designated client contact to obtain them
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Authentication
|
|
29
|
+
1. **Locate `common_data.py`:** Open the SKD project directory on an IDE and navigate to the `common_data.py` file which is located in the following path: `tests/common/common_data.py`.
|
|
30
|
+
2. **Update `get_request_token_dto` function:** Within the `common_data.py` class, locate the method named `get_request_token_dto` and update it with the credentials you were provided.
|
|
31
|
+
<img src="blob:https://webalive.atlassian.net/c058a466-42ce-405e-b3ca-dfbbb81a9939#media-blob-url=true&id=ee9aff06-3e79-4823-b0bf-9ef83f5d3c9a&collection=contentId-558825510&contextId=558825510&mimeType=image%2Fpng&name=image.png&size=435487&width=2049&height=922&alt=image.png" alt="">
|
|
32
|
+
|
|
33
|
+
3. **Provide Credential Values:** Populate the mandatory fields (`clientId`, `clientSecret`, `redirectUri`, and `ExsitedUrl`) within the `RequestTokenDTO` object. However, **replace the placeholder values** in the following code block with your actual credentials:
|
|
34
|
+
|
|
35
|
+
### Code Example:
|
|
36
|
+
```python
|
|
37
|
+
def get_request_token_dto():
|
|
38
|
+
return RequestTokenDTO(
|
|
39
|
+
grantType="client_credentials",
|
|
40
|
+
clientId="[YOUR_CLIENT_ID]", # Replace with your actual Client ID
|
|
41
|
+
clientSecret="[YOUR_CLIENT_SECRET]", # Replace with your actual Client Secret
|
|
42
|
+
redirectUri="[YOUR_REDIRECT_URI]", # Replace with your actual Redirect URL
|
|
43
|
+
ExsitedUrl="[YOUR_EXSITED_SERVER_URL]" # Replace with your Exsited server URL,
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
### Credentials Table
|
|
47
|
+
| Key | value |
|
|
48
|
+
|--------------|---------------------------|
|
|
49
|
+
| clientId | "[YOUR_CLIENT_ID]" |
|
|
50
|
+
| clientSecret | "[YOUR_CLIENT_SECRET]" |
|
|
51
|
+
| redirectUri | "[YOUR_REDIRECT_URI]" |
|
|
52
|
+
| ExsitedUrl | "[YOUR_EXSITED_SERVER_URL]" |
|
|
53
|
+
|
|
54
|
+
# Getting Started
|
|
55
|
+
Follow the common pattern to test the functions on the SDK. All the tests can be done on the test files located in the Tests directory.
|
|
56
|
+
|
|
57
|
+
### Testing SDK Functions
|
|
58
|
+
|
|
59
|
+
### Example Method 1: `test_account_create_basic`
|
|
60
|
+
***
|
|
61
|
+
|
|
62
|
+
### Request Parameters
|
|
63
|
+
|
|
64
|
+
| Parameter | Description | Type | Required |
|
|
65
|
+
|-----------------|---------------------------------------------------------|------------------|----------|
|
|
66
|
+
| account | Contains the account details to be created. | `AccountDataDTO` | Yes |
|
|
67
|
+
| account.name | The name of the account. | `str` | Yes |
|
|
68
|
+
| account.emailAddress | The email address associated with the account. | `str` | Yes |
|
|
69
|
+
|
|
70
|
+
### Example Request Data (JSON Representation)
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"account": {
|
|
75
|
+
"name": "Example Name",
|
|
76
|
+
"emailAddress": "example@example.com"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
### Function Signature
|
|
81
|
+
```Python
|
|
82
|
+
def test_account_create_basic():
|
|
83
|
+
SDKConfig.PRINT_REQUEST_DATA = False
|
|
84
|
+
SDKConfig.PRINT_RAW_RESPONSE = False
|
|
85
|
+
|
|
86
|
+
exsited_sdk: ExsitedSDK = ExsitedSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
|
|
87
|
+
|
|
88
|
+
try:
|
|
89
|
+
# You will edit the following request_data
|
|
90
|
+
request_data = AccountCreateDTO(account=AccountDataDTO(name="Example Name", emailAddress="example@example.com"))
|
|
91
|
+
|
|
92
|
+
response = exsited_sdk.account.create(request_data=request_data)
|
|
93
|
+
print(response)
|
|
94
|
+
except ABException as ab:
|
|
95
|
+
print(ab)
|
|
96
|
+
print(ab.get_errors())
|
|
97
|
+
print(ab.raw_response)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Example Method 2: `test_order_create_basic`
|
|
101
|
+
***
|
|
102
|
+
| Parameter | Description | Type | Required |
|
|
103
|
+
|------------|---------------------------------------------|------|----------|
|
|
104
|
+
| accountId | The ID of the account associated with the order. | str | Yes |
|
|
105
|
+
| item_id | The ID of the item being ordered. | str | Yes |
|
|
106
|
+
| quantity | The quantity of the item being ordered. | str | Yes |
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"order": {
|
|
111
|
+
"accountId": "30PS79",
|
|
112
|
+
"lines": [
|
|
113
|
+
{
|
|
114
|
+
"item_id": "ITEM-0055",
|
|
115
|
+
"quantity": "1"
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
### Function Signature
|
|
122
|
+
```Python
|
|
123
|
+
def test_order_create_basic():
|
|
124
|
+
SDKConfig.PRINT_REQUEST_DATA = True
|
|
125
|
+
SDKConfig.PRINT_RAW_RESPONSE = False
|
|
126
|
+
|
|
127
|
+
exsited_sdk: ExsitedSDK = ExsitedSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
|
|
128
|
+
|
|
129
|
+
try:
|
|
130
|
+
# You will edit the following request_data
|
|
131
|
+
request_data = OrderCreateDTO(order=OrderDataDTO(accountId="30PS79").add_line(item_id="ITEM-0055", quantity="1"))
|
|
132
|
+
response = exsited_sdk.order.create(request_data=request_data)
|
|
133
|
+
print(response)
|
|
134
|
+
|
|
135
|
+
except ABException as ab:
|
|
136
|
+
print(ab)
|
|
137
|
+
print(ab.get_errors())
|
|
138
|
+
print(ab.raw_response)
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
***
|
|
142
|
+
### Response
|
|
143
|
+
| Field | Description |
|
|
144
|
+
|----------|-------------------------------------------------------------|
|
|
145
|
+
| response | The response from the the method being called. |
|
|
146
|
+
| errors | Any errors encountered during the account creation process. |
|
|
147
|
+
|
|
148
|
+
### Error Handling
|
|
149
|
+
| Field | Description |
|
|
150
|
+
|-----------------|---------------------------------------------------------|
|
|
151
|
+
| ab | The exception object. |
|
|
152
|
+
| ab.get_errors() | A list of errors that occurred during the account creation process. |
|
|
153
|
+
| ab.raw_response | The raw response data from the API call, useful for debugging. |
|
|
154
|
+
|
|
155
|
+
# Testing
|
|
156
|
+
### Executing Functions
|
|
157
|
+
To test the SDK functions, adhere to the common pattern outlined below. All tests should be conducted using the provided test files located in the "Tests" directory.
|
|
158
|
+
|
|
159
|
+
1. Set up the environment: Ensure that the SDK configuration is appropriately initialized for testing purposes.
|
|
160
|
+
|
|
161
|
+
2. Customize request data: Adjust the `request_data` as needed for the specific function being tested.
|
|
162
|
+
|
|
163
|
+
3. Execute the function: Call the desired function from the SDK, updating the `request_data` inside the function body.
|
|
164
|
+
|
|
165
|
+
### Required Fields
|
|
166
|
+
The following tables contain for the required fields for the test cases
|
|
167
|
+
### Account
|
|
168
|
+
|
|
169
|
+
| Function Name | Required Fields |
|
|
170
|
+
|-----------------------------------|--------------------------------|
|
|
171
|
+
| test_account_create_basic | name, emailAddress |
|
|
172
|
+
| test_account_update_info | id (Account ID) |
|
|
173
|
+
| test_account_list_basic | n/a |
|
|
174
|
+
| test_account_details | id (Account ID) |
|
|
175
|
+
| test_account_delete | id (Account ID) |
|
|
176
|
+
| test_account_payment_methods_add | processorType, default, paymentProcessor, reference |
|
|
177
|
+
| test_account_payment_card_methods_add | processorType, default, paymentProcessor, reference, cardType, token, cardNumber, expiryMonth, expiryYear |
|
|
178
|
+
| test_list_payment_methods | account_id (Account ID) |
|
|
179
|
+
| test_delete_payment_methods | account_id (Account ID), reference |
|
|
180
|
+
| test_payment_method_details | account_id (Account ID), reference |
|
|
181
|
+
|
|
182
|
+
### Order
|
|
183
|
+
| Function | Required Parameters |
|
|
184
|
+
|----------------------------|-----------------------------------|
|
|
185
|
+
| test_order_create_basic | accountId, item_id, quantity (Item Quantity) |
|
|
186
|
+
| test_order_list_basic | n/a |
|
|
187
|
+
| test_order_details | id (Order ID) |
|
|
188
|
+
| test_order_cancel | id (Order ID), effective_date |
|
|
189
|
+
| test_order_usage_add | chargeItemUuid, chargingPeriod, quantity, startTime, endTime, type |
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### Invoice
|
|
193
|
+
| Function | Required Parameters |
|
|
194
|
+
|-----------------------|----------------------|
|
|
195
|
+
| test_invoice_list | n/a |
|
|
196
|
+
| test_invoice_details | id |
|
|
197
|
+
|
|
198
|
+
# API Documentation
|
|
199
|
+
[API Documentation](https://callservice.atlassian.net/wiki/spaces/Implementa/pages/8159248/API+Documentations)
|
|
200
|
+
|
|
201
|
+
# Usage `charge_item_uuid` Association
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
The `order_usage_db` folder contains the functionality for handling database operations related to orders within the Exsited SDK. This module is responsible for connecting to the database, managing orders, processing order data, and saving the relevant information to the database.
|
|
206
|
+
|
|
207
|
+
### Components of `order_usage_db`
|
|
208
|
+
|
|
209
|
+
1. **`connect_with_db.py`**
|
|
210
|
+
- Manages the database connection setup, including functions for establishing and terminating connections
|
|
211
|
+
|
|
212
|
+
2. **`order_manager.py`**
|
|
213
|
+
- Manages Order data, to create rows for the database where the relevant associations are made in order to create usages easily using **`charge_item_uuid`**
|
|
214
|
+
|
|
215
|
+
3. **`order_model.py`**
|
|
216
|
+
- Contains the structure of the order association table
|
|
217
|
+
|
|
218
|
+
4. **`order_service.py`**
|
|
219
|
+
- Contains the function to create the association records
|
|
220
|
+
|
|
221
|
+
5. **`save_to_db.py`**
|
|
222
|
+
- Implements the logic to persist order association data to the database. It interacts with the `connect_with_db.py` module to perform save operations.
|
|
223
|
+
|
|
224
|
+
### Adding Data To the Association Table
|
|
225
|
+
|
|
226
|
+
After configuring your database connection in `connect_with_db.py`, you can use the other scripts to manage orders and persist data to your database. For example, you can create and process an order using `order_manager.py` and then save it using `save_to_db.py`.
|
|
227
|
+
|
|
228
|
+
#### Example Workflow
|
|
229
|
+
|
|
230
|
+
1. **Adding Database Details:**
|
|
231
|
+
In the SaveToDB class within the order_usage_db module, ensure that you update the OrderManager
|
|
232
|
+
initialization with your specific database connection details, such as the database name, username,
|
|
233
|
+
password, and host address.
|
|
234
|
+
2. ```python
|
|
235
|
+
class SaveToDB:
|
|
236
|
+
def process_order_data(_order_id: str, _account_id: str, _item_id: str, _item_name: str, _charge_item_uuid: str):
|
|
237
|
+
# Add your database details below
|
|
238
|
+
order_manager = OrderManager('your_database_name', 'your_username', 'your_password', 'your_host_address')
|
|
239
|
+
order_manager.connect_to_db()
|
|
240
|
+
order_manager.process_order(
|
|
241
|
+
account_id=_account_id,
|
|
242
|
+
order_id=_order_id,
|
|
243
|
+
item_id=_item_id,
|
|
244
|
+
item_name=_item_name,
|
|
245
|
+
charge_item_uuid=_charge_item_uuid
|
|
246
|
+
)
|
|
247
|
+
order_manager.disconnect_from_db()
|
|
248
|
+
|
|
249
|
+
3. Once the database details and other necessary configurations have been added, you can use the following example to add an order.
|
|
250
|
+
This will automatically update the association tables, allowing you to retrieve the relevant details needed to update usage data.
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
def test_order_create_basic():
|
|
254
|
+
SDKConfig.PRINT_REQUEST_DATA = True
|
|
255
|
+
SDKConfig.PRINT_RAW_RESPONSE = False
|
|
256
|
+
|
|
257
|
+
exsited_sdk: ExsitedSDK = ExsitedSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
|
|
258
|
+
|
|
259
|
+
try:
|
|
260
|
+
request_data = OrderCreateDTO(
|
|
261
|
+
order=OrderDataDTO(accountId="AC01").add_line(item_id="ITEM-001", quantity="1"))
|
|
262
|
+
response = exsited_sdk.order.create(request_data=request_data)
|
|
263
|
+
|
|
264
|
+
if response.order:
|
|
265
|
+
account_id = response.order.accountId
|
|
266
|
+
order_id = response.order.id
|
|
267
|
+
for line in response.order.lines:
|
|
268
|
+
if line.itemChargeType == 'METERED':
|
|
269
|
+
#Note: The item must be of type "Metered" for the association data to be stored.
|
|
270
|
+
SaveToDB.process_order_data(_account_id=account_id, _order_id=order_id, _item_id=line.itemId,
|
|
271
|
+
_item_name=line.itemName, _charge_item_uuid=line.chargeItemUuid)
|
|
272
|
+
except ABException as ab:
|
|
273
|
+
print(ab)
|
|
274
|
+
print(ab.get_errors())
|
|
275
|
+
print(ab.raw_response)
|
|
276
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class ABException(Exception):
|
|
2
|
+
raw_response: any = None
|
|
3
|
+
errors: list = []
|
|
4
|
+
|
|
5
|
+
def __init__(self, message=None, exception_type: str = None):
|
|
6
|
+
super().__init__(message)
|
|
7
|
+
self.exception_type = exception_type
|
|
8
|
+
self.message = message
|
|
9
|
+
|
|
10
|
+
def add_raw_response(self, raw_response: any):
|
|
11
|
+
self.raw_response = raw_response
|
|
12
|
+
return self
|
|
13
|
+
|
|
14
|
+
def add_error(self, error: any):
|
|
15
|
+
self.errors.append(error)
|
|
16
|
+
|
|
17
|
+
def get_errors(self):
|
|
18
|
+
return self.errors
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from exsited.exsited.common.common_enum import SortDirection
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SDKUtil:
|
|
5
|
+
|
|
6
|
+
@staticmethod
|
|
7
|
+
def get_dict_value(data: dict, key: str, default=None):
|
|
8
|
+
if not data or not key:
|
|
9
|
+
return default
|
|
10
|
+
elif key in data:
|
|
11
|
+
return data[key]
|
|
12
|
+
return default
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def init_dict_if_value(data: dict, key: str, value):
|
|
16
|
+
if value:
|
|
17
|
+
data[key] = value
|
|
18
|
+
return data
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def init_pagination_params(params: dict = None, limit: int = None, offset: int = None, direction: SortDirection = None, order_by: str = None):
|
|
22
|
+
if not params:
|
|
23
|
+
params = {}
|
|
24
|
+
params = SDKUtil.init_dict_if_value(params, "limit", limit)
|
|
25
|
+
params = SDKUtil.init_dict_if_value(params, "offset", offset)
|
|
26
|
+
params = SDKUtil.init_dict_if_value(params, "direction", str(direction))
|
|
27
|
+
params = SDKUtil.init_dict_if_value(params, "order_by", order_by)
|
|
28
|
+
return params
|
|
File without changes
|
|
File without changes
|