Skip to content

Commit 947efa8

Browse files
synominitartemlos
andauthored
Added Subscription Class (#49)
* Added add data object to machine method * Added method to remove data object from machine * Added method to list machine data objects * Added method to list data objects for key * Update the reference to method parameters * Added Subscription and Analytics Classes Added Subscription Class with method to increment meter for stripe billing. Added Analytics Class with methods to register single events and get events. * Update methods.py * Removed Redundant Analytics class (See AI Class) * Small typo fix * Update methods.py Co-authored-by: Artem Los <[email protected]>
1 parent 2df0ff4 commit 947efa8

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

licensing/methods.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,4 +1081,43 @@ def HasFeature(license_key, feature_name):
10811081
if not(found):
10821082
return False
10831083

1084-
return True
1084+
return True
1085+
1086+
class Subscription:
1087+
"""
1088+
Subscription related methods
1089+
"""
1090+
1091+
@staticmethod
1092+
def record_usage_to_stripe(token, product_id, key, amount=""):
1093+
1094+
"""
1095+
This method records uses Stripe's metered billing to record usage for a certain subscription. In order to use this method,
1096+
you need to have set up recurring billing. A record will be created using Stripe's API with action set to 'increment'
1097+
1098+
More docs: https://app.cryptolens.io/docs/api/v3/RecordUsage
1099+
"""
1100+
1101+
try:
1102+
response = HelperMethods.send_request("/subscription/RecordUsage/",\
1103+
{"token":token,\
1104+
"ProductId" : product_id,\
1105+
"Key" : key,\
1106+
"Amount" : amount,
1107+
})
1108+
except HTTPError as e:
1109+
response = e.read()
1110+
except URLError as e:
1111+
return (None, "Could not contact the server. Error message: " + str(e))
1112+
except Exception:
1113+
return (None, "Could not contact the server.")
1114+
1115+
jobj = json.loads(response)
1116+
1117+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
1118+
if jobj != None:
1119+
return (None, jobj["message"])
1120+
else:
1121+
return (None, "Could not contact the server.")
1122+
1123+
return (jobj, "")

0 commit comments

Comments
 (0)