-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive.html
113 lines (106 loc) · 3.41 KB
/
interactive.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
<!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>
iframe.hidden {
display: none;
}
iframe.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": "EUR",
"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 }
}
authorize()
}
async function authorize() {
const [status, body] = await post(baseUrl + "/authorization?method=GET", "Bearer " + document.getElementById("key").value.trim(), authorization)
const iframe = document.getElementById("verification")
switch (status) {
case 201:
authorization.card.verification = body
iframe.classList.remove("visible")
iframe.classList.add("hidden")
alert("success: " + JSON.stringify(body))
break
case 400:
if (body.error == "verification required" && body.content.details.method == "GET") {
iframe.classList.replace("hidden", body.content.details.visible ? "visible" : "hidden")
iframe.src = body.content.details.url
authorization.id = body.id
} else
alert("failed: " + JSON.stringify(body))
break
default:
alert("failed: " + JSON.stringify(body))
break
}
}
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" class="hidden"></iframe>
<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="amount">Amount</label>
<input type="text" id="amount" name="amount" value="250" />
</form>
<button onclick="submit()">Submit</button>
</body>
</html>