tonder-web-sdk 1.11.0-beta.1 → 1.11.0-beta.3

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/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
4
+ </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tonder-web-sdk",
3
- "version": "1.11.0-beta.1",
3
+ "version": "1.11.0-beta.3",
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();
@@ -21,6 +21,7 @@ import {
21
21
  } from '../helpers/utils';
22
22
  import { initSkyflow } from '../helpers/skyflow'
23
23
  import { ThreeDSHandler } from './3dsHandler.js';
24
+ import { globalLoader } from './globalLoader.js';
24
25
 
25
26
 
26
27
  export class InlineCheckout {
@@ -152,7 +153,6 @@ export class InlineCheckout {
152
153
  this.#handleCard(data)
153
154
  const response = await this.#checkout()
154
155
  this.process3ds.setPayload(response)
155
- this.process3ds.saveCheckoutId(response.checkout_id)
156
156
  this.callBack(response);
157
157
  const payload = await this.handle3dsRedirect(response)
158
158
  if (payload) {
@@ -248,38 +248,24 @@ export class InlineCheckout {
248
248
 
249
249
  async resumeCheckout(response) {
250
250
  if (["Failed", "Declined", "Cancelled"].includes(response?.status)) {
251
+ globalLoader.show()
251
252
  const routerItems = {
252
- // TODO: Replace this with reponse.checkout_id
253
- checkout_id: this.process3ds.getCurrentCheckoutId(),
253
+ checkout_id: response.checkout?.id,
254
254
  };
255
255
  const routerResponse = await startCheckoutRouter(
256
256
  this.baseUrl,
257
257
  this.apiKeyTonder,
258
258
  routerItems
259
259
  );
260
+ globalLoader.remove()
260
261
  return routerResponse
261
262
  }
262
263
  return response
263
264
  }
264
265
 
265
- #addGlobalLoader() {
266
- let checkoutContainer = document.querySelector("#global-loader");
267
- if (checkoutContainer) {
268
- checkoutContainer.innerHTML = cardTemplateSkeleton;
269
- checkoutContainer.style.display = 'block';
270
- }
271
- }
272
-
273
- #removeGlobalLoader() {
274
- const loader = document.querySelector('#global-loader');
275
- if (loader) {
276
- loader.style.display = 'none';
277
- }
278
- }
279
-
280
266
  #mount(containerTonderCheckout) {
281
267
  containerTonderCheckout.innerHTML = cardTemplate({renderPaymentButton: this.renderPaymentButton, customStyles: this.customStyles});
282
- this.#addGlobalLoader();
268
+ globalLoader.show()
283
269
  this.#mountTonder();
284
270
  InlineCheckout.injected = true;
285
271
  }
@@ -308,7 +294,8 @@ export class InlineCheckout {
308
294
  console.warn("Error getting APMS")
309
295
  }
310
296
  }
311
- async #mountTonder(getCards = true) {
297
+
298
+ async #mountTonder(getCards = false) {
312
299
  this.#mountPayButton()
313
300
  try {
314
301
  const {
@@ -319,23 +306,16 @@ export class InlineCheckout {
319
306
  const customerResponse = await this.getCustomer({ email: this.email });
320
307
  if ("auth_token" in customerResponse) {
321
308
  const { auth_token } = customerResponse
322
- const saveCardCheckbox = document.getElementById('save-card-container');
323
-
324
- saveCardCheckbox.style.display = 'none';
325
- if (this.mode !== 'production') {
326
- const cards = await getCustomerCards(this.baseUrl, auth_token);
327
- saveCardCheckbox.style.display = '';
309
+ const cards = await getCustomerCards(this.baseUrl, auth_token);
328
310
 
329
- if ("cards" in cards) {
330
- const cardsMapped = cards.cards.map(mapCards)
331
- this.#loadCardsList(cardsMapped, auth_token)
332
- }
311
+ if ("cards" in cards) {
312
+ const cardsMapped = cards.cards.map(mapCards)
313
+ this.#loadCardsList(cardsMapped, auth_token)
333
314
  }
334
-
335
-
336
315
  }
337
316
  }
338
- this.#mountAPMs();
317
+
318
+ await this.#mountAPMs();
339
319
 
340
320
  this.collectContainer = await initSkyflow(
341
321
  vault_id,
@@ -347,11 +327,11 @@ export class InlineCheckout {
347
327
  this.collectorIds
348
328
  );
349
329
  setTimeout(() => {
350
- this.#removeGlobalLoader()
330
+ globalLoader.remove()
351
331
  }, 800)
352
332
  } catch (e) {
353
333
  if (e && e.name !== 'AbortError') {
354
- this.#removeGlobalLoader()
334
+ globalLoader.remove()
355
335
  showError("No se pudieron cargar los datos del comercio.")
356
336
  }
357
337
  }
@@ -488,7 +468,7 @@ export class InlineCheckout {
488
468
  metadata: this.metadata,
489
469
  browser_info: getBrowserInfo(),
490
470
  currency: this.currency,
491
- ...( !!selected_apm
471
+ ...( !!selected_apm
492
472
  ? {payment_method: selected_apm.payment_method}
493
473
  : {card: cardTokens}
494
474
  )
@@ -537,7 +517,7 @@ export class InlineCheckout {
537
517
  .filter((apm) =>
538
518
  clearSpace(apm.category.toLowerCase()) !== 'cards' && apm.status.toLowerCase() === 'active')
539
519
  .sort((a, b) => a.priority - b.priority);
540
-
520
+
541
521
  queryElement.innerHTML = apmItemsTemplate(filteredAndSortedApms);
542
522
  clearInterval(injectInterval);
543
523
  this.#mountRadioButtons();
@@ -545,7 +525,7 @@ export class InlineCheckout {
545
525
  }
546
526
  }, 500);
547
527
  }
548
-
528
+
549
529
  #mountRadioButtons(token = '') {
550
530
  const radioButtons = document.getElementsByName(`card_selected`);
551
531
  for (const radio of radioButtons) {
@@ -571,7 +551,7 @@ export class InlineCheckout {
571
551
  }
572
552
  if (radio.id === "new") {
573
553
  if (this.radioChecked !== radio.id) {
574
- this.#addGlobalLoader()
554
+ globalLoader.show()
575
555
  this.#mountTonder(false);
576
556
  InlineCheckout.injected = true;
577
557
  }
@@ -19,12 +19,6 @@ export const cardTemplate = (data) => `
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 pagos futuros
26
- </label>
27
- </div>
28
22
  <div id="msgError"></div>
29
23
  <div id="msgNotification"></div>
30
24
  </div>
@@ -186,6 +180,8 @@ export const cardTemplate = (data) => `
186
180
  flex-direction: column;
187
181
  padding: ;
188
182
  gap: 33% 20px;
183
+ max-height: 300px;
184
+ overflow-y: auto;
189
185
  }
190
186
  .pay-new-card {
191
187
  display: flex;
@@ -485,14 +481,18 @@ export const cardItemsTemplate = (cards) => {
485
481
  }
486
482
 
487
483
  export const apmItemsTemplate = (apms) => {
488
-
484
+
489
485
  const apmItemsHTML = apms.reduce((total, apm) => {
490
486
  const apm_data = getAPMType(apm.payment_method);
491
487
  return `${total}
492
488
  <div class="apm-item" id="card_container-${apm.pk}">
493
489
  <input id="${apm.pk}" class="card_selected" name="card_selected" type="radio"/>
494
490
  <label class="apm-item-label" for="${apm.pk}">
495
- <img class="apm-image" src="${apm_data.icon}" />
491
+
492
+ <div class="apm-image">
493
+ <div class="apm-image-border"></div>
494
+ <img src="${apm_data.icon}" />
495
+ </div>
496
496
  <div class="apm-name">${apm_data.label}</div>
497
497
  </label>
498
498
  </div>`
@@ -528,13 +528,26 @@ export const apmItemsTemplate = (apms) => {
528
528
  .apm-item .apm-name {
529
529
  font-size: 16px;
530
530
  }
531
-
532
531
  .apm-image {
532
+ width: 30px;
533
+ height: 30px;
534
+ position: relative;
535
+ display: flex;
536
+ justify-content: center;
537
+ align-items: center;
538
+ }
539
+ .apm-image img {
533
540
  width: auto;
534
541
  height: 30px;
535
- text-align: left;
536
- border: 1px solid #e2e8f0;
537
- border-radius: 8px;
542
+ }
543
+ .apm-image-border{
544
+ position: absolute;
545
+ border: 1px solid #bababa36;
546
+ border-radius: 4px;
547
+ pointer-events: none;
548
+ box-sizing: border-box;
549
+ width: 100%;
550
+ height: 97%;
538
551
  }
539
552
 
540
553
  .card_selected {
package/src/index-dev.js CHANGED
@@ -104,7 +104,7 @@ const successUrl = "http://127.0.0.1:8080/success"
104
104
  // const apiKey = "8365683bdc33dd6d50fe2397188d79f1a6765852";
105
105
 
106
106
  const inlineCheckout = new InlineCheckout({
107
- mode: 'development',
107
+ mode: 'stage',
108
108
  apiKey,
109
109
  returnUrl,
110
110
  successUrl,