tonder-web-sdk 1.16.3 → 1.16.6-beta.DEV-1433.2

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.
Files changed (106) hide show
  1. package/README.md +22 -25
  2. package/package.json +10 -3
  3. package/types/common.d.ts +4 -0
  4. package/v1/bundle.min.js +1 -18
  5. package/.env-example +0 -1
  6. package/.husky/pre-commit +0 -4
  7. package/.prettierignore +0 -8
  8. package/.prettierrc +0 -10
  9. package/cypress/e2e/1-getting-started/todo.cy.js +0 -143
  10. package/cypress/e2e/2-advanced-examples/actions.cy.js +0 -299
  11. package/cypress/e2e/2-advanced-examples/aliasing.cy.js +0 -39
  12. package/cypress/e2e/2-advanced-examples/assertions.cy.js +0 -176
  13. package/cypress/e2e/2-advanced-examples/connectors.cy.js +0 -98
  14. package/cypress/e2e/2-advanced-examples/cookies.cy.js +0 -118
  15. package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +0 -185
  16. package/cypress/e2e/2-advanced-examples/files.cy.js +0 -85
  17. package/cypress/e2e/2-advanced-examples/location.cy.js +0 -32
  18. package/cypress/e2e/2-advanced-examples/misc.cy.js +0 -104
  19. package/cypress/e2e/2-advanced-examples/navigation.cy.js +0 -56
  20. package/cypress/e2e/2-advanced-examples/network_requests.cy.js +0 -163
  21. package/cypress/e2e/2-advanced-examples/querying.cy.js +0 -114
  22. package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +0 -201
  23. package/cypress/e2e/2-advanced-examples/storage.cy.js +0 -110
  24. package/cypress/e2e/2-advanced-examples/traversal.cy.js +0 -121
  25. package/cypress/e2e/2-advanced-examples/utilities.cy.js +0 -108
  26. package/cypress/e2e/2-advanced-examples/viewport.cy.js +0 -58
  27. package/cypress/e2e/2-advanced-examples/waiting.cy.js +0 -30
  28. package/cypress/e2e/2-advanced-examples/window.cy.js +0 -22
  29. package/cypress/fixtures/example.json +0 -5
  30. package/cypress/support/commands.js +0 -25
  31. package/cypress/support/e2e.js +0 -20
  32. package/cypress.config.js +0 -9
  33. package/eslint.config.mjs +0 -15
  34. package/index.js.example +0 -50
  35. package/samples/react/README.md +0 -70
  36. package/samples/react/build/asset-manifest.json +0 -16
  37. package/samples/react/build/favicon.ico +0 -0
  38. package/samples/react/build/index.html +0 -1
  39. package/samples/react/build/logo192.png +0 -0
  40. package/samples/react/build/logo512.png +0 -0
  41. package/samples/react/build/manifest.json +0 -25
  42. package/samples/react/build/robots.txt +0 -3
  43. package/samples/react/build/static/css/main.073c9b0a.css +0 -2
  44. package/samples/react/build/static/css/main.073c9b0a.css.map +0 -1
  45. package/samples/react/build/static/js/787.b83ed06f.chunk.js +0 -2
  46. package/samples/react/build/static/js/787.b83ed06f.chunk.js.map +0 -1
  47. package/samples/react/build/static/js/main.0a848807.js +0 -3
  48. package/samples/react/build/static/js/main.0a848807.js.LICENSE.txt +0 -39
  49. package/samples/react/build/static/js/main.0a848807.js.map +0 -1
  50. package/samples/react/build/static/media/sdk-icons.b491623214b2af4cccdb.png +0 -0
  51. package/samples/react/package-lock.json +0 -28973
  52. package/samples/react/package.json +0 -44
  53. package/samples/react/public/favicon.ico +0 -0
  54. package/samples/react/public/index.html +0 -43
  55. package/samples/react/public/logo192.png +0 -0
  56. package/samples/react/public/logo512.png +0 -0
  57. package/samples/react/public/manifest.json +0 -25
  58. package/samples/react/public/robots.txt +0 -3
  59. package/samples/react/src/App.css +0 -38
  60. package/samples/react/src/App.js +0 -22
  61. package/samples/react/src/App.test.js +0 -8
  62. package/samples/react/src/assets/img/sdk-icons.png +0 -0
  63. package/samples/react/src/components/Cart.js +0 -29
  64. package/samples/react/src/components/ProductCard.js +0 -27
  65. package/samples/react/src/context/CartContext.js +0 -116
  66. package/samples/react/src/index.css +0 -13
  67. package/samples/react/src/index.js +0 -17
  68. package/samples/react/src/logo.svg +0 -1
  69. package/samples/react/src/reportWebVitals.js +0 -13
  70. package/samples/react/src/screens/Checkout.js +0 -82
  71. package/samples/react/src/screens/Store.js +0 -21
  72. package/samples/react/src/setupTests.js +0 -5
  73. package/samples/react/src/storeProducts.js +0 -30
  74. package/src/classes/3dsHandler.js +0 -199
  75. package/src/classes/BaseInlineCheckout.js +0 -303
  76. package/src/classes/LiteInlineCheckout.js +0 -217
  77. package/src/classes/checkout.js +0 -129
  78. package/src/classes/globalLoader.js +0 -31
  79. package/src/classes/inlineCheckout.js +0 -713
  80. package/src/data/apmApi.js +0 -38
  81. package/src/data/businessApi.js +0 -16
  82. package/src/data/cardApi.js +0 -134
  83. package/src/data/checkoutApi.js +0 -92
  84. package/src/data/customerApi.js +0 -32
  85. package/src/data/index.js +0 -17
  86. package/src/data/openPayApi.js +0 -16
  87. package/src/data/skyflowApi.js +0 -16
  88. package/src/helpers/skyflow.js +0 -370
  89. package/src/helpers/styles.js +0 -90
  90. package/src/helpers/template-skeleton.js +0 -59
  91. package/src/helpers/template.js +0 -1104
  92. package/src/helpers/utils.js +0 -257
  93. package/src/helpers/validations.js +0 -53
  94. package/src/index-dev.js +0 -329
  95. package/src/index.html +0 -180
  96. package/src/index.js +0 -21
  97. package/src/shared/catalog/commonLogosCatalog.js +0 -7
  98. package/src/shared/catalog/paymentMethodsCatalog.js +0 -246
  99. package/src/shared/constants/colors.js +0 -15
  100. package/src/shared/constants/displayMode.js +0 -4
  101. package/src/shared/constants/fieldPathNames.js +0 -4
  102. package/src/shared/constants/htmlTonderIds.js +0 -18
  103. package/src/shared/constants/messages.js +0 -11
  104. package/src/shared/constants/paymentMethodAPM.js +0 -63
  105. package/src/shared/constants/tonderUrl.js +0 -8
  106. package/webpack.config.js +0 -77
@@ -1,257 +0,0 @@
1
- import { defaultStyles } from "./styles";
2
- import get from "lodash.get";
3
- import { HTML_IDS } from "../shared/constants/htmlTonderIds";
4
-
5
- export async function addScripts() {
6
- try {
7
- const skyflowScript = document.createElement("script");
8
- skyflowScript.src = "https://js.skyflow.com/v1/index.js";
9
- await new Promise((resolve, reject) => {
10
- skyflowScript.onload = resolve;
11
- skyflowScript.onerror = reject;
12
- document.head.appendChild(skyflowScript);
13
- });
14
-
15
- const openPay1Script = document.createElement("script");
16
- openPay1Script.src = "https://openpay.s3.amazonaws.com/openpay.v1.min.js";
17
- await new Promise((resolve, reject) => {
18
- openPay1Script.onload = resolve;
19
- openPay1Script.onerror = reject;
20
- document.head.appendChild(openPay1Script);
21
- });
22
-
23
- const openPay2Script = document.createElement("script");
24
- openPay2Script.src = "https://openpay.s3.amazonaws.com/openpay-data.v1.min.js";
25
- await new Promise((resolve, reject) => {
26
- openPay2Script.onload = resolve;
27
- openPay2Script.onerror = reject;
28
- document.head.appendChild(openPay2Script);
29
- });
30
- } catch (error) {
31
- console.error("Error loading scripts", error);
32
- }
33
- }
34
-
35
- export function toCurrency(value) {
36
- if (isNaN(parseFloat(value))) {
37
- return value;
38
- }
39
- var formatter = new Intl.NumberFormat("es-MX", {
40
- style: "currency",
41
- currency: "MXN",
42
- minimumFractionDigits: 2,
43
- });
44
- return formatter.format(value);
45
- }
46
-
47
- export function showError(
48
- message,
49
- selectedId = null,
50
- containerId = HTML_IDS.msgError,
51
- containerTextId = HTML_IDS.msgErrorText,
52
- ) {
53
- try {
54
- const existSelectedId = selectedId && selectedId !== "new";
55
- let msgErrorDiv = document.getElementById(`${containerId}${existSelectedId ? selectedId : ""}`);
56
- let msgErrorText = document.getElementById(
57
- `${containerTextId}${existSelectedId ? selectedId : ""}`,
58
- );
59
- msgErrorText.innerHTML = "";
60
- msgErrorText.innerHTML = message;
61
- msgErrorDiv.style.display = "flex";
62
-
63
- setTimeout(function () {
64
- msgErrorDiv.style.display = "none";
65
- msgErrorText.innerHTML = "";
66
- }, 3000);
67
- } catch (error) {
68
- console.warn("Error showing message error", error);
69
- }
70
- }
71
-
72
- export function showMessage(
73
- message,
74
- selectedId = null,
75
- containerId = HTML_IDS.msgNotification,
76
- containerTextId = HTML_IDS.msgNotificationText,
77
- ) {
78
- try {
79
- const existSelectedId = selectedId && selectedId !== "new";
80
- const msgDiv = document.getElementById(`${containerId}${existSelectedId ? selectedId : ""}`);
81
- if (msgDiv) {
82
- let msgText = document.getElementById(
83
- `${containerTextId}${existSelectedId ? selectedId : ""}`,
84
- );
85
- msgDiv.style.display = "flex";
86
- msgText.innerHTML = "";
87
- msgText.innerHTML = message;
88
- setTimeout(function () {
89
- msgDiv.style.display = "none";
90
- msgText.innerHTML = "";
91
- }, 3000);
92
- }
93
- } catch (error) {
94
- console.error("Error showing message", error);
95
- }
96
- }
97
- export function getBrowserInfo() {
98
- const browserInfo = {
99
- javascript_enabled: true, // Assumed since JavaScript is running
100
- time_zone: new Date().getTimezoneOffset(),
101
- language: navigator.language || "en-US", // Fallback to 'en-US'
102
- color_depth: window.screen ? window.screen.colorDepth : null,
103
- screen_width: window.screen
104
- ? window.screen.width * window.devicePixelRatio || window.screen.width
105
- : null,
106
- screen_height: window.screen
107
- ? window.screen.height * window.devicePixelRatio || window.screen.height
108
- : null,
109
- user_agent: navigator.userAgent,
110
- };
111
- return browserInfo;
112
- }
113
-
114
- export const mapCards = card => {
115
- const newCard = { ...card.fields };
116
- const carArr = newCard.card_number.split("-");
117
- const last = carArr[carArr.length - 1];
118
- newCard.card_number = `••••${last}`;
119
- return newCard;
120
- };
121
-
122
- export const getCardType = (scheme, isDark = false) => {
123
- if (scheme === "Visa") {
124
- // Check if visa
125
- return "https://d35a75syrgujp0.cloudfront.net/cards/visa.png";
126
- } else if (scheme === "Mastercard") {
127
- // Check if master
128
- return "https://d35a75syrgujp0.cloudfront.net/cards/mastercard.png";
129
- } else if (scheme === "American Express") {
130
- // Check if amex
131
- return "https://d35a75syrgujp0.cloudfront.net/cards/american_express.png";
132
- } else {
133
- return `https://d35a75syrgujp0.cloudfront.net/cards/default_card_tonder${isDark ? "_purple" : ""}.png`;
134
- }
135
- };
136
- export const clearSpace = text => {
137
- return text.trim().replace(/\s+/g, "");
138
- };
139
-
140
- export function formatPublicErrorResponse(data, error) {
141
- let code = 200;
142
- try {
143
- code = Number(error?.code || 200);
144
- } catch {}
145
-
146
- const default_res = {
147
- status: "error",
148
- code,
149
- message: "",
150
- detail:
151
- error?.body?.detail || error?.body?.error || error.body || "Ocurrio un error inesperado.",
152
- };
153
-
154
- return {
155
- ...default_res,
156
- ...data,
157
- };
158
- }
159
-
160
- export async function buildErrorResponse(response, resJson) {
161
- let status = response.status.toString();
162
- let message = resJson.detail || "Error";
163
-
164
- return {
165
- code: status,
166
- body: resJson,
167
- name: status,
168
- message: message,
169
- stack: undefined,
170
- };
171
- }
172
-
173
- export function buildErrorResponseFromCatch(e) {
174
- return {
175
- code: e?.status ? e.status : e.code,
176
- body: e?.body,
177
- name: e ? (typeof e == "string" ? "catch" : e.name) : "Error",
178
- message: e ? (typeof e == "string" ? e : e.message) : "Error",
179
- stack: typeof e == "string" ? undefined : e.stack,
180
- };
181
- }
182
-
183
- export function injectMercadoPagoSecurity() {
184
- try {
185
- const script = document.createElement("script");
186
- script.src = "https://www.mercadopago.com/v2/security.js";
187
- script.setAttribute("view", "");
188
- script.onload = () => {
189
- console.log("Mercado Pago script loaded successfully.");
190
- };
191
- script.onerror = error => {
192
- console.error("Error loading Mercado Pago script:", error);
193
- };
194
- document.head.appendChild(script);
195
- } catch (error) {
196
- console.error("Error attempting to inject Mercado Pago script:", error);
197
- }
198
- }
199
-
200
- export function getCardFormLabels(customStyles) {
201
- return {
202
- labels: {
203
- nameLabel: get(customStyles, "labels.nameLabel", defaultStyles.labels.nameLabel),
204
- cardLabel: get(customStyles, "labels.cardLabel", defaultStyles.labels.cardLabel),
205
- cvvLabel: get(customStyles, "labels.cvvLabel", defaultStyles.labels.cvvLabel),
206
- expiryDateLabel: get(
207
- customStyles,
208
- "labels.expiryDateLabel",
209
- defaultStyles.labels.expiryDateLabel,
210
- ),
211
- },
212
- placeholders: {
213
- namePlaceholder: get(
214
- customStyles,
215
- "placeholders.namePlaceholder",
216
- defaultStyles.placeholders.namePlaceholder,
217
- ),
218
- cardPlaceholder: get(
219
- customStyles,
220
- "placeholders.cardPlaceholder",
221
- defaultStyles.placeholders.cardPlaceholder,
222
- ),
223
- cvvPlaceholder: get(
224
- customStyles,
225
- "placeholders.cvvPlaceholder",
226
- defaultStyles.placeholders.cvvPlaceholder,
227
- ),
228
- expiryMonthPlaceholder: get(
229
- customStyles,
230
- "placeholders.expiryMonthPlaceholder",
231
- defaultStyles.placeholders.expiryMonthPlaceholder,
232
- ),
233
- expiryYearPlaceholder: get(
234
- customStyles,
235
- "placeholders.expiryYearPlaceholder",
236
- defaultStyles.placeholders.expiryYearPlaceholder,
237
- ),
238
- },
239
- };
240
- }
241
-
242
- export const executeCallback = async ({ callbacks, callback, data = null, throwError = false }) => {
243
- try {
244
- if (callbacks && callback in callbacks) {
245
- if (data) {
246
- await callbacks[callback](data);
247
- } else {
248
- await callbacks[callback]();
249
- }
250
- }
251
- } catch (e) {
252
- console.error(e);
253
- if (throwError) {
254
- throw e;
255
- }
256
- }
257
- };
@@ -1,53 +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) => (i % 2 !== 0 ? acc + val : acc + ((val *= 2) > 9 ? val - 9 : val)),
49
- 0,
50
- );
51
- sum += lastDigit;
52
- return sum % 10 === 0;
53
- };
package/src/index-dev.js DELETED
@@ -1,329 +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
- displayMode: "light", // usar para cambiar el aspecto ligth/dark
131
- saveCards: {
132
- showSaveCardOption: true, // Usar para mostrar/ocultar el checkbox de guardar tarjeta para futuros pagos
133
- autoSave: false, // Usar para guardar automáticamente la tarjeta (sin necesidad de mostrar el checkbox)
134
- showSaved: true, // Usar para mostrar/ocultar el listado de tarjetas guardadas
135
- },
136
- paymentButton: {
137
- show: false, // Usar para mostrar/ocultar el boton de pago
138
- showAmount: true, // Usar para concatener el monto junto al texto del botón de pago
139
- text: "Pagar", // Usar para cambiar el texto del botón de pago
140
- },
141
- cancelButton: {
142
- show: false, // Usar para mostrar/ocultar el boton de cancelar
143
- text: "Cancelar", // Usar para concatener el monto junto al texto del botón de cancelar
144
- },
145
- paymentMethods: {
146
- show: true, // Usar para mostrar/ocultar el listado de métodos de pago
147
- },
148
- cardForm: {
149
- show: true, // Usar para mostrar/ocultar el formulario de tarjeta
150
- },
151
- },
152
- callbacks: {
153
- // Usar para definir la acción a ejecutar cuando el usuario de click en el botón Cancelar
154
- onCancel: () => {
155
- console.log("onCancel");
156
- },
157
- },
158
- });
159
- inlineCheckout.configureCheckout({
160
- secureToken: "eyJhbGc...",
161
- ...checkoutData,
162
- });
163
- inlineCheckout.injectCheckout();
164
- // ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
165
- inlineCheckout.verify3dsTransaction().then(response => {
166
- console.log("Verify 3ds response", response);
167
- });
168
-
169
- const payButton = document.getElementById("pay-button");
170
- payButton.addEventListener("click", async function () {
171
- try {
172
- payButton.textContent = "Procesando...";
173
- const response = await inlineCheckout.payment(checkoutData);
174
- console.log("Respuesta del pago:", response);
175
- alert("Pago realizado con éxito");
176
- } catch (error) {
177
- console.log("Error en el pago:", error.details);
178
- alert("Error al realizar el pago");
179
- } finally {
180
- payButton.textContent = "Pagar";
181
- }
182
- });
183
- }
184
-
185
- function setupLiteInlineCheckout() {
186
- loadMaskitoMask();
187
- liteInlineCheckout = new LiteInlineCheckout(commonConfig);
188
- liteInlineCheckout.configureCheckout({
189
- customer: checkoutData.customer,
190
- secureToken: "eyJhbGc...",
191
- });
192
- liteInlineCheckout.injectCheckout().then(() => {
193
- liteInlineCheckout.getCustomerCards().then(r => {
194
- console.log("customer cards", r);
195
- });
196
- });
197
-
198
- liteInlineCheckout.verify3dsTransaction().then(response => {
199
- console.log("Verify 3ds response", response);
200
- });
201
-
202
- const liteForm = document.getElementById("lite-payment-form");
203
- const payButton = document.getElementById("pay-button-lite");
204
- liteForm.addEventListener("submit", async function (event) {
205
- event.preventDefault();
206
-
207
- const cardData = {
208
- card_number: document.getElementById("card-number").value,
209
- cardholder_name: document.getElementById("card-name").value,
210
- expiration_month: document.getElementById("month").value,
211
- expiration_year: document.getElementById("year").value,
212
- cvv: document.getElementById("cvv").value,
213
- };
214
-
215
- try {
216
- payButton.textContent = "Procesando...";
217
- const paymentData = {
218
- ...checkoutData,
219
- card: cardData,
220
- };
221
- const response = await liteInlineCheckout.payment(paymentData);
222
- console.log("Respuesta del pago:", response);
223
- alert("Pago realizado con éxito");
224
- } catch (error) {
225
- console.error("Error en el pago:", error);
226
- alert("Error al realizar el pago");
227
- } finally {
228
- payButton.textContent = "Pagar Ahora";
229
- }
230
- });
231
- }
232
-
233
- function setupCheckout() {
234
- const mode = getCheckoutMode();
235
- document.querySelectorAll(".tab-content").forEach(content => {
236
- content.style.display = "none";
237
- });
238
-
239
- if (mode === "inline") {
240
- document.getElementById("inline-content").style.display = "block";
241
- setupInlineCheckout();
242
- } else {
243
- document.getElementById("lite-content").style.display = "block";
244
- setupLiteInlineCheckout();
245
- }
246
- }
247
-
248
- function loadMaskitoMask() {
249
- const cardNumberInput = document.getElementById("card-number");
250
- const monthInput = document.getElementById("month");
251
- const yearInput = document.getElementById("year");
252
- const cvvInput = document.getElementById("cvv");
253
- const nameInput = document.getElementById("card-name");
254
-
255
- // Definir las opciones para las máscaras
256
- const cardNumberOptions = {
257
- mask: [
258
- ...Array(4).fill(/\d/),
259
- " ",
260
- ...Array(4).fill(/\d/),
261
- " ",
262
- ...Array(4).fill(/\d/),
263
- " ",
264
- ...Array(4).fill(/\d/),
265
- " ",
266
- ...Array(3).fill(/\d/),
267
- ],
268
- };
269
-
270
- const monthOptions = {
271
- mask: [/[0-1]/, /\d/],
272
- };
273
-
274
- const yearOptions = {
275
- mask: [/\d/, /\d/],
276
- };
277
-
278
- const nameOptions = {
279
- mask: /^[a-zA-Z\s]*$/,
280
- };
281
-
282
- const cvvOptions = {
283
- mask: [...Array(3).fill(/\d/)],
284
- };
285
-
286
- // Aplicar Maskito a cada campo
287
- const cardNumberMask = new Maskito(cardNumberInput, cardNumberOptions);
288
- const monthMask = new Maskito(monthInput, monthOptions);
289
- const yearMask = new Maskito(yearInput, yearOptions);
290
- const cvvMask = new Maskito(cvvInput, cvvOptions);
291
- const nameMask = new Maskito(nameInput, nameOptions);
292
-
293
- cardNumberInput.addEventListener("input", () => {
294
- const cardNumber = cardNumberInput.value.replace(/\s+/g, "");
295
- if (!validateCardNumber(cardNumber)) {
296
- cardNumberInput.setCustomValidity("Número de tarjeta inválido");
297
- cardNumberInput.classList.add("invalid");
298
- } else {
299
- cardNumberInput.setCustomValidity("");
300
- cardNumberInput.classList.remove("invalid");
301
- }
302
- });
303
-
304
- window.addEventListener("beforeunload", () => {
305
- cardNumberMask.destroy();
306
- monthMask.destroy();
307
- yearMask.destroy();
308
- cvvMask.destroy();
309
- nameMask.destroy();
310
- });
311
- }
312
- function updateActiveTab() {
313
- const mode = getCheckoutMode();
314
- document.querySelectorAll(".tab").forEach(tab => {
315
- tab.classList.remove("active");
316
- });
317
- document.querySelector(`[data-mode="${mode}"]`).classList.add("active");
318
- }
319
-
320
- function switchTab(mode) {
321
- window.location.href = `${window.location.pathname}?mode=${mode}`;
322
- }
323
-
324
- document.addEventListener("DOMContentLoaded", function () {
325
- setupCheckout();
326
- updateActiveTab();
327
- });
328
-
329
- window.switchTab = switchTab;