-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment_processor.py
62 lines (50 loc) · 2.07 KB
/
payment_processor.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
58
59
60
61
62
# IMPORTING IMPORTANT LIBRARIES
import random
from tradehub.public_account_client import PublicClient
import logging
import sys
#Note: Enter your own receiver address. Currently listed with programmers' address
receiver_address = "swth1dwdvy48exj22st0zvwk8s3k9tfnksrj9v7fhuu"
def confirm_payment():
#Setting up logger
root = logging.getLogger()
root.setLevel(logging.WARNING)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.WARNING)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
#Initiating msg dict
msg = {}
#Txn Hash for testing...see example/payment_processor.py
#More functionality is needed - pass Txn Hash to confirm_payment
#Functionality example can be found at example/payment_processor.py
TxnHash = 'ENTER Txn Hash'
denom = 'swth'
#Connect to Tradehub Public Client and retrieve transaction data
pc = PublicClient(network='mainnet', trusted_uris=["http://54.255.5.46:5001", "http://175.41.151.35:5001"])
data = pc.get_transaction(TxnHash)
#Parse out msg from data nd store in msg dict
for m in data['msgs']:
if 'msg' in m:
msg = json.loads(m['msg'])
#Retrieve to_address from msg
to_address = msg['to_address']
#retrieve amount from msg
amount = msg['amount']
#Check if amount, token and fee match
if amount[0]['denom']== denom:
if (int(amount[0]['amount'])/100000000) == fee:
#Do Something
print("Success")
else:
root.error("The fee amount didn't match. Please contact customer support.")
else:
root.error("The denom amount didn't match. Please contact customer support.")
def to_address():
return receiver_address
def calculate_payment():
#Do something to calculate payment and return the value
#For purpose of example, I am using a random int between 100-500
fee = random.randrange(100,500)
return fee