tonder-web-sdk 1.16.1 → 1.16.5
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/.husky/pre-commit +4 -0
- package/.prettierignore +8 -0
- package/.prettierrc +10 -0
- package/README.md +113 -16
- package/eslint.config.mjs +15 -0
- package/package.json +20 -4
- package/src/classes/3dsHandler.js +58 -62
- package/src/classes/BaseInlineCheckout.js +15 -37
- package/src/classes/LiteInlineCheckout.js +5 -8
- package/src/classes/checkout.js +75 -71
- package/src/classes/globalLoader.js +9 -7
- package/src/classes/inlineCheckout.js +519 -321
- package/src/data/apmApi.js +8 -14
- package/src/data/businessApi.js +5 -8
- package/src/data/cardApi.js +5 -14
- package/src/data/checkoutApi.js +54 -54
- package/src/data/customerApi.js +1 -6
- package/src/data/index.js +15 -15
- package/src/data/openPayApi.js +7 -7
- package/src/data/skyflowApi.js +14 -16
- package/src/helpers/skyflow.js +132 -123
- package/src/helpers/styles.js +56 -27
- package/src/helpers/template-skeleton.js +1 -1
- package/src/helpers/template.js +971 -610
- package/src/helpers/utils.js +152 -58
- package/src/helpers/validations.js +34 -35
- package/src/index-dev.js +41 -11
- package/src/index.html +20 -12
- package/src/index.js +19 -13
- package/src/shared/catalog/commonLogosCatalog.js +7 -0
- package/src/shared/catalog/paymentMethodsCatalog.js +242 -243
- package/src/shared/constants/colors.js +15 -0
- package/src/shared/constants/displayMode.js +4 -0
- package/src/shared/constants/fieldPathNames.js +4 -0
- package/src/shared/constants/htmlTonderIds.js +18 -0
- package/src/shared/constants/messages.js +10 -9
- package/types/card.d.ts +17 -17
- package/types/checkout.d.ts +85 -87
- package/types/common.d.ts +4 -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 +3 -3
package/src/helpers/utils.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { defaultStyles } from "./styles";
|
|
2
|
+
import get from "lodash.get";
|
|
3
|
+
import { HTML_IDS } from "../shared/constants/htmlTonderIds";
|
|
4
|
+
|
|
1
5
|
export async function addScripts() {
|
|
2
6
|
try {
|
|
3
7
|
const skyflowScript = document.createElement("script");
|
|
@@ -23,7 +27,6 @@ export async function addScripts() {
|
|
|
23
27
|
openPay2Script.onerror = reject;
|
|
24
28
|
document.head.appendChild(openPay2Script);
|
|
25
29
|
});
|
|
26
|
-
|
|
27
30
|
} catch (error) {
|
|
28
31
|
console.error("Error loading scripts", error);
|
|
29
32
|
}
|
|
@@ -36,88 +39,121 @@ export function toCurrency(value) {
|
|
|
36
39
|
var formatter = new Intl.NumberFormat("es-MX", {
|
|
37
40
|
style: "currency",
|
|
38
41
|
currency: "MXN",
|
|
39
|
-
minimumFractionDigits: 2
|
|
42
|
+
minimumFractionDigits: 2,
|
|
40
43
|
});
|
|
41
44
|
return formatter.format(value);
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
export function showError(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
msgErrorDiv.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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";
|
|
56
62
|
|
|
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
63
|
setTimeout(function () {
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
msgErrorDiv.style.display = "none";
|
|
65
|
+
msgErrorText.innerHTML = "";
|
|
65
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);
|
|
66
95
|
}
|
|
67
96
|
}
|
|
68
97
|
export function getBrowserInfo() {
|
|
69
98
|
const browserInfo = {
|
|
70
|
-
javascript_enabled: true,
|
|
99
|
+
javascript_enabled: true, // Assumed since JavaScript is running
|
|
71
100
|
time_zone: new Date().getTimezoneOffset(),
|
|
72
|
-
language: navigator.language ||
|
|
101
|
+
language: navigator.language || "en-US", // Fallback to 'en-US'
|
|
73
102
|
color_depth: window.screen ? window.screen.colorDepth : null,
|
|
74
|
-
screen_width: window.screen
|
|
75
|
-
|
|
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,
|
|
76
109
|
user_agent: navigator.userAgent,
|
|
77
110
|
};
|
|
78
111
|
return browserInfo;
|
|
79
112
|
}
|
|
80
113
|
|
|
81
|
-
export const mapCards =
|
|
114
|
+
export const mapCards = card => {
|
|
82
115
|
const newCard = { ...card.fields };
|
|
83
116
|
const carArr = newCard.card_number.split("-");
|
|
84
117
|
const last = carArr[carArr.length - 1];
|
|
85
118
|
newCard.card_number = `••••${last}`;
|
|
86
119
|
return newCard;
|
|
87
|
-
}
|
|
120
|
+
};
|
|
88
121
|
|
|
89
|
-
export const getCardType = (scheme) => {
|
|
90
|
-
if(scheme === "Visa") {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return "https://d35a75syrgujp0.cloudfront.net/cards/
|
|
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";
|
|
96
132
|
} else {
|
|
97
|
-
return
|
|
133
|
+
return `https://d35a75syrgujp0.cloudfront.net/cards/default_card_tonder${isDark ? "_purple" : ""}.png`;
|
|
98
134
|
}
|
|
99
|
-
}
|
|
100
|
-
export const clearSpace =
|
|
101
|
-
return text.trim().replace(/\s+/g,
|
|
102
|
-
}
|
|
103
|
-
|
|
135
|
+
};
|
|
136
|
+
export const clearSpace = text => {
|
|
137
|
+
return text.trim().replace(/\s+/g, "");
|
|
138
|
+
};
|
|
104
139
|
|
|
105
140
|
export function formatPublicErrorResponse(data, error) {
|
|
106
|
-
let code = 200
|
|
141
|
+
let code = 200;
|
|
107
142
|
try {
|
|
108
|
-
code = Number(error?.code || 200)
|
|
109
|
-
}catch{}
|
|
143
|
+
code = Number(error?.code || 200);
|
|
144
|
+
} catch {}
|
|
110
145
|
|
|
111
146
|
const default_res = {
|
|
112
147
|
status: "error",
|
|
113
148
|
code,
|
|
114
149
|
message: "",
|
|
115
|
-
detail:
|
|
116
|
-
|
|
150
|
+
detail:
|
|
151
|
+
error?.body?.detail || error?.body?.error || error.body || "Ocurrio un error inesperado.",
|
|
152
|
+
};
|
|
117
153
|
|
|
118
154
|
return {
|
|
119
155
|
...default_res,
|
|
120
|
-
...data
|
|
156
|
+
...data,
|
|
121
157
|
};
|
|
122
158
|
}
|
|
123
159
|
|
|
@@ -138,7 +174,7 @@ export function buildErrorResponseFromCatch(e) {
|
|
|
138
174
|
return {
|
|
139
175
|
code: e?.status ? e.status : e.code,
|
|
140
176
|
body: e?.body,
|
|
141
|
-
name: e ? typeof e == "string" ? "catch" : e.name : "Error",
|
|
177
|
+
name: e ? (typeof e == "string" ? "catch" : e.name) : "Error",
|
|
142
178
|
message: e ? (typeof e == "string" ? e : e.message) : "Error",
|
|
143
179
|
stack: typeof e == "string" ? undefined : e.stack,
|
|
144
180
|
};
|
|
@@ -146,18 +182,76 @@ export function buildErrorResponseFromCatch(e) {
|
|
|
146
182
|
|
|
147
183
|
export function injectMercadoPagoSecurity() {
|
|
148
184
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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);
|
|
159
195
|
} catch (error) {
|
|
160
|
-
|
|
196
|
+
console.error("Error attempting to inject Mercado Pago script:", error);
|
|
161
197
|
}
|
|
162
198
|
}
|
|
163
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,54 +1,53 @@
|
|
|
1
1
|
export function validateCardNumber(cardNumber) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const regex = /^\d{12,19}$/;
|
|
3
|
+
return regex.test(cardNumber) && luhnCheck(cardNumber);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export function validateCardholderName(name) {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const regex = /^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/;
|
|
8
|
+
return regex.test(name);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function validateCVV(cvv) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const regex = /^\d{3,4}$/;
|
|
13
|
+
return regex.test(cvv);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function validateExpirationDate(expirationDate) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
25
|
}
|
|
26
26
|
|
|
27
27
|
export function validateExpirationMonth(month) {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const regex = /^(0[1-9]|1[0-2])$/;
|
|
29
|
+
return regex.test(month);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function validateExpirationYear(year) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
39
|
}
|
|
40
40
|
|
|
41
41
|
const luhnCheck = num => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
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
CHANGED
|
@@ -99,7 +99,7 @@ const checkoutData = {
|
|
|
99
99
|
// order_id: 123456
|
|
100
100
|
// }
|
|
101
101
|
// Reference from the merchant
|
|
102
|
-
order_reference: "ORD-123456"
|
|
102
|
+
order_reference: "ORD-123456",
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
// localhost
|
|
@@ -127,20 +127,50 @@ function setupInlineCheckout() {
|
|
|
127
127
|
inlineCheckout = new InlineCheckout({
|
|
128
128
|
...commonConfig,
|
|
129
129
|
customization: {
|
|
130
|
+
displayMode: "light", // usar para cambiar el aspecto ligth/dark
|
|
130
131
|
saveCards: {
|
|
131
132
|
showSaveCardOption: true, // Usar para mostrar/ocultar el checkbox de guardar tarjeta para futuros pagos
|
|
132
|
-
autoSave: false,
|
|
133
|
-
showSaved: true
|
|
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: true, // 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
|
+
callBack: async response => {
|
|
153
|
+
console.log("Payment response", JSON.stringify(response, null, 2));
|
|
154
|
+
if (response.error) {
|
|
155
|
+
console.log("Payment error", response.error?.details);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
alert("Payment success");
|
|
159
|
+
},
|
|
160
|
+
callbacks: {
|
|
161
|
+
// Usar para definir la acción a ejecutar cuando el usuario de click en el botón Cancelar
|
|
162
|
+
onCancel: () => {
|
|
163
|
+
console.log("onCancel");
|
|
134
164
|
},
|
|
135
165
|
},
|
|
136
166
|
});
|
|
137
167
|
inlineCheckout.configureCheckout({
|
|
138
168
|
secureToken: "eyJhbGc...",
|
|
139
|
-
...checkoutData
|
|
169
|
+
...checkoutData,
|
|
140
170
|
});
|
|
141
171
|
inlineCheckout.injectCheckout();
|
|
142
172
|
// ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
|
|
143
|
-
inlineCheckout.verify3dsTransaction().then(
|
|
173
|
+
inlineCheckout.verify3dsTransaction().then(response => {
|
|
144
174
|
console.log("Verify 3ds response", response);
|
|
145
175
|
});
|
|
146
176
|
|
|
@@ -165,15 +195,15 @@ function setupLiteInlineCheckout() {
|
|
|
165
195
|
liteInlineCheckout = new LiteInlineCheckout(commonConfig);
|
|
166
196
|
liteInlineCheckout.configureCheckout({
|
|
167
197
|
customer: checkoutData.customer,
|
|
168
|
-
secureToken: "eyJhbGc..."
|
|
198
|
+
secureToken: "eyJhbGc...",
|
|
169
199
|
});
|
|
170
200
|
liteInlineCheckout.injectCheckout().then(() => {
|
|
171
|
-
liteInlineCheckout.getCustomerCards().then(
|
|
172
|
-
console.log(
|
|
201
|
+
liteInlineCheckout.getCustomerCards().then(r => {
|
|
202
|
+
console.log("customer cards", r);
|
|
173
203
|
});
|
|
174
204
|
});
|
|
175
205
|
|
|
176
|
-
liteInlineCheckout.verify3dsTransaction().then(
|
|
206
|
+
liteInlineCheckout.verify3dsTransaction().then(response => {
|
|
177
207
|
console.log("Verify 3ds response", response);
|
|
178
208
|
});
|
|
179
209
|
|
|
@@ -210,7 +240,7 @@ function setupLiteInlineCheckout() {
|
|
|
210
240
|
|
|
211
241
|
function setupCheckout() {
|
|
212
242
|
const mode = getCheckoutMode();
|
|
213
|
-
document.querySelectorAll(".tab-content").forEach(
|
|
243
|
+
document.querySelectorAll(".tab-content").forEach(content => {
|
|
214
244
|
content.style.display = "none";
|
|
215
245
|
});
|
|
216
246
|
|
|
@@ -289,7 +319,7 @@ function loadMaskitoMask() {
|
|
|
289
319
|
}
|
|
290
320
|
function updateActiveTab() {
|
|
291
321
|
const mode = getCheckoutMode();
|
|
292
|
-
document.querySelectorAll(".tab").forEach(
|
|
322
|
+
document.querySelectorAll(".tab").forEach(tab => {
|
|
293
323
|
tab.classList.remove("active");
|
|
294
324
|
});
|
|
295
325
|
document.querySelector(`[data-mode="${mode}"]`).classList.add("active");
|
package/src/index.html
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
<!
|
|
1
|
+
<!doctype html>
|
|
2
2
|
<html lang="en">
|
|
3
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"
|
|
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, viewport-fit=cover" />
|
|
7
7
|
<style>
|
|
8
8
|
#checkout-container {
|
|
9
9
|
display: flex;
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
.input-md {
|
|
110
110
|
max-width: 100%;
|
|
111
111
|
}
|
|
112
|
-
.invalid{
|
|
112
|
+
.invalid {
|
|
113
113
|
border: 2px solid red !important;
|
|
114
114
|
}
|
|
115
115
|
</style>
|
|
@@ -118,8 +118,16 @@
|
|
|
118
118
|
<body>
|
|
119
119
|
<div class="checkout-container">
|
|
120
120
|
<div class="tab-container">
|
|
121
|
-
<a
|
|
122
|
-
|
|
121
|
+
<a
|
|
122
|
+
href="?mode=inline"
|
|
123
|
+
class="tab"
|
|
124
|
+
data-mode="inline"
|
|
125
|
+
onclick="switchTab('inline'); return false;"
|
|
126
|
+
>Inline Checkout</a
|
|
127
|
+
>
|
|
128
|
+
<a href="?mode=lite" class="tab" data-mode="lite" onclick="switchTab('lite'); return false;"
|
|
129
|
+
>Lite Inline Checkout</a
|
|
130
|
+
>
|
|
123
131
|
</div>
|
|
124
132
|
|
|
125
133
|
<div id="lite-content" class="tab-content">
|
|
@@ -130,23 +138,23 @@
|
|
|
130
138
|
<form id="lite-payment-form" class="card-form">
|
|
131
139
|
<div class="form-group">
|
|
132
140
|
<label for="card-number">Número de Tarjeta</label>
|
|
133
|
-
<input type="text" id="card-number" placeholder="1234 5678 9012 3456" required
|
|
141
|
+
<input type="text" id="card-number" placeholder="1234 5678 9012 3456" required />
|
|
134
142
|
</div>
|
|
135
143
|
<div class="form-group">
|
|
136
144
|
<label for="card-name">Nombre en la Tarjeta</label>
|
|
137
|
-
<input type="text" id="card-name" placeholder="John Doe" required
|
|
145
|
+
<input type="text" id="card-name" placeholder="John Doe" required />
|
|
138
146
|
</div>
|
|
139
147
|
<div class="form-row">
|
|
140
148
|
<div class="form-group">
|
|
141
149
|
<label for="month">Fecha de Expiración</label>
|
|
142
150
|
<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
|
|
151
|
+
<input class="input-md" type="text" id="month" placeholder="MM" required />
|
|
152
|
+
<input class="input-md" type="text" id="year" placeholder="AA" required />
|
|
145
153
|
</div>
|
|
146
154
|
</div>
|
|
147
155
|
<div class="form-group">
|
|
148
156
|
<label for="cvv">CVV</label>
|
|
149
|
-
<input class="input-md" type="text" id="cvv" placeholder="123" required
|
|
157
|
+
<input class="input-md" type="text" id="cvv" placeholder="123" required />
|
|
150
158
|
</div>
|
|
151
159
|
</div>
|
|
152
160
|
<button type="submit" class="btn" id="pay-button-lite">Pagar Ahora</button>
|
package/src/index.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { Checkout } from
|
|
2
|
-
import { InlineCheckout } from
|
|
3
|
-
import { LiteInlineCheckout } from
|
|
4
|
-
import {
|
|
1
|
+
import { Checkout } from "./classes/checkout";
|
|
2
|
+
import { InlineCheckout } from "./classes/inlineCheckout";
|
|
3
|
+
import { LiteInlineCheckout } from "./classes/LiteInlineCheckout";
|
|
4
|
+
import {
|
|
5
|
+
validateCVV,
|
|
6
|
+
validateCardNumber,
|
|
7
|
+
validateCardholderName,
|
|
8
|
+
validateExpirationMonth,
|
|
9
|
+
validateExpirationYear,
|
|
10
|
+
} from "./helpers/validations";
|
|
5
11
|
|
|
6
12
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
Checkout,
|
|
14
|
+
InlineCheckout,
|
|
15
|
+
LiteInlineCheckout,
|
|
16
|
+
validateCVV,
|
|
17
|
+
validateCardNumber,
|
|
18
|
+
validateCardholderName,
|
|
19
|
+
validateExpirationMonth,
|
|
20
|
+
validateExpirationYear,
|
|
21
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const COMMON_LOGOS = Object.freeze({
|
|
2
|
+
pci: "https://d35a75syrgujp0.cloudfront.net/tonder/logo-pci-500.png",
|
|
3
|
+
tonderBlue: "https://d35a75syrgujp0.cloudfront.net/tonder/logo-tonder-blue.png",
|
|
4
|
+
tonderWhite: "https://d35a75syrgujp0.cloudfront.net/tonder/logo-tonder-white.png",
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
export { COMMON_LOGOS };
|