@tonder.io/ionic-full-sdk 0.0.31-beta → 0.0.32-beta
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/.gitlab-ci.yml +18 -18
- package/README.md +448 -448
- package/cypress.config.js +9 -9
- package/dist/classes/inlineCheckout.d.ts +6 -1
- package/dist/helpers/template.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/commons.d.ts +0 -1
- package/index.js.example +49 -49
- package/package.json +27 -27
- package/rollup.config.js +14 -14
- package/src/classes/3dsHandler.ts +237 -237
- package/src/classes/checkout.ts +147 -147
- package/src/classes/inlineCheckout.ts +734 -622
- package/src/helpers/skyflow.ts +358 -358
- package/src/helpers/styles.ts +60 -60
- package/src/helpers/template.ts +520 -492
- package/src/helpers/utils.ts +148 -148
- package/src/index-dev.js +120 -120
- package/src/index.html +57 -57
- package/src/index.ts +6 -6
- package/src/types/commons.ts +42 -43
- package/src/types/skyflow.ts +40 -40
- package/tsconfig.json +22 -22
- package/dist/data/api.d.ts +0 -18
- package/dist/types/commons-ds.d.ts +0 -40
- package/dist/types/skyflow.ds.d.ts +0 -39
package/src/helpers/skyflow.ts
CHANGED
|
@@ -1,358 +1,358 @@
|
|
|
1
|
-
import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
|
|
2
|
-
import { defaultStyles } from "./styles";
|
|
3
|
-
import Skyflow from 'skyflow-js'
|
|
4
|
-
import { CollectorIds } from "./template";
|
|
5
|
-
import CollectorContainer from "skyflow-js/types/core/external/collect/collect-container"
|
|
6
|
-
import ComposableContainer from "skyflow-js/types/core/external/collect/compose-collect-container"
|
|
7
|
-
import RevealContainer from "skyflow-js/types/core/external/reveal/reveal-container"
|
|
8
|
-
import RevealElement from "skyflow-js/types/core/external/reveal/reveal-element";
|
|
9
|
-
import ComposableElement from "skyflow-js/types/core/external/collect/compose-collect-element";
|
|
10
|
-
|
|
11
|
-
export type InCollectorContainer = {
|
|
12
|
-
container: CollectorContainer | ComposableContainer | RevealContainer,
|
|
13
|
-
elements: { [ index: string ]: CollectElement | ComposableElement | RevealElement }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function initSkyflow(
|
|
17
|
-
vaultId: string,
|
|
18
|
-
vaultUrl: string,
|
|
19
|
-
baseUrl: string,
|
|
20
|
-
signal: AbortSignal,
|
|
21
|
-
customStyles: any = {},
|
|
22
|
-
collectorIds: CollectorIds,
|
|
23
|
-
apiKey: string
|
|
24
|
-
): Promise <InCollectorContainer> {
|
|
25
|
-
const skyflow = await Skyflow.init({
|
|
26
|
-
vaultID: vaultId,
|
|
27
|
-
vaultURL: vaultUrl,
|
|
28
|
-
getBearerToken: async () => {
|
|
29
|
-
// Pass the signal to the fetch call
|
|
30
|
-
const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
|
|
31
|
-
method: 'GET',
|
|
32
|
-
headers: {
|
|
33
|
-
'Authorization': `Token ${apiKey}`,
|
|
34
|
-
},
|
|
35
|
-
signal: signal,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
if (response.ok) {
|
|
39
|
-
const responseBody = await response.json();
|
|
40
|
-
return responseBody.token;
|
|
41
|
-
} else {
|
|
42
|
-
throw new Error('Failed to retrieve bearer token');
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
options: {
|
|
46
|
-
logLevel: Skyflow.LogLevel.ERROR,
|
|
47
|
-
env: Skyflow.Env.DEV,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// Create collect Container.
|
|
52
|
-
const collectContainer = await skyflow.container(
|
|
53
|
-
Skyflow.ContainerType.COLLECT
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// Custom styles for collect elements.
|
|
57
|
-
var collectStylesOptions: any = Object.keys(customStyles).length === 0 ? defaultStyles : customStyles
|
|
58
|
-
|
|
59
|
-
const stylesForCardNumber = { ...collectStylesOptions.inputStyles.base };
|
|
60
|
-
stylesForCardNumber.textIndent = '44px';
|
|
61
|
-
|
|
62
|
-
const lengthMatchRule = {
|
|
63
|
-
type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
|
|
64
|
-
params: {
|
|
65
|
-
max: 70,
|
|
66
|
-
error: "El campo nombre del titular debe tener menos de 70 caracteres"
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const regexEmpty = RegExp("^(?!\s*$).+");
|
|
71
|
-
|
|
72
|
-
const regexMatchRule = {
|
|
73
|
-
type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
|
|
74
|
-
params: {
|
|
75
|
-
regex: regexEmpty,
|
|
76
|
-
error: "El campo es requerido" // Optional, default error is 'VALIDATION FAILED'.
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const cardHolderNameElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
81
|
-
table: "cards",
|
|
82
|
-
column: "cardholder_name",
|
|
83
|
-
...collectStylesOptions,
|
|
84
|
-
label: "Titular de la tarjeta",
|
|
85
|
-
placeholder: "Nombre como aparece en la tarjeta",
|
|
86
|
-
type: Skyflow.ElementType.CARDHOLDER_NAME,
|
|
87
|
-
validations: [lengthMatchRule, regexMatchRule],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
if("on" in cardHolderNameElement) {
|
|
91
|
-
|
|
92
|
-
cardHolderNameElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
93
|
-
|
|
94
|
-
let element = document.getElementById(
|
|
95
|
-
"errorCardHolderIdTonder",
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
if (element && state.isValid && !state.isEmpty) {
|
|
99
|
-
element.remove();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
cardHolderNameElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
104
|
-
let tonderContainer = document.getElementById(
|
|
105
|
-
collectorIds.holderName
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
let element = document.getElementById(
|
|
109
|
-
"errorCardHolderIdTonder",
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
if (element) {
|
|
113
|
-
element.remove();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!state.isValid) {
|
|
117
|
-
let errorLabel = document.createElement("div");
|
|
118
|
-
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
119
|
-
errorLabel.id = "errorCardHolderIdTonder";
|
|
120
|
-
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo titular de la tarjeta es inválido";
|
|
121
|
-
tonderContainer?.appendChild(errorLabel);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Create collect elements.
|
|
129
|
-
const cardNumberElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
130
|
-
table: "cards",
|
|
131
|
-
column: "card_number",
|
|
132
|
-
...collectStylesOptions,
|
|
133
|
-
inputStyles: {
|
|
134
|
-
...collectStylesOptions.inputStyles,
|
|
135
|
-
base: stylesForCardNumber
|
|
136
|
-
},
|
|
137
|
-
label: "Número de tarjeta",
|
|
138
|
-
placeholder: "1234 1234 1234 1234",
|
|
139
|
-
type: Skyflow.ElementType.CARD_NUMBER,
|
|
140
|
-
validations: [regexMatchRule],
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
if("on" in cardNumberElement) {
|
|
144
|
-
|
|
145
|
-
cardNumberElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
146
|
-
|
|
147
|
-
let element = document.getElementById(
|
|
148
|
-
"errorCardNumberIdTonder",
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
if (element && state.isValid && !state.isEmpty) {
|
|
152
|
-
element.remove();
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
cardNumberElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
158
|
-
let tonderContainer = document.getElementById(
|
|
159
|
-
collectorIds.cardNumber
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
let element = document.getElementById(
|
|
163
|
-
"errorCardNumberIdTonder",
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
if (element) {
|
|
167
|
-
element.remove();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (!state.isValid) {
|
|
171
|
-
let errorLabel = document.createElement("div");
|
|
172
|
-
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
173
|
-
errorLabel.id = "errorCardNumberIdTonder";
|
|
174
|
-
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo número de tarjeta es inválido";
|
|
175
|
-
tonderContainer?.appendChild(errorLabel);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const cvvElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
183
|
-
table: "cards",
|
|
184
|
-
column: "cvv",
|
|
185
|
-
...collectStylesOptions,
|
|
186
|
-
label: "CVC/CVV",
|
|
187
|
-
placeholder: "3-4 dígitos",
|
|
188
|
-
type: Skyflow.ElementType.CVV,
|
|
189
|
-
validations: [regexMatchRule],
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
if("on" in cvvElement) {
|
|
193
|
-
|
|
194
|
-
cvvElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
195
|
-
|
|
196
|
-
let element = document.getElementById(
|
|
197
|
-
"errorCvvIdTonder",
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
if (element && state.isValid && !state.isEmpty) {
|
|
201
|
-
element.remove();
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
cvvElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
206
|
-
let tonderContainer = document.getElementById(
|
|
207
|
-
collectorIds.cvv
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
let element = document.getElementById(
|
|
211
|
-
"errorCvvIdTonder",
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
if (element) {
|
|
215
|
-
element.remove();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (!state.isValid) {
|
|
219
|
-
let errorLabel = document.createElement("div");
|
|
220
|
-
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
221
|
-
errorLabel.id = "errorCvvIdTonder";
|
|
222
|
-
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo es inválido";
|
|
223
|
-
tonderContainer?.appendChild(errorLabel);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const expiryMonthElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
231
|
-
table: "cards",
|
|
232
|
-
column: "expiration_month",
|
|
233
|
-
...collectStylesOptions,
|
|
234
|
-
label: "Fecha de expiración",
|
|
235
|
-
placeholder: "MM",
|
|
236
|
-
type: Skyflow.ElementType.EXPIRATION_MONTH,
|
|
237
|
-
validations: [regexMatchRule],
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
if("on" in expiryMonthElement) {
|
|
241
|
-
|
|
242
|
-
expiryMonthElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
243
|
-
|
|
244
|
-
let element = document.getElementById(
|
|
245
|
-
"errorExpiryMonthIdTonder",
|
|
246
|
-
);
|
|
247
|
-
|
|
248
|
-
if (element && state.isValid && !state.isEmpty) {
|
|
249
|
-
element.remove();
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
expiryMonthElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
254
|
-
let tonderContainer = document.getElementById(
|
|
255
|
-
collectorIds.expirationMonth
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
let element = document.getElementById(
|
|
259
|
-
"errorExpiryMonthIdTonder",
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
if (element) {
|
|
263
|
-
element.remove();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (!state.isValid) {
|
|
267
|
-
let errorLabel = document.createElement("div");
|
|
268
|
-
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
269
|
-
errorLabel.id = "errorExpiryMonthIdTonder";
|
|
270
|
-
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo es inválido";
|
|
271
|
-
tonderContainer?.appendChild(errorLabel);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const expiryYearElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
279
|
-
table: "cards",
|
|
280
|
-
column: "expiration_year",
|
|
281
|
-
...collectStylesOptions,
|
|
282
|
-
label: "",
|
|
283
|
-
placeholder: "AA",
|
|
284
|
-
type: Skyflow.ElementType.EXPIRATION_YEAR,
|
|
285
|
-
validations: [regexMatchRule],
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
if("on" in expiryYearElement) {
|
|
289
|
-
|
|
290
|
-
expiryYearElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
291
|
-
|
|
292
|
-
let element = document.getElementById(
|
|
293
|
-
"errorExpiryYearIdTonder",
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
if (element && state.isValid && !state.isEmpty) {
|
|
297
|
-
element.remove();
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
expiryYearElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
302
|
-
let tonderContainer = document.getElementById(
|
|
303
|
-
collectorIds.expirationYear
|
|
304
|
-
);
|
|
305
|
-
|
|
306
|
-
let element = document.getElementById(
|
|
307
|
-
"errorExpiryYearIdTonder",
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
if (element) {
|
|
311
|
-
element.remove();
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (!state.isValid) {
|
|
315
|
-
let errorLabel = document.createElement("div");
|
|
316
|
-
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
317
|
-
errorLabel.id = "errorExpiryYearIdTonder";
|
|
318
|
-
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo es inválido";
|
|
319
|
-
tonderContainer?.appendChild(errorLabel);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
await mountElements(
|
|
327
|
-
{ id: collectorIds.cardNumber, element: cardNumberElement },
|
|
328
|
-
{ id: collectorIds.cvv, element: cvvElement },
|
|
329
|
-
{ id: collectorIds.expirationMonth, element: expiryMonthElement },
|
|
330
|
-
{ id: collectorIds.expirationYear, element: expiryYearElement },
|
|
331
|
-
{ id: collectorIds.holderName, element: cardHolderNameElement }
|
|
332
|
-
)
|
|
333
|
-
|
|
334
|
-
return {
|
|
335
|
-
container: collectContainer,
|
|
336
|
-
elements: {
|
|
337
|
-
cardHolderNameElement,
|
|
338
|
-
cardNumberElement,
|
|
339
|
-
cvvElement,
|
|
340
|
-
expiryMonthElement,
|
|
341
|
-
expiryYearElement
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
async function mountElements(
|
|
347
|
-
cardNumberElement: any,
|
|
348
|
-
cvvElement: any,
|
|
349
|
-
expiryMonthElement: any,
|
|
350
|
-
expiryYearElement: any,
|
|
351
|
-
cardHolderNameElement: any,
|
|
352
|
-
) {
|
|
353
|
-
cardNumberElement.element.mount(`#${cardNumberElement.id}`);
|
|
354
|
-
cvvElement.element.mount(`#${cvvElement.id}`);
|
|
355
|
-
expiryMonthElement.element.mount(`#${expiryMonthElement.id}`);
|
|
356
|
-
expiryYearElement.element.mount(`#${expiryYearElement.id}`);
|
|
357
|
-
cardHolderNameElement.element.mount(`#${cardHolderNameElement.id}`);
|
|
358
|
-
}
|
|
1
|
+
import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
|
|
2
|
+
import { defaultStyles } from "./styles";
|
|
3
|
+
import Skyflow from 'skyflow-js'
|
|
4
|
+
import { CollectorIds } from "./template";
|
|
5
|
+
import CollectorContainer from "skyflow-js/types/core/external/collect/collect-container"
|
|
6
|
+
import ComposableContainer from "skyflow-js/types/core/external/collect/compose-collect-container"
|
|
7
|
+
import RevealContainer from "skyflow-js/types/core/external/reveal/reveal-container"
|
|
8
|
+
import RevealElement from "skyflow-js/types/core/external/reveal/reveal-element";
|
|
9
|
+
import ComposableElement from "skyflow-js/types/core/external/collect/compose-collect-element";
|
|
10
|
+
|
|
11
|
+
export type InCollectorContainer = {
|
|
12
|
+
container: CollectorContainer | ComposableContainer | RevealContainer,
|
|
13
|
+
elements: { [ index: string ]: CollectElement | ComposableElement | RevealElement }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function initSkyflow(
|
|
17
|
+
vaultId: string,
|
|
18
|
+
vaultUrl: string,
|
|
19
|
+
baseUrl: string,
|
|
20
|
+
signal: AbortSignal,
|
|
21
|
+
customStyles: any = {},
|
|
22
|
+
collectorIds: CollectorIds,
|
|
23
|
+
apiKey: string
|
|
24
|
+
): Promise <InCollectorContainer> {
|
|
25
|
+
const skyflow = await Skyflow.init({
|
|
26
|
+
vaultID: vaultId,
|
|
27
|
+
vaultURL: vaultUrl,
|
|
28
|
+
getBearerToken: async () => {
|
|
29
|
+
// Pass the signal to the fetch call
|
|
30
|
+
const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
|
|
31
|
+
method: 'GET',
|
|
32
|
+
headers: {
|
|
33
|
+
'Authorization': `Token ${apiKey}`,
|
|
34
|
+
},
|
|
35
|
+
signal: signal,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (response.ok) {
|
|
39
|
+
const responseBody = await response.json();
|
|
40
|
+
return responseBody.token;
|
|
41
|
+
} else {
|
|
42
|
+
throw new Error('Failed to retrieve bearer token');
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
options: {
|
|
46
|
+
logLevel: Skyflow.LogLevel.ERROR,
|
|
47
|
+
env: Skyflow.Env.DEV,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Create collect Container.
|
|
52
|
+
const collectContainer = await skyflow.container(
|
|
53
|
+
Skyflow.ContainerType.COLLECT
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// Custom styles for collect elements.
|
|
57
|
+
var collectStylesOptions: any = Object.keys(customStyles).length === 0 ? defaultStyles : customStyles
|
|
58
|
+
|
|
59
|
+
const stylesForCardNumber = { ...collectStylesOptions.inputStyles.base };
|
|
60
|
+
stylesForCardNumber.textIndent = '44px';
|
|
61
|
+
|
|
62
|
+
const lengthMatchRule = {
|
|
63
|
+
type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
|
|
64
|
+
params: {
|
|
65
|
+
max: 70,
|
|
66
|
+
error: "El campo nombre del titular debe tener menos de 70 caracteres"
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const regexEmpty = RegExp("^(?!\s*$).+");
|
|
71
|
+
|
|
72
|
+
const regexMatchRule = {
|
|
73
|
+
type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
|
|
74
|
+
params: {
|
|
75
|
+
regex: regexEmpty,
|
|
76
|
+
error: "El campo es requerido" // Optional, default error is 'VALIDATION FAILED'.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const cardHolderNameElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
81
|
+
table: "cards",
|
|
82
|
+
column: "cardholder_name",
|
|
83
|
+
...collectStylesOptions,
|
|
84
|
+
label: "Titular de la tarjeta",
|
|
85
|
+
placeholder: "Nombre como aparece en la tarjeta",
|
|
86
|
+
type: Skyflow.ElementType.CARDHOLDER_NAME,
|
|
87
|
+
validations: [lengthMatchRule, regexMatchRule],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if("on" in cardHolderNameElement) {
|
|
91
|
+
|
|
92
|
+
cardHolderNameElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
93
|
+
|
|
94
|
+
let element = document.getElementById(
|
|
95
|
+
"errorCardHolderIdTonder",
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (element && state.isValid && !state.isEmpty) {
|
|
99
|
+
element.remove();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
cardHolderNameElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
104
|
+
let tonderContainer = document.getElementById(
|
|
105
|
+
collectorIds.holderName
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
let element = document.getElementById(
|
|
109
|
+
"errorCardHolderIdTonder",
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
if (element) {
|
|
113
|
+
element.remove();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!state.isValid) {
|
|
117
|
+
let errorLabel = document.createElement("div");
|
|
118
|
+
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
119
|
+
errorLabel.id = "errorCardHolderIdTonder";
|
|
120
|
+
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo titular de la tarjeta es inválido";
|
|
121
|
+
tonderContainer?.appendChild(errorLabel);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Create collect elements.
|
|
129
|
+
const cardNumberElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
130
|
+
table: "cards",
|
|
131
|
+
column: "card_number",
|
|
132
|
+
...collectStylesOptions,
|
|
133
|
+
inputStyles: {
|
|
134
|
+
...collectStylesOptions.inputStyles,
|
|
135
|
+
base: stylesForCardNumber
|
|
136
|
+
},
|
|
137
|
+
label: "Número de tarjeta",
|
|
138
|
+
placeholder: "1234 1234 1234 1234",
|
|
139
|
+
type: Skyflow.ElementType.CARD_NUMBER,
|
|
140
|
+
validations: [regexMatchRule],
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
if("on" in cardNumberElement) {
|
|
144
|
+
|
|
145
|
+
cardNumberElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
146
|
+
|
|
147
|
+
let element = document.getElementById(
|
|
148
|
+
"errorCardNumberIdTonder",
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (element && state.isValid && !state.isEmpty) {
|
|
152
|
+
element.remove();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
cardNumberElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
158
|
+
let tonderContainer = document.getElementById(
|
|
159
|
+
collectorIds.cardNumber
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
let element = document.getElementById(
|
|
163
|
+
"errorCardNumberIdTonder",
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
if (element) {
|
|
167
|
+
element.remove();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!state.isValid) {
|
|
171
|
+
let errorLabel = document.createElement("div");
|
|
172
|
+
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
173
|
+
errorLabel.id = "errorCardNumberIdTonder";
|
|
174
|
+
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo número de tarjeta es inválido";
|
|
175
|
+
tonderContainer?.appendChild(errorLabel);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const cvvElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
183
|
+
table: "cards",
|
|
184
|
+
column: "cvv",
|
|
185
|
+
...collectStylesOptions,
|
|
186
|
+
label: "CVC/CVV",
|
|
187
|
+
placeholder: "3-4 dígitos",
|
|
188
|
+
type: Skyflow.ElementType.CVV,
|
|
189
|
+
validations: [regexMatchRule],
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
if("on" in cvvElement) {
|
|
193
|
+
|
|
194
|
+
cvvElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
195
|
+
|
|
196
|
+
let element = document.getElementById(
|
|
197
|
+
"errorCvvIdTonder",
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
if (element && state.isValid && !state.isEmpty) {
|
|
201
|
+
element.remove();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
cvvElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
206
|
+
let tonderContainer = document.getElementById(
|
|
207
|
+
collectorIds.cvv
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
let element = document.getElementById(
|
|
211
|
+
"errorCvvIdTonder",
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
if (element) {
|
|
215
|
+
element.remove();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!state.isValid) {
|
|
219
|
+
let errorLabel = document.createElement("div");
|
|
220
|
+
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
221
|
+
errorLabel.id = "errorCvvIdTonder";
|
|
222
|
+
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo es inválido";
|
|
223
|
+
tonderContainer?.appendChild(errorLabel);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const expiryMonthElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
231
|
+
table: "cards",
|
|
232
|
+
column: "expiration_month",
|
|
233
|
+
...collectStylesOptions,
|
|
234
|
+
label: "Fecha de expiración",
|
|
235
|
+
placeholder: "MM",
|
|
236
|
+
type: Skyflow.ElementType.EXPIRATION_MONTH,
|
|
237
|
+
validations: [regexMatchRule],
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
if("on" in expiryMonthElement) {
|
|
241
|
+
|
|
242
|
+
expiryMonthElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
243
|
+
|
|
244
|
+
let element = document.getElementById(
|
|
245
|
+
"errorExpiryMonthIdTonder",
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
if (element && state.isValid && !state.isEmpty) {
|
|
249
|
+
element.remove();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
expiryMonthElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
254
|
+
let tonderContainer = document.getElementById(
|
|
255
|
+
collectorIds.expirationMonth
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
let element = document.getElementById(
|
|
259
|
+
"errorExpiryMonthIdTonder",
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
if (element) {
|
|
263
|
+
element.remove();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (!state.isValid) {
|
|
267
|
+
let errorLabel = document.createElement("div");
|
|
268
|
+
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
269
|
+
errorLabel.id = "errorExpiryMonthIdTonder";
|
|
270
|
+
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo es inválido";
|
|
271
|
+
tonderContainer?.appendChild(errorLabel);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const expiryYearElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
279
|
+
table: "cards",
|
|
280
|
+
column: "expiration_year",
|
|
281
|
+
...collectStylesOptions,
|
|
282
|
+
label: "",
|
|
283
|
+
placeholder: "AA",
|
|
284
|
+
type: Skyflow.ElementType.EXPIRATION_YEAR,
|
|
285
|
+
validations: [regexMatchRule],
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
if("on" in expiryYearElement) {
|
|
289
|
+
|
|
290
|
+
expiryYearElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
291
|
+
|
|
292
|
+
let element = document.getElementById(
|
|
293
|
+
"errorExpiryYearIdTonder",
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
if (element && state.isValid && !state.isEmpty) {
|
|
297
|
+
element.remove();
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
expiryYearElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
302
|
+
let tonderContainer = document.getElementById(
|
|
303
|
+
collectorIds.expirationYear
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
let element = document.getElementById(
|
|
307
|
+
"errorExpiryYearIdTonder",
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
if (element) {
|
|
311
|
+
element.remove();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!state.isValid) {
|
|
315
|
+
let errorLabel = document.createElement("div");
|
|
316
|
+
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
317
|
+
errorLabel.id = "errorExpiryYearIdTonder";
|
|
318
|
+
errorLabel.textContent = state.isEmpty ? "El campo es requerido" : "El campo es inválido";
|
|
319
|
+
tonderContainer?.appendChild(errorLabel);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
await mountElements(
|
|
327
|
+
{ id: collectorIds.cardNumber, element: cardNumberElement },
|
|
328
|
+
{ id: collectorIds.cvv, element: cvvElement },
|
|
329
|
+
{ id: collectorIds.expirationMonth, element: expiryMonthElement },
|
|
330
|
+
{ id: collectorIds.expirationYear, element: expiryYearElement },
|
|
331
|
+
{ id: collectorIds.holderName, element: cardHolderNameElement }
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
return {
|
|
335
|
+
container: collectContainer,
|
|
336
|
+
elements: {
|
|
337
|
+
cardHolderNameElement,
|
|
338
|
+
cardNumberElement,
|
|
339
|
+
cvvElement,
|
|
340
|
+
expiryMonthElement,
|
|
341
|
+
expiryYearElement
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async function mountElements(
|
|
347
|
+
cardNumberElement: any,
|
|
348
|
+
cvvElement: any,
|
|
349
|
+
expiryMonthElement: any,
|
|
350
|
+
expiryYearElement: any,
|
|
351
|
+
cardHolderNameElement: any,
|
|
352
|
+
) {
|
|
353
|
+
cardNumberElement.element.mount(`#${cardNumberElement.id}`);
|
|
354
|
+
cvvElement.element.mount(`#${cvvElement.id}`);
|
|
355
|
+
expiryMonthElement.element.mount(`#${expiryMonthElement.id}`);
|
|
356
|
+
expiryYearElement.element.mount(`#${expiryYearElement.id}`);
|
|
357
|
+
cardHolderNameElement.element.mount(`#${cardHolderNameElement.id}`);
|
|
358
|
+
}
|