tonder-web-sdk 1.16.1 → 1.16.6-beta.DEV-1433.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -40
- package/package.json +29 -6
- package/types/card.d.ts +17 -17
- package/types/checkout.d.ts +85 -87
- package/types/common.d.ts +8 -2
- package/types/customer.d.ts +10 -10
- package/types/index.d.ts +9 -11
- package/types/inlineCheckout.d.ts +81 -61
- package/types/liteInlineCheckout.d.ts +78 -83
- package/types/paymentMethod.d.ts +17 -17
- package/types/transaction.d.ts +94 -94
- package/v1/bundle.min.js +1 -18
- package/.env-example +0 -1
- package/cypress/e2e/1-getting-started/todo.cy.js +0 -143
- package/cypress/e2e/2-advanced-examples/actions.cy.js +0 -299
- package/cypress/e2e/2-advanced-examples/aliasing.cy.js +0 -39
- package/cypress/e2e/2-advanced-examples/assertions.cy.js +0 -176
- package/cypress/e2e/2-advanced-examples/connectors.cy.js +0 -98
- package/cypress/e2e/2-advanced-examples/cookies.cy.js +0 -118
- package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +0 -185
- package/cypress/e2e/2-advanced-examples/files.cy.js +0 -85
- package/cypress/e2e/2-advanced-examples/location.cy.js +0 -32
- package/cypress/e2e/2-advanced-examples/misc.cy.js +0 -104
- package/cypress/e2e/2-advanced-examples/navigation.cy.js +0 -56
- package/cypress/e2e/2-advanced-examples/network_requests.cy.js +0 -163
- package/cypress/e2e/2-advanced-examples/querying.cy.js +0 -114
- package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +0 -201
- package/cypress/e2e/2-advanced-examples/storage.cy.js +0 -110
- package/cypress/e2e/2-advanced-examples/traversal.cy.js +0 -121
- package/cypress/e2e/2-advanced-examples/utilities.cy.js +0 -108
- package/cypress/e2e/2-advanced-examples/viewport.cy.js +0 -58
- package/cypress/e2e/2-advanced-examples/waiting.cy.js +0 -30
- package/cypress/e2e/2-advanced-examples/window.cy.js +0 -22
- package/cypress/fixtures/example.json +0 -5
- package/cypress/support/commands.js +0 -25
- package/cypress/support/e2e.js +0 -20
- package/cypress.config.js +0 -9
- package/index.js.example +0 -50
- package/samples/react/README.md +0 -70
- package/samples/react/build/asset-manifest.json +0 -16
- package/samples/react/build/favicon.ico +0 -0
- package/samples/react/build/index.html +0 -1
- package/samples/react/build/logo192.png +0 -0
- package/samples/react/build/logo512.png +0 -0
- package/samples/react/build/manifest.json +0 -25
- package/samples/react/build/robots.txt +0 -3
- package/samples/react/build/static/css/main.073c9b0a.css +0 -2
- package/samples/react/build/static/css/main.073c9b0a.css.map +0 -1
- package/samples/react/build/static/js/787.b83ed06f.chunk.js +0 -2
- package/samples/react/build/static/js/787.b83ed06f.chunk.js.map +0 -1
- package/samples/react/build/static/js/main.0a848807.js +0 -3
- package/samples/react/build/static/js/main.0a848807.js.LICENSE.txt +0 -39
- package/samples/react/build/static/js/main.0a848807.js.map +0 -1
- package/samples/react/build/static/media/sdk-icons.b491623214b2af4cccdb.png +0 -0
- package/samples/react/package-lock.json +0 -28973
- package/samples/react/package.json +0 -44
- package/samples/react/public/favicon.ico +0 -0
- package/samples/react/public/index.html +0 -43
- package/samples/react/public/logo192.png +0 -0
- package/samples/react/public/logo512.png +0 -0
- package/samples/react/public/manifest.json +0 -25
- package/samples/react/public/robots.txt +0 -3
- package/samples/react/src/App.css +0 -38
- package/samples/react/src/App.js +0 -22
- package/samples/react/src/App.test.js +0 -8
- package/samples/react/src/assets/img/sdk-icons.png +0 -0
- package/samples/react/src/components/Cart.js +0 -29
- package/samples/react/src/components/ProductCard.js +0 -27
- package/samples/react/src/context/CartContext.js +0 -116
- package/samples/react/src/index.css +0 -13
- package/samples/react/src/index.js +0 -17
- package/samples/react/src/logo.svg +0 -1
- package/samples/react/src/reportWebVitals.js +0 -13
- package/samples/react/src/screens/Checkout.js +0 -82
- package/samples/react/src/screens/Store.js +0 -21
- package/samples/react/src/setupTests.js +0 -5
- package/samples/react/src/storeProducts.js +0 -30
- package/src/classes/3dsHandler.js +0 -203
- package/src/classes/BaseInlineCheckout.js +0 -324
- package/src/classes/LiteInlineCheckout.js +0 -220
- package/src/classes/checkout.js +0 -125
- package/src/classes/globalLoader.js +0 -29
- package/src/classes/inlineCheckout.js +0 -515
- package/src/data/apmApi.js +0 -44
- package/src/data/businessApi.js +0 -19
- package/src/data/cardApi.js +0 -143
- package/src/data/checkoutApi.js +0 -92
- package/src/data/customerApi.js +0 -37
- package/src/data/index.js +0 -17
- package/src/data/openPayApi.js +0 -16
- package/src/data/skyflowApi.js +0 -18
- package/src/helpers/skyflow.js +0 -361
- package/src/helpers/styles.js +0 -61
- package/src/helpers/template-skeleton.js +0 -59
- package/src/helpers/template.js +0 -743
- package/src/helpers/utils.js +0 -163
- package/src/helpers/validations.js +0 -54
- package/src/index-dev.js +0 -307
- package/src/index.html +0 -172
- package/src/index.js +0 -15
- package/src/shared/catalog/paymentMethodsCatalog.js +0 -247
- package/src/shared/constants/messages.js +0 -10
- package/src/shared/constants/paymentMethodAPM.js +0 -63
- package/src/shared/constants/tonderUrl.js +0 -8
- package/webpack.config.js +0 -77
package/src/helpers/utils.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
export async function addScripts() {
|
|
2
|
-
try {
|
|
3
|
-
const skyflowScript = document.createElement("script");
|
|
4
|
-
skyflowScript.src = "https://js.skyflow.com/v1/index.js";
|
|
5
|
-
await new Promise((resolve, reject) => {
|
|
6
|
-
skyflowScript.onload = resolve;
|
|
7
|
-
skyflowScript.onerror = reject;
|
|
8
|
-
document.head.appendChild(skyflowScript);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const openPay1Script = document.createElement("script");
|
|
12
|
-
openPay1Script.src = "https://openpay.s3.amazonaws.com/openpay.v1.min.js";
|
|
13
|
-
await new Promise((resolve, reject) => {
|
|
14
|
-
openPay1Script.onload = resolve;
|
|
15
|
-
openPay1Script.onerror = reject;
|
|
16
|
-
document.head.appendChild(openPay1Script);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const openPay2Script = document.createElement("script");
|
|
20
|
-
openPay2Script.src = "https://openpay.s3.amazonaws.com/openpay-data.v1.min.js";
|
|
21
|
-
await new Promise((resolve, reject) => {
|
|
22
|
-
openPay2Script.onload = resolve;
|
|
23
|
-
openPay2Script.onerror = reject;
|
|
24
|
-
document.head.appendChild(openPay2Script);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
} catch (error) {
|
|
28
|
-
console.error("Error loading scripts", error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function toCurrency(value) {
|
|
33
|
-
if (isNaN(parseFloat(value))) {
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
var formatter = new Intl.NumberFormat("es-MX", {
|
|
37
|
-
style: "currency",
|
|
38
|
-
currency: "MXN",
|
|
39
|
-
minimumFractionDigits: 2
|
|
40
|
-
});
|
|
41
|
-
return formatter.format(value);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function showError(message) {
|
|
45
|
-
var msgErrorDiv = document.getElementById("msgError");
|
|
46
|
-
msgErrorDiv.classList.add("error-container");
|
|
47
|
-
msgErrorDiv.innerHTML = message;
|
|
48
|
-
setTimeout(function () {
|
|
49
|
-
try {
|
|
50
|
-
document.querySelector("#tonderPayButton").disabled = false;
|
|
51
|
-
} catch (error) {}
|
|
52
|
-
msgErrorDiv.classList.remove("error-container");
|
|
53
|
-
msgErrorDiv.innerHTML = "";
|
|
54
|
-
}, 3000);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function showMessage(message, containerId) {
|
|
58
|
-
const msgDiv = document.getElementById(`${containerId}`);
|
|
59
|
-
if(msgDiv) {
|
|
60
|
-
msgDiv.classList.add("message-container");
|
|
61
|
-
msgDiv.innerHTML = message;
|
|
62
|
-
setTimeout(function () {
|
|
63
|
-
msgDiv.classList.remove("message-container");
|
|
64
|
-
msgDiv.innerHTML = "";
|
|
65
|
-
}, 3000);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export function getBrowserInfo() {
|
|
69
|
-
const browserInfo = {
|
|
70
|
-
javascript_enabled: true, // Assumed since JavaScript is running
|
|
71
|
-
time_zone: new Date().getTimezoneOffset(),
|
|
72
|
-
language: navigator.language || 'en-US', // Fallback to 'en-US'
|
|
73
|
-
color_depth: window.screen ? window.screen.colorDepth : null,
|
|
74
|
-
screen_width: window.screen ? window.screen.width * window.devicePixelRatio || window.screen.width : null,
|
|
75
|
-
screen_height: window.screen ? window.screen.height * window.devicePixelRatio || window.screen.height : null,
|
|
76
|
-
user_agent: navigator.userAgent,
|
|
77
|
-
};
|
|
78
|
-
return browserInfo;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const mapCards = (card) => {
|
|
82
|
-
const newCard = { ...card.fields };
|
|
83
|
-
const carArr = newCard.card_number.split("-");
|
|
84
|
-
const last = carArr[carArr.length - 1];
|
|
85
|
-
newCard.card_number = `••••${last}`;
|
|
86
|
-
return newCard;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const getCardType = (scheme) => {
|
|
90
|
-
if(scheme === "Visa") { // Check if visa
|
|
91
|
-
return "https://d35a75syrgujp0.cloudfront.net/cards/visa.png"
|
|
92
|
-
} else if(scheme === "Mastercard") { // Check if master
|
|
93
|
-
return "https://d35a75syrgujp0.cloudfront.net/cards/mastercard.png"
|
|
94
|
-
} else if (scheme === "American Express") { // Check if amex
|
|
95
|
-
return "https://d35a75syrgujp0.cloudfront.net/cards/american_express.png"
|
|
96
|
-
} else {
|
|
97
|
-
return "https://d35a75syrgujp0.cloudfront.net/cards/default_card.png"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
export const clearSpace = (text) => {
|
|
101
|
-
return text.trim().replace(/\s+/g, '');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
export function formatPublicErrorResponse(data, error) {
|
|
106
|
-
let code = 200
|
|
107
|
-
try {
|
|
108
|
-
code = Number(error?.code || 200)
|
|
109
|
-
}catch{}
|
|
110
|
-
|
|
111
|
-
const default_res = {
|
|
112
|
-
status: "error",
|
|
113
|
-
code,
|
|
114
|
-
message: "",
|
|
115
|
-
detail: error?.body?.detail || error?.body?.error || error.body || "Ocurrio un error inesperado."
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
...default_res,
|
|
120
|
-
...data
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export async function buildErrorResponse(response, resJson) {
|
|
125
|
-
let status = response.status.toString();
|
|
126
|
-
let message = resJson.detail || "Error";
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
code: status,
|
|
130
|
-
body: resJson,
|
|
131
|
-
name: status,
|
|
132
|
-
message: message,
|
|
133
|
-
stack: undefined,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function buildErrorResponseFromCatch(e) {
|
|
138
|
-
return {
|
|
139
|
-
code: e?.status ? e.status : e.code,
|
|
140
|
-
body: e?.body,
|
|
141
|
-
name: e ? typeof e == "string" ? "catch" : e.name : "Error",
|
|
142
|
-
message: e ? (typeof e == "string" ? e : e.message) : "Error",
|
|
143
|
-
stack: typeof e == "string" ? undefined : e.stack,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function injectMercadoPagoSecurity() {
|
|
148
|
-
try {
|
|
149
|
-
const script = document.createElement('script');
|
|
150
|
-
script.src = "https://www.mercadopago.com/v2/security.js";
|
|
151
|
-
script.setAttribute('view', '');
|
|
152
|
-
script.onload = () => {
|
|
153
|
-
console.log("Mercado Pago script loaded successfully.");
|
|
154
|
-
};
|
|
155
|
-
script.onerror = (error) => {
|
|
156
|
-
console.error("Error loading Mercado Pago script:", error);
|
|
157
|
-
};
|
|
158
|
-
document.head.appendChild(script);
|
|
159
|
-
} catch (error) {
|
|
160
|
-
console.error("Error attempting to inject Mercado Pago script:", error);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export function validateCardNumber(cardNumber) {
|
|
2
|
-
const regex = /^\d{12,19}$/;
|
|
3
|
-
return regex.test(cardNumber) && luhnCheck(cardNumber);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function validateCardholderName(name) {
|
|
7
|
-
const regex = /^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/;
|
|
8
|
-
return regex.test(name);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function validateCVV(cvv) {
|
|
12
|
-
const regex = /^\d{3,4}$/;
|
|
13
|
-
return regex.test(cvv);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function validateExpirationDate(expirationDate) {
|
|
17
|
-
const regex = /^(0[1-9]|1[0-2])\/\d{2}$/;
|
|
18
|
-
if (!regex.test(expirationDate)) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
const [month, year] = expirationDate.split('/');
|
|
22
|
-
const currentDate = new Date();
|
|
23
|
-
const expiration = new Date(`20${year}`, month - 1);
|
|
24
|
-
return expiration >= currentDate;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function validateExpirationMonth(month) {
|
|
28
|
-
const regex = /^(0[1-9]|1[0-2])$/;
|
|
29
|
-
return regex.test(month);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function validateExpirationYear(year) {
|
|
33
|
-
const regex = /^\d{2}$/;
|
|
34
|
-
if (!regex.test(year)) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
const currentYear = new Date().getFullYear() % 100;
|
|
38
|
-
return parseInt(year, 10) >= currentYear;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const luhnCheck = num => {
|
|
42
|
-
const arr = `${num}`
|
|
43
|
-
.split('')
|
|
44
|
-
.reverse()
|
|
45
|
-
.map(x => Number.parseInt(x));
|
|
46
|
-
const lastDigit = arr.shift();
|
|
47
|
-
let sum = arr.reduce(
|
|
48
|
-
(acc, val, i) =>
|
|
49
|
-
i % 2 !== 0 ? acc + val : acc + ((val *= 2) > 9 ? val - 9 : val),
|
|
50
|
-
0
|
|
51
|
-
);
|
|
52
|
-
sum += lastDigit;
|
|
53
|
-
return sum % 10 === 0;
|
|
54
|
-
};
|
package/src/index-dev.js
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { InlineCheckout } from "./classes/inlineCheckout";
|
|
2
|
-
import { LiteInlineCheckout } from "./classes/LiteInlineCheckout";
|
|
3
|
-
import { Maskito } from "@maskito/core";
|
|
4
|
-
import { validateCardNumber } from "./helpers/validations";
|
|
5
|
-
|
|
6
|
-
const customStyles = {
|
|
7
|
-
inputStyles: {
|
|
8
|
-
base: {
|
|
9
|
-
border: "2px dashed #4a90e2",
|
|
10
|
-
padding: "12px 8px",
|
|
11
|
-
borderRadius: "8px",
|
|
12
|
-
color: "#333333",
|
|
13
|
-
backgroundColor: "#f0f0f0",
|
|
14
|
-
fontFamily: '"Arial", sans-serif',
|
|
15
|
-
fontSize: "14px",
|
|
16
|
-
"&::placeholder": {
|
|
17
|
-
color: "#888888",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
cardIcon: {
|
|
21
|
-
position: "absolute",
|
|
22
|
-
left: "6px",
|
|
23
|
-
bottom: "calc(50% - 12px)",
|
|
24
|
-
},
|
|
25
|
-
complete: {
|
|
26
|
-
color: "#4caf50",
|
|
27
|
-
},
|
|
28
|
-
empty: {},
|
|
29
|
-
focus: {},
|
|
30
|
-
invalid: {
|
|
31
|
-
border: "1px solid #f44336",
|
|
32
|
-
},
|
|
33
|
-
global: {
|
|
34
|
-
"@import":
|
|
35
|
-
'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")',
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
labelStyles: {
|
|
39
|
-
base: {
|
|
40
|
-
fontSize: "14px",
|
|
41
|
-
fontWeight: "bold",
|
|
42
|
-
fontFamily: '"Inter", sans-serif',
|
|
43
|
-
color: "#4a90e2",
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
errorTextStyles: {
|
|
47
|
-
base: {
|
|
48
|
-
fontSize: "12px",
|
|
49
|
-
fontWeight: "500",
|
|
50
|
-
color: "#e74c3c",
|
|
51
|
-
fontFamily: '"Inter", sans-serif',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
labels: {
|
|
55
|
-
nameLabel: "Nombre de la de Tarjeta",
|
|
56
|
-
cardLabel: "Número de Tarjeta",
|
|
57
|
-
cvvLabel: "Código de Seguridad",
|
|
58
|
-
expiryDateLabel: "Fecha de Expiración",
|
|
59
|
-
},
|
|
60
|
-
placeholders: {
|
|
61
|
-
namePlaceholder: "Nombre como aparece en la tarjeta",
|
|
62
|
-
cardPlaceholder: "0000 0000 0000 0000",
|
|
63
|
-
cvvPlaceholder: "123",
|
|
64
|
-
expiryMonthPlaceholder: "Mes",
|
|
65
|
-
expiryYearPlaceholder: "Año",
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const checkoutData = {
|
|
70
|
-
customer: {
|
|
71
|
-
firstName: "Adrian",
|
|
72
|
-
lastName: "Martinez",
|
|
73
|
-
country: "Mexico",
|
|
74
|
-
address: "Pinos 507, Col El Tecuan",
|
|
75
|
-
city: "Durango",
|
|
76
|
-
state: "Durango",
|
|
77
|
-
postCode: "34105",
|
|
78
|
-
email: "adrian@email.com",
|
|
79
|
-
phone: "8161234567",
|
|
80
|
-
},
|
|
81
|
-
currency: "mxn",
|
|
82
|
-
cart: {
|
|
83
|
-
total: 399,
|
|
84
|
-
items: [
|
|
85
|
-
{
|
|
86
|
-
description: "Black T-Shirt",
|
|
87
|
-
quantity: 1,
|
|
88
|
-
price_unit: 1,
|
|
89
|
-
discount: 0,
|
|
90
|
-
taxes: 0,
|
|
91
|
-
product_reference: 1,
|
|
92
|
-
name: "T-Shirt",
|
|
93
|
-
amount_total: 399,
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
// card: { "skyflow_id": "53ca875c-16fd-4395-8ac9-c756613dbaf9" },
|
|
98
|
-
// metadata: {
|
|
99
|
-
// order_id: 123456
|
|
100
|
-
// }
|
|
101
|
-
// Reference from the merchant
|
|
102
|
-
order_reference: "ORD-123456"
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// localhost
|
|
106
|
-
const apiKey = "11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27";
|
|
107
|
-
const returnUrl = "http://localhost:8080/";
|
|
108
|
-
// stage
|
|
109
|
-
// const apiKey = "8365683bdc33dd6d50fe2397188d79f1a6765852";
|
|
110
|
-
|
|
111
|
-
const commonConfig = {
|
|
112
|
-
mode: "stage",
|
|
113
|
-
apiKey,
|
|
114
|
-
returnUrl: returnUrl + "?mode=" + getCheckoutMode(),
|
|
115
|
-
styles: customStyles,
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
let inlineCheckout;
|
|
119
|
-
let liteInlineCheckout;
|
|
120
|
-
|
|
121
|
-
function getCheckoutMode() {
|
|
122
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
123
|
-
return urlParams.get("mode") || "inline";
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function setupInlineCheckout() {
|
|
127
|
-
inlineCheckout = new InlineCheckout({
|
|
128
|
-
...commonConfig,
|
|
129
|
-
customization: {
|
|
130
|
-
saveCards: {
|
|
131
|
-
showSaveCardOption: true, // Usar para mostrar/ocultar el checkbox de guardar tarjeta para futuros pagos
|
|
132
|
-
autoSave: false, // Usar para guardar automáticamente la tarjeta (sin necesidad de mostrar el checkbox)
|
|
133
|
-
showSaved: true // Usar para mostrar/ocultar el listado de tarjetas guardadas
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
inlineCheckout.configureCheckout({
|
|
138
|
-
secureToken: "eyJhbGc...",
|
|
139
|
-
...checkoutData
|
|
140
|
-
});
|
|
141
|
-
inlineCheckout.injectCheckout();
|
|
142
|
-
// ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
|
|
143
|
-
inlineCheckout.verify3dsTransaction().then((response) => {
|
|
144
|
-
console.log("Verify 3ds response", response);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
const payButton = document.getElementById("pay-button");
|
|
148
|
-
payButton.addEventListener("click", async function () {
|
|
149
|
-
try {
|
|
150
|
-
payButton.textContent = "Procesando...";
|
|
151
|
-
const response = await inlineCheckout.payment(checkoutData);
|
|
152
|
-
console.log("Respuesta del pago:", response);
|
|
153
|
-
alert("Pago realizado con éxito");
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.log("Error en el pago:", error.details);
|
|
156
|
-
alert("Error al realizar el pago");
|
|
157
|
-
} finally {
|
|
158
|
-
payButton.textContent = "Pagar";
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function setupLiteInlineCheckout() {
|
|
164
|
-
loadMaskitoMask();
|
|
165
|
-
liteInlineCheckout = new LiteInlineCheckout(commonConfig);
|
|
166
|
-
liteInlineCheckout.configureCheckout({
|
|
167
|
-
customer: checkoutData.customer,
|
|
168
|
-
secureToken: "eyJhbGc..."
|
|
169
|
-
});
|
|
170
|
-
liteInlineCheckout.injectCheckout().then(() => {
|
|
171
|
-
liteInlineCheckout.getCustomerCards().then((r) => {
|
|
172
|
-
console.log('customer cards', r)
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
liteInlineCheckout.verify3dsTransaction().then((response) => {
|
|
177
|
-
console.log("Verify 3ds response", response);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const liteForm = document.getElementById("lite-payment-form");
|
|
181
|
-
const payButton = document.getElementById("pay-button-lite");
|
|
182
|
-
liteForm.addEventListener("submit", async function (event) {
|
|
183
|
-
event.preventDefault();
|
|
184
|
-
|
|
185
|
-
const cardData = {
|
|
186
|
-
card_number: document.getElementById("card-number").value,
|
|
187
|
-
cardholder_name: document.getElementById("card-name").value,
|
|
188
|
-
expiration_month: document.getElementById("month").value,
|
|
189
|
-
expiration_year: document.getElementById("year").value,
|
|
190
|
-
cvv: document.getElementById("cvv").value,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
try {
|
|
194
|
-
payButton.textContent = "Procesando...";
|
|
195
|
-
const paymentData = {
|
|
196
|
-
...checkoutData,
|
|
197
|
-
card: cardData,
|
|
198
|
-
};
|
|
199
|
-
const response = await liteInlineCheckout.payment(paymentData);
|
|
200
|
-
console.log("Respuesta del pago:", response);
|
|
201
|
-
alert("Pago realizado con éxito");
|
|
202
|
-
} catch (error) {
|
|
203
|
-
console.error("Error en el pago:", error);
|
|
204
|
-
alert("Error al realizar el pago");
|
|
205
|
-
} finally {
|
|
206
|
-
payButton.textContent = "Pagar Ahora";
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function setupCheckout() {
|
|
212
|
-
const mode = getCheckoutMode();
|
|
213
|
-
document.querySelectorAll(".tab-content").forEach((content) => {
|
|
214
|
-
content.style.display = "none";
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
if (mode === "inline") {
|
|
218
|
-
document.getElementById("inline-content").style.display = "block";
|
|
219
|
-
setupInlineCheckout();
|
|
220
|
-
} else {
|
|
221
|
-
document.getElementById("lite-content").style.display = "block";
|
|
222
|
-
setupLiteInlineCheckout();
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function loadMaskitoMask() {
|
|
227
|
-
const cardNumberInput = document.getElementById("card-number");
|
|
228
|
-
const monthInput = document.getElementById("month");
|
|
229
|
-
const yearInput = document.getElementById("year");
|
|
230
|
-
const cvvInput = document.getElementById("cvv");
|
|
231
|
-
const nameInput = document.getElementById("card-name");
|
|
232
|
-
|
|
233
|
-
// Definir las opciones para las máscaras
|
|
234
|
-
const cardNumberOptions = {
|
|
235
|
-
mask: [
|
|
236
|
-
...Array(4).fill(/\d/),
|
|
237
|
-
" ",
|
|
238
|
-
...Array(4).fill(/\d/),
|
|
239
|
-
" ",
|
|
240
|
-
...Array(4).fill(/\d/),
|
|
241
|
-
" ",
|
|
242
|
-
...Array(4).fill(/\d/),
|
|
243
|
-
" ",
|
|
244
|
-
...Array(3).fill(/\d/),
|
|
245
|
-
],
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
const monthOptions = {
|
|
249
|
-
mask: [/[0-1]/, /\d/],
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
const yearOptions = {
|
|
253
|
-
mask: [/\d/, /\d/],
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
const nameOptions = {
|
|
257
|
-
mask: /^[a-zA-Z\s]*$/,
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
const cvvOptions = {
|
|
261
|
-
mask: [...Array(3).fill(/\d/)],
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
// Aplicar Maskito a cada campo
|
|
265
|
-
const cardNumberMask = new Maskito(cardNumberInput, cardNumberOptions);
|
|
266
|
-
const monthMask = new Maskito(monthInput, monthOptions);
|
|
267
|
-
const yearMask = new Maskito(yearInput, yearOptions);
|
|
268
|
-
const cvvMask = new Maskito(cvvInput, cvvOptions);
|
|
269
|
-
const nameMask = new Maskito(nameInput, nameOptions);
|
|
270
|
-
|
|
271
|
-
cardNumberInput.addEventListener("input", () => {
|
|
272
|
-
const cardNumber = cardNumberInput.value.replace(/\s+/g, "");
|
|
273
|
-
if (!validateCardNumber(cardNumber)) {
|
|
274
|
-
cardNumberInput.setCustomValidity("Número de tarjeta inválido");
|
|
275
|
-
cardNumberInput.classList.add("invalid");
|
|
276
|
-
} else {
|
|
277
|
-
cardNumberInput.setCustomValidity("");
|
|
278
|
-
cardNumberInput.classList.remove("invalid");
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
window.addEventListener("beforeunload", () => {
|
|
283
|
-
cardNumberMask.destroy();
|
|
284
|
-
monthMask.destroy();
|
|
285
|
-
yearMask.destroy();
|
|
286
|
-
cvvMask.destroy();
|
|
287
|
-
nameMask.destroy();
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
function updateActiveTab() {
|
|
291
|
-
const mode = getCheckoutMode();
|
|
292
|
-
document.querySelectorAll(".tab").forEach((tab) => {
|
|
293
|
-
tab.classList.remove("active");
|
|
294
|
-
});
|
|
295
|
-
document.querySelector(`[data-mode="${mode}"]`).classList.add("active");
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function switchTab(mode) {
|
|
299
|
-
window.location.href = `${window.location.pathname}?mode=${mode}`;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
document.addEventListener("DOMContentLoaded", function () {
|
|
303
|
-
setupCheckout();
|
|
304
|
-
updateActiveTab();
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
window.switchTab = switchTab;
|
package/src/index.html
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<style>
|
|
8
|
-
#checkout-container {
|
|
9
|
-
display: flex;
|
|
10
|
-
justify-content: center;
|
|
11
|
-
}
|
|
12
|
-
#pay-button {
|
|
13
|
-
padding: 10px 20px;
|
|
14
|
-
margin-top: 30px;
|
|
15
|
-
background-color: #4a90e2;
|
|
16
|
-
color: white;
|
|
17
|
-
border: none;
|
|
18
|
-
border-radius: 5px;
|
|
19
|
-
font-size: 16px;
|
|
20
|
-
cursor: pointer;
|
|
21
|
-
transition: background-color 0.3s;
|
|
22
|
-
}
|
|
23
|
-
#payButton:hover {
|
|
24
|
-
background-color: #357abd;
|
|
25
|
-
}
|
|
26
|
-
.cart-details {
|
|
27
|
-
font-size: 3rem;
|
|
28
|
-
font-weight: bold;
|
|
29
|
-
padding: 2rem;
|
|
30
|
-
display: flex;
|
|
31
|
-
justify-content: center;
|
|
32
|
-
}
|
|
33
|
-
.button-container {
|
|
34
|
-
width: 100%;
|
|
35
|
-
display: flex;
|
|
36
|
-
justify-content: center;
|
|
37
|
-
}
|
|
38
|
-
.tab-container {
|
|
39
|
-
display: flex;
|
|
40
|
-
justify-content: center;
|
|
41
|
-
margin-bottom: 20px;
|
|
42
|
-
}
|
|
43
|
-
.tab {
|
|
44
|
-
padding: 10px 20px;
|
|
45
|
-
cursor: pointer;
|
|
46
|
-
background-color: #f1f1f1;
|
|
47
|
-
border: 1px solid #ccc;
|
|
48
|
-
border-bottom: none;
|
|
49
|
-
margin-right: 5px;
|
|
50
|
-
}
|
|
51
|
-
.tab.active {
|
|
52
|
-
background-color: #fff;
|
|
53
|
-
border-bottom: 1px solid #4a90e2;
|
|
54
|
-
}
|
|
55
|
-
.tab-content {
|
|
56
|
-
display: none;
|
|
57
|
-
width: 100%;
|
|
58
|
-
}
|
|
59
|
-
.card-form {
|
|
60
|
-
max-width: 400px;
|
|
61
|
-
margin: 0 auto;
|
|
62
|
-
}
|
|
63
|
-
.form-group {
|
|
64
|
-
margin-bottom: 1.5rem;
|
|
65
|
-
}
|
|
66
|
-
.form-group label {
|
|
67
|
-
display: block;
|
|
68
|
-
margin-bottom: 0.5rem;
|
|
69
|
-
font-weight: 500;
|
|
70
|
-
}
|
|
71
|
-
.form-group input {
|
|
72
|
-
width: 100%;
|
|
73
|
-
padding: 0.75rem;
|
|
74
|
-
border: 1px solid #ddd;
|
|
75
|
-
border-radius: 4px;
|
|
76
|
-
font-size: 1rem;
|
|
77
|
-
transition: border-color 0.3s ease;
|
|
78
|
-
}
|
|
79
|
-
.form-group input:focus {
|
|
80
|
-
outline: none;
|
|
81
|
-
border-color: #4a90e2;
|
|
82
|
-
}
|
|
83
|
-
.form-row {
|
|
84
|
-
display: flex;
|
|
85
|
-
gap: 3rem;
|
|
86
|
-
}
|
|
87
|
-
.form-row .form-group {
|
|
88
|
-
flex: 1;
|
|
89
|
-
}
|
|
90
|
-
.btn {
|
|
91
|
-
display: inline-block;
|
|
92
|
-
padding: 0.75rem 1.5rem;
|
|
93
|
-
background-color: #4a90e2;
|
|
94
|
-
color: #fff;
|
|
95
|
-
border: none;
|
|
96
|
-
border-radius: 4px;
|
|
97
|
-
font-size: 1rem;
|
|
98
|
-
cursor: pointer;
|
|
99
|
-
transition: background-color 0.3s ease;
|
|
100
|
-
}
|
|
101
|
-
.btn:hover {
|
|
102
|
-
background-color: #357abd;
|
|
103
|
-
}
|
|
104
|
-
.cart-details {
|
|
105
|
-
text-align: center;
|
|
106
|
-
font-size: 1.5rem;
|
|
107
|
-
margin-bottom: 2rem;
|
|
108
|
-
}
|
|
109
|
-
.input-md {
|
|
110
|
-
max-width: 100%;
|
|
111
|
-
}
|
|
112
|
-
.invalid{
|
|
113
|
-
border: 2px solid red !important;
|
|
114
|
-
}
|
|
115
|
-
</style>
|
|
116
|
-
</head>
|
|
117
|
-
|
|
118
|
-
<body>
|
|
119
|
-
<div class="checkout-container">
|
|
120
|
-
<div class="tab-container">
|
|
121
|
-
<a href="?mode=inline" class="tab" data-mode="inline" onclick="switchTab('inline'); return false;">Inline Checkout</a>
|
|
122
|
-
<a href="?mode=lite" class="tab" data-mode="lite" onclick="switchTab('lite'); return false;">Lite Inline Checkout</a>
|
|
123
|
-
</div>
|
|
124
|
-
|
|
125
|
-
<div id="lite-content" class="tab-content">
|
|
126
|
-
<div class="cart-details">
|
|
127
|
-
<span>Total </span>
|
|
128
|
-
<div id="cart-total-lite">$399</div>
|
|
129
|
-
</div>
|
|
130
|
-
<form id="lite-payment-form" class="card-form">
|
|
131
|
-
<div class="form-group">
|
|
132
|
-
<label for="card-number">Número de Tarjeta</label>
|
|
133
|
-
<input type="text" id="card-number" placeholder="1234 5678 9012 3456" required>
|
|
134
|
-
</div>
|
|
135
|
-
<div class="form-group">
|
|
136
|
-
<label for="card-name">Nombre en la Tarjeta</label>
|
|
137
|
-
<input type="text" id="card-name" placeholder="John Doe" required>
|
|
138
|
-
</div>
|
|
139
|
-
<div class="form-row">
|
|
140
|
-
<div class="form-group">
|
|
141
|
-
<label for="month">Fecha de Expiración</label>
|
|
142
|
-
<div class="form-row">
|
|
143
|
-
<input class="input-md" type="text" id="month" placeholder="MM" required>
|
|
144
|
-
<input class="input-md" type="text" id="year" placeholder="AA" required>
|
|
145
|
-
</div>
|
|
146
|
-
</div>
|
|
147
|
-
<div class="form-group">
|
|
148
|
-
<label for="cvv">CVV</label>
|
|
149
|
-
<input class="input-md" type="text" id="cvv" placeholder="123" required>
|
|
150
|
-
</div>
|
|
151
|
-
</div>
|
|
152
|
-
<button type="submit" class="btn" id="pay-button-lite">Pagar Ahora</button>
|
|
153
|
-
</form>
|
|
154
|
-
</div>
|
|
155
|
-
<div id="inline-content" class="tab-content">
|
|
156
|
-
<div class="cart-details">
|
|
157
|
-
<span>Total </span>
|
|
158
|
-
<div id="cart-total">$399</div>
|
|
159
|
-
</div>
|
|
160
|
-
<form id="payment-form">
|
|
161
|
-
<div id="tonder-checkout"></div>
|
|
162
|
-
</form>
|
|
163
|
-
<div class="button-container">
|
|
164
|
-
<button id="pay-button">Pagar</button>
|
|
165
|
-
</div>
|
|
166
|
-
</div>
|
|
167
|
-
</div>
|
|
168
|
-
</body>
|
|
169
|
-
<script src="https://js.skyflow.com/v1/index.js"></script>
|
|
170
|
-
<script src="https://openpay.s3.amazonaws.com/openpay.v1.min.js"></script>
|
|
171
|
-
<script src="https://openpay.s3.amazonaws.com/openpay-data.v1.min.js"></script>
|
|
172
|
-
</html>
|