Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Subscription Class #49

Merged
merged 11 commits into from
Dec 28, 2021
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, "")