You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-5Lines changed: 59 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ You can install the library by running `pip install openpaygo` or adding `openpa
44
44
45
45
You can use the `generate_token()` function to generate an OpenPAYGOToken Token. The function takes the following parameters, and they should match the configuration in the hardware of the device:
46
46
47
-
-`secret_key` (required): The secret key of the device. Must be passed as an hexadecimal string (with 32 characters).
47
+
-`secret_key` (required): The secret key of the device. Must be passed as an hexadecimal string with 32 characters (e.g. `dac86b1a29ab82edc5fbbc41ec9530f6`).
48
48
-`count` (required): The token count used to make the last token.
49
49
-`value` (optional): The value to be passed in the token (typically the number of days of activation). Optional if the `token_type` is Disable PAYG or Counter Sync. The value must be between 0 and 995.
50
50
-`token_type` (optional): Used to set the type of token (default is Add Time). Token types can be found in the `TokenType` class: ADD_TIME, SET_TIME, DISABLE_PAYG, COUNTER_SYNC.
@@ -100,7 +100,7 @@ device.save() # We save the new count that we set for the device
100
100
You can use the `decode_token()` function to generate an OpenPAYGOToken Token. The function takes the following parameters, and they should match the configuration in the hardware of the device:
101
101
102
102
-`token` (required): The token that was given by the user, as a string
103
-
-`secret_key` (required): The secret key of the device
103
+
-`secret_key` (required): The secret key of the device as a string with 32 hexadecimal characters (e.g. `dac86b1a29ab82edc5fbbc41ec9530f6`)
104
104
-`count` (required): The token count of the last valid token. When a device is new, this is 1.
105
105
-`used_counts` (optional): An array of recently used token counts, as returned by the function itself after the last valid token was decoded. This allows for handling unordered token entry.
106
106
-`starting_code` (optional): If not provided, it is generated according to the method defined in the standard (SipHash-2-4 of the key, transformed to digit by the same method as the token generation).
You can use the `MetricsRequestHandler` object to create a new OpenPAYGO Metrics request from start to finish. It accepts the following initial inputs:
165
165
-`serial_number` (required): The serial number of the device
166
166
-`data_format` (optional): The data format, provided as dictionnary matching the data format object specifications.
167
-
-`secret_key` (optional): The secret key provided as a string containing 32 hexadecimal characters. Required if `auth_method` is defined.
167
+
-`secret_key` (optional): The secret key provided as a string containing 32 hexadecimal characters (e.g. `dac86b1a29ab82edc5fbbc41ec9530f6`). Required if `auth_method` is defined.
168
168
-`auth_method` (optional): One of the auth method contained in the `AuthMethod` class.
169
169
170
170
It provides the following methods:
171
171
-`set_timestamp(timestamp)`: Used to set the `timestamp` of the request.
172
172
-`set_request_count(request_count)`: Used to set the `request_count` of the request.
173
+
-`set_data(data)`: Used to set the `data` of the request, should be set in simple format as a dictionnay.
174
+
-`set_historical_data(data)`: Used to set the `historical_data` of the request, should be set in simple format as a dictionnary. The data is assumed to be separated by the `historical_data_interval` unless an explicit timestamp is provided.
175
+
-`get_simple_request_payload()`: Returns the payload in simple format as a string containing JSON and including the authentication signature.
176
+
-`get_condensed_request_payload()`: Returns the payload in condensed format as a string containing JSON and including the authentication signature. It requires `data_format` to be set. The data is automatically condensed from the set data and the data format and the signature is automatically generated.
177
+
178
+
179
+
**Example - Full Request flow from device side:**
180
+
181
+
```python
182
+
from openpaygo import MetricsRequestHandler, AuthMethod
183
+
import requests
184
+
185
+
# We assume the users enters a token and that the device state is saved in my_device_state
186
+
...
187
+
188
+
metrics_request = MetricsRequestHandler(
189
+
serial_number=my_device_state.serial_number,
190
+
secret_key=my_device_state.secret_key,
191
+
data_format=my_device_state.data_format,
192
+
auth_method=AuthMethod.RECURSIVE_DATA_AUTH
193
+
)
194
+
195
+
metrics_requestset_timestamp(1611583070)
196
+
metrics_requestset_data({
197
+
"token_count": 3,
198
+
"tampered": False,
199
+
"firmware_version": "1.2.3"
200
+
})
201
+
# Here we assume that the data we send is separated by 60 seconds as per the data format
# We can now proceed to send the payload to the URL
219
+
# It looks something like `{"sn":"aaa111222","df":1234,"ts":1611583070,"d":[3,false,"1.2.3"],"hd":[[12.31,12.32,1.23,-1.23],[12.3,12.31,1.22,-1.21]],"a":"raa5cb1fda302cf94e"}`
# Here we decode the tokens received from the server and apply them (see example above)
225
+
...
226
+
```
173
227
174
228
175
229
### Handling a Request and Generating a Response (Server Side)
176
230
177
231
You can use the `MetricsResponseHandler` object to process your OpenPAYGO Metrics request from start to finish. It accepts the following initial inputs:
178
232
-`metrics_payload` (required): The OpenPAYGO Metrics payload, as a string containing the JSON payload.
179
-
-`secret_key` (optional): The secret key provided as a string containing 32 hexadecimal characters
233
+
-`secret_key` (optional): The secret key provided as a string containing 32 hexadecimal characters (e.g. `dac86b1a29ab82edc5fbbc41ec9530f6`)
180
234
-`data_format` (optional): The data format, provided as dictionnary matching the data format object specifications.
181
235
182
236
It provides the following methods:
@@ -191,7 +245,7 @@ It provides the following methods:
191
245
-`get_answer()`: Will return the answer as a string based on the request and the data added to answer, it will automatically handle the authentication and fomatting.
0 commit comments