tonder-web-sdk 1.10.3 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tonder-web-sdk",
3
- "version": "1.10.3",
3
+ "version": "1.10.6",
4
4
  "description": "tonder sdk for integrations",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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
- // TODO: Replace this with reponse.checkout_id
248
- checkout_id: this.process3ds.getCurrentCheckoutId(),
247
+ checkout_id: response.checkout?.id,
249
248
  };
250
- const routerResponse = await startCheckoutRouter(
251
- this.baseUrl,
252
- this.apiKeyTonder,
253
- routerItems
254
- );
255
- return routerResponse
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
- this.#addGlobalLoader();
267
+ globalLoader.show()
278
268
  this.#mountTonder();
279
269
  InlineCheckout.injected = true;
280
270
  }
@@ -323,11 +313,11 @@ export class InlineCheckout {
323
313
  this.collectorIds
324
314
  );
325
315
  setTimeout(() => {
326
- this.#removeGlobalLoader()
316
+ globalLoader.remove()
327
317
  }, 800)
328
318
  } catch (e) {
329
319
  if (e && e.name !== 'AbortError') {
330
- this.#removeGlobalLoader()
320
+ globalLoader.remove()
331
321
  showError("No se pudieron cargar los datos del comercio.")
332
322
  }
333
323
  }
@@ -523,7 +513,7 @@ export class InlineCheckout {
523
513
  }
524
514
  if (radio.id === "new") {
525
515
  if (this.radioChecked !== radio.id) {
526
- this.#addGlobalLoader()
516
+ globalLoader.show()
527
517
  this.#mountTonder(false);
528
518
  InlineCheckout.injected = true;
529
519
  }