-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirmation.html
79 lines (71 loc) · 3.86 KB
/
confirmation.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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Confirmación de Compra</title>
<link rel="stylesheet" href="styles.css">
</head>
<body class="confirmation-page">
<div class="container">
<h1>Confirmación de Compra</h1>
<p class="product-description">Descripción del Producto: <span id="product-description"></span></p>
<p class="product-price">Precio: €<span id="product-price"></span></p>
<form id="redsys-form" method="post" action="display.php">
<input type="hidden" name="Ds_Merchant_Amount" id="amount">
<input type="hidden" name="Ds_Merchant_Order" id="order">
<input type="hidden" name="Ds_Merchant_MerchantCode" value="012809">
<input type="hidden" name="Ds_Merchant_Currency" value="978">
<input type="hidden" name="Ds_Merchant_TransactionType" value="0">
<input type="hidden" name="Ds_Merchant_Terminal" value="50">
<input type="hidden" name="Ds_Merchant_MerchantURL" value="https://palons29.github.io/Comercio-Electronico/notification">
<input type="hidden" name="Ds_Merchant_UrlOK" value="https://palons29.github.io/Comercio-Electronico/success.html">
<input type="hidden" name="Ds_Merchant_UrlKO" value="https://palons29.github.io/Comercio-Electronico/cancel.html">
<input type="hidden" name="Ds_Merchant_ProductDescription" id="product-description-hidden">
<input type="hidden" name="Ds_Merchant_MerchantSignature" id="signature">
<button type="submit">Pagar con Redsýs</button>
</form>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
function getQueryParams() {
const params = {};
const queryString = window.location.search.substring(1);
const pairs = queryString.split("&");
for (let pair of pairs) {
const [key, value] = pair.split("=");
params[decodeURIComponent(key)] = decodeURIComponent(value.replace(/\+/g, ' '));
}
return params;
}
const params = getQueryParams();
const description = params['description'];
const price = params['price'];
if (description && price) {
document.getElementById('product-description').innerText = description;
document.getElementById('product-price').innerText = price;
const order = generateOrder();
document.getElementById('amount').value = (parseFloat(price) * 100).toFixed(0);
document.getElementById('order').value = order;
document.getElementById('product-description-hidden').value = description;
const signature = generateSignature(order, (parseFloat(price) * 100).toFixed(0), '012809', '978', '0', 'UMH2809');
document.getElementById('signature').value = signature;
} else {
alert('No se pudo obtener la información del producto.');
}
});
function generateOrder() {
const date = new Date();
return 'ORD' + date.getTime();
}
function generateSignature(order, amount, merchantCode, currency, transactionType, secretKey) {
const data = `${amount}${order}${merchantCode}${currency}${transactionType}${secretKey}`;
const shaObj = new jsSHA("SHA-1", "TEXT");
shaObj.update(data);
return shaObj.getHash("HEX").toUpperCase();
}
</script>
<!-- Include jsSHA library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsSHA/3.2.0/sha.js"></script>
</body>
</html>