Skip to content

Commit

Permalink
Added Subscription Class (#49)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
synominit and artemlos authored Dec 28, 2021
1 parent 2df0ff4 commit 947efa8
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion licensing/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,4 +1081,43 @@ def HasFeature(license_key, feature_name):
if not(found):
return False

return True
return True

class Subscription:
"""
Subscription related methods
"""

@staticmethod
def record_usage_to_stripe(token, product_id, key, amount=""):

"""
This method records uses Stripe's metered billing to record usage for a certain subscription. In order to use this method,
you need to have set up recurring billing. A record will be created using Stripe's API with action set to 'increment'
More docs: https://app.cryptolens.io/docs/api/v3/RecordUsage
"""

try:
response = HelperMethods.send_request("/subscription/RecordUsage/",\
{"token":token,\
"ProductId" : product_id,\
"Key" : key,\
"Amount" : amount,
})
except HTTPError as e:
response = e.read()
except URLError as e:
return (None, "Could not contact the server. Error message: " + str(e))
except Exception:
return (None, "Could not contact the server.")

jobj = json.loads(response)

if jobj == None or not("result" in jobj) or jobj["result"] == 1:
if jobj != None:
return (None, jobj["message"])
else:
return (None, "Could not contact the server.")

return (jobj, "")

0 comments on commit 947efa8

Please sign in to comment.