tonder-web-sdk 1.9.2-beta.5 → 1.9.3-beta.1

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.9.2-beta.5",
3
+ "version": "1.9.3-beta.1",
4
4
  "description": "tonder sdk for integrations",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -24,6 +24,7 @@ import { ThreeDSHandler } from './3dsHandler.js';
24
24
  export class InlineCheckout {
25
25
  static injected = false;
26
26
  static cardsInjected = false
27
+ deletingCards = [];
27
28
  customer = {}
28
29
  items = []
29
30
  baseUrl = null
@@ -64,6 +65,7 @@ export class InlineCheckout {
64
65
  this.baseUrl = this.#getBaseUrl()
65
66
 
66
67
  this.abortController = new AbortController()
68
+ this.abortRefreshCardsController = new AbortController()
67
69
  this.process3ds = new ThreeDSHandler(
68
70
  { apiKey: apiKey, baseUrl: this.baseUrl, successUrl: successUrl }
69
71
  )
@@ -516,16 +518,29 @@ export class InlineCheckout {
516
518
  if(cardClicked) {
517
519
  cardClicked.style.display = "none"
518
520
  }
519
- await deleteCustomerCard(this.baseUrl, customerToken, skyflow_id)
520
- this.cardsInjected = false
521
- const cards = await getCustomerCards(this.baseUrl, customerToken)
522
- if("cards" in cards) {
523
- const cardsMapped = cards.cards.map(mapCards)
524
- this.#loadCardsList(cardsMapped, customerToken)
521
+ try{
522
+ this.deletingCards.push(skyflow_id);
523
+ if (this.abortRefreshCardsController) {
524
+ this.abortRefreshCardsController.abort();
525
+ this.abortRefreshCardsController = new AbortController();
525
526
  }
527
+ await deleteCustomerCard(this.baseUrl, customerToken, skyflow_id)
528
+ }catch{
529
+ } finally {
530
+ this.deletingCards = this.deletingCards.filter(id => id !== skyflow_id);
531
+ this.#refreshCardOnDelete(customerToken)
532
+ }
533
+ }
534
+ }
535
+ async #refreshCardOnDelete(customerToken){
536
+ if(this.deletingCards.length > 0) return;
537
+ this.cardsInjected = false
538
+ const cards = await getCustomerCards(this.baseUrl, customerToken, "", this.abortRefreshCardsController.signal)
539
+ if("cards" in cards) {
540
+ const cardsMapped = cards.cards.map(mapCards)
541
+ this.#loadCardsList(cardsMapped, customerToken)
526
542
  }
527
543
  }
528
-
529
544
  #unmountForm () {
530
545
  InlineCheckout.injected = false
531
546
  if(this.collectContainer) {
package/src/data/api.js CHANGED
@@ -145,7 +145,7 @@ export async function deleteCustomerCard(baseUrlTonder, customerToken, skyflowId
145
145
  headers: {
146
146
  'Authorization': `Token ${customerToken}`,
147
147
  'Content-Type': 'application/json'
148
- },
148
+ }
149
149
  });
150
150
 
151
151
  if (response.ok) return true;
@@ -154,7 +154,7 @@ export async function deleteCustomerCard(baseUrlTonder, customerToken, skyflowId
154
154
  throw buildErrorResponseFromCatch(error);
155
155
  }
156
156
  }
157
- export async function getCustomerCards(baseUrlTonder, customerToken, query = "") {
157
+ export async function getCustomerCards(baseUrlTonder, customerToken, query = "", signal) {
158
158
  try {
159
159
  const response = await fetch(`${baseUrlTonder}/api/v1/cards/${query}`, {
160
160
  method: 'GET',
@@ -162,6 +162,7 @@ export async function getCustomerCards(baseUrlTonder, customerToken, query = "")
162
162
  'Authorization': `Token ${customerToken}`,
163
163
  'Content-Type': 'application/json'
164
164
  },
165
+ signal
165
166
  });
166
167
 
167
168
  if (response.ok) return await response.json();
@@ -209,7 +209,7 @@ function updateErrorLabel(element, errorStyles, color = "" ){
209
209
  errorTextStyles: {
210
210
  ...errorStyles,
211
211
  base: {
212
- ...errorStyles.base,
212
+ ...(errorStyles.base && {...errorStyles.base}),
213
213
  ...(color != "" && {color})
214
214
  }
215
215
  }