Skip to content

Commit 6ff9472

Browse files
committed
Add "CreateKey", closes #27
1 parent 2db884d commit 6ff9472

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

licensing/methods.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,75 @@ def create_trial_key(token, product_id, machine_code):
143143

144144
return (jobj["key"], "")
145145

146+
@staticmethod
147+
def create_key(token, product_id, period = 0,\
148+
f1=False,\
149+
f2=False,\
150+
f3=False,\
151+
f4=False,\
152+
f5=False,\
153+
f6=False,\
154+
f7=False,\
155+
f8=False,\
156+
notes="",\
157+
block=False,\
158+
customer_id=0,\
159+
new_customer=False,\
160+
add_or_use_existing_customer=False,\
161+
trial_activation=False,\
162+
max_no_of_machines=0,\
163+
no_of_keys=1):
164+
"""
165+
This method allows you to create a new license key. The license can
166+
either be standalone or associated to a specific customer. It is also
167+
possible to add a new customer and associate it with the newly created
168+
license using NewCustomer parameter. If you would like to avoid
169+
duplicates based on the email, you can use the AddOrUseExistingCustomer
170+
parameter.
171+
172+
More docs: https://app.cryptolens.io/docs/api/v3/CreateKey/
173+
"""
174+
175+
response = ""
176+
177+
try:
178+
response = HelperMethods.send_request("key/createkey", {"token":token,\
179+
"ProductId":product_id,\
180+
"Period":period,\
181+
"F1": f1,\
182+
"F2": f2,\
183+
"F3": f3,\
184+
"F4": f4,\
185+
"F5": f5,\
186+
"F6": f6,\
187+
"F7": f7,\
188+
"F8": f2,\
189+
"Notes": notes,\
190+
"Block": block,\
191+
"CustomerId": customer_id,\
192+
"NewCustomer": f2,\
193+
"AddOrUseExistingCustomer": add_or_use_existing_customer,\
194+
"TrialActivation": trial_activation,\
195+
"MaxNoOfMachines": max_no_of_machines,\
196+
"NoOfKeys":no_of_keys})
197+
except HTTPError as e:
198+
response = e.read()
199+
except URLError as e:
200+
return (None, "Could not contact the server. Error message: " + str(e))
201+
except Exception:
202+
return (None, "Could not contact the server.")
203+
204+
jobj = json.loads(response)
205+
206+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
207+
if jobj != None:
208+
return (None, jobj["message"])
209+
else:
210+
return (None, "Could not contact the server.")
211+
212+
return (jobj, "")
213+
214+
146215
@staticmethod
147216
def deactivate(token, product_id, key, machine_code, floating = False):
148217
"""

0 commit comments

Comments
 (0)