Skip to content

Commit aa0480f

Browse files
committed
Add ChangeCustomer
1 parent cb7406d commit aa0480f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

licensing/methods.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,41 @@ def extend_license(token, product_id, key, no_of_days):
300300

301301
return (True, jobj["message"])
302302

303+
@staticmethod
304+
def change_customer(token, product_id, key, customer_id):
305+
"""
306+
This method will change the customer associated with a license.
307+
If the customer is not specified (for example, if CustomerId=0) or
308+
the customer with the provided ID does not exist, any customer that
309+
was previously associated with the license will be dissociated.
310+
311+
More docs: https://app.cryptolens.io/docs/api/v3/ChangeCustomer
312+
"""
313+
314+
response = ""
315+
316+
try:
317+
response = HelperMethods.send_request("key/ChangeCustomer", {"token":token,\
318+
"ProductId":product_id,\
319+
"Key" : key,\
320+
"CustomerId" : customer_id})
321+
except HTTPError as e:
322+
response = e.read()
323+
except URLError as e:
324+
return (None, "Could not contact the server. Error message: " + str(e))
325+
except Exception:
326+
return (None, "Could not contact the server.")
327+
328+
jobj = json.loads(response)
329+
330+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
331+
if jobj != None:
332+
return (False, jobj["message"])
333+
else:
334+
return (False, "Could not contact the server.")
335+
336+
return (True, jobj["message"])
337+
303338
@staticmethod
304339
def unblock_key(token, product_id, key):
305340
"""

0 commit comments

Comments
 (0)