-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_order.py
57 lines (52 loc) · 2.3 KB
/
create_order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import requests
def create_order(api_key, gateway, plan):
if plan == 'basicplan':
value = 599
elif plan == 'goldplan':
value = 999
elif plan == 'diamondplan':
value = 1499
endpoint = 'https://dev.sellix.io/v1/payments'
payload = {
"title": "License Key",
"value": value,
"currency": "USD",
"quantity": 1,
"email": "[email protected]", #Enter your email here for logging purposes
"gateway": gateway,
"white_label": True,
"confirmations" : 2 #change it if needed
}
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
response = requests.post(endpoint, json=payload, headers=headers)
if response.status_code == 200:
data = response.json()
# Check if all expected keys are in the response
if data and isinstance(data.get('data'), dict) and isinstance(data['data'].get('invoice'), dict):
invoice = data['data']['invoice']
crypto_uri = invoice.get('crypto_uri')
uniqid = invoice.get('uniqid')
if crypto_uri and uniqid:
try:
address, amount_param = crypto_uri.split('?')
# Insert a space after the colon in the address
if ':' in address:
protocol, addr = address.split(':', 1)
address = addr
amount = amount_param.split('=')[1]
return address, amount, uniqid, protocol, value
except Exception as e:
print("Error splitting crypto_uri:", crypto_uri)
raise Exception(f"Error processing crypto_uri: {e}")
else:
print("crypto_uri or uniqid is missing:", invoice)
raise Exception("Missing crypto_uri or uniqid in the response.")
else:
print("Unexpected response structure:", data)
raise Exception("Unexpected data structure in response.")
else:
print(f"Failed to create payment. Status Code: {response.status_code}, Response: {response.text}")
raise Exception(f"Failed to create payment. Status Code: {response.status_code}, Response: {response.text}")