-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolled.html
130 lines (123 loc) · 4 KB
/
controlled.html
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0">
<meta http-equiv="x-ua-compatible" content="IE=Edge">
<title>Verification Example</title>
<script type="text/javascript" src="./utilities.js"></script>
<style>
.hidden {
display: none;
}
.visible {
border: none;
height: 70vh;
width: 90vw;
max-width: 40em;
outline: 1px solid red;
}
input {
display: block;
}
</style>
<script>
const baseUrl = "https://merchant.intergiro.com/v1"
let authorization
function submit() {
authorization = {
"number": generateUnique(), // "Should be your unique authorization number"
"amount": Number(document.getElementById("amount").value),
"currency": document.getElementById("currency").value,
"card": {
"pan": document.getElementById("pan").value,
"expires": [
Number(document.getElementById("expires").value.split("/")[0]),
Number(document.getElementById("expires").value.split("/")[1])
],
"csc": document.getElementById("csc").value
},
browser: {
parent: window.location.origin,
ip: "123.100.227.123",
ipCountry: "SE",
colorDepth: 32,
java: false,
javascript: true,
locale: "nb-NO",
timezone: -120,
resolution: [430, 932]
}
}
authorize()
}
async function authorize() {
const [status, body] = await post(baseUrl + "/authorization", "Bearer " + document.getElementById("key").value.trim(), authorization)
const iframe = document.getElementById("verification")
if (status == 201) {
authorization.card.verification = body
iframe.classList.remove("visible")
iframe.classList.add("hidden")
alert("success: " + JSON.stringify(body, null, 2))
}
else if (status == 400 && body.error == "verification required") {
authorization.id = body.id
iframe.classList.replace("hidden", body.content.details.visible ? "visible" : "hidden")
if (body.content.details.method == "GET")
iframe.src = body.content.details.url
else {
const form = document.getElementById("threeD")
const creq = document.getElementById("creq")
form.action = body.content.details.url
creq.value = btoa(JSON.stringify(body.content.details.data))
form.submit()
}
}
else
alert("failed: " + JSON.stringify(body))
}
window.addEventListener("message", async e => {
if (e.data.destination == "parent" && e.data.content.name == "card") {
authorization.card = e.data.content.value
const iframe = document.getElementById("verification")
iframe.class = "hidden"
await authorize()
}
})
async function post(url, key, body) {
const response = await fetch(url, {
method: "POST",
headers: new Headers(
{
Authorization: key,
"Content-Type": "application/json"
}),
body: JSON.stringify(body),
}
)
return [response.status, response.headers.get("Content-Type")?.startsWith("application/json") ? await response.json() : await response.text()]
}
</script>
</head>
<body style="width: 100%; max-width: 20em; margin-left: auto; margin-right: auto;">
<iframe id="verification" name="verification" class="hidden"></iframe>
<form id="threeD" method="post" target="verification" class="hidden">
<input id="creq" name="creq">
</form>
<form method="post">
<label for="key">Public API key</label>
<input type="text" id="key" name="key" />
<label for="pan">PAN</label>
<input type="text" id="pan" name="pan" value="4111111111111111" />
<label for="csc">CSC</label>
<input type="text" id="csc" name="csc" value="987" />
<label for="expires">Expires</label>
<input type="text" id="expires" name="expires" placeholder="MM/YY" value="2/24" />
<label for="currency">Currency</label>
<input type="text" id="currency" name="currency" value="EUR" />
<label for="amount">Amount</label>
<input type="text" id="amount" name="amount" value="250" />
</form>
<button onclick="submit()">Submit</button>
</body>
</html>