-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsec_3ds.py
88 lines (72 loc) · 2.22 KB
/
sec_3ds.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
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import json
import requests
import secrets
from flask import session
if os.path.exists("env.py"):
import env
def sec_3ds_confirm_call():
# auth environment variables
afs_user = os.environ.get("AFS_USER")
afs_pass = os.environ.get("AFS_PASS")
afs_url = os.environ.get("AFS_URL")
afs_version = os.environ.get("AFS_VERSION")
# stub_url = 'https://afs.gateway.mastercard.com/api/rest/version/63/merchant/TEST100065243/session'
order_id = session['order_id']
# this we randomly generate using secrets
transaction_id = secrets.token_hex(8)
init_3ds_payload = json.dumps({
"apiOperation":"INITIATE_AUTHENTICATION",
"authentication":{
"acceptVersions":"3DS1,3DS2",
"channel":"PAYER_BROWSER",
"purpose":"PAYMENT_TRANSACTION"
},
"correlationId":"test",
"order":{
"reference": order_id,
"currency":"BHD"
},
"session": {
"id": session['afs_session_id']
},
"transaction": {
"reference": transaction_id,
# "id": "TxnID_" + transaction_id
}
})
init_3ds_url = f'https://afs.gateway.mastercard.com/api/rest/version/{afs_version}/merchant/{afs_url}/order/OrdID_{order_id}/transaction/{transaction_id}'
init_3ds_res = requests.put(init_3ds_url, auth=(afs_user, afs_pass), data=init_3ds_payload)
init_3ds_response = init_3ds_res.json()
auth_3ds_url = f'https://afs.gateway.mastercard.com/api/rest/version/{afs_version}/merchant/{afs_url}/order/{order_id}/transaction/{transaction_id}'
auth_3ds_payload = json.dumps({
"apiOperation": "AUTHENTICATE_PAYER",
"authentication":{
"redirectResponseUrl": "https://google.com"
},
"correlationId":"test",
"device": {
"browser": "MOZILLA",
"browserDetails": {
"3DSecureChallengeWindowSize": "FULL_SCREEN",
"acceptHeaders": "application/json",
"colorDepth": 24,
"javaEnabled": "true",
"language": "en-US",
"screenHeight": 640,
"screenWidth": 480,
"timeZone": 273
},
"ipAddress": "127.0.0.1"
},
"order":{
"amount":".10",
"currency":"BHD"
},
"session": {
"id": session['afs_session_id']
}
})
auth_3ds_res = requests.put(auth_3ds_url, auth=(afs_user, afs_pass), data=auth_3ds_payload)
response = auth_3ds_res.json()
pass