tonder-web-sdk 1.11.1 → 1.11.12

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.11.1",
3
+ "version": "1.11.12",
4
4
  "description": "tonder sdk for integrations",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -17,7 +17,8 @@ import {
17
17
  getBrowserInfo,
18
18
  mapCards,
19
19
  showMessage,
20
- clearSpace
20
+ clearSpace,
21
+ injectMercadoPagoSecurity
21
22
  } from '../helpers/utils';
22
23
  import { initSkyflow } from '../helpers/skyflow'
23
24
  import { ThreeDSHandler } from './3dsHandler.js';
@@ -237,20 +238,29 @@ export class InlineCheckout {
237
238
  }
238
239
 
239
240
  async verify3dsTransaction () {
241
+ globalLoader.show()
240
242
  const result3ds = await this.process3ds.verifyTransactionStatus()
241
243
  const resultCheckout = await this.resumeCheckout(result3ds)
242
244
  this.process3ds.setPayload(resultCheckout)
243
- if (resultCheckout?.is_route_finished && resultCheckout?.provider === 'tonder') {
244
- return resultCheckout
245
- }
245
+ globalLoader.remove()
246
246
  return this.handle3dsRedirect(resultCheckout)
247
247
  }
248
248
 
249
+
249
250
  async resumeCheckout(response) {
250
- if (["Failed", "Declined", "Cancelled"].includes(response?.status)) {
251
+ // Stop the routing process if the transaction is either hard declined or successful
252
+ if (response?.decline?.error_type === "Hard") {
253
+ return response
254
+ }
255
+
256
+ if (["Success", "Authorized"].includes(response?.transaction_status)) {
257
+ return response;
258
+ }
259
+
260
+ if (response) {
251
261
  globalLoader.show()
252
262
  const routerItems = {
253
- checkout_id: response.checkout?.id,
263
+ checkout_id: response?.checkout?.id,
254
264
  };
255
265
  try {
256
266
  const routerResponse = await startCheckoutRouter(
@@ -260,12 +270,12 @@ export class InlineCheckout {
260
270
  );
261
271
  return routerResponse
262
272
  } catch (error) {
263
- throw error
273
+ // throw error
264
274
  } finally {
265
275
  globalLoader.remove()
266
276
  }
277
+ return response
267
278
  }
268
- return response
269
279
  }
270
280
 
271
281
  #mount(containerTonderCheckout) {
@@ -288,7 +298,7 @@ export class InlineCheckout {
288
298
  return await customerRegister(this.baseUrl, this.apiKeyTonder, customer, signal);
289
299
  }
290
300
 
291
- async #mountAPMs(){
301
+ async #mountAPMs() {
292
302
  try{
293
303
  const apms = await getCustomerAPMs(this.baseUrl, this.apiKeyTonder, "?status=active&page_size=10000");
294
304
  if(apms && apms['results'] && apms['results'].length > 0){
@@ -306,6 +316,7 @@ export class InlineCheckout {
306
316
  const {
307
317
  vault_id,
308
318
  vault_url,
319
+ mercado_pago
309
320
  } = await this.#fetchMerchantData();
310
321
  if (this.email && getCards) {
311
322
  const customerResponse = await this.getCustomer({ email: this.email });
@@ -319,7 +330,10 @@ export class InlineCheckout {
319
330
  }
320
331
  }
321
332
  }
322
-
333
+ if (!!mercado_pago && !!mercado_pago.active){
334
+ injectMercadoPagoSecurity()
335
+ }
336
+
323
337
  await this.#mountAPMs();
324
338
 
325
339
  this.collectContainer = await initSkyflow(
@@ -476,8 +490,10 @@ export class InlineCheckout {
476
490
  ...( selected_apm && Object.keys(selected_apm).length > 0
477
491
  ? {payment_method: selected_apm.payment_method}
478
492
  : {card: cardTokens}
479
- )
493
+ ),
494
+ ...(typeof MP_DEVICE_SESSION_ID !== "undefined" ? {mp_device_session_id: MP_DEVICE_SESSION_ID}:{})
480
495
  };
496
+
481
497
  const jsonResponseRouter = await startCheckoutRouter(
482
498
  this.baseUrl,
483
499
  this.apiKeyTonder,
@@ -386,3 +386,20 @@ export function buildErrorResponseFromCatch(e) {
386
386
  };
387
387
  }
388
388
 
389
+ export function injectMercadoPagoSecurity() {
390
+ try {
391
+ const script = document.createElement('script');
392
+ script.src = "https://www.mercadopago.com/v2/security.js";
393
+ script.setAttribute('view', '');
394
+ script.onload = () => {
395
+ console.log("Mercado Pago script loaded successfully.");
396
+ };
397
+ script.onerror = (error) => {
398
+ console.error("Error loading Mercado Pago script:", error);
399
+ };
400
+ document.head.appendChild(script);
401
+ } catch (error) {
402
+ console.error("Error attempting to inject Mercado Pago script:", error);
403
+ }
404
+ }
405
+