-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirmation.html
72 lines (68 loc) · 3.06 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
<!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="styles2.css">
</head>
<body>
<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>
<div id="paypal-button-container"></div>
</div>
<script src="https://www.paypal.com/sdk/js?client-id=AYcSryXgNttU4G57J2WVdkgM_y12kYeOmlny8Zetf6NuYdu0HXjKZBfzFotgqNrfUj0GvxQt4ynJsyqE"></script>
<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;
paypal.Buttons({
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: price
},
description: description
}],
application_context: {
return_url: 'http://tu-dominio.com/success.html',
cancel_url: 'http://tu-dominio.com/cancel.html'
}
});
},
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
window.location.href = `success.html?orderId=${details.id}`;
});
},
onCancel: function (data) {
window.location.href = 'cancel.html';
},
onError: function (err) {
window.location.href = 'cancel.html';
}
}).render('#paypal-button-container');
} else {
alert('No se pudo obtener la información del producto.');
}
});
</script>
</body>
</html>