@tonder.io/ionic-full-sdk 0.0.46-beta.9 → 0.0.47-beta.DEV1406.a897fdd
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 +4 -1
- package/dist/classes/inlineCheckout.d.ts +5 -0
- package/dist/helpers/skyflow.d.ts +9 -0
- package/dist/helpers/template.d.ts +5 -1
- package/dist/helpers/utils.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/types/inlineCheckout.d.ts +2 -0
- package/package.json +4 -2
- package/rollup.config.js +6 -1
- package/src/classes/inlineCheckout.ts +140 -46
- package/src/helpers/skyflow.ts +311 -190
- package/src/helpers/styles.ts +9 -8
- package/src/helpers/template.ts +179 -27
- package/src/helpers/utils.ts +12 -0
- package/src/types/inlineCheckout.ts +2 -0
package/src/helpers/skyflow.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
|
|
2
2
|
import { defaultStyles } from "./styles";
|
|
3
|
-
import Skyflow from
|
|
3
|
+
import Skyflow from "skyflow-js";
|
|
4
4
|
import { CollectorIds } from "./template";
|
|
5
5
|
import RevealElement from "skyflow-js/types/core/external/reveal/reveal-element";
|
|
6
6
|
import ComposableElement from "skyflow-js/types/core/external/collect/compose-collect-element";
|
|
7
|
-
import {InCollectorContainer} from "../types/commons";
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import { InCollectorContainer } from "../types/commons";
|
|
8
|
+
import { getVaultToken } from "@tonder.io/ionic-lite-sdk/dist/data/skyflowApi";
|
|
10
9
|
|
|
11
10
|
export async function initSkyflow(
|
|
12
11
|
vaultId: string,
|
|
@@ -15,80 +14,67 @@ export async function initSkyflow(
|
|
|
15
14
|
signal: AbortSignal,
|
|
16
15
|
customStyles: any = {},
|
|
17
16
|
collectorIds: CollectorIds,
|
|
18
|
-
apiKey: string
|
|
19
|
-
): Promise
|
|
20
|
-
const skyflow = await
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
headers: {
|
|
28
|
-
'Authorization': `Token ${apiKey}`,
|
|
29
|
-
},
|
|
30
|
-
signal: signal,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if (response.ok) {
|
|
34
|
-
const responseBody = await response.json();
|
|
35
|
-
return responseBody.token;
|
|
36
|
-
} else {
|
|
37
|
-
throw new Error('Failed to retrieve bearer token');
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
options: {
|
|
41
|
-
logLevel: Skyflow.LogLevel.ERROR,
|
|
42
|
-
env: Skyflow.Env.DEV,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
17
|
+
apiKey: string,
|
|
18
|
+
): Promise<InCollectorContainer> {
|
|
19
|
+
const skyflow = await initializeSkyflow(
|
|
20
|
+
vaultId,
|
|
21
|
+
vaultUrl,
|
|
22
|
+
baseUrl,
|
|
23
|
+
apiKey,
|
|
24
|
+
signal,
|
|
25
|
+
);
|
|
45
26
|
|
|
46
27
|
// Create collect Container.
|
|
47
|
-
const collectContainer =
|
|
48
|
-
Skyflow.ContainerType.COLLECT
|
|
49
|
-
);
|
|
28
|
+
const collectContainer = skyflow.container(Skyflow.ContainerType.COLLECT);
|
|
50
29
|
|
|
51
30
|
// Custom styles for collect elements.
|
|
52
|
-
var collectStylesOptions: any =
|
|
31
|
+
var collectStylesOptions: any =
|
|
32
|
+
Object.keys(customStyles).length === 0
|
|
33
|
+
? defaultStyles
|
|
34
|
+
: {
|
|
35
|
+
...customStyles,
|
|
36
|
+
labels: {
|
|
37
|
+
nameLabel: customStyles?.labels?.nameLabel && customStyles?.labels?.nameLabel !== "" ? customStyles?.labels?.nameLabel: defaultStyles.labels.nameLabel,
|
|
38
|
+
cardLabel: customStyles?.labels?.cardLabel && customStyles?.labels?.cardLabel !== "" ? customStyles?.labels?.cardLabel: defaultStyles.labels.cardLabel,
|
|
39
|
+
cvvLabel: customStyles?.labels?.cvvLabel && customStyles?.labels?.cvvLabel !== "" ? customStyles?.labels?.cvvLabel: defaultStyles.labels.cvvLabel,
|
|
40
|
+
expiryDateLabel: customStyles?.labels?.expiryDateLabel && customStyles?.labels?.expiryDateLabel !== "" ? customStyles?.labels?.expiryDateLabel: defaultStyles.labels.expiryDateLabel,
|
|
41
|
+
},
|
|
42
|
+
placeholders: {
|
|
43
|
+
namePlaceholder: customStyles?.placeholders?.namePlaceholder && customStyles?.placeholders?.namePlaceholder !== "" ? customStyles?.placeholders?.namePlaceholder: defaultStyles.placeholders.namePlaceholder,
|
|
44
|
+
cardPlaceholder: customStyles?.placeholders?.cardPlaceholder && customStyles?.placeholders?.cardPlaceholder !== "" ? customStyles?.placeholders?.cardPlaceholder: defaultStyles.placeholders.cardPlaceholder,
|
|
45
|
+
cvvPlaceholder: customStyles?.placeholders?.cvvPlaceholder && customStyles?.placeholders?.cvvPlaceholder !== "" ? customStyles?.placeholders?.cvvPlaceholder: defaultStyles.placeholders.cvvPlaceholder,
|
|
46
|
+
expiryMonthPlaceholder: customStyles?.placeholders?.expiryMonthPlaceholder && customStyles?.placeholders?.expiryMonthPlaceholder !== "" ? customStyles?.placeholders?.expiryMonthPlaceholder: defaultStyles.placeholders.expiryMonthPlaceholder,
|
|
47
|
+
expiryYearPlaceholder: customStyles?.placeholders?.expiryYearPlaceholder && customStyles?.placeholders?.expiryYearPlaceholder !== "" ? customStyles?.placeholders?.expiryYearPlaceholder: defaultStyles.placeholders.expiryYearPlaceholder,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
53
50
|
|
|
54
51
|
const stylesForCardNumber = { ...collectStylesOptions.inputStyles.base };
|
|
55
|
-
stylesForCardNumber.textIndent =
|
|
52
|
+
stylesForCardNumber.textIndent = "44px";
|
|
56
53
|
|
|
57
54
|
const lengthMatchRule = {
|
|
58
55
|
type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
|
|
59
56
|
params: {
|
|
60
57
|
max: 70,
|
|
61
|
-
error: "El campo nombre del titular debe tener menos de 70 caracteres"
|
|
58
|
+
error: "El campo nombre del titular debe tener menos de 70 caracteres",
|
|
62
59
|
},
|
|
63
60
|
};
|
|
64
61
|
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
params: {
|
|
70
|
-
regex: regexEmpty,
|
|
71
|
-
error: "El campo es requerido" // Optional, default error is 'VALIDATION FAILED'.
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const cardHolderNameElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
|
|
62
|
+
const cardHolderNameElement:
|
|
63
|
+
| CollectElement
|
|
64
|
+
| RevealElement
|
|
65
|
+
| ComposableElement = collectContainer.create({
|
|
76
66
|
table: "cards",
|
|
77
67
|
column: "cardholder_name",
|
|
78
68
|
...collectStylesOptions,
|
|
79
|
-
label:
|
|
80
|
-
placeholder:
|
|
69
|
+
label: collectStylesOptions?.labels?.nameLabel,
|
|
70
|
+
placeholder: collectStylesOptions?.placeholders?.namePlaceholder,
|
|
81
71
|
type: Skyflow.ElementType.CARDHOLDER_NAME,
|
|
82
72
|
validations: [lengthMatchRule, regexMatchRule],
|
|
83
73
|
});
|
|
84
74
|
|
|
85
|
-
if("on" in cardHolderNameElement) {
|
|
86
|
-
|
|
75
|
+
if ("on" in cardHolderNameElement) {
|
|
87
76
|
cardHolderNameElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
88
|
-
|
|
89
|
-
let element = document.getElementById(
|
|
90
|
-
"errorCardHolderIdTonder",
|
|
91
|
-
);
|
|
77
|
+
let element = document.getElementById("errorCardHolderIdTonder");
|
|
92
78
|
|
|
93
79
|
if (element && state.isValid && !state.isEmpty) {
|
|
94
80
|
element.remove();
|
|
@@ -96,13 +82,9 @@ export async function initSkyflow(
|
|
|
96
82
|
});
|
|
97
83
|
|
|
98
84
|
cardHolderNameElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
99
|
-
let tonderContainer = document.getElementById(
|
|
100
|
-
collectorIds.holderName
|
|
101
|
-
);
|
|
85
|
+
let tonderContainer = document.getElementById(collectorIds.holderName);
|
|
102
86
|
|
|
103
|
-
let element = document.getElementById(
|
|
104
|
-
"errorCardHolderIdTonder",
|
|
105
|
-
);
|
|
87
|
+
let element = document.getElementById("errorCardHolderIdTonder");
|
|
106
88
|
|
|
107
89
|
if (element) {
|
|
108
90
|
element.remove();
|
|
@@ -112,51 +94,43 @@ export async function initSkyflow(
|
|
|
112
94
|
let errorLabel = document.createElement("div");
|
|
113
95
|
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
114
96
|
errorLabel.id = "errorCardHolderIdTonder";
|
|
115
|
-
errorLabel.textContent = state.isEmpty
|
|
97
|
+
errorLabel.textContent = state.isEmpty
|
|
98
|
+
? "El campo es requerido"
|
|
99
|
+
: "El campo titular de la tarjeta es inválido";
|
|
116
100
|
tonderContainer?.appendChild(errorLabel);
|
|
117
101
|
}
|
|
118
|
-
|
|
119
102
|
});
|
|
120
|
-
|
|
121
103
|
}
|
|
122
104
|
|
|
123
105
|
// Create collect elements.
|
|
124
|
-
const cardNumberElement: CollectElement | RevealElement | ComposableElement =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if("on" in cardNumberElement) {
|
|
106
|
+
const cardNumberElement: CollectElement | RevealElement | ComposableElement =
|
|
107
|
+
collectContainer.create({
|
|
108
|
+
table: "cards",
|
|
109
|
+
column: "card_number",
|
|
110
|
+
...collectStylesOptions,
|
|
111
|
+
inputStyles: {
|
|
112
|
+
...collectStylesOptions.inputStyles,
|
|
113
|
+
base: stylesForCardNumber,
|
|
114
|
+
},
|
|
115
|
+
label: collectStylesOptions.labels?.cardLabel,
|
|
116
|
+
placeholder: collectStylesOptions.placeholders?.cardPlaceholder,
|
|
117
|
+
type: Skyflow.ElementType.CARD_NUMBER,
|
|
118
|
+
validations: [regexMatchRule],
|
|
119
|
+
});
|
|
139
120
|
|
|
121
|
+
if ("on" in cardNumberElement) {
|
|
140
122
|
cardNumberElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
141
|
-
|
|
142
|
-
let element = document.getElementById(
|
|
143
|
-
"errorCardNumberIdTonder",
|
|
144
|
-
);
|
|
123
|
+
let element = document.getElementById("errorCardNumberIdTonder");
|
|
145
124
|
|
|
146
125
|
if (element && state.isValid && !state.isEmpty) {
|
|
147
126
|
element.remove();
|
|
148
127
|
}
|
|
149
|
-
|
|
150
128
|
});
|
|
151
129
|
|
|
152
130
|
cardNumberElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
153
|
-
let tonderContainer = document.getElementById(
|
|
154
|
-
collectorIds.cardNumber
|
|
155
|
-
);
|
|
131
|
+
let tonderContainer = document.getElementById(collectorIds.cardNumber);
|
|
156
132
|
|
|
157
|
-
let element = document.getElementById(
|
|
158
|
-
"errorCardNumberIdTonder",
|
|
159
|
-
);
|
|
133
|
+
let element = document.getElementById("errorCardNumberIdTonder");
|
|
160
134
|
|
|
161
135
|
if (element) {
|
|
162
136
|
element.remove();
|
|
@@ -166,31 +140,28 @@ export async function initSkyflow(
|
|
|
166
140
|
let errorLabel = document.createElement("div");
|
|
167
141
|
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
168
142
|
errorLabel.id = "errorCardNumberIdTonder";
|
|
169
|
-
errorLabel.textContent = state.isEmpty
|
|
143
|
+
errorLabel.textContent = state.isEmpty
|
|
144
|
+
? "El campo es requerido"
|
|
145
|
+
: "El campo número de tarjeta es inválido";
|
|
170
146
|
tonderContainer?.appendChild(errorLabel);
|
|
171
147
|
}
|
|
172
|
-
|
|
173
148
|
});
|
|
174
|
-
|
|
175
149
|
}
|
|
176
150
|
|
|
177
|
-
const cvvElement: CollectElement | RevealElement | ComposableElement =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if("on" in cvvElement) {
|
|
151
|
+
const cvvElement: CollectElement | RevealElement | ComposableElement =
|
|
152
|
+
collectContainer.create({
|
|
153
|
+
table: "cards",
|
|
154
|
+
column: "cvv",
|
|
155
|
+
...collectStylesOptions,
|
|
156
|
+
label: collectStylesOptions.labels?.cvvLabel,
|
|
157
|
+
placeholder: collectStylesOptions.placeholders?.cvvPlaceholder,
|
|
158
|
+
type: Skyflow.ElementType.CVV,
|
|
159
|
+
validations: [regexMatchRule],
|
|
160
|
+
});
|
|
188
161
|
|
|
162
|
+
if ("on" in cvvElement) {
|
|
189
163
|
cvvElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
190
|
-
|
|
191
|
-
let element = document.getElementById(
|
|
192
|
-
"errorCvvIdTonder",
|
|
193
|
-
);
|
|
164
|
+
let element = document.getElementById("errorCvvIdTonder");
|
|
194
165
|
|
|
195
166
|
if (element && state.isValid && !state.isEmpty) {
|
|
196
167
|
element.remove();
|
|
@@ -198,13 +169,9 @@ export async function initSkyflow(
|
|
|
198
169
|
});
|
|
199
170
|
|
|
200
171
|
cvvElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
201
|
-
let tonderContainer = document.getElementById(
|
|
202
|
-
collectorIds.cvv
|
|
203
|
-
);
|
|
172
|
+
let tonderContainer = document.getElementById(collectorIds.cvv);
|
|
204
173
|
|
|
205
|
-
let element = document.getElementById(
|
|
206
|
-
"errorCvvIdTonder",
|
|
207
|
-
);
|
|
174
|
+
let element = document.getElementById("errorCvvIdTonder");
|
|
208
175
|
|
|
209
176
|
if (element) {
|
|
210
177
|
element.remove();
|
|
@@ -214,31 +181,27 @@ export async function initSkyflow(
|
|
|
214
181
|
let errorLabel = document.createElement("div");
|
|
215
182
|
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
216
183
|
errorLabel.id = "errorCvvIdTonder";
|
|
217
|
-
errorLabel.textContent = state.isEmpty
|
|
184
|
+
errorLabel.textContent = state.isEmpty
|
|
185
|
+
? "El campo es requerido"
|
|
186
|
+
: "El campo es inválido";
|
|
218
187
|
tonderContainer?.appendChild(errorLabel);
|
|
219
188
|
}
|
|
220
|
-
|
|
221
189
|
});
|
|
222
|
-
|
|
223
190
|
}
|
|
224
191
|
|
|
225
|
-
const expiryMonthElement: CollectElement | RevealElement | ComposableElement =
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
label:
|
|
230
|
-
placeholder:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if("on" in expiryMonthElement) {
|
|
192
|
+
const expiryMonthElement: CollectElement | RevealElement | ComposableElement = collectContainer.create({
|
|
193
|
+
table: "cards",
|
|
194
|
+
column: "expiration_month",
|
|
195
|
+
...collectStylesOptions,
|
|
196
|
+
label: collectStylesOptions.labels?.expiryDateLabel,
|
|
197
|
+
placeholder: collectStylesOptions.placeholders?.expiryMonthPlaceholder,
|
|
198
|
+
type: Skyflow.ElementType.EXPIRATION_MONTH,
|
|
199
|
+
validations: [regexMatchRule],
|
|
200
|
+
});
|
|
236
201
|
|
|
202
|
+
if ("on" in expiryMonthElement) {
|
|
237
203
|
expiryMonthElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
238
|
-
|
|
239
|
-
let element = document.getElementById(
|
|
240
|
-
"errorExpiryMonthIdTonder",
|
|
241
|
-
);
|
|
204
|
+
let element = document.getElementById("errorExpiryMonthIdTonder");
|
|
242
205
|
|
|
243
206
|
if (element && state.isValid && !state.isEmpty) {
|
|
244
207
|
element.remove();
|
|
@@ -247,12 +210,10 @@ export async function initSkyflow(
|
|
|
247
210
|
|
|
248
211
|
expiryMonthElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
249
212
|
let tonderContainer = document.getElementById(
|
|
250
|
-
collectorIds.expirationMonth
|
|
213
|
+
collectorIds.expirationMonth,
|
|
251
214
|
);
|
|
252
215
|
|
|
253
|
-
let element = document.getElementById(
|
|
254
|
-
"errorExpiryMonthIdTonder",
|
|
255
|
-
);
|
|
216
|
+
let element = document.getElementById("errorExpiryMonthIdTonder");
|
|
256
217
|
|
|
257
218
|
if (element) {
|
|
258
219
|
element.remove();
|
|
@@ -262,31 +223,28 @@ export async function initSkyflow(
|
|
|
262
223
|
let errorLabel = document.createElement("div");
|
|
263
224
|
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
264
225
|
errorLabel.id = "errorExpiryMonthIdTonder";
|
|
265
|
-
errorLabel.textContent = state.isEmpty
|
|
226
|
+
errorLabel.textContent = state.isEmpty
|
|
227
|
+
? "El campo es requerido"
|
|
228
|
+
: "El campo es inválido";
|
|
266
229
|
tonderContainer?.appendChild(errorLabel);
|
|
267
230
|
}
|
|
268
|
-
|
|
269
231
|
});
|
|
270
|
-
|
|
271
232
|
}
|
|
233
|
+
console.log("collectStylesOptions ====", collectStylesOptions)
|
|
234
|
+
|
|
235
|
+
const expiryYearElement: CollectElement | RevealElement | ComposableElement = collectContainer.create({
|
|
236
|
+
table: "cards",
|
|
237
|
+
column: "expiration_year",
|
|
238
|
+
...collectStylesOptions,
|
|
239
|
+
label: "",
|
|
240
|
+
placeholder: collectStylesOptions.placeholders?.expiryYearPlaceholder,
|
|
241
|
+
type: Skyflow.ElementType.EXPIRATION_YEAR,
|
|
242
|
+
validations: [regexMatchRule],
|
|
243
|
+
});
|
|
272
244
|
|
|
273
|
-
|
|
274
|
-
table: "cards",
|
|
275
|
-
column: "expiration_year",
|
|
276
|
-
...collectStylesOptions,
|
|
277
|
-
label: "",
|
|
278
|
-
placeholder: "AA",
|
|
279
|
-
type: Skyflow.ElementType.EXPIRATION_YEAR,
|
|
280
|
-
validations: [regexMatchRule],
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
if("on" in expiryYearElement) {
|
|
284
|
-
|
|
245
|
+
if ("on" in expiryYearElement) {
|
|
285
246
|
expiryYearElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
286
|
-
|
|
287
|
-
let element = document.getElementById(
|
|
288
|
-
"errorExpiryYearIdTonder",
|
|
289
|
-
);
|
|
247
|
+
let element = document.getElementById("errorExpiryYearIdTonder");
|
|
290
248
|
|
|
291
249
|
if (element && state.isValid && !state.isEmpty) {
|
|
292
250
|
element.remove();
|
|
@@ -295,12 +253,10 @@ export async function initSkyflow(
|
|
|
295
253
|
|
|
296
254
|
expiryYearElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
297
255
|
let tonderContainer = document.getElementById(
|
|
298
|
-
collectorIds.expirationYear
|
|
256
|
+
collectorIds.expirationYear,
|
|
299
257
|
);
|
|
300
258
|
|
|
301
|
-
let element = document.getElementById(
|
|
302
|
-
"errorExpiryYearIdTonder",
|
|
303
|
-
);
|
|
259
|
+
let element = document.getElementById("errorExpiryYearIdTonder");
|
|
304
260
|
|
|
305
261
|
if (element) {
|
|
306
262
|
element.remove();
|
|
@@ -310,44 +266,209 @@ export async function initSkyflow(
|
|
|
310
266
|
let errorLabel = document.createElement("div");
|
|
311
267
|
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
312
268
|
errorLabel.id = "errorExpiryYearIdTonder";
|
|
313
|
-
errorLabel.textContent = state.isEmpty
|
|
269
|
+
errorLabel.textContent = state.isEmpty
|
|
270
|
+
? "El campo es requerido"
|
|
271
|
+
: "El campo es inválido";
|
|
314
272
|
tonderContainer?.appendChild(errorLabel);
|
|
315
273
|
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const elementsConfig = {
|
|
278
|
+
cardNumber: {
|
|
279
|
+
element: cardNumberElement,
|
|
280
|
+
container: `#${collectorIds.cardNumber}`,
|
|
281
|
+
},
|
|
282
|
+
cvv: {
|
|
283
|
+
element: cvvElement,
|
|
284
|
+
container: `#${collectorIds.cvv}`,
|
|
285
|
+
},
|
|
286
|
+
expiryMonth: {
|
|
287
|
+
element: expiryMonthElement,
|
|
288
|
+
container: `#${collectorIds.expirationMonth}`,
|
|
289
|
+
},
|
|
290
|
+
expiryYear: {
|
|
291
|
+
element: expiryYearElement,
|
|
292
|
+
container: `#${collectorIds.expirationYear}`,
|
|
293
|
+
},
|
|
294
|
+
cardHolderName: {
|
|
295
|
+
element: cardHolderNameElement,
|
|
296
|
+
container: `#${collectorIds.holderName}`,
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
await mountElements(elementsConfig);
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
container: collectContainer,
|
|
304
|
+
elements: {
|
|
305
|
+
cardHolderNameElement,
|
|
306
|
+
cardNumberElement,
|
|
307
|
+
cvvElement,
|
|
308
|
+
expiryMonthElement,
|
|
309
|
+
expiryYearElement,
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export async function initUpdateSkyflow(
|
|
315
|
+
skyflowId: string,
|
|
316
|
+
vaultId: string,
|
|
317
|
+
vaultUrl: string,
|
|
318
|
+
baseUrl: string,
|
|
319
|
+
signal: AbortSignal,
|
|
320
|
+
customStyles: any = {},
|
|
321
|
+
collectorIds: CollectorIds,
|
|
322
|
+
apiKey: string,
|
|
323
|
+
) {
|
|
324
|
+
const skyflow = await initializeSkyflow(
|
|
325
|
+
vaultId,
|
|
326
|
+
vaultUrl,
|
|
327
|
+
baseUrl,
|
|
328
|
+
apiKey,
|
|
329
|
+
signal,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
var collectStylesOptions: any =
|
|
333
|
+
Object.keys(customStyles).length === 0
|
|
334
|
+
? defaultStyles
|
|
335
|
+
: {
|
|
336
|
+
...customStyles,
|
|
337
|
+
labels: {
|
|
338
|
+
nameLabel: customStyles?.labels?.nameLabel && customStyles?.labels?.nameLabel !== "" ? customStyles?.labels?.nameLabel: defaultStyles.labels.nameLabel,
|
|
339
|
+
cardLabel: customStyles?.labels?.cardLabel && customStyles?.labels?.cardLabel !== "" ? customStyles?.labels?.cardLabel: defaultStyles.labels.cardLabel,
|
|
340
|
+
cvvLabel: customStyles?.labels?.cvvLabel && customStyles?.labels?.cvvLabel !== "" ? customStyles?.labels?.cvvLabel: defaultStyles.labels.cvvLabel,
|
|
341
|
+
expiryDateLabel: customStyles?.labels?.expiryDateLabel && customStyles?.labels?.expiryDateLabel !== "" ? customStyles?.labels?.expiryDateLabel: defaultStyles.labels.expiryDateLabel,
|
|
342
|
+
},
|
|
343
|
+
placeholders: {
|
|
344
|
+
namePlaceholder: customStyles?.placeholders?.namePlaceholder && customStyles?.placeholders?.namePlaceholder !== "" ? customStyles?.placeholders?.namePlaceholder: defaultStyles.placeholders.namePlaceholder,
|
|
345
|
+
cardPlaceholder: customStyles?.placeholders?.cardPlaceholder && customStyles?.placeholders?.cardPlaceholder !== "" ? customStyles?.placeholders?.cardPlaceholder: defaultStyles.placeholders.cardPlaceholder,
|
|
346
|
+
cvvPlaceholder: customStyles?.placeholders?.cvvPlaceholder && customStyles?.placeholders?.cvvPlaceholder !== "" ? customStyles?.placeholders?.cvvPlaceholder: defaultStyles.placeholders.cvvPlaceholder,
|
|
347
|
+
expiryMonthPlaceholder: customStyles?.placeholders?.expiryMonthPlaceholder && customStyles?.placeholders?.expiryMonthPlaceholder !== "" ? customStyles?.placeholders?.expiryMonthPlaceholder: defaultStyles.placeholders.expiryMonthPlaceholder,
|
|
348
|
+
expiryYearPlaceholder: customStyles?.placeholders?.expiryYearPlaceholder && customStyles?.placeholders?.expiryYearPlaceholder !== "" ? customStyles?.placeholders?.expiryYearPlaceholder: defaultStyles.placeholders.expiryYearPlaceholder,
|
|
349
|
+
},
|
|
350
|
+
};
|
|
316
351
|
|
|
352
|
+
// Create collect Container.
|
|
353
|
+
const collectContainer = skyflow.container(Skyflow.ContainerType.COLLECT);
|
|
354
|
+
const cvvElement: CollectElement | RevealElement | ComposableElement =
|
|
355
|
+
collectContainer.create({
|
|
356
|
+
table: "cards",
|
|
357
|
+
column: "cvv",
|
|
358
|
+
...collectStylesOptions,
|
|
359
|
+
label: collectStylesOptions.labels?.cvvLabel,
|
|
360
|
+
placeholder: collectStylesOptions.placeholders?.cvvPlaceholder,
|
|
361
|
+
type: Skyflow.ElementType.CVV,
|
|
362
|
+
validations: [regexMatchRule],
|
|
363
|
+
skyflowID: skyflowId,
|
|
317
364
|
});
|
|
318
365
|
|
|
319
|
-
|
|
366
|
+
if ("on" in cvvElement) {
|
|
367
|
+
cvvElement.on(Skyflow.EventName.CHANGE, (state: any) => {
|
|
368
|
+
let element = document.getElementById(`errorCvvIdTonder${skyflowId}`);
|
|
320
369
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
370
|
+
if (element && state.isValid && !state.isEmpty) {
|
|
371
|
+
element.remove();
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
cvvElement.on(Skyflow.EventName.BLUR, (state: any) => {
|
|
376
|
+
let tonderContainer = document.getElementById(
|
|
377
|
+
collectorIds.cvv + skyflowId,
|
|
378
|
+
);
|
|
379
|
+
let element = document.getElementById("errorCvvIdTonder" + skyflowId);
|
|
380
|
+
|
|
381
|
+
if (element) {
|
|
382
|
+
element.remove();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (!state.isValid) {
|
|
386
|
+
let errorLabel = document.createElement("div");
|
|
387
|
+
errorLabel.classList.add("error-custom-inputs-tonder");
|
|
388
|
+
errorLabel.id = "errorCvvIdTonder" + skyflowId;
|
|
389
|
+
errorLabel.textContent = state.isEmpty
|
|
390
|
+
? "El campo es requerido"
|
|
391
|
+
: "El campo es inválido";
|
|
392
|
+
tonderContainer?.appendChild(errorLabel);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
338
395
|
}
|
|
396
|
+
|
|
397
|
+
const elementsConfig = {
|
|
398
|
+
cvv: {
|
|
399
|
+
element: cvvElement,
|
|
400
|
+
container: `#${collectorIds.cvv}${skyflowId}`,
|
|
401
|
+
},
|
|
402
|
+
};
|
|
403
|
+
await mountElements(elementsConfig);
|
|
404
|
+
|
|
405
|
+
return {
|
|
406
|
+
container: collectContainer,
|
|
407
|
+
elements: {
|
|
408
|
+
cvvElement,
|
|
409
|
+
},
|
|
410
|
+
};
|
|
339
411
|
}
|
|
340
412
|
|
|
341
|
-
async function
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
413
|
+
async function initializeSkyflow(
|
|
414
|
+
vaultId: string,
|
|
415
|
+
vaultUrl: string,
|
|
416
|
+
baseUrl: string,
|
|
417
|
+
apiKey: string,
|
|
418
|
+
signal: AbortSignal,
|
|
347
419
|
) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
420
|
+
return Skyflow.init({
|
|
421
|
+
vaultID: vaultId,
|
|
422
|
+
vaultURL: vaultUrl,
|
|
423
|
+
getBearerToken: async () => {
|
|
424
|
+
// Pass the signal to the fetch call
|
|
425
|
+
const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
|
|
426
|
+
method: "GET",
|
|
427
|
+
headers: {
|
|
428
|
+
Authorization: `Token ${apiKey}`,
|
|
429
|
+
},
|
|
430
|
+
signal: signal,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
if (response.ok) {
|
|
434
|
+
const responseBody = await response.json();
|
|
435
|
+
return responseBody.token;
|
|
436
|
+
} else {
|
|
437
|
+
throw new Error("Failed to retrieve bearer token");
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
options: {
|
|
441
|
+
logLevel: Skyflow.LogLevel.ERROR,
|
|
442
|
+
env: Skyflow.Env.DEV,
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
async function mountElements(elementsConfig: {
|
|
448
|
+
[k: string]: { element: any; container: string };
|
|
449
|
+
}) {
|
|
450
|
+
if (typeof elementsConfig !== "object" || elementsConfig === null) {
|
|
451
|
+
throw new Error("Invalid configuration object");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
for (const [elementKey, { element, container }] of Object.entries(
|
|
455
|
+
elementsConfig,
|
|
456
|
+
)) {
|
|
457
|
+
if (element && container) {
|
|
458
|
+
element.mount(container);
|
|
459
|
+
} else {
|
|
460
|
+
console.warn(
|
|
461
|
+
`Skipping mount for '${elementKey}' due to missing element or container.`,
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
353
465
|
}
|
|
466
|
+
|
|
467
|
+
const regexEmpty = RegExp("^(?!s*$).+");
|
|
468
|
+
const regexMatchRule = {
|
|
469
|
+
type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
|
|
470
|
+
params: {
|
|
471
|
+
regex: regexEmpty,
|
|
472
|
+
error: "El campo es requerido",
|
|
473
|
+
},
|
|
474
|
+
};
|
package/src/helpers/styles.ts
CHANGED
|
@@ -46,15 +46,16 @@ export const defaultStyles: any = {
|
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
labels: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
nameLabel: 'Titular de la tarjeta',
|
|
50
|
+
cardLabel: 'Número de tarjeta',
|
|
51
|
+
cvvLabel: 'CVC/CVV',
|
|
52
|
+
expiryDateLabel: 'Fecha de expiración',
|
|
53
53
|
},
|
|
54
54
|
placeholders: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
namePlaceholder: 'Nombre como aparece en la tarjeta',
|
|
56
|
+
cardPlaceholder: '1234 1234 1234 1234',
|
|
57
|
+
cvvPlaceholder: '3-4 dígitos',
|
|
58
|
+
expiryMonthPlaceholder: 'MM',
|
|
59
|
+
expiryYearPlaceholder: 'AA'
|
|
59
60
|
}
|
|
60
61
|
}
|