134 lines
3.9 KiB
HTML
134 lines
3.9 KiB
HTML
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>MASI 3DSecure</title>
|
|
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
header,
|
|
footer {
|
|
background: #f4f4f4;
|
|
padding: 15px;
|
|
text-align: center;
|
|
}
|
|
|
|
main {
|
|
padding: 20px;
|
|
}
|
|
|
|
#payment {
|
|
display: none;
|
|
}
|
|
|
|
#paymentAccepted {
|
|
display: none;
|
|
color: #36ca3e;
|
|
}
|
|
|
|
#paymentRefused {
|
|
display: none;
|
|
color: #ca3636;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<main>
|
|
<div id="login">
|
|
<h2>Login</h2>
|
|
<input id="username-field" placeholder="Username">
|
|
<br>
|
|
<input id="password-field" placeholder="Password">
|
|
<br>
|
|
<button id="connect-button">Connect</button>
|
|
</div>
|
|
<div id="payment">
|
|
<h2>Payment</h2>
|
|
<input id="token-input" placeholder="Token">
|
|
<br>
|
|
<button id="connect-button-pay">Pay</button>
|
|
</div>
|
|
<div id="paymentAccepted">
|
|
<h3>Payment Accepted</h3>
|
|
</div>
|
|
<div id="paymentRefused">
|
|
<h3>Payment Refused</h3>
|
|
</div>
|
|
</main>
|
|
|
|
<script>
|
|
let btnConnect = document.getElementById("connect-button");
|
|
let btnPay = document.getElementById("connect-button-pay");
|
|
|
|
btnConnect.addEventListener("click", async() => {
|
|
let username = document.getElementById("username-field").value;
|
|
let pwd = document.getElementById("password-field").value;
|
|
|
|
let data = {
|
|
username: username,
|
|
password: pwd
|
|
};
|
|
|
|
await fetch("/login", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(response => {
|
|
if (response.ok) {
|
|
localStorage.setItem("creds", JSON.stringify(data));
|
|
document.getElementById("payment").style.display = 'block';
|
|
} else {
|
|
throw new Error("Authentication request failed")
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
});
|
|
});
|
|
|
|
btnPay.addEventListener("click", async() => {
|
|
|
|
let token = document.getElementById("token-input").value;
|
|
let dataToken = {
|
|
token: token
|
|
};
|
|
|
|
let creds = JSON.parse(localStorage.getItem("creds"));
|
|
|
|
await fetch("/payment", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"Authorization": `Basic ${creds.username}:${creds.password}`
|
|
},
|
|
body: JSON.stringify(dataToken)
|
|
})
|
|
.then(response => {
|
|
if (response.ok) {
|
|
document.getElementById("paymentAccepted").style.display = 'block';
|
|
document.getElementById("paymentRefused").style.display = 'none';
|
|
} else {
|
|
document.getElementById("paymentRefused").style.display = 'block';
|
|
document.getElementById("paymentAccepted").style.display = 'none';
|
|
throw new Error("Payment request failed")
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
});
|
|
})
|
|
</script>
|
|
</body>
|
|
|
|
</html> |