@tonder.io/ionic-lite-sdk 0.0.35-beta.7 → 0.0.36-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.
Files changed (85) hide show
  1. package/.gitlab-ci.yml +28 -28
  2. package/README.md +221 -202
  3. package/dist/classes/errorResponse.d.ts +1 -1
  4. package/dist/classes/liteCheckout.d.ts +32 -56
  5. package/dist/data/api.d.ts +1 -1
  6. package/dist/helpers/utils.d.ts +4 -8
  7. package/dist/index.d.ts +1 -2
  8. package/dist/index.js +1 -1
  9. package/dist/types/commons.d.ts +0 -37
  10. package/dist/types/requests.d.ts +3 -12
  11. package/dist/types/responses.d.ts +3 -0
  12. package/jest.config.ts +14 -14
  13. package/package.json +38 -38
  14. package/rollup.config.js +16 -16
  15. package/src/classes/3dsHandler.ts +237 -237
  16. package/src/classes/errorResponse.ts +16 -16
  17. package/src/classes/liteCheckout.ts +575 -598
  18. package/src/data/api.ts +20 -20
  19. package/src/helpers/constants.ts +63 -63
  20. package/src/helpers/mercadopago.ts +15 -15
  21. package/src/helpers/utils.ts +320 -120
  22. package/src/index.ts +4 -10
  23. package/src/types/commons.ts +83 -125
  24. package/src/types/requests.ts +105 -114
  25. package/src/types/responses.ts +193 -189
  26. package/src/types/skyflow.ts +17 -17
  27. package/tests/classes/liteCheckout.test.ts +57 -57
  28. package/tests/methods/createOrder.test.ts +142 -142
  29. package/tests/methods/createPayment.test.ts +122 -122
  30. package/tests/methods/customerRegister.test.ts +119 -119
  31. package/tests/methods/getBusiness.test.ts +115 -115
  32. package/tests/methods/getCustomerCards.test.ts +119 -113
  33. package/tests/methods/getOpenpayDeviceSessionID.test.ts +95 -0
  34. package/tests/methods/getSkyflowToken.test.ts +155 -0
  35. package/tests/methods/getVaultToken.test.ts +107 -0
  36. package/tests/methods/registerCustomerCard.test.ts +117 -117
  37. package/tests/methods/startCheckoutRouter.test.ts +119 -119
  38. package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
  39. package/tests/utils/defaultMock.ts +20 -21
  40. package/tests/utils/mockClasses.ts +656 -659
  41. package/tsconfig.json +18 -18
  42. package/.idea/aws.xml +0 -17
  43. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  44. package/.idea/prettier.xml +0 -6
  45. package/.idea/vcs.xml +0 -6
  46. package/.idea/workspace.xml +0 -132
  47. package/dist/classes/BaseInlineCheckout.d.ts +0 -45
  48. package/dist/data/businessApi.d.ts +0 -2
  49. package/dist/data/cardApi.d.ts +0 -4
  50. package/dist/data/checkoutApi.d.ts +0 -4
  51. package/dist/data/customerApi.d.ts +0 -2
  52. package/dist/data/openPayApi.d.ts +0 -1
  53. package/dist/data/paymentMethodApi.d.ts +0 -5
  54. package/dist/data/skyflowApi.d.ts +0 -1
  55. package/dist/helpers/skyflow.d.ts +0 -3
  56. package/dist/helpers/validations.d.ts +0 -6
  57. package/dist/shared/catalog/paymentMethodsCatalog.d.ts +0 -1
  58. package/dist/shared/constants/messages.d.ts +0 -11
  59. package/dist/shared/constants/paymentMethodAPM.d.ts +0 -62
  60. package/dist/shared/constants/tonderUrl.d.ts +0 -7
  61. package/dist/types/card.d.ts +0 -29
  62. package/dist/types/checkout.d.ts +0 -103
  63. package/dist/types/customer.d.ts +0 -12
  64. package/dist/types/paymentMethod.d.ts +0 -22
  65. package/src/classes/BaseInlineCheckout.ts +0 -356
  66. package/src/data/businessApi.ts +0 -18
  67. package/src/data/cardApi.ts +0 -89
  68. package/src/data/checkoutApi.ts +0 -87
  69. package/src/data/customerApi.ts +0 -31
  70. package/src/data/openPayApi.ts +0 -12
  71. package/src/data/paymentMethodApi.ts +0 -37
  72. package/src/data/skyflowApi.ts +0 -20
  73. package/src/helpers/skyflow.ts +0 -91
  74. package/src/helpers/validations.ts +0 -55
  75. package/src/shared/catalog/paymentMethodsCatalog.ts +0 -248
  76. package/src/shared/constants/messages.ts +0 -11
  77. package/src/shared/constants/paymentMethodAPM.ts +0 -63
  78. package/src/shared/constants/tonderUrl.ts +0 -8
  79. package/src/types/card.ts +0 -34
  80. package/src/types/checkout.ts +0 -118
  81. package/src/types/customer.ts +0 -12
  82. package/src/types/index.d.ts +0 -10
  83. package/src/types/liteInlineCheckout.d.ts +0 -191
  84. package/src/types/paymentMethod.ts +0 -24
  85. package/src/types/validations.d.ts +0 -11
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import t from"skyflow-js";function e(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{d(o.next(t))}catch(t){i(t)}}function a(t){try{d(o.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}d((o=o.apply(t,e||[])).next())}))}function n(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function o(t,n,o){return e(this,void 0,void 0,(function*(){const e=yield fetch(`${t}/api/v1/payments/business/${n}`,{headers:{Authorization:`Token ${n}`},signal:o});return yield e.json()}))}"function"==typeof SuppressedError&&SuppressedError;class r{constructor({code:t,body:e,name:n,message:o,stack:r}){this.code=t,this.body=e,this.name=n,this.message=o,this.stack=r}}const i=()=>({javascript_enabled:!0,time_zone:(new Date).getTimezoneOffset(),language:navigator.language||"en-US",color_depth:window.screen?window.screen.colorDepth:null,screen_width:window.screen?window.screen.width*window.devicePixelRatio||window.screen.width:null,screen_height:window.screen?window.screen.height*window.devicePixelRatio||window.screen.height:null,user_agent:navigator.userAgent}),s=t=>{var e;return t&&"business"in t?null===(e=null==t?void 0:t.business)||void 0===e?void 0:e.pk:""},a=t=>new r({code:(null==t?void 0:t.status)?t.status:t.code,body:null==t?void 0:t.body,name:t?"string"==typeof t?"catch":t.name:"Error",message:t?"string"==typeof t?t:t.message:"Error",stack:"string"==typeof t?void 0:t.stack}),d=(t,n=void 0)=>e(void 0,void 0,void 0,(function*(){let e,o,i="Error";t&&"json"in t&&(e=yield null==t?void 0:t.json()),t&&"status"in t&&(o=t.status.toString()),!e&&t&&"text"in t&&(i=yield t.text()),(null==e?void 0:e.detail)&&(i=e.detail);return new r({code:o,body:e,name:o,message:i,stack:n})}));function l(t,e){var n,o;let r=200;try{r=Number((null==e?void 0:e.code)||200)}catch(t){}const i={status:"error",code:r,message:"",detail:(null===(n=null==e?void 0:e.body)||void 0===n?void 0:n.detail)||(null===(o=null==e?void 0:e.body)||void 0===o?void 0:o.error)||e.body||"Ocurrio un error inesperado."};return Object.assign(Object.assign({},i),t)}class c{constructor({payload:t=null,apiKey:e,baseUrl:n}){this.localStorageKey="verify_transaction_status_url",this.setPayload=t=>{this.payload=t},this.baseUrl=n,this.apiKey=e,this.payload=t}setStorageItem(t){return localStorage.setItem(this.localStorageKey,JSON.stringify(t))}getStorageItem(){return localStorage.getItem(this.localStorageKey)}removeStorageItem(){return localStorage.removeItem(this.localStorageKey)}saveVerifyTransactionUrl(){var t,e,n,o,r,i;const s=null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===n?void 0:n.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const t=null===(i=null===(r=null===(o=this.payload)||void 0===o?void 0:o.next_action)||void 0===r?void 0:r.iframe_resources)||void 0===i?void 0:i.verify_transaction_status_url;t?this.saveUrlWithExpiration(t):console.log("No verify_transaction_status_url found")}}saveUrlWithExpiration(t){try{const e={url:t,expires:(new Date).getTime()+12e5};this.setStorageItem(e)}catch(t){console.log("error: ",t)}}getUrlWithExpiration(){const t=this.getStorageItem();if(t){const e=JSON.parse(t);if(!e)return;return(new Date).getTime()>e.expires?(this.removeVerifyTransactionUrl(),null):e.url}return null}removeVerifyTransactionUrl(){return this.removeStorageItem()}getVerifyTransactionUrl(){return this.getStorageItem()}loadIframe(){var t,e,n;if(null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.iframe_resources)||void 0===n?void 0:n.iframe)return new Promise(((t,e)=>{var n,o,r;const i=null===(r=null===(o=null===(n=this.payload)||void 0===n?void 0:n.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===r?void 0:r.iframe;if(i){this.saveVerifyTransactionUrl();const n=document.createElement("div");n.innerHTML=i,document.body.appendChild(n);const o=document.createElement("script");o.textContent='document.getElementById("tdsMmethodForm").submit();',n.appendChild(o);const r=document.getElementById("tdsMmethodTgtFrame");r?r.onload=()=>t(!0):(console.log("No redirection found"),e(!1))}else console.log("No redirection found"),e(!1)}))}getRedirectUrl(){var t,e,n;return null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===n?void 0:n.url}redirectToChallenge(){const t=this.getRedirectUrl();t?(this.saveVerifyTransactionUrl(),window.location=t):console.log("No redirection found")}getURLParameters(){const t={},e=new URLSearchParams(window.location.search);for(const[n,o]of e)t[n]=o;return t}handleSuccessTransaction(t){return this.removeVerifyTransactionUrl(),console.log("Transacción autorizada."),t}handleDeclinedTransaction(t){return this.removeVerifyTransactionUrl(),t}handle3dsChallenge(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("form");e.name="frm",e.method="POST",e.action=t.redirect_post_url;const n=document.createElement("input");n.type="hidden",n.name=t.creq,n.value=t.creq,e.appendChild(n);const o=document.createElement("input");o.type="hidden",o.name=t.term_url,o.value=t.TermUrl,e.appendChild(o),document.body.appendChild(e),e.submit(),yield this.verifyTransactionStatus()}))}handleTransactionResponse(t){return e(this,void 0,void 0,(function*(){const e=yield t.json();return"Pending"===e.status&&e.redirect_post_url?yield this.handle3dsChallenge(e):["Success","Authorized"].includes(e.status)?this.handleSuccessTransaction(e):(this.handleDeclinedTransaction(t),e)}))}verifyTransactionStatus(){return e(this,void 0,void 0,(function*(){const t=this.getUrlWithExpiration();if(t){const e=`${this.baseUrl}${t}`;try{const t=yield fetch(e,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`}});return 200!==t.status?(console.error("La verificación de la transacción falló."),this.removeVerifyTransactionUrl(),t):yield this.handleTransactionResponse(t)}catch(t){console.error("Error al verificar la transacción:",t),this.removeVerifyTransactionUrl()}}else console.log("No verify_transaction_status_url found")}))}}const u=Object.freeze({production:"https://app.tonder.io",sandbox:"https://sandbox.tonder.io",stage:"https://stage.tonder.io",development:"http://localhost:8000"});function h(t,n,o){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/checkout-router/`,r=o,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${n}`},body:JSON.stringify(Object.assign(Object.assign({},r),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}))});if(i.status>=200&&i.status<=299)return yield i.json();{const t=yield i.json(),e=new Error("Failed to start checkout router");throw e.details=t,e}}catch(t){throw t}}))}function p(t,n,o=!0,r=null){return e(this,void 0,void 0,(function*(){let e=yield window.OpenPay;return e.setId(t),e.setApiKey(n),e.setSandboxMode(o),yield e.deviceData.setup({signal:r})}))}var m,y,f,g,v,A,_,b;class E{constructor({mode:t="stage",apiKey:e,apiKeyTonder:n,returnUrl:o,callBack:r=(()=>{})}){m.add(this),this.baseUrl="",this.cartTotal="0",this.metadata={},this.card={},this.currency="",y.set(this,void 0),this.apiKeyTonder=e||n||"",this.returnUrl=o,this.callBack=r,this.mode=t,this.baseUrl=u[this.mode]||u.stage,this.abortController=new AbortController,this.process3ds=new c({apiKey:e,baseUrl:this.baseUrl})}configureCheckout(t){"customer"in t&&n(this,m,"m",f).call(this,t.customer)}verify3dsTransaction(){return e(this,void 0,void 0,(function*(){const t=yield this.process3ds.verifyTransactionStatus(),e=yield n(this,m,"m",b).call(this,t);return this.process3ds.setPayload(e),this._handle3dsRedirect(e)}))}payment(t){return new Promise(((o,r)=>e(this,void 0,void 0,(function*(){var e,i;try{n(this,m,"m",f).call(this,t.customer),this._setCartTotal(null===(e=t.cart)||void 0===e?void 0:e.total),n(this,m,"m",g).call(this,null===(i=t.cart)||void 0===i?void 0:i.items),n(this,m,"m",v).call(this,t),n(this,m,"m",A).call(this,t),n(this,m,"m",_).call(this,t);const r=yield this._checkout(t);this.process3ds.setPayload(r),this.callBack&&this.callBack(r);(yield this._handle3dsRedirect(r))&&o(r)}catch(t){r(t)}}))))}_initializeCheckout(){return e(this,void 0,void 0,(function*(){const t=yield this._fetchMerchantData();t&&t.mercado_pago&&t.mercado_pago.active&&function(){try{const t=document.createElement("script");t.src="https://www.mercadopago.com/v2/security.js",t.setAttribute("view",""),t.onload=()=>{console.log("Mercado Pago script loaded successfully.")},t.onerror=t=>{console.error("Error loading Mercado Pago script:",t)},document.head.appendChild(t)}catch(t){console.error("Error attempting to inject Mercado Pago script:",t)}}()}))}_checkout(t){return e(this,void 0,void 0,(function*(){throw new Error("The #checkout method should be implement in child classes.")}))}_setCartTotal(t){throw new Error("The #setCartTotal method should be implement in child classes.")}_getCustomer(t=null){return e(this,void 0,void 0,(function*(){return n(this,y,"f")||function(t,e,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===o?r.call(t,n):r?r.value=n:e.set(t,n)}(this,y,yield function(t,n,o,r=null){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/customer/`,i={email:o.email,first_name:null==o?void 0:o.firstName,last_name:null==o?void 0:o.lastName,phone:null==o?void 0:o.phone},s=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${n}`},signal:r,body:JSON.stringify(i)});if(201===s.status)return yield s.json();throw new Error(`Error: ${s.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,this.customer,t),"f"),n(this,y,"f")}))}_handleCheckout({card:t,payment_method:n,customer:o,isSandbox:r}){return e(this,void 0,void 0,(function*(){const{openpay_keys:s,reference:a,business:d}=this.merchantData,l=Number(this.cartTotal);try{let c;!c&&s.merchant_id&&s.public_key&&(c=yield p(s.merchant_id,s.public_key,r,this.abortController.signal));const{id:u,auth_token:m}=o,y={business:this.apiKeyTonder,client:m,billing_address_id:null,shipping_address_id:null,amount:l,status:"A",reference:a,is_oneclick:!0,items:this.cartItems},f=yield function(t,n,o){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/orders/`,r=o,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${n}`},body:JSON.stringify(r)});if(201===i.status)return yield i.json();throw new Error(`Error: ${i.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,y),g=(new Date).toISOString(),v={business_pk:d.pk,client_id:u,amount:l,date:g,order_id:f.id},A=yield function(t,n,o){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/business/${o.business_pk}/payments/`,r=o,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${n}`},body:JSON.stringify(r)});if(i.status>=200&&i.status<=299)return yield i.json();throw new Error(`Error: ${i.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,v),_=Object.assign({name:this.firstName||"",last_name:this.lastName||"",email_client:this.email,phone_number:this.phone,return_url:this.returnUrl,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:l,title_ship:"shipping",description:"transaction",device_session_id:c||null,token_id:"",order_id:f.id,business_id:d.pk,payment_id:A.pk,source:"sdk",metadata:this.metadata,browser_info:i(),currency:this.currency},n?{payment_method:n}:{card:t}),b=yield h(this.baseUrl,this.apiKeyTonder,_);return b||!1}catch(t){throw console.log(t),t}}))}_fetchMerchantData(){return e(this,void 0,void 0,(function*(){try{return this.merchantData||(this.merchantData=yield o(this.baseUrl,this.apiKeyTonder,this.abortController.signal)),this.merchantData}catch(t){return this.merchantData}}))}_handle3dsRedirect(t){var n,o;return e(this,void 0,void 0,(function*(){if(t&&"next_action"in t?null===(o=null===(n=null==t?void 0:t.next_action)||void 0===n?void 0:n.iframe_resources)||void 0===o?void 0:o.iframe:null)this.process3ds.loadIframe().then((()=>{this.process3ds.verifyTransactionStatus()})).catch((t=>{console.log("Error loading iframe:",t)}));else{if(!this.process3ds.getRedirectUrl())return t;this.process3ds.redirectToChallenge()}}))}}y=new WeakMap,m=new WeakSet,f=function(t){t&&(this.firstName=null==t?void 0:t.firstName,this.lastName=null==t?void 0:t.lastName,this.country=null==t?void 0:t.country,this.address=null==t?void 0:t.street,this.city=null==t?void 0:t.city,this.state=null==t?void 0:t.state,this.postCode=null==t?void 0:t.postCode,this.email=null==t?void 0:t.email,this.phone=null==t?void 0:t.phone,this.customer=t)},g=function(t){this.cartItems=t},v=function(t){this.metadata=null==t?void 0:t.metadata},A=function(t){this.currency=null==t?void 0:t.currency},_=function(t){this.card=null==t?void 0:t.card},b=function(t){var n,o;return e(this,void 0,void 0,(function*(){if("Hard"===(null===(n=null==t?void 0:t.decline)||void 0===n?void 0:n.error_type))return t;if(["Success","Authorized"].includes(null==t?void 0:t.transaction_status))return t;if(t){const e={checkout_id:null===(o=t.checkout)||void 0===o?void 0:o.id};try{return yield h(this.baseUrl,this.apiKeyTonder,e)}catch(t){}return t}}))};const T=Object.freeze({saveCardError:"Ha ocurrido un error guardando la tarjeta. Inténtalo nuevamente.",removeCardError:"Ha ocurrido un error eliminado la tarjeta. Inténtalo nuevamente.",getCardsError:"Ha ocurrido un error obteniendo las tarjetas del customer. Inténtalo nuevamente.",cardExist:"La tarjeta fue registrada previamente.",removedCard:"Card deleted successfully",errorCheckout:"No se ha podido procesar el pago",cardSaved:"Tarjeta registrada con éxito.",getPaymentMethodsError:"Ha ocurrido un error obteniendo las métodos de pago del customer. Inténtalo nuevamente.",getBusinessError:"Ha ocurrido un error obteniendo los datos del comercio. Inténtalo nuevamente."});function O({baseUrl:n,apiKey:o,vault_id:r,vault_url:i,data:s}){return e(this,void 0,void 0,(function*(){const d=t.init({vaultID:r,vaultURL:i,getBearerToken:()=>e(this,void 0,void 0,(function*(){return yield function(t,n,o=null){return e(this,void 0,void 0,(function*(){const e=yield fetch(`${t}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${n}`},signal:o});if(e.ok)return(yield e.json()).token;throw new Error("Failed to retrieve bearer token")}))}(n,o)})),options:{logLevel:t.LogLevel.ERROR,env:t.Env.DEV}}),l=d.container(t.ContainerType.COLLECT),c=yield function(n,o){return e(this,void 0,void 0,(function*(){const r=yield function(n,o){return e(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(n).map((n=>e(this,void 0,void 0,(function*(){return{element:yield o.create({table:"cards",column:n,type:t.ElementType.INPUT_FIELD}),key:n}})))))}))}(n,o);return r?r.map((t=>new Promise((e=>{var o;const r=document.createElement("div");r.hidden=!0,r.id=`id-${t.key}`,null===(o=document.querySelector("body"))||void 0===o||o.appendChild(r),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const o=n[t.key];return t.element.update({value:o}),e(t.element.isMounted())}}),120)}),120)})))):[]}))}(s,l);if((yield Promise.all(c)).some((t=>!t)))throw a(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const t=yield l.collect();if(t)return t.records[0].fields;throw a(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(t){throw a(t)}}))}const S=Object.freeze({SORIANA:"SORIANA",OXXO:"OXXO",SPEI:"SPEI",CODI:"CODI",MERCADOPAGO:"MERCADOPAGO",PAYPAL:"PAYPAL",COMERCIALMEXICANA:"COMERCIALMEXICANA",BANCOMER:"BANCOMER",WALMART:"WALMART",BODEGA:"BODEGA",SAMSCLUB:"SAMSCLUB",SUPERAMA:"SUPERAMA",CALIMAX:"CALIMAX",EXTRA:"EXTRA",CIRCULOK:"CIRCULOK",SEVEN11:"7ELEVEN",TELECOMM:"TELECOMM",BANORTE:"BANORTE",BENAVIDES:"BENAVIDES",DELAHORRO:"DELAHORRO",ELASTURIANO:"ELASTURIANO",WALDOS:"WALDOS",ALSUPER:"ALSUPER",KIOSKO:"KIOSKO",STAMARIA:"STAMARIA",LAMASBARATA:"LAMASBARATA",FARMROMA:"FARMROMA",FARMUNION:"FARMUNION",FARMATODO:"FARMATODO",SFDEASIS:"SFDEASIS",FARM911:"FARM911",FARMECONOMICAS:"FARMECONOMICAS",FARMMEDICITY:"FARMMEDICITY",RIANXEIRA:"RIANXEIRA",WESTERNUNION:"WESTERNUNION",ZONAPAGO:"ZONAPAGO",CAJALOSANDES:"CAJALOSANDES",CAJAPAITA:"CAJAPAITA",CAJASANTA:"CAJASANTA",CAJASULLANA:"CAJASULLANA",CAJATRUJILLO:"CAJATRUJILLO",EDPYME:"EDPYME",KASNET:"KASNET",NORANDINO:"NORANDINO",QAPAQ:"QAPAQ",RAIZ:"RAIZ",PAYSER:"PAYSER",WUNION:"WUNION",BANCOCONTINENTAL:"BANCOCONTINENTAL",GMONEY:"GMONEY",GOPAY:"GOPAY",WU:"WU",PUNTOSHEY:"PUNTOSHEY",AMPM:"AMPM",JUMBOMARKET:"JUMBOMARKET",SMELPUEBLO:"SMELPUEBLO",BAM:"BAM",REFACIL:"REFACIL",ACYVALORES:"ACYVALORES"}),C={[S.SORIANA]:{label:"Soriana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png"},[S.OXXO]:{label:"Oxxo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png"},[S.CODI]:{label:"CoDi",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png"},[S.SPEI]:{label:"SPEI",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png"},[S.PAYPAL]:{label:"Paypal",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png"},[S.COMERCIALMEXICANA]:{label:"Comercial Mexicana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png"},[S.BANCOMER]:{label:"Bancomer",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png"},[S.WALMART]:{label:"Walmart",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png"},[S.BODEGA]:{label:"Bodega Aurrera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png"},[S.SAMSCLUB]:{label:"Sam´s Club",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png"},[S.SUPERAMA]:{label:"Superama",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png"},[S.CALIMAX]:{label:"Calimax",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png"},[S.EXTRA]:{label:"Tiendas Extra",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png"},[S.CIRCULOK]:{label:"Círculo K",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png"},[S.SEVEN11]:{label:"7 Eleven",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png"},[S.TELECOMM]:{label:"Telecomm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png"},[S.BANORTE]:{label:"Banorte",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png"},[S.BENAVIDES]:{label:"Farmacias Benavides",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png"},[S.DELAHORRO]:{label:"Farmacias del Ahorro",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png"},[S.ELASTURIANO]:{label:"El Asturiano",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png"},[S.WALDOS]:{label:"Waldos",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png"},[S.ALSUPER]:{label:"Alsuper",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png"},[S.KIOSKO]:{label:"Kiosko",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png"},[S.STAMARIA]:{label:"Farmacias Santa María",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png"},[S.LAMASBARATA]:{label:"Farmacias la más barata",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png"},[S.FARMROMA]:{label:"Farmacias Roma",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png"},[S.FARMUNION]:{label:"Pago en Farmacias Unión",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png"},[S.FARMATODO]:{label:"Pago en Farmacias Farmatodo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png\t"},[S.SFDEASIS]:{label:"Pago en Farmacias San Francisco de Asís",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png"},[S.FARM911]:{label:"Farmacias 911",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.FARMECONOMICAS]:{label:"Farmacias Economicas",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.FARMMEDICITY]:{label:"Farmacias Medicity",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.RIANXEIRA]:{label:"Rianxeira",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WESTERNUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.ZONAPAGO]:{label:"Zona Pago",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJALOSANDES]:{label:"Caja Los Andes",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJAPAITA]:{label:"Caja Paita",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJASANTA]:{label:"Caja Santa",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJASULLANA]:{label:"Caja Sullana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJATRUJILLO]:{label:"Caja Trujillo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.EDPYME]:{label:"Edpyme",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.KASNET]:{label:"KasNet",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.NORANDINO]:{label:"Norandino",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.QAPAQ]:{label:"Qapaq",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.RAIZ]:{label:"Raiz",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.PAYSER]:{label:"Paysera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.BANCOCONTINENTAL]:{label:"Banco Continental",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.GMONEY]:{label:"Go money",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.GOPAY]:{label:"Go pay",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WU]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.PUNTOSHEY]:{label:"Puntoshey",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.AMPM]:{label:"Ampm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.JUMBOMARKET]:{label:"Jumbomarket",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.SMELPUEBLO]:{label:"Smelpueblo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.BAM]:{label:"Bam",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.REFACIL]:{label:"Refacil",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.ACYVALORES]:{label:"Acyvalores",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"}},j=t=>{const e=t.toUpperCase().trim().replace(/\s+/g,"");return C[e]||{icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",label:""}};class w extends E{constructor({apiKey:t,mode:e,returnUrl:n,callBack:o}){super({mode:e,apiKey:t,returnUrl:n,callBack:o}),this.activeAPMs=[]}injectCheckout(){return e(this,void 0,void 0,(function*(){yield this._initializeCheckout()}))}getCustomerCards(){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:t}=yield this._getCustomer(),n=yield function(t,n,o,r=null){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${o}/cards/`,i=yield fetch(e,{method:"GET",headers:{Authorization:`Token ${n}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,t,this.merchantData.business.pk);return Object.assign(Object.assign({},n),{cards:n.cards.map((t=>{return Object.assign(Object.assign({},t),{icon:(e=t.fields.card_scheme,"Visa"===e?"https://d35a75syrgujp0.cloudfront.net/cards/visa.png":"Mastercard"===e?"https://d35a75syrgujp0.cloudfront.net/cards/mastercard.png":"American Express"===e?"https://d35a75syrgujp0.cloudfront.net/cards/american_express.png":"https://d35a75syrgujp0.cloudfront.net/cards/default_card.png")});var e}))})}catch(t){throw l({message:T.getCardsError},t)}}))}saveCustomerCard(t){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:n}=yield this._getCustomer(),{vault_id:o,vault_url:r,business:i}=this.merchantData,s=yield O({vault_id:o,vault_url:r,data:t,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder});return yield function(t,n,o,r){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${o}/cards/`,i=yield fetch(e,{method:"POST",headers:{Authorization:`Token ${n}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,n,null==i?void 0:i.pk,s)}catch(t){throw l({message:T.saveCardError},t)}}))}removeCustomerCard(t){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:n}=yield this._getCustomer(),{business:o}=this.merchantData;return yield function(t,n,o="",r){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${r}/cards/${o}`,i=yield fetch(e,{method:"DELETE",headers:{Authorization:`Token ${n}`,"Content-Type":"application/json"}});if(204===i.status)return T.cardSaved;if(i.ok&&"json"in i)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,n,t,null==o?void 0:o.pk)}catch(t){throw l({message:T.removeCardError},t)}}))}getCustomerPaymentMethods(){return e(this,void 0,void 0,(function*(){try{const t=yield function(t,n,o={status:"active",pagesize:"10000"},r=null){return e(this,void 0,void 0,(function*(){try{const e=new URLSearchParams(o).toString(),i=yield fetch(`${t}/api/v1/payment_methods?${e}`,{method:"GET",headers:{Authorization:`Token ${n}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,this.apiKeyTonder);return(t&&"results"in t&&t.results.length>0?t.results:[]).filter((t=>"cards"!==t.category.toLowerCase())).map((t=>Object.assign({id:t.pk,payment_method:t.payment_method,priority:t.priority,category:t.category},j(t.payment_method)))).sort(((t,e)=>t.priority-e.priority))}catch(t){throw l({message:T.getPaymentMethodsError},t)}}))}getBusiness(){return e(this,void 0,void 0,(function*(){try{return yield o(this.baseUrl,this.apiKeyTonder,this.abortController.signal)}catch(t){throw l({message:T.getBusinessError},t)}}))}getSkyflowTokens({vault_id:t,vault_url:n,data:o}){return e(this,void 0,void 0,(function*(){return yield O({vault_id:t,vault_url:n,data:o,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})}))}_setCartTotal(t){this.cartTotal=t}_checkout({card:t,payment_method:n,isSandbox:o}){return e(this,void 0,void 0,(function*(){yield this._fetchMerchantData();const e=yield this._getCustomer(this.abortController.signal),{vault_id:r,vault_url:i}=this.merchantData;let s;return n&&""===n&&null!==n||(s="string"==typeof t?{skyflow_id:t}:yield O({vault_id:r,vault_url:i,data:Object.assign(Object.assign({},t),{card_number:t.card_number.replace(/\s+/g,"")}),baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})),yield this._handleCheckout({card:s,payment_method:n,customer:e,isSandbox:o})}))}customerRegister(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/customer/`,n={email:t},o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.abortController.signal,body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield d(o)}catch(t){throw a(t)}}))}createOrder(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/orders/`,n=t,o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield d(o)}catch(t){throw a(t)}}))}createPayment(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/business/${t.business_pk}/payments/`,n=t,o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield d(o)}catch(t){throw a(t)}}))}startCheckoutRouter(t){return e(this,void 0,void 0,(function*(){const e=yield h(this.baseUrl,this.apiKeyTonder,t);if(yield this.init3DSRedirect(e))return e}))}init3DSRedirect(t){return e(this,void 0,void 0,(function*(){return this.process3ds.setPayload(t),yield this._handle3dsRedirect(t)}))}startCheckoutRouterFull(t){return e(this,void 0,void 0,(function*(){try{const{order:e,total:n,customer:o,skyflowTokens:s,return_url:a,isSandbox:d,metadata:l,currency:c,payment_method:u}=t,m=yield this._fetchMerchantData(),y=yield this.customerRegister(o.email);if(!(y&&"auth_token"in y&&m&&"reference"in m))throw new r({code:"500",body:m,name:"Keys error",message:"Merchant or customer reposne errors"});{const t={business:this.apiKeyTonder,client:y.auth_token,billing_address_id:null,shipping_address_id:null,amount:n,reference:m.reference,is_oneclick:!0,items:e.items},f=yield this.createOrder(t),g=(new Date).toISOString();if(!("id"in f&&"id"in y&&"business"in m))throw new r({code:"500",body:f,name:"Keys error",message:"Order response errors"});{const t={business_pk:m.business.pk,amount:n,date:g,order_id:f.id,client_id:y.id},e=yield this.createPayment(t);let r;const{openpay_keys:v,business:A}=m;v.merchant_id&&v.public_key&&(r=yield p(v.merchant_id,v.public_key,d));const _=Object.assign(Object.assign({name:o.name,last_name:o.lastname,email_client:o.email,phone_number:o.phone,return_url:a,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:n,title_ship:"shipping",description:"transaction",device_session_id:r||null,token_id:"",order_id:"id"in f&&f.id,business_id:A.pk,payment_id:"pk"in e&&e.pk,source:"sdk",metadata:l,browser_info:i(),currency:c},u?{payment_method:u}:{card:s}),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}),b=yield h(this.baseUrl,this.apiKeyTonder,_);if(yield this.init3DSRedirect(b))return b}}}catch(t){throw a(t)}}))}registerCustomerCard(t,n){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const e=yield fetch(`${this.baseUrl}/api/v1/business/${s(this.merchantData)}/cards/`,{method:"POST",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},body:JSON.stringify(Object.assign({},n))});if(e.ok)return yield e.json();throw yield d(e)}catch(t){throw a(t)}}))}deleteCustomerCard(t,n=""){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const e=yield fetch(`${this.baseUrl}/api/v1/business/${s(this.merchantData)}/cards/${n}`,{method:"DELETE",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},signal:this.abortController.signal});if(e.ok)return!0;throw yield d(e)}catch(t){throw a(t)}}))}getActiveAPMs(){return e(this,void 0,void 0,(function*(){try{const t=yield function(t,n,o="?status=active&page_size=10000&country=México",r=null){return e(this,void 0,void 0,(function*(){try{const e=yield fetch(`${t}/api/v1/payment_methods${o}`,{method:"GET",headers:{Authorization:`Token ${n}`,"Content-Type":"application/json"},signal:r});if(e.ok)return yield e.json();throw yield d(e)}catch(t){throw a(t)}}))}(this.baseUrl,this.apiKeyTonder),n=t&&t.results&&t.results.length>0?t.results:[];return this.activeAPMs=n.filter((t=>"cards"!==t.category.toLowerCase())).map((t=>Object.assign({id:t.pk,payment_method:t.payment_method,priority:t.priority,category:t.category},j(t.payment_method)))).sort(((t,e)=>t.priority-e.priority)),this.activeAPMs}catch(t){return console.error("Error getting APMS",t),[]}}))}}function N(t){return/^\d{12,19}$/.test(t)&&U(t)}function R(t){return/^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/.test(t)}function M(t){return/^\d{3,4}$/.test(t)}function I(t){return/^(0[1-9]|1[0-2])$/.test(t)}function k(t){if(!/^\d{2}$/.test(t))return!1;const e=(new Date).getFullYear()%100;return parseInt(t,10)>=e}const U=t=>{const e=`${t}`.split("").reverse().map((t=>Number.parseInt(t))),n=e.shift();let o=e.reduce(((t,e,n)=>n%2!=0?t+e:t+((e*=2)>9?e-9:e)),0);return o+=n,o%10==0};export{w as LiteCheckout,M as validateCVV,N as validateCardNumber,R as validateCardholderName,I as validateExpirationMonth,k as validateExpirationYear};
1
+ import e from"skyflow-js";function t(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{d(o.next(e))}catch(e){r(e)}}function a(e){try{d(o.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}function n(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}"function"==typeof SuppressedError&&SuppressedError;class o{constructor({code:e,body:t,name:n,message:o,stack:i}){this.code=e,this.body=t,this.name=n,this.message=o,this.stack=i}}var i;!function(e){e.SORIANA="SORIANA",e.OXXO="OXXO",e.SPEI="SPEI",e.CODI="CODI",e.MERCADOPAGO="MERCADOPAGO",e.PAYPAL="PAYPAL",e.COMERCIALMEXICANA="COMERCIALMEXICANA",e.BANCOMER="BANCOMER",e.WALMART="WALMART",e.BODEGA="BODEGA",e.SAMSCLUB="SAMSCLUB",e.SUPERAMA="SUPERAMA",e.CALIMAX="CALIMAX",e.EXTRA="EXTRA",e.CIRCULOK="CIRCULOK",e.SEVEN11="7ELEVEN",e.TELECOMM="TELECOMM",e.BANORTE="BANORTE",e.BENAVIDES="BENAVIDES",e.DELAHORRO="DELAHORRO",e.ELASTURIANO="ELASTURIANO",e.WALDOS="WALDOS",e.ALSUPER="ALSUPER",e.KIOSKO="KIOSKO",e.STAMARIA="STAMARIA",e.LAMASBARATA="LAMASBARATA",e.FARMROMA="FARMROMA",e.FARMUNION="FARMUNION",e.FARMATODO="FARMATODO",e.SFDEASIS="SFDEASIS",e.FARM911="FARM911",e.FARMECONOMICAS="FARMECONOMICAS",e.FARMMEDICITY="FARMMEDICITY",e.RIANXEIRA="RIANXEIRA",e.WESTERNUNION="WESTERNUNION",e.ZONAPAGO="ZONAPAGO",e.CAJALOSANDES="CAJALOSANDES",e.CAJAPAITA="CAJAPAITA",e.CAJASANTA="CAJASANTA",e.CAJASULLANA="CAJASULLANA",e.CAJATRUJILLO="CAJATRUJILLO",e.EDPYME="EDPYME",e.KASNET="KASNET",e.NORANDINO="NORANDINO",e.QAPAQ="QAPAQ",e.RAIZ="RAIZ",e.PAYSER="PAYSER",e.WUNION="WUNION",e.BANCOCONTINENTAL="BANCOCONTINENTAL",e.GMONEY="GMONEY",e.GOPAY="GOPAY",e.WU="WU",e.PUNTOSHEY="PUNTOSHEY",e.AMPM="AMPM",e.JUMBOMARKET="JUMBOMARKET",e.SMELPUEBLO="SMELPUEBLO",e.BAM="BAM",e.REFACIL="REFACIL",e.ACYVALORES="ACYVALORES"}(i||(i={}));const r=e=>{var t;return e&&"business"in e?null===(t=null==e?void 0:e.business)||void 0===t?void 0:t.pk:""},s=e=>new o({code:(null==e?void 0:e.status)?e.status:e.code,body:null==e?void 0:e.body,name:e?"string"==typeof e?"catch":e.name:"Error",message:e?"string"==typeof e?e:e.message:"Error",stack:"string"==typeof e?void 0:e.stack}),a=(e,n=void 0)=>t(void 0,void 0,void 0,(function*(){let t,i,r="Error";e&&"json"in e&&(t=yield null==e?void 0:e.json()),e&&"status"in e&&(i=e.status.toString()),!t&&e&&"text"in e&&(r=yield e.text()),(null==t?void 0:t.detail)&&(r=t.detail);return new o({code:i,body:t,name:i,message:r,stack:n})})),d=e=>e.trim().replace(/\s+/g,"");class l{constructor({payload:e=null,apiKey:t,baseUrl:n}){this.localStorageKey="verify_transaction_status_url",this.setPayload=e=>{this.payload=e},this.baseUrl=n,this.apiKey=t,this.payload=e}setStorageItem(e){return localStorage.setItem(this.localStorageKey,JSON.stringify(e))}getStorageItem(){return localStorage.getItem(this.localStorageKey)}removeStorageItem(){return localStorage.removeItem(this.localStorageKey)}saveVerifyTransactionUrl(){var e,t,n,o,i,r;const s=null===(n=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.redirect_to_url)||void 0===n?void 0:n.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const e=null===(r=null===(i=null===(o=this.payload)||void 0===o?void 0:o.next_action)||void 0===i?void 0:i.iframe_resources)||void 0===r?void 0:r.verify_transaction_status_url;e?this.saveUrlWithExpiration(e):console.log("No verify_transaction_status_url found")}}saveUrlWithExpiration(e){try{const t={url:e,expires:(new Date).getTime()+12e5};this.setStorageItem(t)}catch(e){console.log("error: ",e)}}getUrlWithExpiration(){const e=this.getStorageItem();if(e){const t=JSON.parse(e);if(!t)return;return(new Date).getTime()>t.expires?(this.removeVerifyTransactionUrl(),null):t.url}return null}removeVerifyTransactionUrl(){return this.removeStorageItem()}getVerifyTransactionUrl(){return this.getStorageItem()}loadIframe(){var e,t,n;if(null===(n=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.iframe_resources)||void 0===n?void 0:n.iframe)return new Promise(((e,t)=>{var n,o,i;const r=null===(i=null===(o=null===(n=this.payload)||void 0===n?void 0:n.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===i?void 0:i.iframe;if(r){this.saveVerifyTransactionUrl();const n=document.createElement("div");n.innerHTML=r,document.body.appendChild(n);const o=document.createElement("script");o.textContent='document.getElementById("tdsMmethodForm").submit();',n.appendChild(o);const i=document.getElementById("tdsMmethodTgtFrame");i?i.onload=()=>e(!0):(console.log("No redirection found"),t(!1))}else console.log("No redirection found"),t(!1)}))}getRedirectUrl(){var e,t,n;return null===(n=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.redirect_to_url)||void 0===n?void 0:n.url}redirectToChallenge(){const e=this.getRedirectUrl();e?(this.saveVerifyTransactionUrl(),window.location=e):console.log("No redirection found")}getURLParameters(){const e={},t=new URLSearchParams(window.location.search);for(const[n,o]of t)e[n]=o;return e}handleSuccessTransaction(e){return this.removeVerifyTransactionUrl(),console.log("Transacción autorizada."),e}handleDeclinedTransaction(e){return this.removeVerifyTransactionUrl(),e}handle3dsChallenge(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("form");t.name="frm",t.method="POST",t.action=e.redirect_post_url;const n=document.createElement("input");n.type="hidden",n.name=e.creq,n.value=e.creq,t.appendChild(n);const o=document.createElement("input");o.type="hidden",o.name=e.term_url,o.value=e.TermUrl,t.appendChild(o),document.body.appendChild(t),t.submit(),yield this.verifyTransactionStatus()}))}handleTransactionResponse(e){return t(this,void 0,void 0,(function*(){const t=yield e.json();return"Pending"===t.status&&t.redirect_post_url?yield this.handle3dsChallenge(t):["Success","Authorized"].includes(t.status)?this.handleSuccessTransaction(t):(this.handleDeclinedTransaction(e),t)}))}verifyTransactionStatus(){return t(this,void 0,void 0,(function*(){const e=this.getUrlWithExpiration();if(e){const t=`${this.baseUrl}${e}`;try{const e=yield fetch(t,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`}});return 200!==e.status?(console.error("La verificación de la transacción falló."),this.removeVerifyTransactionUrl(),e):yield this.handleTransactionResponse(e)}catch(e){console.error("Error al verificar la transacción:",e),this.removeVerifyTransactionUrl()}}else console.log("No verify_transaction_status_url found")}))}}var c,u,h;class p{constructor({signal:e,baseUrlTonder:t,publicApiKeyTonder:o}){c.add(this),this.activeAPMs=[],this.baseUrlTonder=t,this.signal=e,this.publicApiKeyTonder=o,this.process3ds=new l({apiKey:this.publicApiKeyTonder,baseUrl:this.baseUrlTonder}),n(this,c,"m",u).call(this)}getOpenpayDeviceSessionID(e,n,o){return t(this,void 0,void 0,(function*(){try{let t=yield window.OpenPay;return t.setId(e),t.setApiKey(n),t.setSandboxMode(o),yield t.deviceData.setup({signal:this.signal})}catch(e){throw s(e)}}))}getBusiness(){return t(this,void 0,void 0,(function*(){try{const e=yield fetch(`${this.baseUrlTonder}/api/v1/payments/business/${this.publicApiKeyTonder}`,{headers:{Authorization:`Token ${this.publicApiKeyTonder}`},signal:this.signal});if(e.ok)return yield e.json();throw yield a(e)}catch(e){throw s(e)}}))}verify3dsTransaction(){return t(this,void 0,void 0,(function*(){const e=yield this.process3ds.verifyTransactionStatus(),t=yield this.resumeCheckout(e);return this.process3ds.setPayload(t),this.handle3dsRedirect(t)}))}resumeCheckout(e){var n,o;return t(this,void 0,void 0,(function*(){if("Hard"===(null===(n=null==e?void 0:e.decline)||void 0===n?void 0:n.error_type))return e;if(["Success","Authorized"].includes(null==e?void 0:e.transaction_status))return e;if(e){const t={checkout_id:null===(o=null==e?void 0:e.checkout)||void 0===o?void 0:o.id};try{return yield this.handleCheckoutRouter(t)}catch(e){}return e}}))}handle3dsRedirect(e){var n,o;return t(this,void 0,void 0,(function*(){if(e&&"next_action"in e?null===(o=null===(n=null==e?void 0:e.next_action)||void 0===n?void 0:n.iframe_resources)||void 0===o?void 0:o.iframe:null)this.process3ds.loadIframe().then((()=>{this.process3ds.verifyTransactionStatus()})).catch((e=>{console.log("Error loading iframe:",e)}));else{if(!this.process3ds.getRedirectUrl())return e;this.process3ds.redirectToChallenge()}}))}customerRegister(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/customer/`,n={email:e},o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.publicApiKeyTonder}`},signal:this.signal,body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield a(o)}catch(e){throw s(e)}}))}createOrder(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/orders/`,n=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.publicApiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield a(o)}catch(e){throw s(e)}}))}createPayment(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/business/${e.business_pk}/payments/`,n=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.publicApiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield a(o)}catch(e){throw s(e)}}))}handleCheckoutRouter(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/checkout-router/`,n=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.publicApiKeyTonder}`},body:JSON.stringify(Object.assign(Object.assign({},n),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}))});if(o.ok)return yield o.json();throw yield a(o)}catch(e){throw s(e)}}))}startCheckoutRouter(e){return t(this,void 0,void 0,(function*(){const t=yield this.handleCheckoutRouter(e);if(yield this.init3DSRedirect(t))return t}))}startCheckoutRouterFull(e){return t(this,void 0,void 0,(function*(){try{const{order:t,total:n,customer:i,skyflowTokens:r,return_url:s,isSandbox:a,metadata:d,currency:l,payment_method:c}=e,u=yield this.getBusiness(),h=yield this.customerRegister(i.email);if(!(h&&"auth_token"in h&&u&&"reference"in u))throw new o({code:"500",body:u,name:"Keys error",message:"Merchant or customer reposne errors"});{const e={business:this.publicApiKeyTonder,client:h.auth_token,billing_address_id:null,shipping_address_id:null,amount:n,reference:u.reference,is_oneclick:!0,items:t.items},p=yield this.createOrder(e),y=(new Date).toISOString();if(!("id"in p&&"id"in h&&"business"in u))throw new o({code:"500",body:p,name:"Keys error",message:"Order response errors"});{const e={business_pk:u.business.pk,amount:n,date:y,order_id:p.id,client_id:h.id},t=yield this.createPayment(e);let o;const{openpay_keys:m,business:A}=u;m.merchant_id&&m.public_key&&(o=yield this.getOpenpayDeviceSessionID(m.merchant_id,m.public_key,a));const g=Object.assign(Object.assign({name:i.name,last_name:i.lastname,email_client:i.email,phone_number:i.phone,return_url:s,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:n,title_ship:"shipping",description:"transaction",device_session_id:o||null,token_id:"",order_id:"id"in p&&p.id,business_id:A.pk,payment_id:"pk"in t&&t.pk,source:"sdk",metadata:d,browser_info:{javascript_enabled:!0,time_zone:(new Date).getTimezoneOffset(),language:navigator.language||"en-US",color_depth:window.screen?window.screen.colorDepth:null,screen_width:window.screen?window.screen.width*window.devicePixelRatio||window.screen.width:null,screen_height:window.screen?window.screen.height*window.devicePixelRatio||window.screen.height:null,user_agent:navigator.userAgent},currency:l},c?{payment_method:c}:{card:r}),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}),f=yield this.handleCheckoutRouter(g);if(yield this.init3DSRedirect(f))return f}}}catch(e){throw s(e)}}))}init3DSRedirect(e){return t(this,void 0,void 0,(function*(){return this.process3ds.setPayload(e),yield this.handle3dsRedirect(e)}))}getSkyflowTokens({vault_id:n,vault_url:o,data:i}){return t(this,void 0,void 0,(function*(){const r=e.init({vaultID:n,vaultURL:o,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield this.getVaultToken()})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}).container(e.ContainerType.COLLECT),a=yield this.getFieldsPromise(i,r);if((yield Promise.all(a)).some((e=>!e)))throw s(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const e=yield r.collect();if(e)return e.records[0].fields;throw s(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(e){throw s(e)}}))}getVaultToken(){var e;return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${this.publicApiKeyTonder}`},signal:this.signal});if(t.ok)return null===(e=yield t.json())||void 0===e?void 0:e.token;throw new Error(`HTTPCODE: ${t.status}`)}catch(e){throw new Error(`Failed to retrieve bearer token; ${"string"==typeof e?e:e.message}`)}}))}getFieldsPromise(e,n){return t(this,void 0,void 0,(function*(){const t=yield this.getFields(e,n);return t?t.map((t=>new Promise((n=>{var o;const i=document.createElement("div");i.hidden=!0,i.id=`id-${t.key}`,null===(o=document.querySelector("body"))||void 0===o||o.appendChild(i),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const o=e[t.key];return t.element.update({value:o}),n(t.element.isMounted())}}),120)}),120)})))):[]}))}registerCustomerCard(e,o,i){return t(this,void 0,void 0,(function*(){try{yield n(this,c,"m",h).call(this);const t=yield fetch(`${this.baseUrlTonder}/api/v1/business/${r(this.merchantData)}/cards/`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"User-token":o,"Content-Type":"application/json"},signal:this.signal,body:JSON.stringify(Object.assign({},i))});if(t.ok)return yield t.json();throw yield a(t)}catch(e){throw s(e)}}))}getCustomerCards(e,o){return t(this,void 0,void 0,(function*(){try{yield n(this,c,"m",h).call(this);const t=yield fetch(`${this.baseUrlTonder}/api/v1/business/${r(this.merchantData)}/cards`,{method:"GET",headers:{Authorization:`Bearer ${o}`,"User-Token":e,"Content-Type":"application/json",Accept:"application/json"},signal:this.signal});if(t.ok)return yield t.json();throw yield a(t)}catch(e){throw s(e)}}))}deleteCustomerCard(e,o=""){return t(this,void 0,void 0,(function*(){try{yield n(this,c,"m",h).call(this);const t=yield fetch(`${this.baseUrlTonder}/api/v1/business/${r(this.merchantData)}/cards/${o}`,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});if(t.ok)return!0;throw yield a(t)}catch(e){throw s(e)}}))}getFields(n,o){return t(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(n).map((n=>t(this,void 0,void 0,(function*(){return{element:yield o.create({table:"cards",column:n,type:e.ElementType.INPUT_FIELD}),key:n}})))))}))}getActiveAPMs(){return t(this,void 0,void 0,(function*(){try{const e=yield function(e,n,o="?status=active&page_size=10000&country=México",i=null){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${e}/api/v1/payment_methods${o}`,{method:"GET",headers:{Authorization:`Token ${n}`,"Content-Type":"application/json"},signal:i});if(t.ok)return yield t.json();throw yield a(t)}catch(e){throw s(e)}}))}(this.baseUrlTonder,this.publicApiKeyTonder),n=e&&e.results&&e.results.length>0?e.results:[];return this.activeAPMs=n.filter((e=>"cards"!==e.category.toLowerCase())).map((e=>Object.assign({id:e.pk,payment_method:e.payment_method,priority:e.priority,category:e.category},(e=>{const t=d(e.toUpperCase());return{[i.SORIANA]:{label:"Soriana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png"},[i.OXXO]:{label:"Oxxo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png"},[i.CODI]:{label:"CoDi",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png"},[i.SPEI]:{label:"SPEI",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png"},[i.PAYPAL]:{label:"Paypal",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png"},[i.COMERCIALMEXICANA]:{label:"Comercial Mexicana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png"},[i.BANCOMER]:{label:"Bancomer",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png"},[i.WALMART]:{label:"Walmart",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png"},[i.BODEGA]:{label:"Bodega Aurrera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png"},[i.SAMSCLUB]:{label:"Sam´s Club",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png"},[i.SUPERAMA]:{label:"Superama",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png"},[i.CALIMAX]:{label:"Calimax",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png"},[i.EXTRA]:{label:"Tiendas Extra",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png"},[i.CIRCULOK]:{label:"Círculo K",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png"},[i.SEVEN11]:{label:"7 Eleven",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png"},[i.TELECOMM]:{label:"Telecomm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png"},[i.BANORTE]:{label:"Banorte",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png"},[i.BENAVIDES]:{label:"Farmacias Benavides",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png"},[i.DELAHORRO]:{label:"Farmacias del Ahorro",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png"},[i.ELASTURIANO]:{label:"El Asturiano",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png"},[i.WALDOS]:{label:"Waldos",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png"},[i.ALSUPER]:{label:"Alsuper",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png"},[i.KIOSKO]:{label:"Kiosko",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png"},[i.STAMARIA]:{label:"Farmacias Santa María",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png"},[i.LAMASBARATA]:{label:"Farmacias la más barata",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png"},[i.FARMROMA]:{label:"Farmacias Roma",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png"},[i.FARMUNION]:{label:"Pago en Farmacias Unión",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png"},[i.FARMATODO]:{label:"Pago en Farmacias Farmatodo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png\t"},[i.SFDEASIS]:{label:"Pago en Farmacias San Francisco de Asís",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png"},[i.FARM911]:{label:"Farmacias 911",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.FARMECONOMICAS]:{label:"Farmacias Economicas",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.FARMMEDICITY]:{label:"Farmacias Medicity",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.RIANXEIRA]:{label:"Rianxeira",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.WESTERNUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.ZONAPAGO]:{label:"Zona Pago",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.CAJALOSANDES]:{label:"Caja Los Andes",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.CAJAPAITA]:{label:"Caja Paita",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.CAJASANTA]:{label:"Caja Santa",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.CAJASULLANA]:{label:"Caja Sullana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.CAJATRUJILLO]:{label:"Caja Trujillo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.EDPYME]:{label:"Edpyme",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.KASNET]:{label:"KasNet",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.NORANDINO]:{label:"Norandino",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.QAPAQ]:{label:"Qapaq",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.RAIZ]:{label:"Raiz",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.PAYSER]:{label:"Paysera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.WUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.BANCOCONTINENTAL]:{label:"Banco Continental",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.GMONEY]:{label:"Go money",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.GOPAY]:{label:"Go pay",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.WU]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.PUNTOSHEY]:{label:"Puntoshey",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.AMPM]:{label:"Ampm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.JUMBOMARKET]:{label:"Jumbomarket",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.SMELPUEBLO]:{label:"Smelpueblo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.BAM]:{label:"Bam",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.REFACIL]:{label:"Refacil",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[i.ACYVALORES]:{label:"Acyvalores",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"}}[t]||{icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",label:""}})(e.payment_method)))).sort(((e,t)=>e.priority-t.priority)),this.activeAPMs}catch(e){return console.error("Error getting APMS",e),[]}}))}getSecureToken(e){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/secure-token/`,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});if(t.ok)return yield t.json();throw yield a(t)}catch(e){throw s(e)}}))}}c=new WeakSet,u=function(){return t(this,void 0,void 0,(function*(){this.getActiveAPMs();const{mercado_pago:e}=yield n(this,c,"m",h).call(this);e&&e.active&&function(){try{const e=document.createElement("script");e.src="https://www.mercadopago.com/v2/security.js",e.setAttribute("view",""),e.onload=()=>{console.log("Mercado Pago script loaded successfully.")},e.onerror=e=>{console.error("Error loading Mercado Pago script:",e)},document.head.appendChild(e)}catch(e){console.error("Error attempting to inject Mercado Pago script:",e)}}()}))},h=function(){return t(this,void 0,void 0,(function*(){try{return this.merchantData||(this.merchantData=yield this.getBusiness()),this.merchantData}catch(e){return this.merchantData}}))};export{p as LiteCheckout};
@@ -1,4 +1,3 @@
1
- import { ICustomer } from "./customer";
2
1
  export type Business = {
3
2
  business: {
4
3
  pk: number;
@@ -77,39 +76,3 @@ export type APM = {
77
76
  icon: string;
78
77
  label: string;
79
78
  };
80
- export interface IConfigureCheckout {
81
- customer: ICustomer;
82
- }
83
- export interface IInlineCheckoutBaseOptions {
84
- mode?: "production" | "sandbox" | "stage" | "development";
85
- /**
86
- * @deprecated This property is deprecated and will be removed in a future release.
87
- * `baseUrlTonder` is no longer required.
88
- */
89
- baseUrlTonder?: string;
90
- /**
91
- * @deprecated This property is deprecated and will be removed in a future release.
92
- * Use `apiKey` instead, as `apiKeyTonder` is no longer required.
93
- */
94
- apiKeyTonder?: string;
95
- /**
96
- * @deprecated This property is deprecated and will be removed in a future release.
97
- * `signal` is no longer required.
98
- */
99
- signal?: AbortSignal;
100
- apiKey: string;
101
- returnUrl: string;
102
- callBack?: (response: any) => void;
103
- }
104
- export interface IApiError {
105
- code: string;
106
- body: Record<string, string> | string;
107
- name: string;
108
- message: string;
109
- }
110
- export interface IPublicError {
111
- status: string;
112
- code: number;
113
- message: string;
114
- detail: Record<string, any> | string;
115
- }
@@ -1,5 +1,5 @@
1
+ import { OrderItem } from "./commons";
1
2
  import { SkyflowRecord } from "./skyflow";
2
- import { IItem } from "./checkout";
3
3
  export interface CreateOrderRequest {
4
4
  business: string;
5
5
  client: string;
@@ -9,7 +9,7 @@ export interface CreateOrderRequest {
9
9
  status?: string;
10
10
  reference: string | number;
11
11
  is_oneclick: boolean;
12
- items: IItem[];
12
+ items: OrderItem[];
13
13
  }
14
14
  export type CreatePaymentRequest = {
15
15
  business_pk?: string | number;
@@ -61,15 +61,6 @@ export interface VaultRequest extends SkyflowRecord {
61
61
  export type RegisterCustomerCardRequest = {
62
62
  skyflow_id: string;
63
63
  };
64
- export type TokensSkyflowRequest = {
65
- baseUrl: string;
66
- apiKey: string;
67
- vault_id: string;
68
- vault_url: string;
69
- data: {
70
- [key: string]: any;
71
- };
72
- };
73
64
  export type TokensRequest = {
74
65
  vault_id: string;
75
66
  vault_url: string;
@@ -79,7 +70,7 @@ export type TokensRequest = {
79
70
  };
80
71
  export type StartCheckoutFullRequest = {
81
72
  order: {
82
- items: IItem[];
73
+ items: OrderItem[];
83
74
  };
84
75
  total: number;
85
76
  customer: {
@@ -178,3 +178,6 @@ export type RegisterCustomerCardResponse = {
178
178
  skyflow_id: string;
179
179
  user_id: number;
180
180
  };
181
+ export type GetSecureTokenResponse = {
182
+ access: string;
183
+ };
package/jest.config.ts CHANGED
@@ -1,15 +1,15 @@
1
- import type { JestConfigWithTsJest } from 'ts-jest'
2
-
3
- const jestConfig: JestConfigWithTsJest = {
4
- testEnvironment: "jsdom",
5
- preset: 'ts-jest',
6
- transform: {
7
- '^.+\\.tsx?$': [
8
- 'ts-jest',
9
- {
10
- },
11
- ],
12
- },
13
- }
14
-
1
+ import type { JestConfigWithTsJest } from 'ts-jest'
2
+
3
+ const jestConfig: JestConfigWithTsJest = {
4
+ testEnvironment: "jsdom",
5
+ preset: 'ts-jest',
6
+ transform: {
7
+ '^.+\\.tsx?$': [
8
+ 'ts-jest',
9
+ {
10
+ },
11
+ ],
12
+ },
13
+ }
14
+
15
15
  export default jestConfig
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
- {
2
- "name": "@tonder.io/ionic-lite-sdk",
3
- "version": "0.0.35-beta.7",
4
- "description": "Tonder ionic lite SDK",
5
- "main": "dist/index.js",
6
- "types": "src/types/index.d.ts",
7
- "scripts": {
8
- "build": "tsc -noEmit && rollup --config",
9
- "test": "jest",
10
- "ts-coverage": "typescript-coverage-report"
11
- },
12
- "author": "",
13
- "license": "ISC",
14
- "dependencies": {
15
- "skyflow-js": "^1.34.1",
16
- "ts-node": "^10.9.2"
17
- },
18
- "publishConfig": {
19
- "access": "public",
20
- "registry": "https://registry.npmjs.org/"
21
- },
22
- "devDependencies": {
23
- "@rollup/plugin-terser": "^0.4.4",
24
- "@rollup/plugin-typescript": "11.1.6",
25
- "@types/crypto-js": "^4.2.2",
26
- "@types/jest": "^29.5.11",
27
- "@types/node": "^20.11.5",
28
- "jest": "^29.7.0",
29
- "jest-environment-jsdom": "^29.7.0",
30
- "jsdom": "^24.0.0",
31
- "rollup": "4.9.6",
32
- "ts-jest": "^29.1.2",
33
- "ts-loader": "^9.5.1",
34
- "tslib": "^2.6.2",
35
- "typescript": "^5.3.3",
36
- "typescript-coverage-report": "^0.8.0"
37
- }
38
- }
1
+ {
2
+ "name": "@tonder.io/ionic-lite-sdk",
3
+ "version": "0.0.36-beta.1",
4
+ "description": "Tonder ionic lite SDK",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -noEmit && rollup --config",
9
+ "test": "jest",
10
+ "ts-coverage": "typescript-coverage-report"
11
+ },
12
+ "author": "",
13
+ "license": "ISC",
14
+ "dependencies": {
15
+ "skyflow-js": "^1.34.1",
16
+ "ts-node": "^10.9.2"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "registry": "https://registry.npmjs.org/"
21
+ },
22
+ "devDependencies": {
23
+ "@rollup/plugin-terser": "^0.4.4",
24
+ "@rollup/plugin-typescript": "11.1.6",
25
+ "@types/crypto-js": "^4.2.2",
26
+ "@types/jest": "^29.5.11",
27
+ "@types/node": "^20.11.5",
28
+ "jest": "^29.7.0",
29
+ "jest-environment-jsdom": "^29.7.0",
30
+ "jsdom": "^24.0.0",
31
+ "rollup": "4.9.6",
32
+ "ts-jest": "^29.1.2",
33
+ "ts-loader": "^9.5.1",
34
+ "tslib": "^2.6.2",
35
+ "typescript": "^5.3.3",
36
+ "typescript-coverage-report": "^0.8.0"
37
+ }
38
+ }
package/rollup.config.js CHANGED
@@ -1,17 +1,17 @@
1
- const typescript = require('@rollup/plugin-typescript');
2
- const terser = require('@rollup/plugin-terser');
3
-
4
- module.exports = {
5
- input: './src/index.ts',
6
- output: {
7
- dir: 'dist',
8
- format: 'es',
9
- plugins: [terser()]
10
- },
11
- plugins: [
12
- typescript({
13
- exclude: ["tests/**", "jest.config.ts"]
14
- })
15
- ],
16
- external: ["skyflow-js", "crypto-js"]
1
+ const typescript = require('@rollup/plugin-typescript');
2
+ const terser = require('@rollup/plugin-terser');
3
+
4
+ module.exports = {
5
+ input: './src/index.ts',
6
+ output: {
7
+ dir: 'dist',
8
+ format: 'es',
9
+ plugins: [terser()]
10
+ },
11
+ plugins: [
12
+ typescript({
13
+ exclude: ["tests/**", "jest.config.ts"]
14
+ })
15
+ ],
16
+ external: ["skyflow-js", "crypto-js"]
17
17
  };