tonder-web-sdk 1.10.2 → 1.10.6
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/package.json +1 -1
- package/src/classes/3dsHandler.js +0 -12
- package/src/classes/globalLoader.js +29 -0
- package/src/classes/inlineCheckout.js +25 -42
- package/src/helpers/template.js +0 -6
- package/v1/bundle.min.js +1 -1
package/package.json
CHANGED
|
@@ -39,18 +39,6 @@ export class ThreeDSHandler {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
saveCheckoutId(checkoutId) {
|
|
43
|
-
localStorage.setItem('checkout_id', JSON.stringify(checkoutId))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
removeCheckoutId() {
|
|
47
|
-
localStorage.removeItem("checkout_id")
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
getCurrentCheckoutId() {
|
|
51
|
-
return JSON.parse(localStorage.getItem("checkout_id"));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
42
|
getUrlWithExpiration() {
|
|
55
43
|
const item = JSON.parse(localStorage.getItem("verify_transaction_status"))
|
|
56
44
|
if (!item) return
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { cardTemplateSkeleton } from '../helpers/template-skeleton.js'
|
|
2
|
+
|
|
3
|
+
class GlobalLoader {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.requestCount = 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
show() {
|
|
9
|
+
this.requestCount++;
|
|
10
|
+
const checkoutContainer = document.querySelector("#global-loader");
|
|
11
|
+
if (checkoutContainer) {
|
|
12
|
+
checkoutContainer.innerHTML = cardTemplateSkeleton;
|
|
13
|
+
checkoutContainer.style.display = 'block';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
remove() {
|
|
18
|
+
this.requestCount--;
|
|
19
|
+
if (this.requestCount <= 0) {
|
|
20
|
+
this.requestCount = 0;
|
|
21
|
+
const loader = document.querySelector('#global-loader');
|
|
22
|
+
if (loader) {
|
|
23
|
+
loader.style.display = 'none';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const globalLoader = new GlobalLoader();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { cardItemsTemplate, cardTemplate } from '../helpers/template.js'
|
|
2
|
-
import { cardTemplateSkeleton } from '../helpers/template-skeleton.js'
|
|
3
2
|
import {
|
|
4
3
|
getBusiness,
|
|
5
4
|
customerRegister,
|
|
@@ -19,6 +18,7 @@ import {
|
|
|
19
18
|
} from '../helpers/utils';
|
|
20
19
|
import { initSkyflow } from '../helpers/skyflow'
|
|
21
20
|
import { ThreeDSHandler } from './3dsHandler.js';
|
|
21
|
+
import { globalLoader } from './globalLoader.js';
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
export class InlineCheckout {
|
|
@@ -147,7 +147,6 @@ export class InlineCheckout {
|
|
|
147
147
|
this.#handleCard(data)
|
|
148
148
|
const response = await this.#checkout()
|
|
149
149
|
this.process3ds.setPayload(response)
|
|
150
|
-
this.process3ds.saveCheckoutId(response.checkout_id)
|
|
151
150
|
this.callBack(response);
|
|
152
151
|
const payload = await this.handle3dsRedirect(response)
|
|
153
152
|
if (payload) {
|
|
@@ -243,38 +242,29 @@ export class InlineCheckout {
|
|
|
243
242
|
|
|
244
243
|
async resumeCheckout(response) {
|
|
245
244
|
if (["Failed", "Declined", "Cancelled"].includes(response?.status)) {
|
|
245
|
+
globalLoader.show()
|
|
246
246
|
const routerItems = {
|
|
247
|
-
|
|
248
|
-
checkout_id: this.process3ds.getCurrentCheckoutId(),
|
|
247
|
+
checkout_id: response.checkout?.id,
|
|
249
248
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
249
|
+
try {
|
|
250
|
+
const routerResponse = await startCheckoutRouter(
|
|
251
|
+
this.baseUrl,
|
|
252
|
+
this.apiKeyTonder,
|
|
253
|
+
routerItems
|
|
254
|
+
);
|
|
255
|
+
return routerResponse
|
|
256
|
+
} catch (error) {
|
|
257
|
+
throw error
|
|
258
|
+
} finally {
|
|
259
|
+
globalLoader.remove()
|
|
260
|
+
}
|
|
256
261
|
}
|
|
257
262
|
return response
|
|
258
263
|
}
|
|
259
264
|
|
|
260
|
-
#addGlobalLoader() {
|
|
261
|
-
let checkoutContainer = document.querySelector("#global-loader");
|
|
262
|
-
if (checkoutContainer) {
|
|
263
|
-
checkoutContainer.innerHTML = cardTemplateSkeleton;
|
|
264
|
-
checkoutContainer.style.display = 'block';
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
#removeGlobalLoader() {
|
|
269
|
-
const loader = document.querySelector('#global-loader');
|
|
270
|
-
if (loader) {
|
|
271
|
-
loader.style.display = 'none';
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
265
|
#mount(containerTonderCheckout) {
|
|
276
266
|
containerTonderCheckout.innerHTML = cardTemplate;
|
|
277
|
-
|
|
267
|
+
globalLoader.show()
|
|
278
268
|
this.#mountTonder();
|
|
279
269
|
InlineCheckout.injected = true;
|
|
280
270
|
}
|
|
@@ -292,7 +282,7 @@ export class InlineCheckout {
|
|
|
292
282
|
return await customerRegister(this.baseUrl, this.apiKeyTonder, customer, signal);
|
|
293
283
|
}
|
|
294
284
|
|
|
295
|
-
async #mountTonder(getCards =
|
|
285
|
+
async #mountTonder(getCards = false) {
|
|
296
286
|
this.#mountPayButton()
|
|
297
287
|
try {
|
|
298
288
|
const {
|
|
@@ -304,18 +294,11 @@ export class InlineCheckout {
|
|
|
304
294
|
const customerResponse = await this.getCustomer({ email: this.email });
|
|
305
295
|
if ("auth_token" in customerResponse) {
|
|
306
296
|
const { auth_token } = customerResponse
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const cards = await getCustomerCards(this.baseUrl, auth_token);
|
|
313
|
-
saveCardCheckbox.style.display = '';
|
|
314
|
-
|
|
315
|
-
if ("cards" in cards) {
|
|
316
|
-
const cardsMapped = cards.cards.map(mapCards)
|
|
317
|
-
this.#loadCardsList(cardsMapped, auth_token)
|
|
318
|
-
}
|
|
297
|
+
const cards = await getCustomerCards(this.baseUrl, auth_token);
|
|
298
|
+
|
|
299
|
+
if ("cards" in cards) {
|
|
300
|
+
const cardsMapped = cards.cards.map(mapCards)
|
|
301
|
+
this.#loadCardsList(cardsMapped, auth_token)
|
|
319
302
|
}
|
|
320
303
|
}
|
|
321
304
|
}
|
|
@@ -330,11 +313,11 @@ export class InlineCheckout {
|
|
|
330
313
|
this.collectorIds
|
|
331
314
|
);
|
|
332
315
|
setTimeout(() => {
|
|
333
|
-
|
|
316
|
+
globalLoader.remove()
|
|
334
317
|
}, 800)
|
|
335
318
|
} catch (e) {
|
|
336
319
|
if (e && e.name !== 'AbortError') {
|
|
337
|
-
|
|
320
|
+
globalLoader.remove()
|
|
338
321
|
showError("No se pudieron cargar los datos del comercio.")
|
|
339
322
|
}
|
|
340
323
|
}
|
|
@@ -530,7 +513,7 @@ export class InlineCheckout {
|
|
|
530
513
|
}
|
|
531
514
|
if (radio.id === "new") {
|
|
532
515
|
if (this.radioChecked !== radio.id) {
|
|
533
|
-
|
|
516
|
+
globalLoader.show()
|
|
534
517
|
this.#mountTonder(false);
|
|
535
518
|
InlineCheckout.injected = true;
|
|
536
519
|
}
|
package/src/helpers/template.js
CHANGED
|
@@ -19,12 +19,6 @@ export const cardTemplate = `
|
|
|
19
19
|
<div id="collectExpirationYear" class="expiration-year"></div>
|
|
20
20
|
<div id="collectCvv" class="empty-div"></div>
|
|
21
21
|
</div>
|
|
22
|
-
<div class="checkbox" id="save-card-container">
|
|
23
|
-
<input id="save-checkout-card" type="checkbox">
|
|
24
|
-
<label for="save-checkout-card">
|
|
25
|
-
Guardar tarjeta para futuros pagos
|
|
26
|
-
</label>
|
|
27
|
-
</div>
|
|
28
22
|
<div id="msgError"></div>
|
|
29
23
|
<div id="msgNotification"></div>
|
|
30
24
|
</div>
|