-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
75 lines (63 loc) · 2.23 KB
/
web.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
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import hashlib
import pprint
import json
from dotenv import load_dotenv
from flask import Flask, render_template, request
app = Flask(__name__)
load_dotenv()
# Parameters
acquirer_id = os.getenv('ACQUIRERID')
id_commerce = os.getenv('ID_COMMERCE')
purchase_operation = os.getenv('PURCHASE_OPERATION')
currency_code = os.getenv('PURCHASE_CURRENCY_CODE')
secret_key = os.getenv('SECRET_KEY_2')
@app.route('/')
def hello():
return 'Alignet Send and receive test!. Go to /send or /receive'
@app.route('/receive', methods=['POST'])
def receive():
purchase_verication = request.form.get('purchaseVerification')
# Compute verification
data = '{}{}{}{}{}{}'.format(request.form.get('acquirerId'),
request.form.get('idCommerce'),
request.form.get('purchaseOperationNumber'),
request.form.get('purchaseAmount'),
request.form.get('purchaseCurrencyCode'),
request.form.get('authorizationResult'),
secret_key)
m = hashlib.sha512()
m.update(data.encode())
verification = m.hexdigest()
print('request POST:')
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(request.form)
if verification == purchase_verication:
return 'Verification OK: {}'.format(json.dumps(request.form))
else:
return 'Failed verification'
@app.route('/send')
def send():
# ammount
ammount = 1000
# Compute verification
data = '{}{}{}{}{}{}'.format(acquirer_id,
id_commerce,
purchase_operation,
ammount,
currency_code,
secret_key)
m = hashlib.sha512()
m.update(data.encode())
verification = m.hexdigest()
context = {
'acquirer_id': acquirer_id,
'id_commerce': id_commerce,
'purchase_operation': purchase_operation,
'ammount': 1000,
'currency_code': currency_code,
'verification': verification
}
return render_template('send.html', context=context)
if __name__ == '__main__':
app.run()