tonder-web-sdk 1.12.0-beta.9 → 1.14.0
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 +664 -106
- package/package.json +2 -1
- package/src/classes/3dsHandler.js +20 -9
- package/src/classes/BaseInlineCheckout.js +17 -23
- package/src/classes/LiteInlineCheckout.js +46 -41
- package/src/classes/inlineCheckout.js +86 -75
- package/src/data/cardApi.js +21 -4
- package/src/helpers/template.js +9 -1
- package/src/helpers/utils.js +4 -4
- package/src/helpers/validations.js +54 -0
- package/src/index-dev.js +160 -78
- package/src/index.html +4 -1
- package/src/index.js +7 -1
- package/types/{card.ts → card.d.ts} +1 -0
- package/types/{checkout.ts → checkout.d.ts} +1 -1
- package/types/{common.ts → common.d.ts} +1 -0
- package/types/{customer.ts → customer.d.ts} +1 -0
- package/types/index.d.ts +1 -1
- package/types/inlineCheckout.d.ts +53 -1
- package/types/liteInlineCheckout.d.ts +65 -8
- package/types/validations.d.ts +11 -0
- package/v1/bundle.min.js +3 -3
- package/webpack.config.js +12 -1
- package/.idea/aws.xml +0 -17
- package/.idea/inspectionProfiles/profiles_settings.xml +0 -6
- package/.idea/misc.xml +0 -4
- package/.idea/prettier.xml +0 -6
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -153
- /package/types/{paymentMethod.ts → paymentMethod.d.ts} +0 -0
- /package/types/{transaction.ts → transaction.d.ts} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
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
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { InlineCheckout } from
|
|
2
|
-
import {LiteInlineCheckout} from "./classes/LiteInlineCheckout";
|
|
1
|
+
import { InlineCheckout } from "./classes/inlineCheckout";
|
|
2
|
+
import { LiteInlineCheckout } from "./classes/LiteInlineCheckout";
|
|
3
|
+
import { Maskito } from "@maskito/core";
|
|
4
|
+
import { validateCardNumber } from "./helpers/validations";
|
|
3
5
|
|
|
4
6
|
const customStyles = {
|
|
5
7
|
inputStyles: {
|
|
@@ -10,15 +12,15 @@ const customStyles = {
|
|
|
10
12
|
color: "#333333",
|
|
11
13
|
backgroundColor: "#f0f0f0",
|
|
12
14
|
fontFamily: '"Arial", sans-serif',
|
|
13
|
-
fontSize:
|
|
14
|
-
|
|
15
|
+
fontSize: "14px",
|
|
16
|
+
"&::placeholder": {
|
|
15
17
|
color: "#888888",
|
|
16
18
|
},
|
|
17
19
|
},
|
|
18
20
|
cardIcon: {
|
|
19
|
-
position:
|
|
20
|
-
left:
|
|
21
|
-
bottom:
|
|
21
|
+
position: "absolute",
|
|
22
|
+
left: "6px",
|
|
23
|
+
bottom: "calc(50% - 12px)",
|
|
22
24
|
},
|
|
23
25
|
complete: {
|
|
24
26
|
color: "#4caf50",
|
|
@@ -29,39 +31,40 @@ const customStyles = {
|
|
|
29
31
|
border: "1px solid #f44336",
|
|
30
32
|
},
|
|
31
33
|
global: {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
"@import":
|
|
35
|
+
'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")',
|
|
36
|
+
},
|
|
34
37
|
},
|
|
35
38
|
labelStyles: {
|
|
36
39
|
base: {
|
|
37
|
-
fontSize:
|
|
38
|
-
fontWeight:
|
|
40
|
+
fontSize: "14px",
|
|
41
|
+
fontWeight: "bold",
|
|
39
42
|
fontFamily: '"Inter", sans-serif',
|
|
40
43
|
color: "#4a90e2",
|
|
41
44
|
},
|
|
42
45
|
},
|
|
43
46
|
errorTextStyles: {
|
|
44
47
|
base: {
|
|
45
|
-
fontSize:
|
|
46
|
-
fontWeight:
|
|
48
|
+
fontSize: "12px",
|
|
49
|
+
fontWeight: "500",
|
|
47
50
|
color: "#e74c3c",
|
|
48
51
|
fontFamily: '"Inter", sans-serif',
|
|
49
52
|
},
|
|
50
53
|
},
|
|
51
54
|
labels: {
|
|
52
|
-
nameLabel:
|
|
53
|
-
cardLabel:
|
|
54
|
-
cvvLabel:
|
|
55
|
-
expiryDateLabel:
|
|
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",
|
|
56
59
|
},
|
|
57
60
|
placeholders: {
|
|
58
|
-
namePlaceholder:
|
|
59
|
-
cardPlaceholder:
|
|
60
|
-
cvvPlaceholder:
|
|
61
|
-
expiryMonthPlaceholder:
|
|
62
|
-
expiryYearPlaceholder:
|
|
63
|
-
}
|
|
64
|
-
}
|
|
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
|
+
};
|
|
65
68
|
|
|
66
69
|
const checkoutData = {
|
|
67
70
|
customer: {
|
|
@@ -75,7 +78,7 @@ const checkoutData = {
|
|
|
75
78
|
email: "adrian@email.com",
|
|
76
79
|
phone: "8161234567",
|
|
77
80
|
},
|
|
78
|
-
currency:
|
|
81
|
+
currency: "mxn",
|
|
79
82
|
cart: {
|
|
80
83
|
total: 399,
|
|
81
84
|
items: [
|
|
@@ -89,7 +92,7 @@ const checkoutData = {
|
|
|
89
92
|
name: "T-Shirt",
|
|
90
93
|
amount_total: 399,
|
|
91
94
|
},
|
|
92
|
-
]
|
|
95
|
+
],
|
|
93
96
|
},
|
|
94
97
|
// card: { "skyflow_id": "53ca875c-16fd-4395-8ac9-c756613dbaf9" },
|
|
95
98
|
// metadata: {
|
|
@@ -97,122 +100,201 @@ const checkoutData = {
|
|
|
97
100
|
// }
|
|
98
101
|
};
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
102
103
|
// localhost
|
|
103
104
|
const apiKey = "11e3d3c3e95e0eaabbcae61ebad34ee5f93c3d27";
|
|
104
|
-
const returnUrl = "http://127.0.0.1:8080/"
|
|
105
|
+
const returnUrl = "http://127.0.0.1:8080/";
|
|
105
106
|
// stage
|
|
106
107
|
// const apiKey = "8365683bdc33dd6d50fe2397188d79f1a6765852";
|
|
107
108
|
|
|
108
|
-
|
|
109
109
|
const commonConfig = {
|
|
110
|
-
mode:
|
|
110
|
+
mode: "stage",
|
|
111
111
|
apiKey,
|
|
112
|
-
returnUrl: returnUrl+"?mode="+getCheckoutMode(),
|
|
113
|
-
styles: customStyles
|
|
112
|
+
returnUrl: returnUrl + "?mode=" + getCheckoutMode(),
|
|
113
|
+
styles: customStyles,
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
let checkout;
|
|
117
116
|
let inlineCheckout;
|
|
118
117
|
let liteInlineCheckout;
|
|
119
118
|
|
|
120
|
-
|
|
121
119
|
function getCheckoutMode() {
|
|
122
120
|
const urlParams = new URLSearchParams(window.location.search);
|
|
123
|
-
return urlParams.get(
|
|
121
|
+
return urlParams.get("mode") || "inline";
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
function setupInlineCheckout() {
|
|
127
|
-
inlineCheckout = new InlineCheckout({
|
|
128
|
-
|
|
125
|
+
inlineCheckout = new InlineCheckout({
|
|
126
|
+
...commonConfig,
|
|
127
|
+
customization: {
|
|
128
|
+
saveCards: {
|
|
129
|
+
showSaveCardOption: true, // Usar para mostrar/ocultar el checkbox de guardar tarjeta para futuros pagos
|
|
130
|
+
autoSave: false, // Usar para guardar automáticamente la tarjeta (sin necesidad de mostrar el checkbox)
|
|
131
|
+
showSaved: true // Usar para mostrar/ocultar el listado de tarjetas guardadas
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
inlineCheckout.configureCheckout({
|
|
136
|
+
customer: checkoutData.customer,
|
|
137
|
+
secureToken: "eyJhbGc..."
|
|
138
|
+
});
|
|
129
139
|
inlineCheckout.injectCheckout();
|
|
130
140
|
// ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
|
|
131
|
-
inlineCheckout.verify3dsTransaction().then(response => {
|
|
132
|
-
console.log(
|
|
133
|
-
})
|
|
141
|
+
inlineCheckout.verify3dsTransaction().then((response) => {
|
|
142
|
+
console.log("Verify 3ds response", response);
|
|
143
|
+
});
|
|
134
144
|
|
|
135
|
-
const payButton = document.getElementById(
|
|
136
|
-
payButton.addEventListener(
|
|
145
|
+
const payButton = document.getElementById("pay-button");
|
|
146
|
+
payButton.addEventListener("click", async function () {
|
|
137
147
|
try {
|
|
138
|
-
payButton.textContent =
|
|
148
|
+
payButton.textContent = "Procesando...";
|
|
139
149
|
const response = await inlineCheckout.payment(checkoutData);
|
|
140
|
-
console.log("Respuesta del pago:", response)
|
|
141
|
-
alert(
|
|
150
|
+
console.log("Respuesta del pago:", response);
|
|
151
|
+
alert("Pago realizado con éxito");
|
|
142
152
|
} catch (error) {
|
|
143
153
|
console.log("Error en el pago:", error.details);
|
|
144
|
-
alert(
|
|
154
|
+
alert("Error al realizar el pago");
|
|
145
155
|
} finally {
|
|
146
|
-
payButton.textContent =
|
|
156
|
+
payButton.textContent = "Pagar";
|
|
147
157
|
}
|
|
148
158
|
});
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
function setupLiteInlineCheckout() {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
162
|
+
loadMaskitoMask();
|
|
163
|
+
liteInlineCheckout = new LiteInlineCheckout(commonConfig);
|
|
164
|
+
liteInlineCheckout.configureCheckout({
|
|
165
|
+
customer: checkoutData.customer,
|
|
166
|
+
secureToken: "eyJhbGc..."
|
|
167
|
+
});
|
|
168
|
+
liteInlineCheckout.injectCheckout().then(() => {});
|
|
169
|
+
liteInlineCheckout.verify3dsTransaction().then((response) => {
|
|
170
|
+
console.log("Verify 3ds response", response);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const liteForm = document.getElementById("lite-payment-form");
|
|
174
|
+
const payButton = document.getElementById("pay-button-lite");
|
|
175
|
+
liteForm.addEventListener("submit", async function (event) {
|
|
161
176
|
event.preventDefault();
|
|
162
177
|
|
|
163
178
|
const cardData = {
|
|
164
|
-
card_number: document.getElementById(
|
|
165
|
-
cardholder_name: document.getElementById(
|
|
166
|
-
expiration_month: document.getElementById(
|
|
167
|
-
expiration_year: document.getElementById(
|
|
168
|
-
cvv: document.getElementById(
|
|
179
|
+
card_number: document.getElementById("card-number").value,
|
|
180
|
+
cardholder_name: document.getElementById("card-name").value,
|
|
181
|
+
expiration_month: document.getElementById("month").value,
|
|
182
|
+
expiration_year: document.getElementById("year").value,
|
|
183
|
+
cvv: document.getElementById("cvv").value,
|
|
169
184
|
};
|
|
170
185
|
|
|
171
186
|
try {
|
|
187
|
+
payButton.textContent = "Procesando...";
|
|
172
188
|
const paymentData = {
|
|
173
189
|
...checkoutData,
|
|
174
|
-
card: cardData
|
|
190
|
+
card: cardData,
|
|
175
191
|
};
|
|
176
192
|
const response = await liteInlineCheckout.payment(paymentData);
|
|
177
193
|
console.log("Respuesta del pago:", response);
|
|
178
|
-
alert(
|
|
194
|
+
alert("Pago realizado con éxito");
|
|
179
195
|
} catch (error) {
|
|
180
196
|
console.error("Error en el pago:", error);
|
|
181
|
-
alert(
|
|
197
|
+
alert("Error al realizar el pago");
|
|
198
|
+
} finally {
|
|
199
|
+
payButton.textContent = "Pagar Ahora";
|
|
182
200
|
}
|
|
183
201
|
});
|
|
184
202
|
}
|
|
185
203
|
|
|
186
204
|
function setupCheckout() {
|
|
187
205
|
const mode = getCheckoutMode();
|
|
188
|
-
document.querySelectorAll(
|
|
189
|
-
content.style.display =
|
|
206
|
+
document.querySelectorAll(".tab-content").forEach((content) => {
|
|
207
|
+
content.style.display = "none";
|
|
190
208
|
});
|
|
191
209
|
|
|
192
|
-
if (mode ===
|
|
193
|
-
document.getElementById(
|
|
194
|
-
setupInlineCheckout()
|
|
195
|
-
}else{
|
|
196
|
-
document.getElementById(
|
|
197
|
-
setupLiteInlineCheckout()
|
|
210
|
+
if (mode === "inline") {
|
|
211
|
+
document.getElementById("inline-content").style.display = "block";
|
|
212
|
+
setupInlineCheckout();
|
|
213
|
+
} else {
|
|
214
|
+
document.getElementById("lite-content").style.display = "block";
|
|
215
|
+
setupLiteInlineCheckout();
|
|
198
216
|
}
|
|
199
217
|
}
|
|
200
218
|
|
|
219
|
+
function loadMaskitoMask() {
|
|
220
|
+
const cardNumberInput = document.getElementById("card-number");
|
|
221
|
+
const monthInput = document.getElementById("month");
|
|
222
|
+
const yearInput = document.getElementById("year");
|
|
223
|
+
const cvvInput = document.getElementById("cvv");
|
|
224
|
+
const nameInput = document.getElementById("card-name");
|
|
225
|
+
|
|
226
|
+
// Definir las opciones para las máscaras
|
|
227
|
+
const cardNumberOptions = {
|
|
228
|
+
mask: [
|
|
229
|
+
...Array(4).fill(/\d/),
|
|
230
|
+
" ",
|
|
231
|
+
...Array(4).fill(/\d/),
|
|
232
|
+
" ",
|
|
233
|
+
...Array(4).fill(/\d/),
|
|
234
|
+
" ",
|
|
235
|
+
...Array(4).fill(/\d/),
|
|
236
|
+
" ",
|
|
237
|
+
...Array(3).fill(/\d/),
|
|
238
|
+
],
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const monthOptions = {
|
|
242
|
+
mask: [/[0-1]/, /\d/],
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const yearOptions = {
|
|
246
|
+
mask: [/\d/, /\d/],
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const nameOptions = {
|
|
250
|
+
mask: /^[a-zA-Z\s]*$/,
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const cvvOptions = {
|
|
254
|
+
mask: [...Array(3).fill(/\d/)],
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// Aplicar Maskito a cada campo
|
|
258
|
+
const cardNumberMask = new Maskito(cardNumberInput, cardNumberOptions);
|
|
259
|
+
const monthMask = new Maskito(monthInput, monthOptions);
|
|
260
|
+
const yearMask = new Maskito(yearInput, yearOptions);
|
|
261
|
+
const cvvMask = new Maskito(cvvInput, cvvOptions);
|
|
262
|
+
const nameMask = new Maskito(nameInput, nameOptions);
|
|
263
|
+
|
|
264
|
+
cardNumberInput.addEventListener("input", () => {
|
|
265
|
+
const cardNumber = cardNumberInput.value.replace(/\s+/g, "");
|
|
266
|
+
if (!validateCardNumber(cardNumber)) {
|
|
267
|
+
cardNumberInput.setCustomValidity("Número de tarjeta inválido");
|
|
268
|
+
cardNumberInput.classList.add("invalid");
|
|
269
|
+
} else {
|
|
270
|
+
cardNumberInput.setCustomValidity("");
|
|
271
|
+
cardNumberInput.classList.remove("invalid");
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
window.addEventListener("beforeunload", () => {
|
|
276
|
+
cardNumberMask.destroy();
|
|
277
|
+
monthMask.destroy();
|
|
278
|
+
yearMask.destroy();
|
|
279
|
+
cvvMask.destroy();
|
|
280
|
+
nameMask.destroy();
|
|
281
|
+
});
|
|
282
|
+
}
|
|
201
283
|
function updateActiveTab() {
|
|
202
284
|
const mode = getCheckoutMode();
|
|
203
|
-
document.querySelectorAll(
|
|
204
|
-
tab.classList.remove(
|
|
285
|
+
document.querySelectorAll(".tab").forEach((tab) => {
|
|
286
|
+
tab.classList.remove("active");
|
|
205
287
|
});
|
|
206
|
-
document.querySelector(`[data-mode="${mode}"]`).classList.add(
|
|
288
|
+
document.querySelector(`[data-mode="${mode}"]`).classList.add("active");
|
|
207
289
|
}
|
|
208
290
|
|
|
209
291
|
function switchTab(mode) {
|
|
210
292
|
window.location.href = `${window.location.pathname}?mode=${mode}`;
|
|
211
293
|
}
|
|
212
294
|
|
|
213
|
-
document.addEventListener(
|
|
295
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
214
296
|
setupCheckout();
|
|
215
297
|
updateActiveTab();
|
|
216
298
|
});
|
|
217
299
|
|
|
218
|
-
window.switchTab = switchTab;
|
|
300
|
+
window.switchTab = switchTab;
|
package/src/index.html
CHANGED
|
@@ -109,6 +109,9 @@
|
|
|
109
109
|
.input-md {
|
|
110
110
|
max-width: 100%;
|
|
111
111
|
}
|
|
112
|
+
.invalid{
|
|
113
|
+
border: 2px solid red !important;
|
|
114
|
+
}
|
|
112
115
|
</style>
|
|
113
116
|
</head>
|
|
114
117
|
|
|
@@ -146,7 +149,7 @@
|
|
|
146
149
|
<input class="input-md" type="text" id="cvv" placeholder="123" required>
|
|
147
150
|
</div>
|
|
148
151
|
</div>
|
|
149
|
-
<button type="submit" class="btn">Pagar Ahora</button>
|
|
152
|
+
<button type="submit" class="btn" id="pay-button-lite">Pagar Ahora</button>
|
|
150
153
|
</form>
|
|
151
154
|
</div>
|
|
152
155
|
<div id="inline-content" class="tab-content">
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { Checkout } from './classes/checkout'
|
|
2
2
|
import { InlineCheckout } from './classes/inlineCheckout'
|
|
3
3
|
import { LiteInlineCheckout } from './classes/LiteInlineCheckout'
|
|
4
|
+
import { validateCVV, validateCardNumber, validateCardholderName, validateExpirationMonth, validateExpirationYear } from "./helpers/validations";
|
|
4
5
|
|
|
5
6
|
export {
|
|
6
7
|
Checkout,
|
|
7
8
|
InlineCheckout,
|
|
8
|
-
LiteInlineCheckout
|
|
9
|
+
LiteInlineCheckout,
|
|
10
|
+
validateCVV,
|
|
11
|
+
validateCardNumber,
|
|
12
|
+
validateCardholderName,
|
|
13
|
+
validateExpirationMonth,
|
|
14
|
+
validateExpirationYear
|
|
9
15
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -5,18 +5,70 @@ import {ITransaction} from "./transaction";
|
|
|
5
5
|
export class InlineCheckout {
|
|
6
6
|
constructor(options: IInlineCheckoutOptions);
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The configureCheckout function allows you to set initial information, such as the customer's email, which is used to retrieve a list of saved cards.
|
|
10
|
+
* @param {import("../types").IConfigureCheckout} data - Configuration data including customer information and potentially other settings.
|
|
11
|
+
* @returns {void}.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
configureCheckout(data: IConfigureCheckout): void;
|
|
9
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Injects the checkout into the DOM and initializes it.
|
|
18
|
+
* Checks for an existing container and sets up an observer if needed.
|
|
19
|
+
* @returns {void}
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
10
22
|
injectCheckout(): Promise<void>;
|
|
11
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Processes a payment.
|
|
26
|
+
* @param {import("../types").IProcessPaymentRequest} data - Payment data including customer, cart, and other relevant information.
|
|
27
|
+
* @returns {Promise<import("../types").IStartCheckoutResponse>} A promise that resolves with the payment response or 3DS redirect or is rejected with an error.
|
|
28
|
+
*
|
|
29
|
+
* @throws {Error} Throws an error if the checkout process fails. The error object contains
|
|
30
|
+
* additional `details` property with the response from the server if available.
|
|
31
|
+
* @property {import("../types").IStartCheckoutErrorResponse} error.details - The response body from the server when an error occurs.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
12
35
|
payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse>;
|
|
13
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Verifies the 3DS transaction status.
|
|
39
|
+
* @returns {Promise<import("../types").ITransaction | void>} The result of the 3DS verification and checkout resumption.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
14
42
|
verify3dsTransaction(): Promise<ITransaction | void>;
|
|
15
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Removes the checkout from the DOM and cleans up associated resources.
|
|
46
|
+
*
|
|
47
|
+
* This method performs the following actions:
|
|
48
|
+
* 1. Resets the injection status flags for the checkout, cards, and APMs.
|
|
49
|
+
* 2. Aborts any ongoing requests using the AbortController.
|
|
50
|
+
* 3. Creates a new AbortController for future use.
|
|
51
|
+
* 4. Clears any existing injection intervals.
|
|
52
|
+
*
|
|
53
|
+
* Note: This method should be called when you want to completely remove
|
|
54
|
+
* the checkout from the page and reset its state.
|
|
55
|
+
*
|
|
56
|
+
* @returns {void}
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
16
59
|
removeCheckout(): void;
|
|
17
60
|
}
|
|
18
61
|
|
|
62
|
+
export type CustomizationOptions = {
|
|
63
|
+
saveCards?: {
|
|
64
|
+
showSaveCardOption?: boolean;
|
|
65
|
+
showSaved?: boolean;
|
|
66
|
+
autoSave?: boolean;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
19
70
|
export interface IInlineCheckoutOptions extends IInlineCheckoutBaseOptions{
|
|
20
71
|
styles?: Record<string, string>;
|
|
21
72
|
renderPaymentButton?: boolean;
|
|
73
|
+
customization?: CustomizationOptions;
|
|
22
74
|
}
|
|
@@ -7,31 +7,88 @@ import {ITransaction} from "./transaction";
|
|
|
7
7
|
export class LiteInlineCheckout {
|
|
8
8
|
constructor(options: IInlineLiteCheckoutOptions);
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* The configureCheckout function allows you to set initial information, such as the customer's email, which is used to retrieve a list of saved cards.
|
|
12
|
+
* @param {import("../types").IConfigureCheckout} data - Configuration data including customer information and potentially other settings.
|
|
13
|
+
* @returns {Promise<void>}.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
10
16
|
configureCheckout(data: IConfigureCheckout): void;
|
|
11
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Initializes and prepares the checkout for use.
|
|
20
|
+
* This method set up the initial environment.
|
|
21
|
+
* @returns {Promise<void>} A promise that resolves when the checkout has been initialized.
|
|
22
|
+
* @throws {Error} If there's any problem during the checkout initialization.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
12
25
|
injectCheckout(): Promise<void>;
|
|
13
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Processes a payment.
|
|
29
|
+
* @param {import("../types").IProcessPaymentRequest} data - Payment data including customer, cart, and other relevant information.
|
|
30
|
+
* @returns {Promise<import("../types").IStartCheckoutResponse>} A promise that resolves with the payment response or 3DS redirect or is rejected with an error.
|
|
31
|
+
*
|
|
32
|
+
* @throws {Error} Throws an error if the checkout process fails. The error object contains
|
|
33
|
+
* additional `details` property with the response from the server if available.
|
|
34
|
+
* @property {import("../types").IStartCheckoutErrorResponse} error.details - The response body from the server when an error occurs.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
14
38
|
payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse>;
|
|
15
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Verifies the 3DS transaction status.
|
|
42
|
+
* @returns {Promise<import("../types").ITransaction | void>} The result of the 3DS verification and checkout resumption.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
16
45
|
verify3dsTransaction(): Promise<ITransaction | void>;
|
|
17
46
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the list of cards associated with a customer.
|
|
49
|
+
* @returns {Promise<import("../types").ICustomerCardsResponse>} A promise that resolves with the customer's card data.
|
|
50
|
+
*
|
|
51
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
getCustomerCards(): Promise<ICustomerCardsResponse>;
|
|
22
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Saves a card to a customer's account. This method can be used to add a new card
|
|
59
|
+
* or update an existing one.
|
|
60
|
+
* @param {import("../types").ISaveCardRequest} card - The card information to be saved.
|
|
61
|
+
* @returns {Promise<import("../types").ISaveCardResponse>} A promise that resolves with the saved card data.
|
|
62
|
+
*
|
|
63
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
23
67
|
saveCustomerCard(
|
|
24
|
-
authToken: string,
|
|
25
|
-
businessId: string,
|
|
26
68
|
card: ISaveCardRequest,
|
|
27
69
|
): Promise<ISaveCardResponse>;
|
|
28
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Removes a card from a customer's account.
|
|
73
|
+
* @param {string} skyflowId - The unique identifier of the card to be deleted.
|
|
74
|
+
* @returns {Promise<string>} A promise that resolves when the card is successfully deleted.
|
|
75
|
+
*
|
|
76
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
29
80
|
removeCustomerCard(
|
|
30
|
-
authToken: string,
|
|
31
81
|
skyflowId: string,
|
|
32
|
-
businessId: string,
|
|
33
82
|
): Promise<void>;
|
|
34
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Retrieves the list of available Alternative Payment Methods (APMs).
|
|
86
|
+
* @returns {Promise<import("../types").IPaymentMethod[]>} A promise that resolves with the list of APMs.
|
|
87
|
+
*
|
|
88
|
+
* @throws {import("../types").IPublicError} Throws an error object if the operation fails.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
35
92
|
getCustomerPaymentMethods(): Promise<IPaymentMethod[]>;
|
|
36
93
|
}
|
|
37
94
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function validateCardNumber(cardNumber: string): boolean;
|
|
2
|
+
|
|
3
|
+
export declare function validateCardholderName(name: string): boolean;
|
|
4
|
+
|
|
5
|
+
export declare function validateCVV(cvv: string): boolean;
|
|
6
|
+
|
|
7
|
+
export declare function validateExpirationMonth(month: string): boolean;
|
|
8
|
+
|
|
9
|
+
export declare function validateExpirationYear(year: string): boolean;
|
|
10
|
+
|
|
11
|
+
export declare function validateExpirationDateParts(month: string, year: string): boolean;
|