@tonder.io/ionic-lite-sdk 1.0.0 → 1.0.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/dist/helpers/get.d.ts +12 -0
- package/dist/helpers/utils.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/shared/catalog/paymentMethodsCatalog.d.ts +4 -1
- package/dist/shared/constants/assetUrl.d.ts +17 -0
- package/package.json +24 -8
- package/src/classes/BaseInlineCheckout.ts +1 -1
- package/src/classes/liteCheckout.ts +3 -3
- package/src/helpers/get.ts +26 -0
- package/src/helpers/skyflow.ts +1 -1
- package/src/helpers/utils.ts +11 -5
- package/src/shared/catalog/paymentMethodsCatalog.ts +71 -63
- package/src/shared/constants/assetUrl.ts +22 -0
- package/.gitlab-ci.yml +0 -29
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a nested value by path, falling back when it is missing.
|
|
3
|
+
*
|
|
4
|
+
* Replaces lodash `get`, and keeps its one surprising rule: the fallback
|
|
5
|
+
* applies only to `undefined`. A stored `null` is a real value and is returned
|
|
6
|
+
* as-is, so callers relying on that distinction keep working.
|
|
7
|
+
*
|
|
8
|
+
* Bracket indexes are normalised into path segments, so `a[0].b` and `a.0.b`
|
|
9
|
+
* resolve alike. Without that, a bracketed path would silently miss and return
|
|
10
|
+
* the fallback instead of the value that is actually there.
|
|
11
|
+
*/
|
|
12
|
+
export declare function get<T>(source: unknown, path: string, fallback: T): T;
|
package/dist/helpers/utils.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export declare const getBrowserInfo: () => {
|
|
|
9
9
|
};
|
|
10
10
|
export declare const getBusinessId: (merchantData: any) => any;
|
|
11
11
|
declare const clearSpace: (text: string) => string;
|
|
12
|
-
declare const getCardType: (scheme: string
|
|
12
|
+
declare const getCardType: (scheme: string, mode?: "production" | "sandbox" | "stage" | "development") => string;
|
|
13
13
|
export { getCardType, clearSpace, };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{get as e}from"lodash";import t from"skyflow-js";function r(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{d(o.next(e))}catch(e){i(e)}}function a(e){try{d(o.throw(e))}catch(e){i(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}function o(e,t,r,o){if("a"===r&&!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"===r?o:"a"===r?o.call(e):o?o.value:t.get(e)}function n(e,t,r,o,n){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?n.call(e,r):n?n.value=r:t.set(e,r),r}function i(e,t,o){return r(this,void 0,void 0,(function*(){const r=yield fetch(`${e}/api/v1/payments/business/${t}`,{headers:{Authorization:`Token ${t}`},signal:o});return yield r.json()}))}var s;"function"==typeof SuppressedError&&SuppressedError,function(e){e.INIT_ERROR="INIT_ERROR",e.CREATE_ERROR="CREATE_ERROR",e.REMOVE_SDK_ERROR="REMOVE_SDK_ERROR",e.INVALID_TYPE="INVALID_TYPE",e.STATE_ERROR="STATE_ERROR",e.FETCH_BUSINESS_ERROR="FETCH_BUSINESS_ERROR",e.INVALID_CONFIG="INVALID_CONFIG",e.MERCHANT_CREDENTIAL_REQUIRED="MERCHANT_CREDENTIAL_REQUIRED",e.INVALID_PAYMENT_REQUEST="INVALID_PAYMENT_REQUEST",e.INVALID_PAYMENT_REQUEST_CARD_PM="INVALID_PAYMENT_REQUEST_CARD_PM",e.TYPE_SDK_REQUIRED="TYPE_SDK_REQUIRED",e.ENVIRONMENT_REQUIRED="ENVIRONMENT_REQUIRED",e.FETCH_CARDS_ERROR="FETCH_CARDS_ERROR",e.FETCH_TRANSACTION_ERROR="FETCH_TRANSACTION_ERROR",e.CUSTOMER_AUTH_TOKEN_NOT_VALID="CUSTOMER_AUTH_TOKEN_NOT_VALID",e.SAVE_CARD_ERROR="SAVE_CARD_ERROR",e.REMOVE_CARD_ERROR="REMOVE_CARD_ERROR",e.SUMMARY_CARD_ERROR="SUMMARY_CARD_ERROR",e.CREATE_PAYMENT_ERROR="CREATE_PAYMENT_ERROR",e.PAYMENT_PROCESS_ERROR="PAYMENT_PROCESS_ERROR",e.INVALID_CARD_DATA="INVALID_CARD_DATA",e.SAVE_CARD_PROCESS_ERROR="SAVE_CARD_PROCESS_ERROR",e.START_CHECKOUT_ERROR="START_CHECKOUT_ERROR",e.CREATE_ORDER_ERROR="CREATE_ORDER_ERROR",e.BUSINESS_ID_REQUIRED="BUSINESS_ID_REQUIRED",e.CLIENT_ID_REQUIRED="CLIENT_ID_REQUIRED",e.INVALID_AMOUNT="INVALID_AMOUNT",e.INVALID_ITEMS="INVALID_ITEMS",e.CUSTOMER_OPERATION_ERROR="CUSTOMER_OPERATION_ERROR",e.INVALID_EMAIL="INVALID_EMAIL",e.FETCH_PAYMENT_METHODS_ERROR="FETCH_PAYMENT_METHODS_ERROR",e.INVALID_VAULT_TOKEN="INVALID_VAULT_TOKEN",e.VAULT_TOKEN_ERROR="VAULT_TOKEN_ERROR",e.SECURE_TOKEN_ERROR="SECURE_TOKEN_ERROR",e.SECURE_TOKEN_INVALID="SECURE_TOKEN_INVALID",e.INVALID_SECRET_API_KEY="INVALID_SECRET_API_KEY",e.REMOVE_CARD="REMOVE_CARD",e.SKYFLOW_NOT_INITIALIZED="SKYFLOW_NOT_INITIALIZED",e.ERROR_LOAD_PAYMENT_FORM="ERROR_LOAD_PAYMENT_FORM",e.ERROR_LOAD_ENROLLMENT_FORM="ERROR_LOAD_ENROLLMENT_FORM",e.MOUNT_COLLECT_ERROR="MOUNT_COLLECT_ERROR",e.CARD_ON_FILE_DECLINED="CARD_ON_FILE_DECLINED",e.CARD_SAVED_SUCCESSFULLY="CARD_SAVED_SUCCESSFULLY",e.CARD_REMOVED_SUCCESSFULLY="CARD_REMOVED_SUCCESSFULLY",e.REQUEST_ABORTED="REQUEST_ABORTED",e.REQUEST_FAILED="REQUEST_FAILED",e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.THREEDS_REDIRECTION_ERROR="THREEDS_REDIRECTION_ERROR"}(s||(s={}));const a={[s.INIT_ERROR]:"Error initializing the SDK.",[s.INVALID_TYPE]:"SDK Type invalid.",[s.STATE_ERROR]:"Error updating SDK state.",[s.FETCH_BUSINESS_ERROR]:"Error retrieving merchant information.",[s.INVALID_CONFIG]:"Required configuration options.",[s.MERCHANT_CREDENTIAL_REQUIRED]:"Merchant credential required.",[s.INVALID_PAYMENT_REQUEST]:"The payment data must be of type: :::interface:::.",[s.INVALID_PAYMENT_REQUEST_CARD_PM]:"The fields card and payment_method cannot be provided together.",[s.TYPE_SDK_REQUIRED]:"SDK type required.",[s.ENVIRONMENT_REQUIRED]:"Environment required.",[s.FETCH_CARDS_ERROR]:"Error retrieving cards.",[s.CUSTOMER_AUTH_TOKEN_NOT_VALID]:"The customer's auth token is invalid. Please verify that the customer's data was provided when creating the SDK (sdk.create) and try again.",[s.SAVE_CARD_ERROR]:"Error saving the card.",[s.REMOVE_CARD_ERROR]:"Error deleting the card.",[s.CREATE_PAYMENT_ERROR]:"Error creating the payment.",[s.PAYMENT_PROCESS_ERROR]:"There was an issue processing the payment.",[s.CARD_SAVED_SUCCESSFULLY]:"Card saved successfully.",[s.CARD_REMOVED_SUCCESSFULLY]:"Card deleted successfully.",[s.SAVE_CARD_PROCESS_ERROR]:"Error processing card data.",[s.START_CHECKOUT_ERROR]:"Error processing the payment.",[s.CREATE_ORDER_ERROR]:"Error creating the order.",[s.BUSINESS_ID_REQUIRED]:"Business ID is required.",[s.CLIENT_ID_REQUIRED]:"Client ID is required.",[s.INVALID_AMOUNT]:"Invalid amount.",[s.INVALID_ITEMS]:"Invalid items.",[s.CUSTOMER_OPERATION_ERROR]:"Error registering or fetching customer",[s.INVALID_EMAIL]:"Invalid email.",[s.FETCH_PAYMENT_METHODS_ERROR]:"Error retrieving active payment methods.",[s.INVALID_VAULT_TOKEN]:"An invalid vault token response was received.",[s.VAULT_TOKEN_ERROR]:"Error retrieving the vault token.",[s.SECURE_TOKEN_ERROR]:"Error getting secure token.",[s.SECURE_TOKEN_INVALID]:"Invalid secure token.",[s.INVALID_SECRET_API_KEY]:"SECRET API KEY is required.",[s.REMOVE_CARD]:"Card deleted successfully",[s.SKYFLOW_NOT_INITIALIZED]:"Skyflow not initialized.",[s.ERROR_LOAD_PAYMENT_FORM]:"There was an issue loading the payment form.",[s.INVALID_CARD_DATA]:"Invalid card data.",[s.ERROR_LOAD_ENROLLMENT_FORM]:"There was an issue loading the card form.",[s.MOUNT_COLLECT_ERROR]:"Mount failed. Make sure all inputs are complete and valid.",[s.CARD_ON_FILE_DECLINED]:"Transaction declined. Please verify your card details.",[s.REQUEST_ABORTED]:"Requests canceled.",[s.REQUEST_FAILED]:"Request failed.",[s.UNKNOWN_ERROR]:"An unexpected error occurred.",[s.CREATE_ERROR]:"Error creating the SDK.",[s.FETCH_TRANSACTION_ERROR]:"Error retrieving the transaction.",[s.THREEDS_REDIRECTION_ERROR]:"Ocurrió un error durante la redirección de 3DS.",[s.REMOVE_SDK_ERROR]:"Ocurrió un error removiendo la instancia del SDK."};s.INIT_ERROR,s.STATE_ERROR,s.FETCH_BUSINESS_ERROR,s.INVALID_CONFIG,s.TYPE_SDK_REQUIRED,s.ENVIRONMENT_REQUIRED,s.FETCH_CARDS_ERROR,s.SAVE_CARD_ERROR,s.REMOVE_CARD_ERROR,s.CREATE_PAYMENT_ERROR,s.START_CHECKOUT_ERROR,s.CREATE_ORDER_ERROR,s.BUSINESS_ID_REQUIRED,s.CLIENT_ID_REQUIRED,s.INVALID_AMOUNT,s.INVALID_ITEMS,s.CUSTOMER_OPERATION_ERROR,s.INVALID_EMAIL,s.FETCH_PAYMENT_METHODS_ERROR,s.INVALID_VAULT_TOKEN,s.VAULT_TOKEN_ERROR,s.SECURE_TOKEN_ERROR,s.INVALID_SECRET_API_KEY,s.CUSTOMER_AUTH_TOKEN_NOT_VALID,s.SECURE_TOKEN_INVALID,s.REMOVE_CARD,s.SKYFLOW_NOT_INITIALIZED,s.INVALID_TYPE,s.PAYMENT_PROCESS_ERROR,s.INVALID_PAYMENT_REQUEST,s.INVALID_PAYMENT_REQUEST_CARD_PM,s.SAVE_CARD_PROCESS_ERROR,s.ERROR_LOAD_PAYMENT_FORM,s.INVALID_CARD_DATA,s.ERROR_LOAD_ENROLLMENT_FORM,s.MOUNT_COLLECT_ERROR,s.CARD_ON_FILE_DECLINED,s.CARD_SAVED_SUCCESSFULLY,s.CARD_REMOVED_SUCCESSFULLY,s.REQUEST_ABORTED,s.REQUEST_FAILED,s.UNKNOWN_ERROR,s.CREATE_ERROR,s.FETCH_TRANSACTION_ERROR,s.THREEDS_REDIRECTION_ERROR,s.REMOVE_SDK_ERROR;class d extends Error{constructor(e){var t,r;const o=e.message||a[e.code]||"Unknown error";super(o),this.name="TonderError",this.code=e.code,this.details={code:(null===(t=e.details)||void 0===t?void 0:t.code)||e.code,message:(null===(r=e.details)||void 0===r?void 0:r.message)||o}}}const l=()=>({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}),c=e=>{var t;return e&&"business"in e?null===(t=null==e?void 0:e.business)||void 0===t?void 0:t.pk:""},u="__tonderLockErrorCode__";function h(e){return"object"==typeof e&&null!==e}class E extends Error{constructor(e){var t,r;const o=E.resolveStatusCode(e.statusCode,e.originalError),n=E.resolveMessage(e.errorCode,e.message),i=E.resolveSystemError(null===(t=e.details)||void 0===t?void 0:t.systemError,e.originalError);super(n),this.status="error",Object.setPrototypeOf(this,new.target.prototype),this.name="TonderError",this.code=e.errorCode,this.statusCode=o,this.originalError=e.originalError,this.details={code:e.errorCode,statusCode:o,systemError:i},e.lockErrorCode&&Object.defineProperty(this,u,{value:!0,enumerable:!1,configurable:!0}),null===(r=Error.captureStackTrace)||void 0===r||r.call(Error,this,E)}static isRecord(e){return"object"==typeof e&&null!==e}static parseStatusCode(e){const t=Number(e);return Number.isFinite(t)?t<100||t>599?500:Math.trunc(t):500}static resolveStatusCode(e,t){const r=[e];if(E.isRecord(t)){r.push(t.statusCode,t.status);const e=E.isRecord(t.body)?t.body:null;e&&r.push(e.statusCode,e.status)}for(const e of r)if(E.isHttpStatusCode(e))return Math.trunc(Number(e));return 500}static resolveMessage(e,t){return t||(a[e]||a[s.UNKNOWN_ERROR]||"An unexpected error occurred.")}static isHttpStatusCode(e){const t=Number(e);return Number.isFinite(t)&&t>=100&&t<=599}static normalizeSystemError(e){if("string"!=typeof e)return null;return e.trim()||null}static resolveSystemError(e,t){const r=[e];if(E.isRecord(t)){const e=E.isRecord(t.details)?t.details:null,o=E.isRecord(t.body)?t.body:null,n=o&&E.isRecord(o.details)?o.details:null;r.push(t.systemError,t.code,null==e?void 0:e.systemError,null==e?void 0:e.code,null==o?void 0:o.systemError,null==o?void 0:o.code,null==n?void 0:n.systemError,null==n?void 0:n.code)}for(const e of r){const t=E.normalizeSystemError(e);if(t)return t}return"APP_INTERNAL_001"}}function _(e){return h(e)&&!0===e[u]}function p(e){return e instanceof E&&void 0!==e.originalError?e.originalError:e}function R(e,t){var r;if(!(null==e?void 0:e.errorCode))throw new Error("buildPublicAppError requires errorCode");const o=null===(r=e.details)||void 0===r?void 0:r.systemError,n=!!e.message||void 0!==e.statusCode||void 0!==o;return!function(e){return h(e)&&"TonderError"===e.name&&"string"==typeof e.code}(t)||(e.lockErrorCode&&function(e){Object.defineProperty(e,u,{value:!0,enumerable:!1,configurable:!0})}(t),n||e.errorCode!==t.code&&!_(t))?new E({errorCode:e.errorCode,message:e.message,statusCode:e.statusCode,details:void 0!==o?{systemError:o}:void 0,originalError:p(t),lockErrorCode:e.lockErrorCode||_(t)}):t}function m(e){var t,o;return r(this,void 0,void 0,(function*(){const n=yield function(e){return r(this,void 0,void 0,(function*(){try{return yield e.clone().json()}catch(e){}try{return(yield e.text())||void 0}catch(e){return}}))}(e.response),i={status:e.response.status};return e.response.statusText&&(i.statusText=e.response.statusText),void 0!==n&&(i.body=n),new E({errorCode:e.errorCode,message:e.message,statusCode:null!==(t=e.statusCode)&&void 0!==t?t:e.response.status,details:void 0!==(null===(o=e.details)||void 0===o?void 0:o.systemError)?{systemError:e.details.systemError}:void 0,originalError:i,lockErrorCode:e.lockErrorCode})}))}function y(e,t){return(null==e?void 0:e.response)?m(e):R(e,t)}class v{constructor({payload:e=null,apiKey:t,baseUrl:r,redirectOnComplete:o,tdsIframeId:n,tonderPayButtonId:i,callBack:s}){this.localStorageKey="verify_transaction_status_url",this.setPayload=e=>{this.payload=e},this.baseUrl=r,this.apiKey=t,this.payload=e,this.tdsIframeId=n,this.tonderPayButtonId=i,this.redirectOnComplete=o,this.callBack=s}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,r,o,n,i;const s=null===(r=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===r?void 0:r.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const e=null===(i=null===(n=null===(o=this.payload)||void 0===o?void 0:o.next_action)||void 0===n?void 0:n.iframe_resources)||void 0===i?void 0:i.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,r;if(null===(r=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.iframe_resources)||void 0===r?void 0:r.iframe)return new Promise(((e,t)=>{var r,o,n;const i=null===(n=null===(o=null===(r=this.payload)||void 0===r?void 0:r.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===n?void 0:n.iframe;if(i){this.saveVerifyTransactionUrl();const r=document.createElement("div");r.innerHTML=i,document.body.appendChild(r);const o=document.createElement("script");o.textContent='document.getElementById("tdsMmethodForm").submit();',r.appendChild(o);const n=document.getElementById("tdsMmethodTgtFrame");n?n.onload=()=>e(!0):(console.log("No redirection found"),t(!1))}else console.log("No redirection found"),t(!1)}))}getRedirectUrl(){var e,t,r;return null===(r=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===r?void 0:r.url}redirectToChallenge(){const e=this.getRedirectUrl();if(e)if(this.saveVerifyTransactionUrl(),this.redirectOnComplete)window.location=e;else{const t=document.querySelector(`#${this.tdsIframeId}`);if(t){t.setAttribute("src",e),t.setAttribute("style","display: block");const o=this,n=e=>r(this,void 0,void 0,(function*(){const e=()=>{try{const e=document.querySelector(`#${this.tonderPayButtonId}`);e&&(e.disabled=!1)}catch(e){}t&&t.setAttribute("style","display: none"),o.callBack&&o.callBack(o.payload),t.removeEventListener("load",n)},i=t=>r(this,void 0,void 0,(function*(){const n=yield new Promise(((e,r)=>e(t)));if(n){if((e=>"Pending"!==(null==e?void 0:e.transaction_status))(n))return e();{const e=setTimeout((()=>r(this,void 0,void 0,(function*(){clearTimeout(e),yield i(o.requestTransactionStatus())}))),7e3)}}}));yield i(o.requestTransactionStatus())}));t.addEventListener("load",n)}else console.log("No iframe found")}else this.callBack&&this.callBack(this.payload)}requestTransactionStatus(){return r(this,void 0,void 0,(function*(){const e=this.getUrlWithExpiration(),t=e.startsWith("https://")?e:`${this.baseUrl}${e}`,r=yield fetch(t,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`}});if(200!==r.status)return console.error("La verificación de la transacción falló."),null;return yield r.json()}))}getURLParameters(){const e={},t=new URLSearchParams(window.location.search);for(const[r,o]of t)e[r]=o;return e}handleSuccessTransaction(e){return this.removeVerifyTransactionUrl(),e}handleDeclinedTransaction(e){return this.removeVerifyTransactionUrl(),e}handle3dsChallenge(e){return r(this,void 0,void 0,(function*(){const t=document.createElement("form");t.name="frm",t.method="POST",t.action=e.redirect_post_url;const r=document.createElement("input");r.type="hidden",r.name=e.creq,r.value=e.creq,t.appendChild(r);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 r(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 r(this,void 0,void 0,(function*(){const e=this.getUrlWithExpiration();if(e){const t=e.startsWith("https://")?e:`${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")}))}}const f=Object.freeze({production:"https://app.tonder.io",sandbox:"https://sandbox.tonder.io",stage:"https://stage.tonder.io",development:"http://localhost:8000"});function C(e,t,o){return r(this,void 0,void 0,(function*(){const r=`${e}/api/v1/checkout-router/`,n=o,i=yield fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${t}`},body:JSON.stringify(Object.assign(Object.assign({},n),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}))});if(i.ok)return yield i.json();throw yield y({response:i,errorCode:s.START_CHECKOUT_ERROR})}))}function A(e,t,o=!0,n=null){return r(this,void 0,void 0,(function*(){let r=yield window.OpenPay;return r.setId(e),r.setApiKey(t),r.setSandboxMode(o),yield r.deviceData.setup({signal:n})}))}const O=Object.freeze({production:"https://api.tonder.io",sandbox:"https://api-stage.tonder.io",stage:"https://api-stage.tonder.io",development:"https://api-stage.tonder.io"}),T=Object.freeze({TELEMETRY:"/telemetry/v1/events",ACQ_SUBSCRIPTION_TOKEN:"/acq-kushki/subscription/token",ACQ_SUBSCRIPTION_CREATE:"/acq-kushki/subscription/create"});function g(e="stage"){return`${O[e]}${T.TELEMETRY}`}const S="https://cdn.kushkipagos.com/kushki.min.js",I=s.CARD_ON_FILE_DECLINED;let N=!1,D=null;class b{constructor(e){var t;this.acquirerInstance=null,this.isTestEnvironment=null===(t=e.isTestEnvironment)||void 0===t||t;const r=this.isTestEnvironment?"stage":"production";this.apiUrl=function(e="stage"){return O[e]}(r),this.merchantId=e.merchantId,this.apiKey=e.apiKey}initialize(){return r(this,void 0,void 0,(function*(){yield function(){return r(this,void 0,void 0,(function*(){return N?Promise.resolve():D||(D=new Promise(((e,t)=>{if(document.querySelector(`script[src="${S}"]`))return N=!0,void e();const r=document.createElement("script");r.src=S,r.async=!0,r.onload=()=>{N=!0,e()},r.onerror=()=>{D=null,t(y({errorCode:I,lockErrorCode:!0,details:{step:"load_acquirer_script",message:"Failed to load acquirer script"}}))},document.head.appendChild(r)})),D)}))}(),this.acquirerInstance=function(e,t){if(!window.Kushki)throw y({errorCode:I,lockErrorCode:!0,details:{step:"create_acquirer_instance",message:"Acquirer script not loaded. Call initialize() first."}});return new window.Kushki({merchantId:e,inTestEnvironment:t})}(this.merchantId,this.isTestEnvironment)}))}getAcquirerInstance(){if(!this.acquirerInstance)throw y({errorCode:I,lockErrorCode:!0,details:{step:"get_acquirer_instance",message:"CardOnFile not initialized. Call initialize() first."}});return this.acquirerInstance}getJwt(e){return r(this,void 0,void 0,(function*(){const t=this.getAcquirerInstance();return new Promise(((r,o)=>{t.requestSecureInit({card:{number:e}},(e=>{if("code"in e&&e.code)return void o(y({errorCode:I,lockErrorCode:!0,details:{step:"get_jwt",acquirerResponse:e}}));const t=e;t.jwt?r(t.jwt):o(y({errorCode:I,lockErrorCode:!0,details:{step:"get_jwt",message:"No JWT returned from acquirer",acquirerResponse:t}}))}))}))}))}generateToken(e){return r(this,void 0,void 0,(function*(){const t=yield fetch(`${this.apiUrl}${T.ACQ_SUBSCRIPTION_TOKEN}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`},body:JSON.stringify(e)});if(!t.ok)throw yield y({response:t,errorCode:I,lockErrorCode:!0,details:{step:"generate_token"}});return t.json()}))}createSubscription(e){return r(this,void 0,void 0,(function*(){const t=yield fetch(`${this.apiUrl}${T.ACQ_SUBSCRIPTION_CREATE}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`},body:JSON.stringify(e)});if(!t.ok)throw yield y({response:t,errorCode:I,lockErrorCode:!0,details:{step:"create_subscription"}});return t.json()}))}validate3DS(e,t){return r(this,void 0,void 0,(function*(){const r=this.getAcquirerInstance();return new Promise(((o,n)=>{r.requestValidate3DS({secureId:e,security:t},(e=>{const t=e;t.code&&"3DS000"!==t.code?n(y({errorCode:I,lockErrorCode:!0,details:{step:"validate_3ds",message:"3DS validation failed",acquirerResponse:t}})):!1!==t.isValid?o(!0):n(y({errorCode:I,lockErrorCode:!0,details:{step:"validate_3ds",message:"3DS validation failed",acquirerResponse:t}}))}))}))}))}process(e){var t,o;return r(this,void 0,void 0,(function*(){const r=yield this.getJwt(e.cardBin),n=yield this.generateToken({card:e.cardTokens,currency:e.currency,jwt:r}),i=n.secureId||(null===(t=n.details)||void 0===t?void 0:t.secureId),s=n.security||(null===(o=n.details)||void 0===o?void 0:o.security);if(!i||!s)throw y({errorCode:I,lockErrorCode:!0,details:{step:"process",message:"Missing secureId or security in token response",tokenResponse:n}});return yield this.validate3DS(i,s),this.createSubscription({token:n.token,contactDetails:e.contactDetails,metadata:{customerId:e.customerId},currency:e.currency})}))}}class M{constructor(e){this.REQUEST_TIMEOUT_MS=5e3,this.MAX_MESSAGE_LENGTH=500,this.config=e}captureException(e,t){try{const r=this.buildEvent(e,t||{});this.sendEvent(r)}catch(e){}}extractErrorInfo(e){try{if(e instanceof Error)return{name:e.name||"Error",message:this.truncate(e.message||"Unknown error",this.MAX_MESSAGE_LENGTH),stack:e.stack||void 0};const t=this.safeStringify(e);return{name:"NonErrorException",message:this.truncate(t,this.MAX_MESSAGE_LENGTH),stack:void 0}}catch(e){return{name:"SerializationError",message:"Failed to serialize error",stack:void 0}}}safeStringify(e){try{const t=new WeakSet;return JSON.stringify(e,((e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return"[Circular]";t.add(r)}return r}))}catch(t){return String(e)}}buildEvent(e,t){const r=this.extractErrorInfo(e),o=Object.assign({},t.metadata||{});void 0===o.error&&(o.error=e),"undefined"!=typeof window&&(o.url=window.location.href);const n={platform:this.config.platform,platform_version:this.config.platform_version,env:this.config.mode,feature:t.feature||"unknown",level:"error",message:r.message,name:r.name,metadata:o};return t.tenant_id&&(n.tenant_id=t.tenant_id),t.request_id&&(n.request_id=t.request_id),t.process_id&&(n.process_id=t.process_id),t.user_id&&(n.user_id=t.user_id),r.stack&&(n.stack=r.stack),t.error_code&&(n.error_code=t.error_code),t.http_status&&(n.http_status=t.http_status),n}truncate(e,t){return e.length<=t?e:e.substring(0,t)+"..."}sendEvent(e){this.sendHttpRequest(e).then((()=>{})).catch((()=>{}))}sendHttpRequest(e){return r(this,void 0,void 0,(function*(){try{const t=JSON.stringify(e),r=new AbortController,o=setTimeout((()=>r.abort()),this.REQUEST_TIMEOUT_MS);try{const e=yield fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.config.apiKey}`},body:t,keepalive:!0,signal:r.signal});return clearTimeout(o),e.ok}catch(e){return clearTimeout(o),!1}}catch(e){return!1}}))}}const k=Object.freeze({name:"@tonder.io/ionic-lite-sdk",version:"1.0.0"});var U,L,P,w,j,V,F,K,x,B,Y,$,H;class z{constructor({mode:e="stage",customization:t,apiKey:r,apiKeyTonder:o,returnUrl:n,tdsIframeId:i,callBack:s=(()=>{}),baseUrlTonder:a,tonderPayButtonId:d,sdkInfo:l}){U.add(this),this.baseUrl="",this.cartTotal="0",this.secureToken="",this.customization={redirectOnComplete:!0},this.metadata={},this.order_reference=null,this.card={},this.currency="",this.cardOnFileInstance=null,L.set(this,void 0),P.set(this,void 0),this.apiKeyTonder=o||r||"",this.returnUrl=n,this.callBack=s,this.mode=e,this.customer={},this.baseUrl=a||f[this.mode]||f.stage,this.abortController=new AbortController,this.requestId=this.generateRequestId(),this.customization=Object.assign(Object.assign({},this.customization),t||{}),this.process3ds=new v({apiKey:r,baseUrl:this.baseUrl,redirectOnComplete:this.customization.redirectOnComplete,tdsIframeId:i,tonderPayButtonId:d,callBack:s}),this.tdsIframeId=i;const c=l||k;this.telemetry=new M({endpoint:g(this.mode),apiKey:this.apiKeyTonder,platform:c.name,platform_version:c.version,mode:this.mode||"stage"})}configureCheckout(e){"secureToken"in e&&o(this,U,"m",V).call(this,e.secureToken),o(this,U,"m",w).call(this,e)}getCustomerId(){var e,t;return null===(t=null===(e=o(this,P,"f"))||void 0===e?void 0:e.id)||void 0===t?void 0:t.toString()}reportSdkError(e,t){var r,o,n,i;try{const s=this.getCustomerId(),a=e instanceof E&&void 0!==e.originalError?e.originalError:e,d=Object.assign(Object.assign({},(null==t?void 0:t.metadata)||{}),void 0===(null===(r=null==t?void 0:t.metadata)||void 0===r?void 0:r.error)?{error:a}:{}),l=Object.assign(Object.assign({tenant_id:null===(i=null===(n=null===(o=this.merchantData)||void 0===o?void 0:o.business)||void 0===n?void 0:n.pk)||void 0===i?void 0:i.toString(),user_id:s},t||{}),{metadata:d,request_id:this.requestId});l.user_id||delete l.user_id,l.feature=(null==t?void 0:t.feature)||"unknown",this.telemetry.captureException(e,l)}catch(e){}}generateRequestId(){return`req_${Date.now()}_${Math.random().toString(36).slice(2,10)}`}verify3dsTransaction(){return r(this,void 0,void 0,(function*(){const e=yield this.process3ds.verifyTransactionStatus(),t=yield o(this,U,"m",Y).call(this,e);return this.process3ds.setPayload(t),this._handle3dsRedirect(t)}))}payment(e){return new Promise(((t,n)=>r(this,void 0,void 0,(function*(){var r,i;let a;try{o(this,U,"m",w).call(this,e),a=yield this._checkout(e),this.process3ds.setPayload(a);if(yield this._handle3dsRedirect(a)){try{const e=document.querySelector(`#${this.tonderPayButtonId}`);e&&(e.disabled=!1)}catch(e){}this.callBack&&this.callBack(a),t(a)}}catch(t){this.reportSdkError(t,{feature:"payment",process_id:(null==a?void 0:a.payment_id)||(null===(r=null==a?void 0:a.payment)||void 0===r?void 0:r.id)||(null===(i=null==a?void 0:a.payment)||void 0===i?void 0:i.pk),metadata:{step:"payment",request:e,response:a}}),n(y({errorCode:s.PAYMENT_PROCESS_ERROR},t))}}))))}getSecureToken(e){return r(this,void 0,void 0,(function*(){try{return yield function(e,t,o=null){return r(this,void 0,void 0,(function*(){const r=yield fetch(`${e}/api/secure-token/`,{method:"POST",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},signal:o});if(r.ok)return yield r.json();throw yield y({response:r,errorCode:s.SECURE_TOKEN_ERROR})}))}(this.baseUrl,e)}catch(e){throw this.reportSdkError(e,{feature:"secure-token",metadata:{step:"getSecureToken"}}),y({errorCode:s.SECURE_TOKEN_ERROR},e)}}))}_initializeCheckout(){return r(this,void 0,void 0,(function*(){const e=yield this._fetchMerchantData();e&&e.mercado_pago&&e.mercado_pago.active&&function(){try{const e=document.createElement("script");e.src="https://www.mercadopago.com/v2/security.js",e.setAttribute("view",""),e.onload=()=>{},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)}}(),this._hasCardOnFileKeys()&&(yield this._initializeCardOnFile())}))}_checkout(e){return r(this,void 0,void 0,(function*(){throw new Error("The #checkout method should be implement in child classes.")}))}_setCartTotal(e){throw new Error("The #setCartTotal method should be implement in child classes.")}_getCustomer(e=null){return r(this,void 0,void 0,(function*(){return o(this,P,"f")||n(this,P,yield function(e,t,o,n=null){return r(this,void 0,void 0,(function*(){const r=`${e}/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},a=yield fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${t}`},signal:n,body:JSON.stringify(i)});if(a.ok)return yield a.json();throw yield y({response:a,errorCode:s.CUSTOMER_OPERATION_ERROR})}))}(this.baseUrl,this.apiKeyTonder,this.customer,e),"f"),o(this,P,"f")}))}_handleCheckout({card:t,payment_method:n,customer:i,isSandbox:a,enable_card_on_file:d,returnUrl:c}){return r(this,void 0,void 0,(function*(){const{openpay_keys:u,reference:h,business:E}=this.merchantData,_=Number(this.cartTotal);let p,R,m;try{let v;!v&&u.merchant_id&&u.public_key&&!n&&(v=yield A(u.merchant_id,u.public_key,a,this.abortController.signal));const{id:f,auth_token:O}=i;p={business:this.apiKeyTonder,client:O,billing_address_id:null,shipping_address_id:null,amount:_,status:"A",reference:h,is_oneclick:!0,items:this.cartItems,currency:this.currency,metadata:this.metadata};const T=yield function(e,t,o){return r(this,void 0,void 0,(function*(){const r=`${e}/api/v1/orders/`,n=o,i=yield fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${t}`},body:JSON.stringify(n)});if(i.ok)return yield i.json();throw yield y({response:i,errorCode:s.CREATE_ORDER_ERROR})}))}(this.baseUrl,this.apiKeyTonder,p),g=(new Date).toISOString();R={business_pk:E.pk,client_id:f,amount:_,date:g,order_id:T.id,customer_order_reference:this.order_reference?this.order_reference:h,items:this.cartItems,currency:this.currency,metadata:this.metadata};const S=yield function(e,t,o){return r(this,void 0,void 0,(function*(){const r=`${e}/api/v1/business/${o.business_pk}/payments/`,n=o,i=yield fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${t}`},body:JSON.stringify(n)});if(i.ok)return yield i.json();throw yield y({response:i,errorCode:s.CREATE_PAYMENT_ERROR})}))}(this.baseUrl,this.apiKeyTonder,R);m=Object.assign(Object.assign(Object.assign(Object.assign({name:e(this.customer,"firstName",e(this.customer,"name","")),last_name:e(this.customer,"lastName",e(this.customer,"lastname","")),email_client:e(this.customer,"email",""),phone_number:e(this.customer,"phone",""),return_url:c||this.returnUrl,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:_,title_ship:"shipping",description:"transaction",device_session_id:v||null,token_id:"",order_id:T.id,business_id:E.pk,payment_id:S.pk,source:"sdk",items:this.cartItems,metadata:this.metadata,browser_info:l(),currency:this.currency},n?{payment_method:n}:{card:t}),{apm_config:o(this,L,"f")}),this.customer&&"identification"in this.customer?{identification:this.customer.identification}:{}),void 0!==d?{enable_card_on_file:d}:{});const I=yield C(this.baseUrl,this.apiKeyTonder,m);return I||!1}catch(e){throw this.reportSdkError(e,{feature:"payment",process_id:null==m?void 0:m.payment_id,metadata:{step:"_handleCheckout",orderItems:p,paymentItems:R,routerItems:m}}),e}}))}_fetchMerchantData(){return r(this,void 0,void 0,(function*(){try{return this.merchantData||(this.merchantData=yield i(this.baseUrl,this.apiKeyTonder,this.abortController.signal)),this.merchantData}catch(e){return this.reportSdkError(e,{feature:"fetch-merchant-data",metadata:{step:"_fetchMerchantData"}}),this.merchantData}}))}_getCustomerCards(e,t){return r(this,void 0,void 0,(function*(){return yield function(e,t,o,n,i=null){return r(this,void 0,void 0,(function*(){const r=`${e}/api/v1/business/${n}/cards/`,a=yield fetch(r,{method:"GET",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json","User-token":t},signal:i});if(a.ok)return yield a.json();if(401===a.status)return{user_id:0,cards:[]};throw yield y({response:a,errorCode:s.FETCH_CARDS_ERROR})}))}(this.baseUrl,e,this.secureToken,t)}))}_saveCustomerCard(e,t,o,n=!1){return r(this,void 0,void 0,(function*(){return yield function(e,t,o,n,i,a=!1){return r(this,void 0,void 0,(function*(){const r=`${e}/api/v1/business/${n}/cards/`,d=yield fetch(r,{method:"POST",headers:Object.assign({Authorization:`Bearer ${o}`,"Content-Type":"application/json","User-token":t},a?{"X-App-Origin":"sdk/ionic"}:{}),body:JSON.stringify(i)});if(d.ok)return yield d.json();throw yield y({response:d,errorCode:s.SAVE_CARD_ERROR})}))}(this.baseUrl,e,this.secureToken,t,o,n)}))}_removeCustomerCard(e,t,o){return r(this,void 0,void 0,(function*(){return yield function(e,t,o,n="",i){return r(this,void 0,void 0,(function*(){const r=`${e}/api/v1/business/${i}/cards/${n}`,d=yield fetch(r,{method:"DELETE",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json","User-token":t}});if(204===d.status)return a[s.CARD_REMOVED_SUCCESSFULLY];if(d.ok&&"json"in d)return yield d.json();throw yield y({response:d,errorCode:s.REMOVE_CARD_ERROR})}))}(this.baseUrl,e,this.secureToken,o,t)}))}_fetchCustomerPaymentMethods(){return r(this,void 0,void 0,(function*(){return yield function(e,t,o={status:"active",pagesize:"10000"},n=null){return r(this,void 0,void 0,(function*(){const r=new URLSearchParams(o).toString(),i=yield fetch(`${e}/api/v1/payment_methods?${r}`,{method:"GET",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},signal:n});if(i.ok)return yield i.json();throw yield y({response:i,errorCode:s.FETCH_PAYMENT_METHODS_ERROR})}))}(this.baseUrl,this.apiKeyTonder)}))}_hasCardOnFileKeys(){var e,t;return!!(null===(t=null===(e=this.merchantData)||void 0===e?void 0:e.cardonfile_keys)||void 0===t?void 0:t.public_key)}_initializeCardOnFile(){var e;return r(this,void 0,void 0,(function*(){return this.cardOnFileInstance||(this.cardOnFileInstance=new b({merchantId:null===(e=this.merchantData)||void 0===e?void 0:e.cardonfile_keys.public_key,apiKey:this.apiKeyTonder,isTestEnvironment:"production"!==this.mode}),yield this.cardOnFileInstance.initialize()),this.cardOnFileInstance}))}_handle3dsRedirect(e){var t,o;return r(this,void 0,void 0,(function*(){if(e&&"next_action"in e?null===(o=null===(t=null==e?void 0:e.next_action)||void 0===t?void 0:t.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),this.reportSdkError(t,{feature:"3ds-verification",metadata:{step:"_handle3dsRedirect",response:e}})}));else{if(!this.process3ds.getRedirectUrl())return e;this.process3ds.redirectToChallenge()}}))}}function q(e,t,o=null){return r(this,void 0,void 0,(function*(){const r=yield fetch(`${e}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${t}`},signal:o});if(r.ok){return(yield r.json()).token}throw yield y({response:r,errorCode:s.VAULT_TOKEN_ERROR})}))}L=new WeakMap,P=new WeakMap,U=new WeakSet,w=function(e){var t,r;!e||e&&0===Object.keys(e).length||(o(this,U,"m",j).call(this,e.customer),this._setCartTotal((null===(t=e.cart)||void 0===t?void 0:t.total)||0),o(this,U,"m",F).call(this,(null===(r=e.cart)||void 0===r?void 0:r.items)||[]),o(this,U,"m",K).call(this,e),o(this,U,"m",x).call(this,e),o(this,U,"m",B).call(this,e),o(this,U,"m",$).call(this,e))},j=function(e){e&&(this.customer=e)},V=function(e){this.secureToken=e},F=function(e){this.cartItems=e},K=function(e){this.metadata=null==e?void 0:e.metadata,this.order_reference=null==e?void 0:e.order_reference},x=function(e){this.currency=null==e?void 0:e.currency},B=function(e){this.card=null==e?void 0:e.card},Y=function(e){var t,o,n,i,s;return r(this,void 0,void 0,(function*(){if("Hard"===(null===(t=null==e?void 0:e.decline)||void 0===t?void 0:t.error_type)||(null===(o=null==e?void 0:e.checkout)||void 0===o?void 0:o.is_route_finished)||(null==e?void 0:e.is_route_finished)||["Pending"].includes(null==e?void 0:e.transaction_status))return e;if(["Success","Authorized"].includes(null==e?void 0:e.transaction_status))return e;if(e){const t={checkout_id:(null===(n=e.checkout)||void 0===n?void 0:n.id)||(null==e?void 0:e.checkout_id)};try{return yield C(this.baseUrl,this.apiKeyTonder,t)}catch(t){this.reportSdkError(t,{feature:"payment",process_id:(null==e?void 0:e.payment_id)||(null===(i=null==e?void 0:e.payment)||void 0===i?void 0:i.id)||(null===(s=null==e?void 0:e.payment)||void 0===s?void 0:s.pk),metadata:{step:"#resumeCheckout",response:e}})}return e}}))},$=function(e){n(this,L,null==e?void 0:e.apm_config,"f")},function(e){e.CARD_NUMBER="card_number",e.CVV="cvv",e.EXPIRATION_MONTH="expiration_month",e.EXPIRATION_YEAR="expiration_year",e.CARDHOLDER_NAME="cardholder_name"}(H||(H={}));const X={type:t.ValidationRuleType.LENGTH_MATCH_RULE,params:{max:70}},Q=RegExp("^(?!s*$).+"),W={type:t.ValidationRuleType.REGEX_MATCH_RULE,params:{regex:Q,error:"El campo es requerido"}},J="Titular de la tarjeta",G="Número de tarjeta",Z="CVC/CVV",ee="Mes",te="Año",re="Fecha de expiración",oe="Nombre como aparece en la tarjeta",ne="1234 1234 1234 1234",ie="3-4 dígitos",se="MM",ae="AA",de={base:{border:"1px solid #e0e0e0",padding:"10px 7px",borderRadius:"5px",color:"#1d1d1d",marginTop:"2px",backgroundColor:"white",fontFamily:'"Inter", sans-serif',fontSize:"16px","&::placeholder":{color:"#ccc"}},complete:{color:"#4caf50"},invalid:{border:"1px solid #f44336"},empty:{},focus:{},global:{"@import":'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")'}},le={base:{fontSize:"12px",fontWeight:"500",fontFamily:'"Inter", sans-serif'}},ce={base:{fontSize:"12px",fontWeight:"500",fontFamily:'"Inter", sans-serif',color:"#f44336"}};function ue({baseUrl:e,apiKey:o,vault_id:n,vault_url:i,data:a}){return r(this,void 0,void 0,(function*(){const d=t.init({vaultID:n,vaultURL:i,getBearerToken:()=>r(this,void 0,void 0,(function*(){return yield q(e,o)})),options:{logLevel:t.LogLevel.ERROR,env:t.Env.DEV}}).container(t.ContainerType.COLLECT),l=yield function(e,o){return r(this,void 0,void 0,(function*(){const n=yield function(e,o){return r(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(e).map((e=>r(this,void 0,void 0,(function*(){return{element:yield o.create({table:"cards",column:e,type:t.ElementType.INPUT_FIELD}),key:e}})))))}))}(e,o);return n?n.map((t=>new Promise((r=>{var o;const n=document.createElement("div");n.hidden=!0,n.id=`id-${t.key}`,null===(o=document.querySelector("body"))||void 0===o||o.appendChild(n),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const o=e[t.key];return t.element.setValue(o),r(t.element.isMounted())}}),120)}),120)})))):[]}))}(a,d);if((yield Promise.all(l)).some((e=>!e)))throw y({errorCode:s.SAVE_CARD_PROCESS_ERROR,details:{step:"get_skyflow_tokens"}});try{const e=yield d.collect();if(e)return e.records[0].fields;throw y({errorCode:s.SAVE_CARD_PROCESS_ERROR,details:{step:"get_skyflow_tokens"}})}catch(e){throw y({errorCode:s.SAVE_CARD_PROCESS_ERROR},e)}}))}function he(e){const{element:r,fieldMessage:o="",errorStyles:n={},requiredMessage:i="Campo requerido",invalidMessage:s="Campo no válido",events:a}=e;"on"in r&&(r.on(t.EventName.CHANGE,(e=>{_e({eventName:"onChange",data:e,events:a}),Ee({element:r,errorStyles:n,color:"transparent"})})),r.on(t.EventName.BLUR,(e=>{if(_e({eventName:"onBlur",data:e,events:a}),!e.isValid){const t=e.isEmpty?i:""!=o?`El campo ${o} no es válido`:s;r.setError(t)}Ee({element:r,errorStyles:n})})),r.on(t.EventName.FOCUS,(e=>{_e({eventName:"onFocus",data:e,events:a}),Ee({element:r,errorStyles:n,color:"transparent"}),r.resetError()})))}function Ee(e){const{element:t,errorStyles:r={},color:o=""}=e;Object.keys(r).length>0&&t.update({errorTextStyles:Object.assign(Object.assign({},r),{base:Object.assign(Object.assign({},r.base&&Object.assign({},r.base)),""!=o&&{color:o})})})}const _e=t=>{const{eventName:r,data:o,events:n}=t;if(n&&r in n){const t=n[r];"function"==typeof t&&t({elementType:e(o,"elementType",""),isEmpty:e(o,"isEmpty",!1),isFocused:e(o,"isFocused",!1),isValid:e(o,"isValid",!1),value:e(o,"value","")})}};function pe(e){return r(this,void 0,void 0,(function*(){const{element:t,containerId:r,retries:o=2,delay:n=30}=e;for(let e=0;e<=o;e++){if(document.querySelector(r))return void t.mount(r);e<o&&(yield new Promise((e=>setTimeout(e,n))))}console.warn(`[mountCardFields] Container ${r} was not found after ${o+1} attempts`)}))}const Re=Object.freeze({SORIANA:"SORIANA",OXXO:"OXXO",OXXOPAY:"OXXOPAY",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"}),me={[Re.SORIANA]:{label:"Soriana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png"},[Re.OXXO]:{label:"Oxxo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png"},[Re.CODI]:{label:"CoDi",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png"},[Re.MERCADOPAGO]:{label:"Mercado Pago",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/mercadopago.png"},[Re.OXXOPAY]:{label:"Oxxo Pay",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxopay.png"},[Re.SPEI]:{label:"SPEI",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png"},[Re.PAYPAL]:{label:"Paypal",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png"},[Re.COMERCIALMEXICANA]:{label:"Comercial Mexicana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png"},[Re.BANCOMER]:{label:"Bancomer",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png"},[Re.WALMART]:{label:"Walmart",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png"},[Re.BODEGA]:{label:"Bodega Aurrera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png"},[Re.SAMSCLUB]:{label:"Sam´s Club",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png"},[Re.SUPERAMA]:{label:"Superama",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png"},[Re.CALIMAX]:{label:"Calimax",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png"},[Re.EXTRA]:{label:"Tiendas Extra",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png"},[Re.CIRCULOK]:{label:"Círculo K",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png"},[Re.SEVEN11]:{label:"7 Eleven",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png"},[Re.TELECOMM]:{label:"Telecomm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png"},[Re.BANORTE]:{label:"Banorte",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png"},[Re.BENAVIDES]:{label:"Farmacias Benavides",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png"},[Re.DELAHORRO]:{label:"Farmacias del Ahorro",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png"},[Re.ELASTURIANO]:{label:"El Asturiano",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png"},[Re.WALDOS]:{label:"Waldos",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png"},[Re.ALSUPER]:{label:"Alsuper",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png"},[Re.KIOSKO]:{label:"Kiosko",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png"},[Re.STAMARIA]:{label:"Farmacias Santa María",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png"},[Re.LAMASBARATA]:{label:"Farmacias la más barata",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png"},[Re.FARMROMA]:{label:"Farmacias Roma",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png"},[Re.FARMUNION]:{label:"Pago en Farmacias Unión",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png"},[Re.FARMATODO]:{label:"Pago en Farmacias Farmatodo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png\t"},[Re.SFDEASIS]:{label:"Pago en Farmacias San Francisco de Asís",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png"},[Re.FARM911]:{label:"Farmacias 911",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.FARMECONOMICAS]:{label:"Farmacias Economicas",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.FARMMEDICITY]:{label:"Farmacias Medicity",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.RIANXEIRA]:{label:"Rianxeira",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.WESTERNUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.ZONAPAGO]:{label:"Zona Pago",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.CAJALOSANDES]:{label:"Caja Los Andes",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.CAJAPAITA]:{label:"Caja Paita",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.CAJASANTA]:{label:"Caja Santa",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.CAJASULLANA]:{label:"Caja Sullana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.CAJATRUJILLO]:{label:"Caja Trujillo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.EDPYME]:{label:"Edpyme",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.KASNET]:{label:"KasNet",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.NORANDINO]:{label:"Norandino",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.QAPAQ]:{label:"Qapaq",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.RAIZ]:{label:"Raiz",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.PAYSER]:{label:"Paysera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.WUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.BANCOCONTINENTAL]:{label:"Banco Continental",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.GMONEY]:{label:"Go money",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.GOPAY]:{label:"Go pay",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.WU]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.PUNTOSHEY]:{label:"Puntoshey",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.AMPM]:{label:"Ampm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.JUMBOMARKET]:{label:"Jumbomarket",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.SMELPUEBLO]:{label:"Smelpueblo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.BAM]:{label:"Bam",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.REFACIL]:{label:"Refacil",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[Re.ACYVALORES]:{label:"Acyvalores",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"}},ye=e=>{const t=e.toUpperCase().trim().replace(/\s+/g,"");return me[t]||{icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",label:""}};class ve extends z{constructor({apiKey:e,mode:t,returnUrl:r,callBack:o,apiKeyTonder:n,baseUrlTonder:i,customization:s,collectorIds:a,events:d}){super({mode:t,apiKey:e,returnUrl:r,callBack:o,apiKeyTonder:n,baseUrlTonder:i,customization:s,tdsIframeId:a&&"tdsIframe"in a?null==a?void 0:a.tdsIframe:"tdsIframe",sdkInfo:k}),this.activeAPMs=[],this.mountedElementsByContext=new Map,this.customerCardsCache=null,this.lastCollectedTokens=null,this.skyflowInstance=null,this.events=d||{}}injectCheckout(){return r(this,void 0,void 0,(function*(){yield this._initializeCheckout()}))}getCustomerCards(){return r(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:e}=yield this._getCustomer(),t=yield this._getCustomerCards(e,this.merchantData.business.pk);return this.customerCardsCache=t,Object.assign(Object.assign({},t),{cards:t.cards.map((e=>{return Object.assign(Object.assign({},e),{fields:Object.assign(Object.assign({},e.fields),{subscription_id:this._hasCardOnFileKeys()?e.fields.subscription_id:void 0}),icon:(t=e.fields.card_scheme,"Visa"===t?"https://d35a75syrgujp0.cloudfront.net/cards/visa.png":"Mastercard"===t?"https://d35a75syrgujp0.cloudfront.net/cards/mastercard.png":"American Express"===t?"https://d35a75syrgujp0.cloudfront.net/cards/american_express.png":"https://d35a75syrgujp0.cloudfront.net/cards/default_card.png")});var t}))})}catch(e){throw this.reportSdkError(e,{feature:"get-cards",process_id:this.getCustomerId(),metadata:{step:"getCustomerCards"}}),y({errorCode:s.FETCH_CARDS_ERROR},e)}}))}saveCustomerCard(){return r(this,void 0,void 0,(function*(){let e=null;try{yield this._fetchMerchantData();const t=yield this._getCustomer(),{auth_token:r,first_name:o="",last_name:n="",email:i=""}=t,{business:a}=this.merchantData,d=this._hasCardOnFileKeys(),l=yield this.collectCreateCardTokens(),c=yield this._saveCustomerCard(r,null==a?void 0:a.pk,l,d);if(e=c.skyflow_id,d){const e=c.card_bin;if(!e)throw new Error("Card BIN not returned from save card");const t=yield this._initializeCardOnFile();let d;try{d=yield t.process({cardTokens:{name:l.cardholder_name,number:l.card_number,expiryMonth:l.expiration_month,expiryYear:l.expiration_year,cvv:l.cvv},cardBin:e,contactDetails:{firstName:o||"",lastName:n||"",email:i||""},customerId:r,currency:this.currency||"MXN"})}catch(e){throw y({errorCode:s.CARD_ON_FILE_DECLINED,lockErrorCode:!0},e)}const u={skyflow_id:l.skyflow_id,subscription_id:d.subscriptionId};yield this._saveCustomerCard(r,null==a?void 0:a.pk,u)}return c}catch(t){throw e&&(yield this.removeCustomerCard(e)),this.reportSdkError(t,{feature:"save-card",process_id:e||this.getCustomerId(),metadata:{step:"saveCustomerCard"}}),y({errorCode:s.SAVE_CARD_ERROR},t)}}))}removeCustomerCard(e){return r(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:t}=yield this._getCustomer(),{business:r}=this.merchantData;return yield this._removeCustomerCard(t,null==r?void 0:r.pk,e)}catch(t){throw this.reportSdkError(t,{feature:"remove-card",process_id:e,metadata:{step:"removeCustomerCard"}}),y({errorCode:s.REMOVE_CARD_ERROR},t)}}))}getCustomerPaymentMethods(){return r(this,void 0,void 0,(function*(){try{const e=yield this._fetchCustomerPaymentMethods();return(e&&"results"in e&&e.results.length>0?e.results:[]).filter((e=>"cards"!==e.category.toLowerCase())).map((e=>Object.assign({id:e.pk,payment_method:e.payment_method,priority:e.priority,category:e.category},ye(e.payment_method)))).sort(((e,t)=>e.priority-t.priority))}catch(e){throw this.reportSdkError(e,{feature:"get-payment-methods",metadata:{step:"getCustomerPaymentMethods"}}),y({errorCode:s.FETCH_PAYMENT_METHODS_ERROR},e)}}))}mountCardFields(e){var o;return r(this,void 0,void 0,(function*(){const n=e.card_id?`update:${e.card_id}`:"create",i=null!==(o=e.unmount_context)&&void 0!==o?o:"all";"none"!==i&&("current"===i?this.unmountCardFields(n):this.unmountCardFields(i)),yield this.createSkyflowInstance();const s=yield function(e){var o,n,i,s,a,d,l,c,u,h,E,_,p;return r(this,void 0,void 0,(function*(){const{skyflowInstance:r,data:R,customization:m,events:y}=e,v=r.container(t.ContainerType.COLLECT),f=[],C={[H.CVV]:t.ElementType.CVV,[H.CARD_NUMBER]:t.ElementType.CARD_NUMBER,[H.EXPIRATION_MONTH]:t.ElementType.EXPIRATION_MONTH,[H.EXPIRATION_YEAR]:t.ElementType.EXPIRATION_YEAR,[H.CARDHOLDER_NAME]:t.ElementType.CARDHOLDER_NAME},A={[H.CVV]:[W],[H.CARD_NUMBER]:[W],[H.EXPIRATION_MONTH]:[W],[H.EXPIRATION_YEAR]:[W],[H.CARDHOLDER_NAME]:[X,W]},O={[H.CARDHOLDER_NAME]:"cardholderName",[H.CARD_NUMBER]:"cardNumber",[H.CVV]:"cvv",[H.EXPIRATION_MONTH]:"expirationMonth",[H.EXPIRATION_YEAR]:"expirationYear"},T=e=>{var t,r,o,n,i,s,a,d,l;const c=null===(t=null==m?void 0:m.styles)||void 0===t?void 0:t[O[e]],u=null===(r=null==m?void 0:m.styles)||void 0===r?void 0:r.cardForm,h=null!==(n=null!==(o=null==c?void 0:c.inputStyles)&&void 0!==o?o:null==u?void 0:u.inputStyles)&&void 0!==n?n:de;return{inputStyles:e===H.CARD_NUMBER&&!1!==(null===(i=null==m?void 0:m.styles)||void 0===i?void 0:i.enableCardIcon)?Object.assign(Object.assign({},h),{base:Object.assign({paddingLeft:"15px"},null==h?void 0:h.base)}):h,labelStyles:null!==(a=null!==(s=null==c?void 0:c.labelStyles)&&void 0!==s?s:null==u?void 0:u.labelStyles)&&void 0!==a?a:le,errorStyles:null!==(l=null!==(d=null==c?void 0:c.errorStyles)&&void 0!==d?d:null==u?void 0:u.errorStyles)&&void 0!==l?l:ce}},g={cardholder_name:(null===(o=null==m?void 0:m.labels)||void 0===o?void 0:o.name)||J,card_number:(null===(n=null==m?void 0:m.labels)||void 0===n?void 0:n.card_number)||G,cvv:(null===(i=null==m?void 0:m.labels)||void 0===i?void 0:i.cvv)||Z,expiration_date:(null===(s=null==m?void 0:m.labels)||void 0===s?void 0:s.expiry_date)||re,expiration_month:(null===(a=null==m?void 0:m.labels)||void 0===a?void 0:a.expiration_month)||ee,expiration_year:(null===(d=null==m?void 0:m.labels)||void 0===d?void 0:d.expiration_year)||te},S={cardholder_name:(null===(l=null==m?void 0:m.placeholders)||void 0===l?void 0:l.name)||oe,card_number:(null===(c=null==m?void 0:m.placeholders)||void 0===c?void 0:c.card_number)||ne,cvv:(null===(u=null==m?void 0:m.placeholders)||void 0===u?void 0:u.cvv)||ie,expiration_month:(null===(h=null==m?void 0:m.placeholders)||void 0===h?void 0:h.expiration_month)||se,expiration_year:(null===(E=null==m?void 0:m.placeholders)||void 0===E?void 0:E.expiration_year)||ae},I={[H.CVV]:null==y?void 0:y.cvvEvents,[H.CARD_NUMBER]:null==y?void 0:y.cardNumberEvents,[H.EXPIRATION_MONTH]:null==y?void 0:y.monthEvents,[H.EXPIRATION_YEAR]:null==y?void 0:y.yearEvents,[H.CARDHOLDER_NAME]:null==y?void 0:y.cardHolderEvents};if("fields"in R&&Array.isArray(R.fields)){const e={enableCardIcon:null===(p=null===(_=null==m?void 0:m.styles)||void 0===_?void 0:_.enableCardIcon)||void 0===p||p};if(R.fields.length>0&&"string"==typeof R.fields[0])for(const t of R.fields){const r=v.create(Object.assign(Object.assign(Object.assign({table:"cards",column:t,type:C[t],validations:A[t]},T(t)),{label:g[t],placeholder:S[t]}),R.card_id?{skyflowID:R.card_id}:{}),t===H.CARD_NUMBER?e:void 0);he({element:r,errorStyles:T(t).errorStyles,fieldMessage:[H.CVV,H.EXPIRATION_MONTH,H.EXPIRATION_YEAR].includes(t)?"":g[t],events:I[t]});const o=`#collect_${String(t)}`+(R.card_id?`_${R.card_id}`:"");yield pe({element:r,containerId:o}),f.push({element:r,containerId:o})}else for(const t of R.fields){const r=t.field,o=v.create(Object.assign(Object.assign(Object.assign({table:"cards",column:r,type:C[r],validations:A[r]},T(r)),{label:g[r],placeholder:S[r]}),R.card_id?{skyflowID:R.card_id}:{}),r===H.CARD_NUMBER?e:void 0);he({element:o,errorStyles:T(r).errorStyles,fieldMessage:[H.CVV,H.EXPIRATION_MONTH,H.EXPIRATION_YEAR].includes(r)?"":g[r],events:I[r]});const n=t.container_id||`#collect_${String(r)}`+(R.card_id?`_${R.card_id}`:"");yield pe({element:o,containerId:n}),f.push({element:o,containerId:n})}}return{elements:f.map((e=>e.element)),container:v}}))}({skyflowInstance:this.skyflowInstance,data:e,customization:this.customization,events:this.events});this.mountedElementsByContext.set(n,{elements:s.elements||[],container:s})}))}getContainerByCardId(e){var t;const r=`update:${e}`,o=this.mountedElementsByContext.get(r);return(null===(t=null==o?void 0:o.container)||void 0===t?void 0:t.container)||null}collectCardTokens(e){var t,o,n;return r(this,void 0,void 0,(function*(){const r=this.getContainerByCardId(e);if(!r)return null;try{const e=yield r.collect();return(null===(o=null===(t=null==e?void 0:e.records)||void 0===t?void 0:t[0])||void 0===o?void 0:o.fields)||null}catch(t){const r=null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.description;throw this.reportSdkError(t,{feature:"collect-card-tokens",process_id:e,metadata:{step:"collectCardTokens"}}),new d({code:s.MOUNT_COLLECT_ERROR,details:{message:r}})}}))}collectCreateCardTokens(){var e,t,o,n;return r(this,void 0,void 0,(function*(){const r=this.mountedElementsByContext.get("create"),i=null===(e=null==r?void 0:r.container)||void 0===e?void 0:e.container;if(!i)throw new d({code:s.MOUNT_COLLECT_ERROR,details:{message:"No card fields are mounted. Call mountCardFields() with the required fields before proceeding."}});try{const e=yield i.collect(),r=(null===(o=null===(t=null==e?void 0:e.records)||void 0===t?void 0:t[0])||void 0===o?void 0:o.fields)||{};return this.lastCollectedTokens=r,r}catch(e){const t=null===(n=null==e?void 0:e.error)||void 0===n?void 0:n.description;throw this.reportSdkError(e,{feature:"collect-create-card-tokens",metadata:{step:"collectCreateCardTokens"}}),new d({code:s.MOUNT_COLLECT_ERROR,details:{message:t}})}}))}revealCardFields(e){return r(this,void 0,void 0,(function*(){if(!this.lastCollectedTokens)throw y({errorCode:s.MOUNT_COLLECT_ERROR,details:{message:"No card tokens available. Call saveCustomerCard() or payment() with a new card before calling revealCardFields()."}});if(!this.skyflowInstance)throw y({errorCode:s.MOUNT_COLLECT_ERROR,details:{message:"Skyflow instance not initialized. Ensure mountCardFields() was called before saveCustomerCard() or payment()."}});yield function(e){var o,n,i,s,a,d;return r(this,void 0,void 0,(function*(){const{skyflowInstance:r,tokens:l,request:c}=e,u=r.container(t.ContainerType.REVEAL),h={[H.CARD_NUMBER]:"MASKED",[H.CARDHOLDER_NAME]:"PLAIN_TEXT",[H.EXPIRATION_MONTH]:"PLAIN_TEXT",[H.EXPIRATION_YEAR]:"PLAIN_TEXT"};for(const e of c.fields){const r="string"==typeof e,E=r?e:e.field;if(E===H.CVV){console.warn("[revealCardFields] CVV cannot be revealed (PCI DSS req. 3.2.1). Skipping.");continue}const _=l[E];if(!_){console.warn(`[revealCardFields] No token found for field "${E}", skipping.`);continue}const p=r?{}:e,R=null!==(o=p.container_id)&&void 0!==o?o:`#reveal_${E}`,m=h[E],y=null!==(n=p.styles)&&void 0!==n?n:{},v=null!==(i=c.styles)&&void 0!==i?i:{},f=u.create(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({token:_,redaction:t.RedactionType[m]},void 0!==p.altText&&{altText:p.altText}),void 0!==p.label&&{label:p.label}),y.inputStyles||v.inputStyles?{inputStyles:null!==(s=y.inputStyles)&&void 0!==s?s:v.inputStyles}:{}),y.labelStyles||v.labelStyles?{labelStyles:null!==(a=y.labelStyles)&&void 0!==a?a:v.labelStyles}:{}),y.errorTextStyles||v.errorTextStyles?{errorTextStyles:null!==(d=y.errorTextStyles)&&void 0!==d?d:v.errorTextStyles}:{}));yield pe({element:f,containerId:R})}try{yield u.reveal()}catch(e){console.warn("[revealCardFields] reveal completed with errors:",e)}}))}({skyflowInstance:this.skyflowInstance,tokens:this.lastCollectedTokens,request:e})}))}unmountCardFields(e="all"){"all"===e?(this.mountedElementsByContext.forEach(((e,t)=>{this.unmountContext(t)})),this.mountedElementsByContext.clear()):(this.unmountContext(e),this.mountedElementsByContext.delete(e))}unmountContext(e){const t=this.mountedElementsByContext.get(e);if(!t)return;const{elements:r}=t;r&&r.length>0&&r.forEach((t=>{try{t&&"function"==typeof t.unmount&&t.unmount()}catch(t){console.warn(`Error unmounting Skyflow element from context '${e}':`,t),this.reportSdkError(t,{feature:"unmount-card-fields",metadata:{step:"unmountContext",context:e}})}}))}getBusiness(){return r(this,void 0,void 0,(function*(){try{return yield i(this.baseUrl,this.apiKeyTonder,this.abortController.signal)}catch(e){throw this.reportSdkError(e,{feature:"get-business",metadata:{step:"getBusiness"}}),y({errorCode:s.FETCH_BUSINESS_ERROR},e)}}))}createSkyflowInstance(){return r(this,void 0,void 0,(function*(){if(this.skyflowInstance)return this.skyflowInstance;yield this._fetchMerchantData();const{vault_id:e,vault_url:o}=this.merchantData;this.skyflowInstance=yield function({baseUrl:e,apiKey:o,vault_id:n,vault_url:i,mode:s}){return r(this,void 0,void 0,(function*(){const a="production"===s?t.Env.PROD:t.Env.DEV;return t.init({vaultID:n,vaultURL:i,getBearerToken:()=>r(this,void 0,void 0,(function*(){return yield q(e,o)})),options:{logLevel:t.LogLevel.ERROR,env:a}})}))}({vault_id:e,vault_url:o,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder,mode:this.mode})}))}getOpenpayDeviceSessionID(e,t,o){return r(this,void 0,void 0,(function*(){try{return yield A(e,t,o)}catch(e){throw this.reportSdkError(e,{feature:"get-openpay-device-session",metadata:{step:"getOpenpayDeviceSessionID"}}),y({errorCode:s.START_CHECKOUT_ERROR},e)}}))}getSkyflowTokens({vault_id:e,vault_url:t,data:o}){return r(this,void 0,void 0,(function*(){return yield ue({vault_id:e,vault_url:t,data:o,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})}))}_setCartTotal(e){this.cartTotal=e}_checkout({card:e,payment_method:t,isSandbox:o,returnUrl:n}){var i,a;return r(this,void 0,void 0,(function*(){yield this._fetchMerchantData();const d=yield this._getCustomer(this.abortController.signal),{business:l}=this.merchantData,{auth_token:c,first_name:u="",last_name:h="",email:E=""}=d,_=this._hasCardOnFileKeys();let p,R=null,m=null,v=null,f=!1;const C=()=>r(this,void 0,void 0,(function*(){var e,t;(null===(t=null===(e=this.customerCardsCache)||void 0===e?void 0:e.cards)||void 0===t?void 0:t.length)||(this.customerCardsCache=yield this._getCustomerCards(c,this.merchantData.business.pk))}));if(!t){if("string"==typeof e)if(m=e,p={skyflow_id:e},_){yield C();const t=null===(a=null===(i=this.customerCardsCache)||void 0===i?void 0:i.cards)||void 0===a?void 0:a.find((t=>t.fields.skyflow_id===e));if(!t)throw new Error("Card not found for card-on-file processing");const r=!!t.fields.subscription_id;r||(yield this.collectCardTokens(e)),r&&(R={subscriptionId:t.fields.subscription_id})}else yield this.collectCardTokens(e);else p=yield this.collectCreateCardTokens(),m=p.skyflow_id,_&&(v={name:p.cardholder_name,number:p.card_number,expiryMonth:p.expiration_month,expiryYear:p.expiration_year,cvv:p.cvv},f=!0);if(f){if(!m||!v)throw new Error("Missing card data for card-on-file processing");let e=null;try{const t=yield this._saveCustomerCard(c,null==l?void 0:l.pk,{skyflow_id:m},!0);e=t.skyflow_id;const r=t.card_bin;if(!r)throw new Error("Card BIN not returned from save card");const o=yield this._initializeCardOnFile();let n;try{n=yield o.process({cardTokens:v,cardBin:r,contactDetails:{firstName:u||"",lastName:h||"",email:E||""},customerId:c,currency:this.currency||"MXN"})}catch(e){throw y({errorCode:s.CARD_ON_FILE_DECLINED,lockErrorCode:!0},e)}R={subscriptionId:n.subscriptionId},yield this._saveCustomerCard(c,null==l?void 0:l.pk,{skyflow_id:m,subscription_id:R.subscriptionId})}catch(t){throw e&&(yield this.removeCustomerCard(e)),this.reportSdkError(t,{feature:"payment",process_id:e||this.getCustomerId(),metadata:{step:"card_on_file"}}),t}}}return yield this._handleCheckout({card:p,payment_method:t,customer:d,isSandbox:o,returnUrl:n,enable_card_on_file:!!(null==R?void 0:R.subscriptionId)&&_})}))}customerRegister(e){return r(this,void 0,void 0,(function*(){try{const t=`${this.baseUrl}/api/v1/customer/`,r={email:e},o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.abortController.signal,body:JSON.stringify(r)});if(o.ok)return yield o.json();throw yield y({response:o,errorCode:s.CUSTOMER_OPERATION_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"customer-register",metadata:{step:"customerRegister"}}),y({errorCode:s.CUSTOMER_OPERATION_ERROR},e)}}))}createOrder(e){return r(this,void 0,void 0,(function*(){try{const t=`${this.baseUrl}/api/v1/orders/`,r=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(r)});if(o.ok)return yield o.json();throw yield y({response:o,errorCode:s.CREATE_ORDER_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"create-order",metadata:{step:"createOrder"}}),y({errorCode:s.CREATE_ORDER_ERROR},e)}}))}createPayment(e){return r(this,void 0,void 0,(function*(){try{const t=`${this.baseUrl}/api/v1/business/${e.business_pk}/payments/`,r=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(r)});if(o.ok)return yield o.json();throw yield y({response:o,errorCode:s.CREATE_PAYMENT_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"create-payment",metadata:{step:"createPayment"}}),y({errorCode:s.CREATE_PAYMENT_ERROR},e)}}))}startCheckoutRouter(e){return r(this,void 0,void 0,(function*(){const t=yield C(this.baseUrl,this.apiKeyTonder,e);if(yield this.init3DSRedirect(t))return t}))}init3DSRedirect(e){return r(this,void 0,void 0,(function*(){return this.process3ds.setPayload(e),yield this._handle3dsRedirect(e)}))}startCheckoutRouterFull(e){return r(this,void 0,void 0,(function*(){try{const{order:t,total:r,customer:o,skyflowTokens:n,return_url:i,isSandbox:a,metadata:d,currency:c,payment_method:u}=e,h=yield this._fetchMerchantData(),E=yield this.customerRegister(o.email);if(!(E&&"auth_token"in E&&h&&"reference"in h))throw y({errorCode:s.START_CHECKOUT_ERROR,details:{message:"Merchant or customer reposne errors",merchantResult:h,customerResult:E}});{const e={business:this.apiKeyTonder,client:E.auth_token,billing_address_id:null,shipping_address_id:null,amount:r,reference:h.reference,is_oneclick:!0,items:t.items},_=yield this.createOrder(e),p=(new Date).toISOString();if(!("id"in _&&"id"in E&&"business"in h))throw y({errorCode:s.START_CHECKOUT_ERROR,details:{message:"Order response errors",orderResult:_}});{const e={business_pk:h.business.pk,amount:r,date:p,order_id:_.id,client_id:E.id},t=yield this.createPayment(e);let s;const{openpay_keys:R,business:m}=h;R.merchant_id&&R.public_key&&(s=yield A(R.merchant_id,R.public_key,a));const y=Object.assign(Object.assign({name:o.name,last_name:o.lastname,email_client:o.email,phone_number:o.phone,return_url:i,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:r,title_ship:"shipping",description:"transaction",device_session_id:s||null,token_id:"",order_id:"id"in _&&_.id,business_id:m.pk,payment_id:"pk"in t&&t.pk,source:"sdk",metadata:d,browser_info:l(),currency:c},u?{payment_method:u}:{card:n}),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}),v=yield C(this.baseUrl,this.apiKeyTonder,y);if(yield this.init3DSRedirect(v))return v}}}catch(e){throw this.reportSdkError(e,{feature:"start-checkout-router-full",metadata:{step:"startCheckoutRouterFull"}}),y({errorCode:s.START_CHECKOUT_ERROR},e)}}))}registerCustomerCard(e,t,o){return r(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const r=yield fetch(`${this.baseUrl}/api/v1/business/${c(this.merchantData)}/cards/`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"User-token":t,"Content-Type":"application/json"},body:JSON.stringify(Object.assign({},o))});if(r.ok)return yield r.json();throw yield y({response:r,errorCode:s.SAVE_CARD_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"register-customer-card",metadata:{step:"registerCustomerCard"}}),y({errorCode:s.SAVE_CARD_ERROR},e)}}))}deleteCustomerCard(e,t=""){return r(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const r=yield fetch(`${this.baseUrl}/api/v1/business/${c(this.merchantData)}/cards/${t}`,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.abortController.signal});if(r.ok)return!0;throw yield y({response:r,errorCode:s.REMOVE_CARD_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"delete-customer-card",process_id:t,metadata:{step:"deleteCustomerCard"}}),y({errorCode:s.REMOVE_CARD_ERROR},e)}}))}getActiveAPMs(){return r(this,void 0,void 0,(function*(){try{const e=yield function(e,t,o="?status=active&page_size=10000&country=México",n=null){return r(this,void 0,void 0,(function*(){const r=yield fetch(`${e}/api/v1/payment_methods${o}`,{method:"GET",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},signal:n});if(r.ok)return yield r.json();throw yield y({response:r,errorCode:s.FETCH_PAYMENT_METHODS_ERROR})}))}(this.baseUrl,this.apiKeyTonder),t=e&&e.results&&e.results.length>0?e.results:[];return this.activeAPMs=t.filter((e=>"cards"!==e.category.toLowerCase())).map((e=>Object.assign({id:e.pk,payment_method:e.payment_method,priority:e.priority,category:e.category},ye(e.payment_method)))).sort(((e,t)=>e.priority-t.priority)),this.activeAPMs}catch(e){return console.error("Error getting APMS",e),[]}}))}}function fe(e){return/^\d{12,19}$/.test(e)&&ge(e)}function Ce(e){return/^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/.test(e)}function Ae(e){return/^\d{3,4}$/.test(e)}function Oe(e){return/^(0[1-9]|1[0-2])$/.test(e)}function Te(e){if(!/^\d{2}$/.test(e))return!1;const t=(new Date).getFullYear()%100;return parseInt(e,10)>=t}const ge=e=>{const t=`${e}`.split("").reverse().map((e=>Number.parseInt(e))),r=t.shift();let o=t.reduce(((e,t,r)=>r%2!=0?e+t:e+((t*=2)>9?t-9:t)),0);return o+=r,o%10==0};export{E as AppError,z as BaseInlineCheckout,ve as LiteCheckout,M as SdkTelemetryClient,Ae as validateCVV,fe as validateCardNumber,Ce as validateCardholderName,Oe as validateExpirationMonth,Te as validateExpirationYear};
|
|
1
|
+
import e from"skyflow-js";function t(e,t,r,o){return new(r||(r=Promise))((function(i,n){function s(e){try{d(o.next(e))}catch(e){n(e)}}function a(e){try{d(o.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}function r(e,t,r,o){if("a"===r&&!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"===r?o:"a"===r?o.call(e):o?o.value:t.get(e)}function o(e,t,r,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,r):i?i.value=r:t.set(e,r),r}function i(e,r,o){return t(this,void 0,void 0,(function*(){const t=yield fetch(`${e}/api/v1/payments/business/${r}`,{headers:{Authorization:`Token ${r}`},signal:o});return yield t.json()}))}var n;"function"==typeof SuppressedError&&SuppressedError,function(e){e.INIT_ERROR="INIT_ERROR",e.CREATE_ERROR="CREATE_ERROR",e.REMOVE_SDK_ERROR="REMOVE_SDK_ERROR",e.INVALID_TYPE="INVALID_TYPE",e.STATE_ERROR="STATE_ERROR",e.FETCH_BUSINESS_ERROR="FETCH_BUSINESS_ERROR",e.INVALID_CONFIG="INVALID_CONFIG",e.MERCHANT_CREDENTIAL_REQUIRED="MERCHANT_CREDENTIAL_REQUIRED",e.INVALID_PAYMENT_REQUEST="INVALID_PAYMENT_REQUEST",e.INVALID_PAYMENT_REQUEST_CARD_PM="INVALID_PAYMENT_REQUEST_CARD_PM",e.TYPE_SDK_REQUIRED="TYPE_SDK_REQUIRED",e.ENVIRONMENT_REQUIRED="ENVIRONMENT_REQUIRED",e.FETCH_CARDS_ERROR="FETCH_CARDS_ERROR",e.FETCH_TRANSACTION_ERROR="FETCH_TRANSACTION_ERROR",e.CUSTOMER_AUTH_TOKEN_NOT_VALID="CUSTOMER_AUTH_TOKEN_NOT_VALID",e.SAVE_CARD_ERROR="SAVE_CARD_ERROR",e.REMOVE_CARD_ERROR="REMOVE_CARD_ERROR",e.SUMMARY_CARD_ERROR="SUMMARY_CARD_ERROR",e.CREATE_PAYMENT_ERROR="CREATE_PAYMENT_ERROR",e.PAYMENT_PROCESS_ERROR="PAYMENT_PROCESS_ERROR",e.INVALID_CARD_DATA="INVALID_CARD_DATA",e.SAVE_CARD_PROCESS_ERROR="SAVE_CARD_PROCESS_ERROR",e.START_CHECKOUT_ERROR="START_CHECKOUT_ERROR",e.CREATE_ORDER_ERROR="CREATE_ORDER_ERROR",e.BUSINESS_ID_REQUIRED="BUSINESS_ID_REQUIRED",e.CLIENT_ID_REQUIRED="CLIENT_ID_REQUIRED",e.INVALID_AMOUNT="INVALID_AMOUNT",e.INVALID_ITEMS="INVALID_ITEMS",e.CUSTOMER_OPERATION_ERROR="CUSTOMER_OPERATION_ERROR",e.INVALID_EMAIL="INVALID_EMAIL",e.FETCH_PAYMENT_METHODS_ERROR="FETCH_PAYMENT_METHODS_ERROR",e.INVALID_VAULT_TOKEN="INVALID_VAULT_TOKEN",e.VAULT_TOKEN_ERROR="VAULT_TOKEN_ERROR",e.SECURE_TOKEN_ERROR="SECURE_TOKEN_ERROR",e.SECURE_TOKEN_INVALID="SECURE_TOKEN_INVALID",e.INVALID_SECRET_API_KEY="INVALID_SECRET_API_KEY",e.REMOVE_CARD="REMOVE_CARD",e.SKYFLOW_NOT_INITIALIZED="SKYFLOW_NOT_INITIALIZED",e.ERROR_LOAD_PAYMENT_FORM="ERROR_LOAD_PAYMENT_FORM",e.ERROR_LOAD_ENROLLMENT_FORM="ERROR_LOAD_ENROLLMENT_FORM",e.MOUNT_COLLECT_ERROR="MOUNT_COLLECT_ERROR",e.CARD_ON_FILE_DECLINED="CARD_ON_FILE_DECLINED",e.CARD_SAVED_SUCCESSFULLY="CARD_SAVED_SUCCESSFULLY",e.CARD_REMOVED_SUCCESSFULLY="CARD_REMOVED_SUCCESSFULLY",e.REQUEST_ABORTED="REQUEST_ABORTED",e.REQUEST_FAILED="REQUEST_FAILED",e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.THREEDS_REDIRECTION_ERROR="THREEDS_REDIRECTION_ERROR"}(n||(n={}));const s={[n.INIT_ERROR]:"Error initializing the SDK.",[n.INVALID_TYPE]:"SDK Type invalid.",[n.STATE_ERROR]:"Error updating SDK state.",[n.FETCH_BUSINESS_ERROR]:"Error retrieving merchant information.",[n.INVALID_CONFIG]:"Required configuration options.",[n.MERCHANT_CREDENTIAL_REQUIRED]:"Merchant credential required.",[n.INVALID_PAYMENT_REQUEST]:"The payment data must be of type: :::interface:::.",[n.INVALID_PAYMENT_REQUEST_CARD_PM]:"The fields card and payment_method cannot be provided together.",[n.TYPE_SDK_REQUIRED]:"SDK type required.",[n.ENVIRONMENT_REQUIRED]:"Environment required.",[n.FETCH_CARDS_ERROR]:"Error retrieving cards.",[n.CUSTOMER_AUTH_TOKEN_NOT_VALID]:"The customer's auth token is invalid. Please verify that the customer's data was provided when creating the SDK (sdk.create) and try again.",[n.SAVE_CARD_ERROR]:"Error saving the card.",[n.REMOVE_CARD_ERROR]:"Error deleting the card.",[n.CREATE_PAYMENT_ERROR]:"Error creating the payment.",[n.PAYMENT_PROCESS_ERROR]:"There was an issue processing the payment.",[n.CARD_SAVED_SUCCESSFULLY]:"Card saved successfully.",[n.CARD_REMOVED_SUCCESSFULLY]:"Card deleted successfully.",[n.SAVE_CARD_PROCESS_ERROR]:"Error processing card data.",[n.START_CHECKOUT_ERROR]:"Error processing the payment.",[n.CREATE_ORDER_ERROR]:"Error creating the order.",[n.BUSINESS_ID_REQUIRED]:"Business ID is required.",[n.CLIENT_ID_REQUIRED]:"Client ID is required.",[n.INVALID_AMOUNT]:"Invalid amount.",[n.INVALID_ITEMS]:"Invalid items.",[n.CUSTOMER_OPERATION_ERROR]:"Error registering or fetching customer",[n.INVALID_EMAIL]:"Invalid email.",[n.FETCH_PAYMENT_METHODS_ERROR]:"Error retrieving active payment methods.",[n.INVALID_VAULT_TOKEN]:"An invalid vault token response was received.",[n.VAULT_TOKEN_ERROR]:"Error retrieving the vault token.",[n.SECURE_TOKEN_ERROR]:"Error getting secure token.",[n.SECURE_TOKEN_INVALID]:"Invalid secure token.",[n.INVALID_SECRET_API_KEY]:"SECRET API KEY is required.",[n.REMOVE_CARD]:"Card deleted successfully",[n.SKYFLOW_NOT_INITIALIZED]:"Skyflow not initialized.",[n.ERROR_LOAD_PAYMENT_FORM]:"There was an issue loading the payment form.",[n.INVALID_CARD_DATA]:"Invalid card data.",[n.ERROR_LOAD_ENROLLMENT_FORM]:"There was an issue loading the card form.",[n.MOUNT_COLLECT_ERROR]:"Mount failed. Make sure all inputs are complete and valid.",[n.CARD_ON_FILE_DECLINED]:"Transaction declined. Please verify your card details.",[n.REQUEST_ABORTED]:"Requests canceled.",[n.REQUEST_FAILED]:"Request failed.",[n.UNKNOWN_ERROR]:"An unexpected error occurred.",[n.CREATE_ERROR]:"Error creating the SDK.",[n.FETCH_TRANSACTION_ERROR]:"Error retrieving the transaction.",[n.THREEDS_REDIRECTION_ERROR]:"Ocurrió un error durante la redirección de 3DS.",[n.REMOVE_SDK_ERROR]:"Ocurrió un error removiendo la instancia del SDK."};n.INIT_ERROR,n.STATE_ERROR,n.FETCH_BUSINESS_ERROR,n.INVALID_CONFIG,n.TYPE_SDK_REQUIRED,n.ENVIRONMENT_REQUIRED,n.FETCH_CARDS_ERROR,n.SAVE_CARD_ERROR,n.REMOVE_CARD_ERROR,n.CREATE_PAYMENT_ERROR,n.START_CHECKOUT_ERROR,n.CREATE_ORDER_ERROR,n.BUSINESS_ID_REQUIRED,n.CLIENT_ID_REQUIRED,n.INVALID_AMOUNT,n.INVALID_ITEMS,n.CUSTOMER_OPERATION_ERROR,n.INVALID_EMAIL,n.FETCH_PAYMENT_METHODS_ERROR,n.INVALID_VAULT_TOKEN,n.VAULT_TOKEN_ERROR,n.SECURE_TOKEN_ERROR,n.INVALID_SECRET_API_KEY,n.CUSTOMER_AUTH_TOKEN_NOT_VALID,n.SECURE_TOKEN_INVALID,n.REMOVE_CARD,n.SKYFLOW_NOT_INITIALIZED,n.INVALID_TYPE,n.PAYMENT_PROCESS_ERROR,n.INVALID_PAYMENT_REQUEST,n.INVALID_PAYMENT_REQUEST_CARD_PM,n.SAVE_CARD_PROCESS_ERROR,n.ERROR_LOAD_PAYMENT_FORM,n.INVALID_CARD_DATA,n.ERROR_LOAD_ENROLLMENT_FORM,n.MOUNT_COLLECT_ERROR,n.CARD_ON_FILE_DECLINED,n.CARD_SAVED_SUCCESSFULLY,n.CARD_REMOVED_SUCCESSFULLY,n.REQUEST_ABORTED,n.REQUEST_FAILED,n.UNKNOWN_ERROR,n.CREATE_ERROR,n.FETCH_TRANSACTION_ERROR,n.THREEDS_REDIRECTION_ERROR,n.REMOVE_SDK_ERROR;class a extends Error{constructor(e){var t,r;const o=e.message||s[e.code]||"Unknown error";super(o),this.name="TonderError",this.code=e.code,this.details={code:(null===(t=e.details)||void 0===t?void 0:t.code)||e.code,message:(null===(r=e.details)||void 0===r?void 0:r.message)||o}}}const d=Object.freeze({production:"https://d35a75syrgujp0.cloudfront.net",sandbox:"https://static.staging.tonder.io",stage:"https://static.staging.tonder.io",development:"https://static.staging.tonder.io"});function l(e="stage"){return d[e]||d.stage}const c=()=>({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}),u=e=>{var t;return e&&"business"in e?null===(t=null==e?void 0:e.business)||void 0===t?void 0:t.pk:""},h=(e,t="stage")=>{const r=l(t);return"Visa"===e?`${r}/cards/visa.png`:"Mastercard"===e?`${r}/cards/mastercard.png`:"American Express"===e?`${r}/cards/american_express.png`:`${r}/cards/default_card.png`},E="__tonderLockErrorCode__";function _(e){return"object"==typeof e&&null!==e}class R extends Error{constructor(e){var t,r;const o=R.resolveStatusCode(e.statusCode,e.originalError),i=R.resolveMessage(e.errorCode,e.message),n=R.resolveSystemError(null===(t=e.details)||void 0===t?void 0:t.systemError,e.originalError);super(i),this.status="error",Object.setPrototypeOf(this,new.target.prototype),this.name="TonderError",this.code=e.errorCode,this.statusCode=o,this.originalError=e.originalError,this.details={code:e.errorCode,statusCode:o,systemError:n},e.lockErrorCode&&Object.defineProperty(this,E,{value:!0,enumerable:!1,configurable:!0}),null===(r=Error.captureStackTrace)||void 0===r||r.call(Error,this,R)}static isRecord(e){return"object"==typeof e&&null!==e}static parseStatusCode(e){const t=Number(e);return Number.isFinite(t)?t<100||t>599?500:Math.trunc(t):500}static resolveStatusCode(e,t){const r=[e];if(R.isRecord(t)){r.push(t.statusCode,t.status);const e=R.isRecord(t.body)?t.body:null;e&&r.push(e.statusCode,e.status)}for(const e of r)if(R.isHttpStatusCode(e))return Math.trunc(Number(e));return 500}static resolveMessage(e,t){return t||(s[e]||s[n.UNKNOWN_ERROR]||"An unexpected error occurred.")}static isHttpStatusCode(e){const t=Number(e);return Number.isFinite(t)&&t>=100&&t<=599}static normalizeSystemError(e){if("string"!=typeof e)return null;return e.trim()||null}static resolveSystemError(e,t){const r=[e];if(R.isRecord(t)){const e=R.isRecord(t.details)?t.details:null,o=R.isRecord(t.body)?t.body:null,i=o&&R.isRecord(o.details)?o.details:null;r.push(t.systemError,t.code,null==e?void 0:e.systemError,null==e?void 0:e.code,null==o?void 0:o.systemError,null==o?void 0:o.code,null==i?void 0:i.systemError,null==i?void 0:i.code)}for(const e of r){const t=R.normalizeSystemError(e);if(t)return t}return"APP_INTERNAL_001"}}function m(e){return _(e)&&!0===e[E]}function p(e){return e instanceof R&&void 0!==e.originalError?e.originalError:e}function y(e,t){var r;if(!(null==e?void 0:e.errorCode))throw new Error("buildPublicAppError requires errorCode");const o=null===(r=e.details)||void 0===r?void 0:r.systemError,i=!!e.message||void 0!==e.statusCode||void 0!==o;return!function(e){return _(e)&&"TonderError"===e.name&&"string"==typeof e.code}(t)||(e.lockErrorCode&&function(e){Object.defineProperty(e,E,{value:!0,enumerable:!1,configurable:!0})}(t),i||e.errorCode!==t.code&&!m(t))?new R({errorCode:e.errorCode,message:e.message,statusCode:e.statusCode,details:void 0!==o?{systemError:o}:void 0,originalError:p(t),lockErrorCode:e.lockErrorCode||m(t)}):t}function v(e){var r,o;return t(this,void 0,void 0,(function*(){const i=yield function(e){return t(this,void 0,void 0,(function*(){try{return yield e.clone().json()}catch(e){}try{return(yield e.text())||void 0}catch(e){return}}))}(e.response),n={status:e.response.status};return e.response.statusText&&(n.statusText=e.response.statusText),void 0!==i&&(n.body=i),new R({errorCode:e.errorCode,message:e.message,statusCode:null!==(r=e.statusCode)&&void 0!==r?r:e.response.status,details:void 0!==(null===(o=e.details)||void 0===o?void 0:o.systemError)?{systemError:e.details.systemError}:void 0,originalError:n,lockErrorCode:e.lockErrorCode})}))}function C(e,t){return(null==e?void 0:e.response)?v(e):y(e,t)}class A{constructor({payload:e=null,apiKey:t,baseUrl:r,redirectOnComplete:o,tdsIframeId:i,tonderPayButtonId:n,callBack:s}){this.localStorageKey="verify_transaction_status_url",this.setPayload=e=>{this.payload=e},this.baseUrl=r,this.apiKey=t,this.payload=e,this.tdsIframeId=i,this.tonderPayButtonId=n,this.redirectOnComplete=o,this.callBack=s}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,r,o,i,n;const s=null===(r=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===r?void 0:r.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const e=null===(n=null===(i=null===(o=this.payload)||void 0===o?void 0:o.next_action)||void 0===i?void 0:i.iframe_resources)||void 0===n?void 0:n.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,r;if(null===(r=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.iframe_resources)||void 0===r?void 0:r.iframe)return new Promise(((e,t)=>{var r,o,i;const n=null===(i=null===(o=null===(r=this.payload)||void 0===r?void 0:r.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===i?void 0:i.iframe;if(n){this.saveVerifyTransactionUrl();const r=document.createElement("div");r.innerHTML=n,document.body.appendChild(r);const o=document.createElement("script");o.textContent='document.getElementById("tdsMmethodForm").submit();',r.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,r;return null===(r=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===r?void 0:r.url}redirectToChallenge(){const e=this.getRedirectUrl();if(e)if(this.saveVerifyTransactionUrl(),this.redirectOnComplete)window.location=e;else{const r=document.querySelector(`#${this.tdsIframeId}`);if(r){r.setAttribute("src",e),r.setAttribute("style","display: block");const o=this,i=e=>t(this,void 0,void 0,(function*(){const e=()=>{try{const e=document.querySelector(`#${this.tonderPayButtonId}`);e&&(e.disabled=!1)}catch(e){}r&&r.setAttribute("style","display: none"),o.callBack&&o.callBack(o.payload),r.removeEventListener("load",i)},n=r=>t(this,void 0,void 0,(function*(){const i=yield new Promise(((e,t)=>e(r)));if(i){if((e=>"Pending"!==(null==e?void 0:e.transaction_status))(i))return e();{const e=setTimeout((()=>t(this,void 0,void 0,(function*(){clearTimeout(e),yield n(o.requestTransactionStatus())}))),7e3)}}}));yield n(o.requestTransactionStatus())}));r.addEventListener("load",i)}else console.log("No iframe found")}else this.callBack&&this.callBack(this.payload)}requestTransactionStatus(){return t(this,void 0,void 0,(function*(){const e=this.getUrlWithExpiration(),t=e.startsWith("https://")?e:`${this.baseUrl}${e}`,r=yield fetch(t,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`}});if(200!==r.status)return console.error("La verificación de la transacción falló."),null;return yield r.json()}))}getURLParameters(){const e={},t=new URLSearchParams(window.location.search);for(const[r,o]of t)e[r]=o;return e}handleSuccessTransaction(e){return this.removeVerifyTransactionUrl(),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 r=document.createElement("input");r.type="hidden",r.name=e.creq,r.value=e.creq,t.appendChild(r);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=e.startsWith("https://")?e:`${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")}))}}const O=Object.freeze({production:"https://app.tonder.io",sandbox:"https://sandbox.tonder.io",stage:"https://stage.tonder.io",development:"http://localhost:8000"});function T(e,r,o){return t(this,void 0,void 0,(function*(){const t=`${e}/api/v1/checkout-router/`,i=o,s=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${r}`},body:JSON.stringify(Object.assign(Object.assign({},i),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}))});if(s.ok)return yield s.json();throw yield C({response:s,errorCode:n.START_CHECKOUT_ERROR})}))}function f(e,r,o=!0,i=null){return t(this,void 0,void 0,(function*(){let t=yield window.OpenPay;return t.setId(e),t.setApiKey(r),t.setSandboxMode(o),yield t.deviceData.setup({signal:i})}))}function S(e,t,r){const o=t.replace(/\[(\w+)\]/g,".$1").split(".").filter((e=>""!==e));let i=e;for(const e of o){if(null==i)return r;i=i[e]}return void 0===i?r:i}const I=Object.freeze({production:"https://api.tonder.io",sandbox:"https://api-stage.tonder.io",stage:"https://api-stage.tonder.io",development:"https://api-stage.tonder.io"}),g=Object.freeze({TELEMETRY:"/telemetry/v1/events",ACQ_SUBSCRIPTION_TOKEN:"/acq-kushki/subscription/token",ACQ_SUBSCRIPTION_CREATE:"/acq-kushki/subscription/create"});function N(e="stage"){return`${I[e]}${g.TELEMETRY}`}const b="https://cdn.kushkipagos.com/kushki.min.js",D=n.CARD_ON_FILE_DECLINED;let M=!1,k=null;class P{constructor(e){var t;this.acquirerInstance=null,this.isTestEnvironment=null===(t=e.isTestEnvironment)||void 0===t||t;const r=this.isTestEnvironment?"stage":"production";this.apiUrl=function(e="stage"){return I[e]}(r),this.merchantId=e.merchantId,this.apiKey=e.apiKey}initialize(){return t(this,void 0,void 0,(function*(){yield function(){return t(this,void 0,void 0,(function*(){return M?Promise.resolve():k||(k=new Promise(((e,t)=>{if(document.querySelector(`script[src="${b}"]`))return M=!0,void e();const r=document.createElement("script");r.src=b,r.async=!0,r.onload=()=>{M=!0,e()},r.onerror=()=>{k=null,t(C({errorCode:D,lockErrorCode:!0,details:{step:"load_acquirer_script",message:"Failed to load acquirer script"}}))},document.head.appendChild(r)})),k)}))}(),this.acquirerInstance=function(e,t){if(!window.Kushki)throw C({errorCode:D,lockErrorCode:!0,details:{step:"create_acquirer_instance",message:"Acquirer script not loaded. Call initialize() first."}});return new window.Kushki({merchantId:e,inTestEnvironment:t})}(this.merchantId,this.isTestEnvironment)}))}getAcquirerInstance(){if(!this.acquirerInstance)throw C({errorCode:D,lockErrorCode:!0,details:{step:"get_acquirer_instance",message:"CardOnFile not initialized. Call initialize() first."}});return this.acquirerInstance}getJwt(e){return t(this,void 0,void 0,(function*(){const t=this.getAcquirerInstance();return new Promise(((r,o)=>{t.requestSecureInit({card:{number:e}},(e=>{if("code"in e&&e.code)return void o(C({errorCode:D,lockErrorCode:!0,details:{step:"get_jwt",acquirerResponse:e}}));const t=e;t.jwt?r(t.jwt):o(C({errorCode:D,lockErrorCode:!0,details:{step:"get_jwt",message:"No JWT returned from acquirer",acquirerResponse:t}}))}))}))}))}generateToken(e){return t(this,void 0,void 0,(function*(){const t=yield fetch(`${this.apiUrl}${g.ACQ_SUBSCRIPTION_TOKEN}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`},body:JSON.stringify(e)});if(!t.ok)throw yield C({response:t,errorCode:D,lockErrorCode:!0,details:{step:"generate_token"}});return t.json()}))}createSubscription(e){return t(this,void 0,void 0,(function*(){const t=yield fetch(`${this.apiUrl}${g.ACQ_SUBSCRIPTION_CREATE}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`},body:JSON.stringify(e)});if(!t.ok)throw yield C({response:t,errorCode:D,lockErrorCode:!0,details:{step:"create_subscription"}});return t.json()}))}validate3DS(e,r){return t(this,void 0,void 0,(function*(){const t=this.getAcquirerInstance();return new Promise(((o,i)=>{t.requestValidate3DS({secureId:e,security:r},(e=>{const t=e;t.code&&"3DS000"!==t.code?i(C({errorCode:D,lockErrorCode:!0,details:{step:"validate_3ds",message:"3DS validation failed",acquirerResponse:t}})):!1!==t.isValid?o(!0):i(C({errorCode:D,lockErrorCode:!0,details:{step:"validate_3ds",message:"3DS validation failed",acquirerResponse:t}}))}))}))}))}process(e){var r,o;return t(this,void 0,void 0,(function*(){const t=yield this.getJwt(e.cardBin),i=yield this.generateToken({card:e.cardTokens,currency:e.currency,jwt:t}),n=i.secureId||(null===(r=i.details)||void 0===r?void 0:r.secureId),s=i.security||(null===(o=i.details)||void 0===o?void 0:o.security);if(!n||!s)throw C({errorCode:D,lockErrorCode:!0,details:{step:"process",message:"Missing secureId or security in token response",tokenResponse:i}});return yield this.validate3DS(n,s),this.createSubscription({token:i.token,contactDetails:e.contactDetails,metadata:{customerId:e.customerId},currency:e.currency})}))}}class U{constructor(e){this.REQUEST_TIMEOUT_MS=5e3,this.MAX_MESSAGE_LENGTH=500,this.config=e}captureException(e,t){try{const r=this.buildEvent(e,t||{});this.sendEvent(r)}catch(e){}}extractErrorInfo(e){try{if(e instanceof Error)return{name:e.name||"Error",message:this.truncate(e.message||"Unknown error",this.MAX_MESSAGE_LENGTH),stack:e.stack||void 0};const t=this.safeStringify(e);return{name:"NonErrorException",message:this.truncate(t,this.MAX_MESSAGE_LENGTH),stack:void 0}}catch(e){return{name:"SerializationError",message:"Failed to serialize error",stack:void 0}}}safeStringify(e){try{const t=new WeakSet;return JSON.stringify(e,((e,r)=>{if("object"==typeof r&&null!==r){if(t.has(r))return"[Circular]";t.add(r)}return r}))}catch(t){return String(e)}}buildEvent(e,t){const r=this.extractErrorInfo(e),o=Object.assign({},t.metadata||{});void 0===o.error&&(o.error=e),"undefined"!=typeof window&&(o.url=window.location.href);const i={platform:this.config.platform,platform_version:this.config.platform_version,env:this.config.mode,feature:t.feature||"unknown",level:"error",message:r.message,name:r.name,metadata:o};return t.tenant_id&&(i.tenant_id=t.tenant_id),t.request_id&&(i.request_id=t.request_id),t.process_id&&(i.process_id=t.process_id),t.user_id&&(i.user_id=t.user_id),r.stack&&(i.stack=r.stack),t.error_code&&(i.error_code=t.error_code),t.http_status&&(i.http_status=t.http_status),i}truncate(e,t){return e.length<=t?e:e.substring(0,t)+"..."}sendEvent(e){this.sendHttpRequest(e).then((()=>{})).catch((()=>{}))}sendHttpRequest(e){return t(this,void 0,void 0,(function*(){try{const t=JSON.stringify(e),r=new AbortController,o=setTimeout((()=>r.abort()),this.REQUEST_TIMEOUT_MS);try{const e=yield fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.config.apiKey}`},body:t,keepalive:!0,signal:r.signal});return clearTimeout(o),e.ok}catch(e){return clearTimeout(o),!1}}catch(e){return!1}}))}}const L=Object.freeze({name:"@tonder.io/ionic-lite-sdk",version:"1.0.1"});var w,V,F,K,j,x,B,Y,$,H,z,q,X;class Q{constructor({mode:e="stage",customization:t,apiKey:r,apiKeyTonder:o,returnUrl:i,tdsIframeId:n,callBack:s=(()=>{}),baseUrlTonder:a,tonderPayButtonId:d,sdkInfo:l}){w.add(this),this.baseUrl="",this.cartTotal="0",this.secureToken="",this.customization={redirectOnComplete:!0},this.metadata={},this.order_reference=null,this.card={},this.currency="",this.cardOnFileInstance=null,V.set(this,void 0),F.set(this,void 0),this.apiKeyTonder=o||r||"",this.returnUrl=i,this.callBack=s,this.mode=e,this.customer={},this.baseUrl=a||O[this.mode]||O.stage,this.abortController=new AbortController,this.requestId=this.generateRequestId(),this.customization=Object.assign(Object.assign({},this.customization),t||{}),this.process3ds=new A({apiKey:r,baseUrl:this.baseUrl,redirectOnComplete:this.customization.redirectOnComplete,tdsIframeId:n,tonderPayButtonId:d,callBack:s}),this.tdsIframeId=n;const c=l||L;this.telemetry=new U({endpoint:N(this.mode),apiKey:this.apiKeyTonder,platform:c.name,platform_version:c.version,mode:this.mode||"stage"})}configureCheckout(e){"secureToken"in e&&r(this,w,"m",x).call(this,e.secureToken),r(this,w,"m",K).call(this,e)}getCustomerId(){var e,t;return null===(t=null===(e=r(this,F,"f"))||void 0===e?void 0:e.id)||void 0===t?void 0:t.toString()}reportSdkError(e,t){var r,o,i,n;try{const s=this.getCustomerId(),a=e instanceof R&&void 0!==e.originalError?e.originalError:e,d=Object.assign(Object.assign({},(null==t?void 0:t.metadata)||{}),void 0===(null===(r=null==t?void 0:t.metadata)||void 0===r?void 0:r.error)?{error:a}:{}),l=Object.assign(Object.assign({tenant_id:null===(n=null===(i=null===(o=this.merchantData)||void 0===o?void 0:o.business)||void 0===i?void 0:i.pk)||void 0===n?void 0:n.toString(),user_id:s},t||{}),{metadata:d,request_id:this.requestId});l.user_id||delete l.user_id,l.feature=(null==t?void 0:t.feature)||"unknown",this.telemetry.captureException(e,l)}catch(e){}}generateRequestId(){return`req_${Date.now()}_${Math.random().toString(36).slice(2,10)}`}verify3dsTransaction(){return t(this,void 0,void 0,(function*(){const e=yield this.process3ds.verifyTransactionStatus(),t=yield r(this,w,"m",z).call(this,e);return this.process3ds.setPayload(t),this._handle3dsRedirect(t)}))}payment(e){return new Promise(((o,i)=>t(this,void 0,void 0,(function*(){var t,s;let a;try{r(this,w,"m",K).call(this,e),a=yield this._checkout(e),this.process3ds.setPayload(a);if(yield this._handle3dsRedirect(a)){try{const e=document.querySelector(`#${this.tonderPayButtonId}`);e&&(e.disabled=!1)}catch(e){}this.callBack&&this.callBack(a),o(a)}}catch(r){this.reportSdkError(r,{feature:"payment",process_id:(null==a?void 0:a.payment_id)||(null===(t=null==a?void 0:a.payment)||void 0===t?void 0:t.id)||(null===(s=null==a?void 0:a.payment)||void 0===s?void 0:s.pk),metadata:{step:"payment",request:e,response:a}}),i(C({errorCode:n.PAYMENT_PROCESS_ERROR},r))}}))))}getSecureToken(e){return t(this,void 0,void 0,(function*(){try{return yield function(e,r,o=null){return t(this,void 0,void 0,(function*(){const t=yield fetch(`${e}/api/secure-token/`,{method:"POST",headers:{Authorization:`Token ${r}`,"Content-Type":"application/json"},signal:o});if(t.ok)return yield t.json();throw yield C({response:t,errorCode:n.SECURE_TOKEN_ERROR})}))}(this.baseUrl,e)}catch(e){throw this.reportSdkError(e,{feature:"secure-token",metadata:{step:"getSecureToken"}}),C({errorCode:n.SECURE_TOKEN_ERROR},e)}}))}_initializeCheckout(){return t(this,void 0,void 0,(function*(){const e=yield this._fetchMerchantData();e&&e.mercado_pago&&e.mercado_pago.active&&function(){try{const e=document.createElement("script");e.src="https://www.mercadopago.com/v2/security.js",e.setAttribute("view",""),e.onload=()=>{},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)}}(),this._hasCardOnFileKeys()&&(yield this._initializeCardOnFile())}))}_checkout(e){return t(this,void 0,void 0,(function*(){throw new Error("The #checkout method should be implement in child classes.")}))}_setCartTotal(e){throw new Error("The #setCartTotal method should be implement in child classes.")}_getCustomer(e=null){return t(this,void 0,void 0,(function*(){return r(this,F,"f")||o(this,F,yield function(e,r,o,i=null){return t(this,void 0,void 0,(function*(){const t=`${e}/api/v1/customer/`,s={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},a=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${r}`},signal:i,body:JSON.stringify(s)});if(a.ok)return yield a.json();throw yield C({response:a,errorCode:n.CUSTOMER_OPERATION_ERROR})}))}(this.baseUrl,this.apiKeyTonder,this.customer,e),"f"),r(this,F,"f")}))}_handleCheckout({card:e,payment_method:o,customer:i,isSandbox:s,enable_card_on_file:a,returnUrl:d}){return t(this,void 0,void 0,(function*(){const{openpay_keys:l,reference:u,business:h}=this.merchantData,E=Number(this.cartTotal);let _,R,m;try{let p;!p&&l.merchant_id&&l.public_key&&!o&&(p=yield f(l.merchant_id,l.public_key,s,this.abortController.signal));const{id:y,auth_token:v}=i;_={business:this.apiKeyTonder,client:v,billing_address_id:null,shipping_address_id:null,amount:E,status:"A",reference:u,is_oneclick:!0,items:this.cartItems,currency:this.currency,metadata:this.metadata};const A=yield function(e,r,o){return t(this,void 0,void 0,(function*(){const t=`${e}/api/v1/orders/`,i=o,s=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${r}`},body:JSON.stringify(i)});if(s.ok)return yield s.json();throw yield C({response:s,errorCode:n.CREATE_ORDER_ERROR})}))}(this.baseUrl,this.apiKeyTonder,_),O=(new Date).toISOString();R={business_pk:h.pk,client_id:y,amount:E,date:O,order_id:A.id,customer_order_reference:this.order_reference?this.order_reference:u,items:this.cartItems,currency:this.currency,metadata:this.metadata};const I=yield function(e,r,o){return t(this,void 0,void 0,(function*(){const t=`${e}/api/v1/business/${o.business_pk}/payments/`,i=o,s=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${r}`},body:JSON.stringify(i)});if(s.ok)return yield s.json();throw yield C({response:s,errorCode:n.CREATE_PAYMENT_ERROR})}))}(this.baseUrl,this.apiKeyTonder,R);m=Object.assign(Object.assign(Object.assign(Object.assign({name:S(this.customer,"firstName",S(this.customer,"name","")),last_name:S(this.customer,"lastName",S(this.customer,"lastname","")),email_client:S(this.customer,"email",""),phone_number:S(this.customer,"phone",""),return_url:d||this.returnUrl,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:E,title_ship:"shipping",description:"transaction",device_session_id:p||null,token_id:"",order_id:A.id,business_id:h.pk,payment_id:I.pk,source:"sdk",items:this.cartItems,metadata:this.metadata,browser_info:c(),currency:this.currency},o?{payment_method:o}:{card:e}),{apm_config:r(this,V,"f")}),this.customer&&"identification"in this.customer?{identification:this.customer.identification}:{}),void 0!==a?{enable_card_on_file:a}:{});const g=yield T(this.baseUrl,this.apiKeyTonder,m);return g||!1}catch(e){throw this.reportSdkError(e,{feature:"payment",process_id:null==m?void 0:m.payment_id,metadata:{step:"_handleCheckout",orderItems:_,paymentItems:R,routerItems:m}}),e}}))}_fetchMerchantData(){return t(this,void 0,void 0,(function*(){try{return this.merchantData||(this.merchantData=yield i(this.baseUrl,this.apiKeyTonder,this.abortController.signal)),this.merchantData}catch(e){return this.reportSdkError(e,{feature:"fetch-merchant-data",metadata:{step:"_fetchMerchantData"}}),this.merchantData}}))}_getCustomerCards(e,r){return t(this,void 0,void 0,(function*(){return yield function(e,r,o,i,s=null){return t(this,void 0,void 0,(function*(){const t=`${e}/api/v1/business/${i}/cards/`,a=yield fetch(t,{method:"GET",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json","User-token":r},signal:s});if(a.ok)return yield a.json();if(401===a.status)return{user_id:0,cards:[]};throw yield C({response:a,errorCode:n.FETCH_CARDS_ERROR})}))}(this.baseUrl,e,this.secureToken,r)}))}_saveCustomerCard(e,r,o,i=!1){return t(this,void 0,void 0,(function*(){return yield function(e,r,o,i,s,a=!1){return t(this,void 0,void 0,(function*(){const t=`${e}/api/v1/business/${i}/cards/`,d=yield fetch(t,{method:"POST",headers:Object.assign({Authorization:`Bearer ${o}`,"Content-Type":"application/json","User-token":r},a?{"X-App-Origin":"sdk/ionic"}:{}),body:JSON.stringify(s)});if(d.ok)return yield d.json();throw yield C({response:d,errorCode:n.SAVE_CARD_ERROR})}))}(this.baseUrl,e,this.secureToken,r,o,i)}))}_removeCustomerCard(e,r,o){return t(this,void 0,void 0,(function*(){return yield function(e,r,o,i="",a){return t(this,void 0,void 0,(function*(){const t=`${e}/api/v1/business/${a}/cards/${i}`,d=yield fetch(t,{method:"DELETE",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json","User-token":r}});if(204===d.status)return s[n.CARD_REMOVED_SUCCESSFULLY];if(d.ok&&"json"in d)return yield d.json();throw yield C({response:d,errorCode:n.REMOVE_CARD_ERROR})}))}(this.baseUrl,e,this.secureToken,o,r)}))}_fetchCustomerPaymentMethods(){return t(this,void 0,void 0,(function*(){return yield function(e,r,o={status:"active",pagesize:"10000"},i=null){return t(this,void 0,void 0,(function*(){const t=new URLSearchParams(o).toString(),s=yield fetch(`${e}/api/v1/payment_methods?${t}`,{method:"GET",headers:{Authorization:`Token ${r}`,"Content-Type":"application/json"},signal:i});if(s.ok)return yield s.json();throw yield C({response:s,errorCode:n.FETCH_PAYMENT_METHODS_ERROR})}))}(this.baseUrl,this.apiKeyTonder)}))}_hasCardOnFileKeys(){var e,t;return!!(null===(t=null===(e=this.merchantData)||void 0===e?void 0:e.cardonfile_keys)||void 0===t?void 0:t.public_key)}_initializeCardOnFile(){var e;return t(this,void 0,void 0,(function*(){return this.cardOnFileInstance||(this.cardOnFileInstance=new P({merchantId:null===(e=this.merchantData)||void 0===e?void 0:e.cardonfile_keys.public_key,apiKey:this.apiKeyTonder,isTestEnvironment:"production"!==this.mode}),yield this.cardOnFileInstance.initialize()),this.cardOnFileInstance}))}_handle3dsRedirect(e){var r,o;return t(this,void 0,void 0,(function*(){if(e&&"next_action"in e?null===(o=null===(r=null==e?void 0:e.next_action)||void 0===r?void 0:r.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),this.reportSdkError(t,{feature:"3ds-verification",metadata:{step:"_handle3dsRedirect",response:e}})}));else{if(!this.process3ds.getRedirectUrl())return e;this.process3ds.redirectToChallenge()}}))}}function W(e,r,o=null){return t(this,void 0,void 0,(function*(){const t=yield fetch(`${e}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${r}`},signal:o});if(t.ok){return(yield t.json()).token}throw yield C({response:t,errorCode:n.VAULT_TOKEN_ERROR})}))}V=new WeakMap,F=new WeakMap,w=new WeakSet,K=function(e){var t,o;!e||e&&0===Object.keys(e).length||(r(this,w,"m",j).call(this,e.customer),this._setCartTotal((null===(t=e.cart)||void 0===t?void 0:t.total)||0),r(this,w,"m",B).call(this,(null===(o=e.cart)||void 0===o?void 0:o.items)||[]),r(this,w,"m",Y).call(this,e),r(this,w,"m",$).call(this,e),r(this,w,"m",H).call(this,e),r(this,w,"m",q).call(this,e))},j=function(e){e&&(this.customer=e)},x=function(e){this.secureToken=e},B=function(e){this.cartItems=e},Y=function(e){this.metadata=null==e?void 0:e.metadata,this.order_reference=null==e?void 0:e.order_reference},$=function(e){this.currency=null==e?void 0:e.currency},H=function(e){this.card=null==e?void 0:e.card},z=function(e){var r,o,i,n,s;return t(this,void 0,void 0,(function*(){if("Hard"===(null===(r=null==e?void 0:e.decline)||void 0===r?void 0:r.error_type)||(null===(o=null==e?void 0:e.checkout)||void 0===o?void 0:o.is_route_finished)||(null==e?void 0:e.is_route_finished)||["Pending"].includes(null==e?void 0:e.transaction_status))return e;if(["Success","Authorized"].includes(null==e?void 0:e.transaction_status))return e;if(e){const t={checkout_id:(null===(i=e.checkout)||void 0===i?void 0:i.id)||(null==e?void 0:e.checkout_id)};try{return yield T(this.baseUrl,this.apiKeyTonder,t)}catch(t){this.reportSdkError(t,{feature:"payment",process_id:(null==e?void 0:e.payment_id)||(null===(n=null==e?void 0:e.payment)||void 0===n?void 0:n.id)||(null===(s=null==e?void 0:e.payment)||void 0===s?void 0:s.pk),metadata:{step:"#resumeCheckout",response:e}})}return e}}))},q=function(e){o(this,V,null==e?void 0:e.apm_config,"f")},function(e){e.CARD_NUMBER="card_number",e.CVV="cvv",e.EXPIRATION_MONTH="expiration_month",e.EXPIRATION_YEAR="expiration_year",e.CARDHOLDER_NAME="cardholder_name"}(X||(X={}));const J={type:e.ValidationRuleType.LENGTH_MATCH_RULE,params:{max:70}},G=RegExp("^(?!s*$).+"),Z={type:e.ValidationRuleType.REGEX_MATCH_RULE,params:{regex:G,error:"El campo es requerido"}},ee="Titular de la tarjeta",te="Número de tarjeta",re="CVC/CVV",oe="Mes",ie="Año",ne="Fecha de expiración",se="Nombre como aparece en la tarjeta",ae="1234 1234 1234 1234",de="3-4 dígitos",le="MM",ce="AA",ue={base:{border:"1px solid #e0e0e0",padding:"10px 7px",borderRadius:"5px",color:"#1d1d1d",marginTop:"2px",backgroundColor:"white",fontFamily:'"Inter", sans-serif',fontSize:"16px","&::placeholder":{color:"#ccc"}},complete:{color:"#4caf50"},invalid:{border:"1px solid #f44336"},empty:{},focus:{},global:{"@import":'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")'}},he={base:{fontSize:"12px",fontWeight:"500",fontFamily:'"Inter", sans-serif'}},Ee={base:{fontSize:"12px",fontWeight:"500",fontFamily:'"Inter", sans-serif',color:"#f44336"}};function _e({baseUrl:r,apiKey:o,vault_id:i,vault_url:s,data:a}){return t(this,void 0,void 0,(function*(){const d=e.init({vaultID:i,vaultURL:s,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield W(r,o)})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}).container(e.ContainerType.COLLECT),l=yield function(r,o){return t(this,void 0,void 0,(function*(){const i=yield function(r,o){return t(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(r).map((r=>t(this,void 0,void 0,(function*(){return{element:yield o.create({table:"cards",column:r,type:e.ElementType.INPUT_FIELD}),key:r}})))))}))}(r,o);return i?i.map((e=>new Promise((t=>{var o;const i=document.createElement("div");i.hidden=!0,i.id=`id-${e.key}`,null===(o=document.querySelector("body"))||void 0===o||o.appendChild(i),setTimeout((()=>{e.element.mount(`#id-${e.key}`),setInterval((()=>{if(e.element.isMounted()){const o=r[e.key];return e.element.setValue(o),t(e.element.isMounted())}}),120)}),120)})))):[]}))}(a,d);if((yield Promise.all(l)).some((e=>!e)))throw C({errorCode:n.SAVE_CARD_PROCESS_ERROR,details:{step:"get_skyflow_tokens"}});try{const e=yield d.collect();if(e)return e.records[0].fields;throw C({errorCode:n.SAVE_CARD_PROCESS_ERROR,details:{step:"get_skyflow_tokens"}})}catch(e){throw C({errorCode:n.SAVE_CARD_PROCESS_ERROR},e)}}))}function Re(t){const{element:r,fieldMessage:o="",errorStyles:i={},requiredMessage:n="Campo requerido",invalidMessage:s="Campo no válido",events:a}=t;"on"in r&&(r.on(e.EventName.CHANGE,(e=>{pe({eventName:"onChange",data:e,events:a}),me({element:r,errorStyles:i,color:"transparent"})})),r.on(e.EventName.BLUR,(e=>{if(pe({eventName:"onBlur",data:e,events:a}),!e.isValid){const t=e.isEmpty?n:""!=o?`El campo ${o} no es válido`:s;r.setError(t)}me({element:r,errorStyles:i})})),r.on(e.EventName.FOCUS,(e=>{pe({eventName:"onFocus",data:e,events:a}),me({element:r,errorStyles:i,color:"transparent"}),r.resetError()})))}function me(e){const{element:t,errorStyles:r={},color:o=""}=e;Object.keys(r).length>0&&t.update({errorTextStyles:Object.assign(Object.assign({},r),{base:Object.assign(Object.assign({},r.base&&Object.assign({},r.base)),""!=o&&{color:o})})})}const pe=e=>{const{eventName:t,data:r,events:o}=e;if(o&&t in o){const e=o[t];"function"==typeof e&&e({elementType:S(r,"elementType",""),isEmpty:S(r,"isEmpty",!1),isFocused:S(r,"isFocused",!1),isValid:S(r,"isValid",!1),value:S(r,"value","")})}};function ye(e){return t(this,void 0,void 0,(function*(){const{element:t,containerId:r,retries:o=2,delay:i=30}=e;for(let e=0;e<=o;e++){if(document.querySelector(r))return void t.mount(r);e<o&&(yield new Promise((e=>setTimeout(e,i))))}console.warn(`[mountCardFields] Container ${r} was not found after ${o+1} attempts`)}))}const ve=Object.freeze({SORIANA:"SORIANA",OXXO:"OXXO",OXXOPAY:"OXXOPAY",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"}),Ce={[ve.SORIANA]:{label:"Soriana",iconPath:"/payment_methods/soriana.png"},[ve.OXXO]:{label:"Oxxo",iconPath:"/payment_methods/oxxo.png"},[ve.CODI]:{label:"CoDi",iconPath:"/payment_methods/codi.png"},[ve.MERCADOPAGO]:{label:"Mercado Pago",iconPath:"/payment_methods/mercadopago.png"},[ve.OXXOPAY]:{label:"Oxxo Pay",iconPath:"/payment_methods/oxxopay.png"},[ve.SPEI]:{label:"SPEI",iconPath:"/payment_methods/spei.png"},[ve.PAYPAL]:{label:"Paypal",iconPath:"/payment_methods/paypal.png"},[ve.COMERCIALMEXICANA]:{label:"Comercial Mexicana",iconPath:"/payment_methods/comercial_exicana.png"},[ve.BANCOMER]:{label:"Bancomer",iconPath:"/payment_methods/bancomer.png"},[ve.WALMART]:{label:"Walmart",iconPath:"/payment_methods/walmart.png"},[ve.BODEGA]:{label:"Bodega Aurrera",iconPath:"/payment_methods/bodega_aurrera.png"},[ve.SAMSCLUB]:{label:"Sam´s Club",iconPath:"/payment_methods/sams_club.png"},[ve.SUPERAMA]:{label:"Superama",iconPath:"/payment_methods/superama.png"},[ve.CALIMAX]:{label:"Calimax",iconPath:"/payment_methods/calimax.png"},[ve.EXTRA]:{label:"Tiendas Extra",iconPath:"/payment_methods/tiendas_extra.png"},[ve.CIRCULOK]:{label:"Círculo K",iconPath:"/payment_methods/circulo_k.png"},[ve.SEVEN11]:{label:"7 Eleven",iconPath:"/payment_methods/7_eleven.png"},[ve.TELECOMM]:{label:"Telecomm",iconPath:"/payment_methods/telecomm.png"},[ve.BANORTE]:{label:"Banorte",iconPath:"/payment_methods/banorte.png"},[ve.BENAVIDES]:{label:"Farmacias Benavides",iconPath:"/payment_methods/farmacias_benavides.png"},[ve.DELAHORRO]:{label:"Farmacias del Ahorro",iconPath:"/payment_methods/farmacias_ahorro.png"},[ve.ELASTURIANO]:{label:"El Asturiano",iconPath:"/payment_methods/asturiano.png"},[ve.WALDOS]:{label:"Waldos",iconPath:"/payment_methods/waldos.png"},[ve.ALSUPER]:{label:"Alsuper",iconPath:"/payment_methods/al_super.png"},[ve.KIOSKO]:{label:"Kiosko",iconPath:"/payment_methods/kiosko.png"},[ve.STAMARIA]:{label:"Farmacias Santa María",iconPath:"/payment_methods/farmacias_santa_maria.png"},[ve.LAMASBARATA]:{label:"Farmacias la más barata",iconPath:"/payment_methods/farmacias_barata.png"},[ve.FARMROMA]:{label:"Farmacias Roma",iconPath:"/payment_methods/farmacias_roma.png"},[ve.FARMUNION]:{label:"Pago en Farmacias Unión",iconPath:"/payment_methods/farmacias_union.png"},[ve.FARMATODO]:{label:"Pago en Farmacias Farmatodo",iconPath:"/payment_methods/farmacias_farmatodo.png\t"},[ve.SFDEASIS]:{label:"Pago en Farmacias San Francisco de Asís",iconPath:"/payment_methods/farmacias_san_francisco.png"},[ve.FARM911]:{label:"Farmacias 911",iconPath:"/payment_methods/store.png"},[ve.FARMECONOMICAS]:{label:"Farmacias Economicas",iconPath:"/payment_methods/store.png"},[ve.FARMMEDICITY]:{label:"Farmacias Medicity",iconPath:"/payment_methods/store.png"},[ve.RIANXEIRA]:{label:"Rianxeira",iconPath:"/payment_methods/store.png"},[ve.WESTERNUNION]:{label:"Western Union",iconPath:"/payment_methods/store.png"},[ve.ZONAPAGO]:{label:"Zona Pago",iconPath:"/payment_methods/store.png"},[ve.CAJALOSANDES]:{label:"Caja Los Andes",iconPath:"/payment_methods/store.png"},[ve.CAJAPAITA]:{label:"Caja Paita",iconPath:"/payment_methods/store.png"},[ve.CAJASANTA]:{label:"Caja Santa",iconPath:"/payment_methods/store.png"},[ve.CAJASULLANA]:{label:"Caja Sullana",iconPath:"/payment_methods/store.png"},[ve.CAJATRUJILLO]:{label:"Caja Trujillo",iconPath:"/payment_methods/store.png"},[ve.EDPYME]:{label:"Edpyme",iconPath:"/payment_methods/store.png"},[ve.KASNET]:{label:"KasNet",iconPath:"/payment_methods/store.png"},[ve.NORANDINO]:{label:"Norandino",iconPath:"/payment_methods/store.png"},[ve.QAPAQ]:{label:"Qapaq",iconPath:"/payment_methods/store.png"},[ve.RAIZ]:{label:"Raiz",iconPath:"/payment_methods/store.png"},[ve.PAYSER]:{label:"Paysera",iconPath:"/payment_methods/store.png"},[ve.WUNION]:{label:"Western Union",iconPath:"/payment_methods/store.png"},[ve.BANCOCONTINENTAL]:{label:"Banco Continental",iconPath:"/payment_methods/store.png"},[ve.GMONEY]:{label:"Go money",iconPath:"/payment_methods/store.png"},[ve.GOPAY]:{label:"Go pay",iconPath:"/payment_methods/store.png"},[ve.WU]:{label:"Western Union",iconPath:"/payment_methods/store.png"},[ve.PUNTOSHEY]:{label:"Puntoshey",iconPath:"/payment_methods/store.png"},[ve.AMPM]:{label:"Ampm",iconPath:"/payment_methods/store.png"},[ve.JUMBOMARKET]:{label:"Jumbomarket",iconPath:"/payment_methods/store.png"},[ve.SMELPUEBLO]:{label:"Smelpueblo",iconPath:"/payment_methods/store.png"},[ve.BAM]:{label:"Bam",iconPath:"/payment_methods/store.png"},[ve.REFACIL]:{label:"Refacil",iconPath:"/payment_methods/store.png"},[ve.ACYVALORES]:{label:"Acyvalores",iconPath:"/payment_methods/store.png"}},Ae=(e,t="stage")=>{const r=e.toUpperCase().trim().replace(/\s+/g,"");const o=Ce[r]||{iconPath:"/payment_methods/store.png",label:""};return{label:o.label,icon:`${l(t)}${o.iconPath}`}};class Oe extends Q{constructor({apiKey:e,mode:t,returnUrl:r,callBack:o,apiKeyTonder:i,baseUrlTonder:n,customization:s,collectorIds:a,events:d}){super({mode:t,apiKey:e,returnUrl:r,callBack:o,apiKeyTonder:i,baseUrlTonder:n,customization:s,tdsIframeId:a&&"tdsIframe"in a?null==a?void 0:a.tdsIframe:"tdsIframe",sdkInfo:L}),this.activeAPMs=[],this.mountedElementsByContext=new Map,this.customerCardsCache=null,this.lastCollectedTokens=null,this.skyflowInstance=null,this.events=d||{}}injectCheckout(){return t(this,void 0,void 0,(function*(){yield this._initializeCheckout()}))}getCustomerCards(){return t(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:e}=yield this._getCustomer(),t=yield this._getCustomerCards(e,this.merchantData.business.pk);return this.customerCardsCache=t,Object.assign(Object.assign({},t),{cards:t.cards.map((e=>Object.assign(Object.assign({},e),{fields:Object.assign(Object.assign({},e.fields),{subscription_id:this._hasCardOnFileKeys()?e.fields.subscription_id:void 0}),icon:h(e.fields.card_scheme,this.mode)})))})}catch(e){throw this.reportSdkError(e,{feature:"get-cards",process_id:this.getCustomerId(),metadata:{step:"getCustomerCards"}}),C({errorCode:n.FETCH_CARDS_ERROR},e)}}))}saveCustomerCard(){return t(this,void 0,void 0,(function*(){let e=null;try{yield this._fetchMerchantData();const t=yield this._getCustomer(),{auth_token:r,first_name:o="",last_name:i="",email:s=""}=t,{business:a}=this.merchantData,d=this._hasCardOnFileKeys(),l=yield this.collectCreateCardTokens(),c=yield this._saveCustomerCard(r,null==a?void 0:a.pk,l,d);if(e=c.skyflow_id,d){const e=c.card_bin;if(!e)throw new Error("Card BIN not returned from save card");const t=yield this._initializeCardOnFile();let d;try{d=yield t.process({cardTokens:{name:l.cardholder_name,number:l.card_number,expiryMonth:l.expiration_month,expiryYear:l.expiration_year,cvv:l.cvv},cardBin:e,contactDetails:{firstName:o||"",lastName:i||"",email:s||""},customerId:r,currency:this.currency||"MXN"})}catch(e){throw C({errorCode:n.CARD_ON_FILE_DECLINED,lockErrorCode:!0},e)}const u={skyflow_id:l.skyflow_id,subscription_id:d.subscriptionId};yield this._saveCustomerCard(r,null==a?void 0:a.pk,u)}return c}catch(t){throw e&&(yield this.removeCustomerCard(e)),this.reportSdkError(t,{feature:"save-card",process_id:e||this.getCustomerId(),metadata:{step:"saveCustomerCard"}}),C({errorCode:n.SAVE_CARD_ERROR},t)}}))}removeCustomerCard(e){return t(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:t}=yield this._getCustomer(),{business:r}=this.merchantData;return yield this._removeCustomerCard(t,null==r?void 0:r.pk,e)}catch(t){throw this.reportSdkError(t,{feature:"remove-card",process_id:e,metadata:{step:"removeCustomerCard"}}),C({errorCode:n.REMOVE_CARD_ERROR},t)}}))}getCustomerPaymentMethods(){return t(this,void 0,void 0,(function*(){try{const e=yield this._fetchCustomerPaymentMethods();return(e&&"results"in e&&e.results.length>0?e.results:[]).filter((e=>"cards"!==e.category.toLowerCase())).map((e=>Object.assign({id:e.pk,payment_method:e.payment_method,priority:e.priority,category:e.category},Ae(e.payment_method,this.mode)))).sort(((e,t)=>e.priority-t.priority))}catch(e){throw this.reportSdkError(e,{feature:"get-payment-methods",metadata:{step:"getCustomerPaymentMethods"}}),C({errorCode:n.FETCH_PAYMENT_METHODS_ERROR},e)}}))}mountCardFields(r){var o;return t(this,void 0,void 0,(function*(){const i=r.card_id?`update:${r.card_id}`:"create",n=null!==(o=r.unmount_context)&&void 0!==o?o:"all";"none"!==n&&("current"===n?this.unmountCardFields(i):this.unmountCardFields(n)),yield this.createSkyflowInstance();const s=yield function(r){var o,i,n,s,a,d,l,c,u,h,E,_,R;return t(this,void 0,void 0,(function*(){const{skyflowInstance:t,data:m,customization:p,events:y}=r,v=t.container(e.ContainerType.COLLECT),C=[],A={[X.CVV]:e.ElementType.CVV,[X.CARD_NUMBER]:e.ElementType.CARD_NUMBER,[X.EXPIRATION_MONTH]:e.ElementType.EXPIRATION_MONTH,[X.EXPIRATION_YEAR]:e.ElementType.EXPIRATION_YEAR,[X.CARDHOLDER_NAME]:e.ElementType.CARDHOLDER_NAME},O={[X.CVV]:[Z],[X.CARD_NUMBER]:[Z],[X.EXPIRATION_MONTH]:[Z],[X.EXPIRATION_YEAR]:[Z],[X.CARDHOLDER_NAME]:[J,Z]},T={[X.CARDHOLDER_NAME]:"cardholderName",[X.CARD_NUMBER]:"cardNumber",[X.CVV]:"cvv",[X.EXPIRATION_MONTH]:"expirationMonth",[X.EXPIRATION_YEAR]:"expirationYear"},f=e=>{var t,r,o,i,n,s,a,d,l;const c=null===(t=null==p?void 0:p.styles)||void 0===t?void 0:t[T[e]],u=null===(r=null==p?void 0:p.styles)||void 0===r?void 0:r.cardForm,h=null!==(i=null!==(o=null==c?void 0:c.inputStyles)&&void 0!==o?o:null==u?void 0:u.inputStyles)&&void 0!==i?i:ue;return{inputStyles:e===X.CARD_NUMBER&&!1!==(null===(n=null==p?void 0:p.styles)||void 0===n?void 0:n.enableCardIcon)?Object.assign(Object.assign({},h),{base:Object.assign({paddingLeft:"15px"},null==h?void 0:h.base)}):h,labelStyles:null!==(a=null!==(s=null==c?void 0:c.labelStyles)&&void 0!==s?s:null==u?void 0:u.labelStyles)&&void 0!==a?a:he,errorStyles:null!==(l=null!==(d=null==c?void 0:c.errorStyles)&&void 0!==d?d:null==u?void 0:u.errorStyles)&&void 0!==l?l:Ee}},S={cardholder_name:(null===(o=null==p?void 0:p.labels)||void 0===o?void 0:o.name)||ee,card_number:(null===(i=null==p?void 0:p.labels)||void 0===i?void 0:i.card_number)||te,cvv:(null===(n=null==p?void 0:p.labels)||void 0===n?void 0:n.cvv)||re,expiration_date:(null===(s=null==p?void 0:p.labels)||void 0===s?void 0:s.expiry_date)||ne,expiration_month:(null===(a=null==p?void 0:p.labels)||void 0===a?void 0:a.expiration_month)||oe,expiration_year:(null===(d=null==p?void 0:p.labels)||void 0===d?void 0:d.expiration_year)||ie},I={cardholder_name:(null===(l=null==p?void 0:p.placeholders)||void 0===l?void 0:l.name)||se,card_number:(null===(c=null==p?void 0:p.placeholders)||void 0===c?void 0:c.card_number)||ae,cvv:(null===(u=null==p?void 0:p.placeholders)||void 0===u?void 0:u.cvv)||de,expiration_month:(null===(h=null==p?void 0:p.placeholders)||void 0===h?void 0:h.expiration_month)||le,expiration_year:(null===(E=null==p?void 0:p.placeholders)||void 0===E?void 0:E.expiration_year)||ce},g={[X.CVV]:null==y?void 0:y.cvvEvents,[X.CARD_NUMBER]:null==y?void 0:y.cardNumberEvents,[X.EXPIRATION_MONTH]:null==y?void 0:y.monthEvents,[X.EXPIRATION_YEAR]:null==y?void 0:y.yearEvents,[X.CARDHOLDER_NAME]:null==y?void 0:y.cardHolderEvents};if("fields"in m&&Array.isArray(m.fields)){const e={enableCardIcon:null===(R=null===(_=null==p?void 0:p.styles)||void 0===_?void 0:_.enableCardIcon)||void 0===R||R};if(m.fields.length>0&&"string"==typeof m.fields[0])for(const t of m.fields){const r=v.create(Object.assign(Object.assign(Object.assign({table:"cards",column:t,type:A[t],validations:O[t]},f(t)),{label:S[t],placeholder:I[t]}),m.card_id?{skyflowID:m.card_id}:{}),t===X.CARD_NUMBER?e:void 0);Re({element:r,errorStyles:f(t).errorStyles,fieldMessage:[X.CVV,X.EXPIRATION_MONTH,X.EXPIRATION_YEAR].includes(t)?"":S[t],events:g[t]});const o=`#collect_${String(t)}`+(m.card_id?`_${m.card_id}`:"");yield ye({element:r,containerId:o}),C.push({element:r,containerId:o})}else for(const t of m.fields){const r=t.field,o=v.create(Object.assign(Object.assign(Object.assign({table:"cards",column:r,type:A[r],validations:O[r]},f(r)),{label:S[r],placeholder:I[r]}),m.card_id?{skyflowID:m.card_id}:{}),r===X.CARD_NUMBER?e:void 0);Re({element:o,errorStyles:f(r).errorStyles,fieldMessage:[X.CVV,X.EXPIRATION_MONTH,X.EXPIRATION_YEAR].includes(r)?"":S[r],events:g[r]});const i=t.container_id||`#collect_${String(r)}`+(m.card_id?`_${m.card_id}`:"");yield ye({element:o,containerId:i}),C.push({element:o,containerId:i})}}return{elements:C.map((e=>e.element)),container:v}}))}({skyflowInstance:this.skyflowInstance,data:r,customization:this.customization,events:this.events});this.mountedElementsByContext.set(i,{elements:s.elements||[],container:s})}))}getContainerByCardId(e){var t;const r=`update:${e}`,o=this.mountedElementsByContext.get(r);return(null===(t=null==o?void 0:o.container)||void 0===t?void 0:t.container)||null}collectCardTokens(e){var r,o,i;return t(this,void 0,void 0,(function*(){const t=this.getContainerByCardId(e);if(!t)return null;try{const e=yield t.collect();return(null===(o=null===(r=null==e?void 0:e.records)||void 0===r?void 0:r[0])||void 0===o?void 0:o.fields)||null}catch(t){const r=null===(i=null==t?void 0:t.error)||void 0===i?void 0:i.description;throw this.reportSdkError(t,{feature:"collect-card-tokens",process_id:e,metadata:{step:"collectCardTokens"}}),new a({code:n.MOUNT_COLLECT_ERROR,details:{message:r}})}}))}collectCreateCardTokens(){var e,r,o,i;return t(this,void 0,void 0,(function*(){const t=this.mountedElementsByContext.get("create"),s=null===(e=null==t?void 0:t.container)||void 0===e?void 0:e.container;if(!s)throw new a({code:n.MOUNT_COLLECT_ERROR,details:{message:"No card fields are mounted. Call mountCardFields() with the required fields before proceeding."}});try{const e=yield s.collect(),t=(null===(o=null===(r=null==e?void 0:e.records)||void 0===r?void 0:r[0])||void 0===o?void 0:o.fields)||{};return this.lastCollectedTokens=t,t}catch(e){const t=null===(i=null==e?void 0:e.error)||void 0===i?void 0:i.description;throw this.reportSdkError(e,{feature:"collect-create-card-tokens",metadata:{step:"collectCreateCardTokens"}}),new a({code:n.MOUNT_COLLECT_ERROR,details:{message:t}})}}))}revealCardFields(r){return t(this,void 0,void 0,(function*(){if(!this.lastCollectedTokens)throw C({errorCode:n.MOUNT_COLLECT_ERROR,details:{message:"No card tokens available. Call saveCustomerCard() or payment() with a new card before calling revealCardFields()."}});if(!this.skyflowInstance)throw C({errorCode:n.MOUNT_COLLECT_ERROR,details:{message:"Skyflow instance not initialized. Ensure mountCardFields() was called before saveCustomerCard() or payment()."}});yield function(r){var o,i,n,s,a,d;return t(this,void 0,void 0,(function*(){const{skyflowInstance:t,tokens:l,request:c}=r,u=t.container(e.ContainerType.REVEAL),h={[X.CARD_NUMBER]:"MASKED",[X.CARDHOLDER_NAME]:"PLAIN_TEXT",[X.EXPIRATION_MONTH]:"PLAIN_TEXT",[X.EXPIRATION_YEAR]:"PLAIN_TEXT"};for(const t of c.fields){const r="string"==typeof t,E=r?t:t.field;if(E===X.CVV){console.warn("[revealCardFields] CVV cannot be revealed (PCI DSS req. 3.2.1). Skipping.");continue}const _=l[E];if(!_){console.warn(`[revealCardFields] No token found for field "${E}", skipping.`);continue}const R=r?{}:t,m=null!==(o=R.container_id)&&void 0!==o?o:`#reveal_${E}`,p=h[E],y=null!==(i=R.styles)&&void 0!==i?i:{},v=null!==(n=c.styles)&&void 0!==n?n:{},C=u.create(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({token:_,redaction:e.RedactionType[p]},void 0!==R.altText&&{altText:R.altText}),void 0!==R.label&&{label:R.label}),y.inputStyles||v.inputStyles?{inputStyles:null!==(s=y.inputStyles)&&void 0!==s?s:v.inputStyles}:{}),y.labelStyles||v.labelStyles?{labelStyles:null!==(a=y.labelStyles)&&void 0!==a?a:v.labelStyles}:{}),y.errorTextStyles||v.errorTextStyles?{errorTextStyles:null!==(d=y.errorTextStyles)&&void 0!==d?d:v.errorTextStyles}:{}));yield ye({element:C,containerId:m})}try{yield u.reveal()}catch(e){console.warn("[revealCardFields] reveal completed with errors:",e)}}))}({skyflowInstance:this.skyflowInstance,tokens:this.lastCollectedTokens,request:r})}))}unmountCardFields(e="all"){"all"===e?(this.mountedElementsByContext.forEach(((e,t)=>{this.unmountContext(t)})),this.mountedElementsByContext.clear()):(this.unmountContext(e),this.mountedElementsByContext.delete(e))}unmountContext(e){const t=this.mountedElementsByContext.get(e);if(!t)return;const{elements:r}=t;r&&r.length>0&&r.forEach((t=>{try{t&&"function"==typeof t.unmount&&t.unmount()}catch(t){console.warn(`Error unmounting Skyflow element from context '${e}':`,t),this.reportSdkError(t,{feature:"unmount-card-fields",metadata:{step:"unmountContext",context:e}})}}))}getBusiness(){return t(this,void 0,void 0,(function*(){try{return yield i(this.baseUrl,this.apiKeyTonder,this.abortController.signal)}catch(e){throw this.reportSdkError(e,{feature:"get-business",metadata:{step:"getBusiness"}}),C({errorCode:n.FETCH_BUSINESS_ERROR},e)}}))}createSkyflowInstance(){return t(this,void 0,void 0,(function*(){if(this.skyflowInstance)return this.skyflowInstance;yield this._fetchMerchantData();const{vault_id:r,vault_url:o}=this.merchantData;this.skyflowInstance=yield function({baseUrl:r,apiKey:o,vault_id:i,vault_url:n,mode:s}){return t(this,void 0,void 0,(function*(){const a="production"===s?e.Env.PROD:e.Env.DEV;return e.init({vaultID:i,vaultURL:n,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield W(r,o)})),options:{logLevel:e.LogLevel.ERROR,env:a}})}))}({vault_id:r,vault_url:o,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder,mode:this.mode})}))}getOpenpayDeviceSessionID(e,r,o){return t(this,void 0,void 0,(function*(){try{return yield f(e,r,o)}catch(e){throw this.reportSdkError(e,{feature:"get-openpay-device-session",metadata:{step:"getOpenpayDeviceSessionID"}}),C({errorCode:n.START_CHECKOUT_ERROR},e)}}))}getSkyflowTokens({vault_id:e,vault_url:r,data:o}){return t(this,void 0,void 0,(function*(){return yield _e({vault_id:e,vault_url:r,data:o,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})}))}_setCartTotal(e){this.cartTotal=e}_checkout({card:e,payment_method:r,isSandbox:o,returnUrl:i}){var s,a;return t(this,void 0,void 0,(function*(){yield this._fetchMerchantData();const d=yield this._getCustomer(this.abortController.signal),{business:l}=this.merchantData,{auth_token:c,first_name:u="",last_name:h="",email:E=""}=d,_=this._hasCardOnFileKeys();let R,m=null,p=null,y=null,v=!1;const A=()=>t(this,void 0,void 0,(function*(){var e,t;(null===(t=null===(e=this.customerCardsCache)||void 0===e?void 0:e.cards)||void 0===t?void 0:t.length)||(this.customerCardsCache=yield this._getCustomerCards(c,this.merchantData.business.pk))}));if(!r){if("string"==typeof e)if(p=e,R={skyflow_id:e},_){yield A();const t=null===(a=null===(s=this.customerCardsCache)||void 0===s?void 0:s.cards)||void 0===a?void 0:a.find((t=>t.fields.skyflow_id===e));if(!t)throw new Error("Card not found for card-on-file processing");const r=!!t.fields.subscription_id;r||(yield this.collectCardTokens(e)),r&&(m={subscriptionId:t.fields.subscription_id})}else yield this.collectCardTokens(e);else R=yield this.collectCreateCardTokens(),p=R.skyflow_id,_&&(y={name:R.cardholder_name,number:R.card_number,expiryMonth:R.expiration_month,expiryYear:R.expiration_year,cvv:R.cvv},v=!0);if(v){if(!p||!y)throw new Error("Missing card data for card-on-file processing");let e=null;try{const t=yield this._saveCustomerCard(c,null==l?void 0:l.pk,{skyflow_id:p},!0);e=t.skyflow_id;const r=t.card_bin;if(!r)throw new Error("Card BIN not returned from save card");const o=yield this._initializeCardOnFile();let i;try{i=yield o.process({cardTokens:y,cardBin:r,contactDetails:{firstName:u||"",lastName:h||"",email:E||""},customerId:c,currency:this.currency||"MXN"})}catch(e){throw C({errorCode:n.CARD_ON_FILE_DECLINED,lockErrorCode:!0},e)}m={subscriptionId:i.subscriptionId},yield this._saveCustomerCard(c,null==l?void 0:l.pk,{skyflow_id:p,subscription_id:m.subscriptionId})}catch(t){throw e&&(yield this.removeCustomerCard(e)),this.reportSdkError(t,{feature:"payment",process_id:e||this.getCustomerId(),metadata:{step:"card_on_file"}}),t}}}return yield this._handleCheckout({card:R,payment_method:r,customer:d,isSandbox:o,returnUrl:i,enable_card_on_file:!!(null==m?void 0:m.subscriptionId)&&_})}))}customerRegister(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrl}/api/v1/customer/`,r={email:e},o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.abortController.signal,body:JSON.stringify(r)});if(o.ok)return yield o.json();throw yield C({response:o,errorCode:n.CUSTOMER_OPERATION_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"customer-register",metadata:{step:"customerRegister"}}),C({errorCode:n.CUSTOMER_OPERATION_ERROR},e)}}))}createOrder(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrl}/api/v1/orders/`,r=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(r)});if(o.ok)return yield o.json();throw yield C({response:o,errorCode:n.CREATE_ORDER_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"create-order",metadata:{step:"createOrder"}}),C({errorCode:n.CREATE_ORDER_ERROR},e)}}))}createPayment(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrl}/api/v1/business/${e.business_pk}/payments/`,r=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(r)});if(o.ok)return yield o.json();throw yield C({response:o,errorCode:n.CREATE_PAYMENT_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"create-payment",metadata:{step:"createPayment"}}),C({errorCode:n.CREATE_PAYMENT_ERROR},e)}}))}startCheckoutRouter(e){return t(this,void 0,void 0,(function*(){const t=yield T(this.baseUrl,this.apiKeyTonder,e);if(yield this.init3DSRedirect(t))return t}))}init3DSRedirect(e){return t(this,void 0,void 0,(function*(){return this.process3ds.setPayload(e),yield this._handle3dsRedirect(e)}))}startCheckoutRouterFull(e){return t(this,void 0,void 0,(function*(){try{const{order:t,total:r,customer:o,skyflowTokens:i,return_url:s,isSandbox:a,metadata:d,currency:l,payment_method:u}=e,h=yield this._fetchMerchantData(),E=yield this.customerRegister(o.email);if(!(E&&"auth_token"in E&&h&&"reference"in h))throw C({errorCode:n.START_CHECKOUT_ERROR,details:{message:"Merchant or customer reposne errors",merchantResult:h,customerResult:E}});{const e={business:this.apiKeyTonder,client:E.auth_token,billing_address_id:null,shipping_address_id:null,amount:r,reference:h.reference,is_oneclick:!0,items:t.items},_=yield this.createOrder(e),R=(new Date).toISOString();if(!("id"in _&&"id"in E&&"business"in h))throw C({errorCode:n.START_CHECKOUT_ERROR,details:{message:"Order response errors",orderResult:_}});{const e={business_pk:h.business.pk,amount:r,date:R,order_id:_.id,client_id:E.id},t=yield this.createPayment(e);let n;const{openpay_keys:m,business:p}=h;m.merchant_id&&m.public_key&&(n=yield f(m.merchant_id,m.public_key,a));const y=Object.assign(Object.assign({name:o.name,last_name:o.lastname,email_client:o.email,phone_number:o.phone,return_url:s,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:r,title_ship:"shipping",description:"transaction",device_session_id:n||null,token_id:"",order_id:"id"in _&&_.id,business_id:p.pk,payment_id:"pk"in t&&t.pk,source:"sdk",metadata:d,browser_info:c(),currency:l},u?{payment_method:u}:{card:i}),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}),v=yield T(this.baseUrl,this.apiKeyTonder,y);if(yield this.init3DSRedirect(v))return v}}}catch(e){throw this.reportSdkError(e,{feature:"start-checkout-router-full",metadata:{step:"startCheckoutRouterFull"}}),C({errorCode:n.START_CHECKOUT_ERROR},e)}}))}registerCustomerCard(e,r,o){return t(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const t=yield fetch(`${this.baseUrl}/api/v1/business/${u(this.merchantData)}/cards/`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"User-token":r,"Content-Type":"application/json"},body:JSON.stringify(Object.assign({},o))});if(t.ok)return yield t.json();throw yield C({response:t,errorCode:n.SAVE_CARD_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"register-customer-card",metadata:{step:"registerCustomerCard"}}),C({errorCode:n.SAVE_CARD_ERROR},e)}}))}deleteCustomerCard(e,r=""){return t(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const t=yield fetch(`${this.baseUrl}/api/v1/business/${u(this.merchantData)}/cards/${r}`,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.abortController.signal});if(t.ok)return!0;throw yield C({response:t,errorCode:n.REMOVE_CARD_ERROR})}catch(e){throw this.reportSdkError(e,{feature:"delete-customer-card",process_id:r,metadata:{step:"deleteCustomerCard"}}),C({errorCode:n.REMOVE_CARD_ERROR},e)}}))}getActiveAPMs(){return t(this,void 0,void 0,(function*(){try{const e=yield function(e,r,o="?status=active&page_size=10000&country=México",i=null){return t(this,void 0,void 0,(function*(){const t=yield fetch(`${e}/api/v1/payment_methods${o}`,{method:"GET",headers:{Authorization:`Token ${r}`,"Content-Type":"application/json"},signal:i});if(t.ok)return yield t.json();throw yield C({response:t,errorCode:n.FETCH_PAYMENT_METHODS_ERROR})}))}(this.baseUrl,this.apiKeyTonder),r=e&&e.results&&e.results.length>0?e.results:[];return this.activeAPMs=r.filter((e=>"cards"!==e.category.toLowerCase())).map((e=>Object.assign({id:e.pk,payment_method:e.payment_method,priority:e.priority,category:e.category},Ae(e.payment_method,this.mode)))).sort(((e,t)=>e.priority-t.priority)),this.activeAPMs}catch(e){return console.error("Error getting APMS",e),[]}}))}}function Te(e){return/^\d{12,19}$/.test(e)&&Ne(e)}function fe(e){return/^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/.test(e)}function Se(e){return/^\d{3,4}$/.test(e)}function Ie(e){return/^(0[1-9]|1[0-2])$/.test(e)}function ge(e){if(!/^\d{2}$/.test(e))return!1;const t=(new Date).getFullYear()%100;return parseInt(e,10)>=t}const Ne=e=>{const t=`${e}`.split("").reverse().map((e=>Number.parseInt(e))),r=t.shift();let o=t.reduce(((e,t,r)=>r%2!=0?e+t:e+((t*=2)>9?t-9:t)),0);return o+=r,o%10==0};export{R as AppError,Q as BaseInlineCheckout,Oe as LiteCheckout,U as SdkTelemetryClient,Se as validateCVV,Te as validateCardNumber,fe as validateCardholderName,Ie as validateExpirationMonth,ge as validateExpirationYear};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static asset host by environment mode.
|
|
3
|
+
*
|
|
4
|
+
* Production keeps pointing at the legacy CloudFront distribution because
|
|
5
|
+
* merchants running already-published versions of the SDK still resolve their
|
|
6
|
+
* logos and card art from it. Every other mode uses the staging distribution.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ASSET_BASE_URL_BY_MODE: Readonly<{
|
|
9
|
+
production: "https://d35a75syrgujp0.cloudfront.net";
|
|
10
|
+
sandbox: "https://static.staging.tonder.io";
|
|
11
|
+
stage: "https://static.staging.tonder.io";
|
|
12
|
+
development: "https://static.staging.tonder.io";
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Get the static asset base URL for a given mode
|
|
16
|
+
*/
|
|
17
|
+
export declare function getAssetBaseUrl(mode?: "production" | "sandbox" | "stage" | "development"): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonder.io/ionic-lite-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Tonder ionic lite SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
},
|
|
12
12
|
"author": "",
|
|
13
13
|
"license": "ISC",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20"
|
|
16
|
+
},
|
|
14
17
|
"dependencies": {
|
|
15
|
-
"lodash.get": "^4.4.2",
|
|
16
18
|
"skyflow-js": "2.5.0",
|
|
17
19
|
"ts-node": "^10.9.2"
|
|
18
20
|
},
|
|
@@ -23,21 +25,35 @@
|
|
|
23
25
|
"devDependencies": {
|
|
24
26
|
"@rollup/plugin-json": "^6.1.0",
|
|
25
27
|
"@rollup/plugin-replace": "^6.0.3",
|
|
26
|
-
"@rollup/plugin-terser": "^0.
|
|
28
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
27
29
|
"@rollup/plugin-typescript": "11.1.6",
|
|
28
30
|
"@types/crypto-js": "^4.2.2",
|
|
29
31
|
"@types/jest": "^29.5.11",
|
|
30
|
-
"@types/lodash": "^4.17.10",
|
|
31
|
-
"@types/lodash.get": "^4.4.9",
|
|
32
32
|
"@types/node": "^20.11.5",
|
|
33
33
|
"jest": "^29.7.0",
|
|
34
34
|
"jest-environment-jsdom": "^29.7.0",
|
|
35
|
-
"
|
|
36
|
-
"rollup": "4.9.6",
|
|
35
|
+
"rollup": "4.59.0",
|
|
37
36
|
"ts-jest": "^29.1.2",
|
|
38
|
-
"ts-loader": "^9.5.1",
|
|
39
37
|
"tslib": "^2.6.2",
|
|
40
38
|
"typescript": "^5.3.3",
|
|
41
39
|
"typescript-coverage-report": "^0.8.0"
|
|
40
|
+
},
|
|
41
|
+
"overrides": {
|
|
42
|
+
"@babel/core@^7": "^7.29.7",
|
|
43
|
+
"@babel/helpers@^7": "^7.26.10",
|
|
44
|
+
"@babel/runtime@^7": "^7.26.10",
|
|
45
|
+
"@tootallnate/once@^2": "^2.0.1",
|
|
46
|
+
"brace-expansion@^1": "^1.1.18",
|
|
47
|
+
"brace-expansion@^2": "^2.1.4",
|
|
48
|
+
"braces@^3": "^3.0.3",
|
|
49
|
+
"cross-spawn@^7": "^7.0.6",
|
|
50
|
+
"diff@^4": "^4.0.4",
|
|
51
|
+
"form-data@^4": "^4.0.6",
|
|
52
|
+
"js-yaml@^3": "^3.15.1",
|
|
53
|
+
"micromatch@^4": "^4.0.8",
|
|
54
|
+
"minimatch@^3": "^3.1.4",
|
|
55
|
+
"minimatch@^9": "^9.0.7",
|
|
56
|
+
"picomatch@^2": "^2.3.2",
|
|
57
|
+
"ws@^8": "^8.21.0"
|
|
42
58
|
}
|
|
43
59
|
}
|
|
@@ -102,7 +102,7 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteCheckout{
|
|
|
102
102
|
...ic.fields,
|
|
103
103
|
subscription_id: this._hasCardOnFileKeys() ? ic.fields.subscription_id : undefined,
|
|
104
104
|
},
|
|
105
|
-
icon: getCardType(ic.fields.card_scheme),
|
|
105
|
+
icon: getCardType(ic.fields.card_scheme, this.mode),
|
|
106
106
|
})),
|
|
107
107
|
};
|
|
108
108
|
} catch (error) {
|
|
@@ -254,7 +254,7 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteCheckout{
|
|
|
254
254
|
payment_method: apmItem.payment_method,
|
|
255
255
|
priority: apmItem.priority,
|
|
256
256
|
category: apmItem.category,
|
|
257
|
-
...getPaymentMethodDetails(apmItem.payment_method),
|
|
257
|
+
...getPaymentMethodDetails(apmItem.payment_method, this.mode),
|
|
258
258
|
};
|
|
259
259
|
return apm;
|
|
260
260
|
})
|
|
@@ -1076,7 +1076,7 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteCheckout{
|
|
|
1076
1076
|
payment_method: apmItem.payment_method,
|
|
1077
1077
|
priority: apmItem.priority,
|
|
1078
1078
|
category: apmItem.category,
|
|
1079
|
-
...getPaymentMethodDetails(apmItem.payment_method),
|
|
1079
|
+
...getPaymentMethodDetails(apmItem.payment_method, this.mode),
|
|
1080
1080
|
};
|
|
1081
1081
|
return apm;
|
|
1082
1082
|
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a nested value by path, falling back when it is missing.
|
|
3
|
+
*
|
|
4
|
+
* Replaces lodash `get`, and keeps its one surprising rule: the fallback
|
|
5
|
+
* applies only to `undefined`. A stored `null` is a real value and is returned
|
|
6
|
+
* as-is, so callers relying on that distinction keep working.
|
|
7
|
+
*
|
|
8
|
+
* Bracket indexes are normalised into path segments, so `a[0].b` and `a.0.b`
|
|
9
|
+
* resolve alike. Without that, a bracketed path would silently miss and return
|
|
10
|
+
* the fallback instead of the value that is actually there.
|
|
11
|
+
*/
|
|
12
|
+
export function get<T>(source: unknown, path: string, fallback: T): T {
|
|
13
|
+
const keys = path
|
|
14
|
+
.replace(/\[(\w+)\]/g, ".$1")
|
|
15
|
+
.split(".")
|
|
16
|
+
.filter((key) => key !== "");
|
|
17
|
+
|
|
18
|
+
let current: unknown = source;
|
|
19
|
+
|
|
20
|
+
for (const key of keys) {
|
|
21
|
+
if (current === null || current === undefined) return fallback;
|
|
22
|
+
current = (current as Record<string, unknown>)[key];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return current === undefined ? fallback : (current as T);
|
|
26
|
+
}
|
package/src/helpers/skyflow.ts
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
DEFAULT_SKYFLOW_INPUT_STYLES,
|
|
24
24
|
DEFAULT_SKYFLOW_lABEL_STYLES,
|
|
25
25
|
} from "../shared/styles/skyflow.styles";
|
|
26
|
-
import { get } from "
|
|
26
|
+
import { get } from "./get";
|
|
27
27
|
import { buildPublicAppError } from "../shared/utils/appError";
|
|
28
28
|
import { ErrorKeyEnum } from "../shared/enum/ErrorKeyEnum";
|
|
29
29
|
|
package/src/helpers/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getAssetBaseUrl } from "../shared/constants/assetUrl";
|
|
2
|
+
|
|
1
3
|
export const getBrowserInfo = () => {
|
|
2
4
|
const browserInfo = {
|
|
3
5
|
javascript_enabled: true, // Assumed since JavaScript is running
|
|
@@ -25,18 +27,22 @@ const clearSpace = (text: string) => {
|
|
|
25
27
|
return text.trim().replace(/\s+/g, "");
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
const getCardType = (
|
|
30
|
+
const getCardType = (
|
|
31
|
+
scheme: string,
|
|
32
|
+
mode: "production" | "sandbox" | "stage" | "development" = "stage",
|
|
33
|
+
) => {
|
|
34
|
+
const assetBaseUrl = getAssetBaseUrl(mode);
|
|
29
35
|
if (scheme === "Visa") {
|
|
30
36
|
// Check if visa
|
|
31
|
-
return
|
|
37
|
+
return `${assetBaseUrl}/cards/visa.png`;
|
|
32
38
|
} else if (scheme === "Mastercard") {
|
|
33
39
|
// Check if master
|
|
34
|
-
return
|
|
40
|
+
return `${assetBaseUrl}/cards/mastercard.png`;
|
|
35
41
|
} else if (scheme === "American Express") {
|
|
36
42
|
// Check if amex
|
|
37
|
-
return
|
|
43
|
+
return `${assetBaseUrl}/cards/american_express.png`;
|
|
38
44
|
} else {
|
|
39
|
-
return
|
|
45
|
+
return `${assetBaseUrl}/cards/default_card.png`;
|
|
40
46
|
}
|
|
41
47
|
};
|
|
42
48
|
|
|
@@ -1,256 +1,264 @@
|
|
|
1
1
|
import {clearSpace} from "../../helpers/utils";
|
|
2
2
|
import {PAYMENT_METHOD_APM} from "../constants/paymentMethodAPM";
|
|
3
|
+
import {getAssetBaseUrl} from "../constants/assetUrl";
|
|
3
4
|
|
|
4
5
|
const PAYMENT_METHODS_CATALOG = {
|
|
5
6
|
[PAYMENT_METHOD_APM.SORIANA]: {
|
|
6
7
|
label: "Soriana",
|
|
7
|
-
|
|
8
|
+
iconPath: "/payment_methods/soriana.png",
|
|
8
9
|
},
|
|
9
10
|
[PAYMENT_METHOD_APM.OXXO]: {
|
|
10
11
|
label: "Oxxo",
|
|
11
|
-
|
|
12
|
+
iconPath: "/payment_methods/oxxo.png",
|
|
12
13
|
},
|
|
13
14
|
[PAYMENT_METHOD_APM.CODI]: {
|
|
14
15
|
label: "CoDi",
|
|
15
|
-
|
|
16
|
+
iconPath: "/payment_methods/codi.png",
|
|
16
17
|
},
|
|
17
18
|
[PAYMENT_METHOD_APM.MERCADOPAGO]: {
|
|
18
19
|
label: "Mercado Pago",
|
|
19
|
-
|
|
20
|
+
iconPath: "/payment_methods/mercadopago.png",
|
|
20
21
|
},
|
|
21
22
|
[PAYMENT_METHOD_APM.OXXOPAY]: {
|
|
22
23
|
label: "Oxxo Pay",
|
|
23
|
-
|
|
24
|
+
iconPath: "/payment_methods/oxxopay.png",
|
|
24
25
|
},
|
|
25
26
|
[PAYMENT_METHOD_APM.SPEI]: {
|
|
26
27
|
label: "SPEI",
|
|
27
|
-
|
|
28
|
+
iconPath: "/payment_methods/spei.png",
|
|
28
29
|
},
|
|
29
30
|
[PAYMENT_METHOD_APM.PAYPAL]: {
|
|
30
31
|
label: "Paypal",
|
|
31
|
-
|
|
32
|
+
iconPath: "/payment_methods/paypal.png",
|
|
32
33
|
},
|
|
33
34
|
[PAYMENT_METHOD_APM.COMERCIALMEXICANA]: {
|
|
34
35
|
label: "Comercial Mexicana",
|
|
35
|
-
|
|
36
|
+
iconPath: "/payment_methods/comercial_exicana.png",
|
|
36
37
|
},
|
|
37
38
|
[PAYMENT_METHOD_APM.BANCOMER]: {
|
|
38
39
|
label: "Bancomer",
|
|
39
|
-
|
|
40
|
+
iconPath: "/payment_methods/bancomer.png",
|
|
40
41
|
},
|
|
41
42
|
[PAYMENT_METHOD_APM.WALMART]: {
|
|
42
43
|
label: "Walmart",
|
|
43
|
-
|
|
44
|
+
iconPath: "/payment_methods/walmart.png",
|
|
44
45
|
},
|
|
45
46
|
[PAYMENT_METHOD_APM.BODEGA]: {
|
|
46
47
|
label: "Bodega Aurrera",
|
|
47
|
-
|
|
48
|
+
iconPath: "/payment_methods/bodega_aurrera.png",
|
|
48
49
|
},
|
|
49
50
|
[PAYMENT_METHOD_APM.SAMSCLUB]: {
|
|
50
51
|
label: "Sam´s Club",
|
|
51
|
-
|
|
52
|
+
iconPath: "/payment_methods/sams_club.png",
|
|
52
53
|
},
|
|
53
54
|
[PAYMENT_METHOD_APM.SUPERAMA]: {
|
|
54
55
|
label: "Superama",
|
|
55
|
-
|
|
56
|
+
iconPath: "/payment_methods/superama.png",
|
|
56
57
|
},
|
|
57
58
|
[PAYMENT_METHOD_APM.CALIMAX]: {
|
|
58
59
|
label: "Calimax",
|
|
59
|
-
|
|
60
|
+
iconPath: "/payment_methods/calimax.png",
|
|
60
61
|
},
|
|
61
62
|
[PAYMENT_METHOD_APM.EXTRA]: {
|
|
62
63
|
label: "Tiendas Extra",
|
|
63
|
-
|
|
64
|
+
iconPath: "/payment_methods/tiendas_extra.png",
|
|
64
65
|
},
|
|
65
66
|
[PAYMENT_METHOD_APM.CIRCULOK]: {
|
|
66
67
|
label: "Círculo K",
|
|
67
|
-
|
|
68
|
+
iconPath: "/payment_methods/circulo_k.png",
|
|
68
69
|
},
|
|
69
70
|
[PAYMENT_METHOD_APM.SEVEN11]: {
|
|
70
71
|
label: "7 Eleven",
|
|
71
|
-
|
|
72
|
+
iconPath: "/payment_methods/7_eleven.png",
|
|
72
73
|
},
|
|
73
74
|
[PAYMENT_METHOD_APM.TELECOMM]: {
|
|
74
75
|
label: "Telecomm",
|
|
75
|
-
|
|
76
|
+
iconPath: "/payment_methods/telecomm.png",
|
|
76
77
|
},
|
|
77
78
|
[PAYMENT_METHOD_APM.BANORTE]: {
|
|
78
79
|
label: "Banorte",
|
|
79
|
-
|
|
80
|
+
iconPath: "/payment_methods/banorte.png",
|
|
80
81
|
},
|
|
81
82
|
[PAYMENT_METHOD_APM.BENAVIDES]: {
|
|
82
83
|
label: "Farmacias Benavides",
|
|
83
|
-
|
|
84
|
+
iconPath: "/payment_methods/farmacias_benavides.png",
|
|
84
85
|
},
|
|
85
86
|
[PAYMENT_METHOD_APM.DELAHORRO]: {
|
|
86
87
|
label: "Farmacias del Ahorro",
|
|
87
|
-
|
|
88
|
+
iconPath: "/payment_methods/farmacias_ahorro.png",
|
|
88
89
|
},
|
|
89
90
|
[PAYMENT_METHOD_APM.ELASTURIANO]: {
|
|
90
91
|
label: "El Asturiano",
|
|
91
|
-
|
|
92
|
+
iconPath: "/payment_methods/asturiano.png",
|
|
92
93
|
},
|
|
93
94
|
[PAYMENT_METHOD_APM.WALDOS]: {
|
|
94
95
|
label: "Waldos",
|
|
95
|
-
|
|
96
|
+
iconPath: "/payment_methods/waldos.png",
|
|
96
97
|
},
|
|
97
98
|
[PAYMENT_METHOD_APM.ALSUPER]: {
|
|
98
99
|
label: "Alsuper",
|
|
99
|
-
|
|
100
|
+
iconPath: "/payment_methods/al_super.png",
|
|
100
101
|
},
|
|
101
102
|
[PAYMENT_METHOD_APM.KIOSKO]: {
|
|
102
103
|
label: "Kiosko",
|
|
103
|
-
|
|
104
|
+
iconPath: "/payment_methods/kiosko.png",
|
|
104
105
|
},
|
|
105
106
|
[PAYMENT_METHOD_APM.STAMARIA]: {
|
|
106
107
|
label: "Farmacias Santa María",
|
|
107
|
-
|
|
108
|
+
iconPath: "/payment_methods/farmacias_santa_maria.png",
|
|
108
109
|
},
|
|
109
110
|
[PAYMENT_METHOD_APM.LAMASBARATA]: {
|
|
110
111
|
label: "Farmacias la más barata",
|
|
111
|
-
|
|
112
|
+
iconPath: "/payment_methods/farmacias_barata.png",
|
|
112
113
|
},
|
|
113
114
|
[PAYMENT_METHOD_APM.FARMROMA]: {
|
|
114
115
|
label: "Farmacias Roma",
|
|
115
|
-
|
|
116
|
+
iconPath: "/payment_methods/farmacias_roma.png",
|
|
116
117
|
},
|
|
117
118
|
[PAYMENT_METHOD_APM.FARMUNION]: {
|
|
118
119
|
label: "Pago en Farmacias Unión",
|
|
119
|
-
|
|
120
|
+
iconPath: "/payment_methods/farmacias_union.png",
|
|
120
121
|
},
|
|
121
122
|
[PAYMENT_METHOD_APM.FARMATODO]: {
|
|
122
123
|
label: "Pago en Farmacias Farmatodo",
|
|
123
|
-
|
|
124
|
+
iconPath: "/payment_methods/farmacias_farmatodo.png ",
|
|
124
125
|
},
|
|
125
126
|
[PAYMENT_METHOD_APM.SFDEASIS]: {
|
|
126
127
|
label: "Pago en Farmacias San Francisco de Asís",
|
|
127
|
-
|
|
128
|
+
iconPath: "/payment_methods/farmacias_san_francisco.png",
|
|
128
129
|
},
|
|
129
130
|
[PAYMENT_METHOD_APM.FARM911]: {
|
|
130
131
|
label: "Farmacias 911",
|
|
131
|
-
|
|
132
|
+
iconPath: "/payment_methods/store.png",
|
|
132
133
|
},
|
|
133
134
|
[PAYMENT_METHOD_APM.FARMECONOMICAS]: {
|
|
134
135
|
label: "Farmacias Economicas",
|
|
135
|
-
|
|
136
|
+
iconPath: "/payment_methods/store.png",
|
|
136
137
|
},
|
|
137
138
|
[PAYMENT_METHOD_APM.FARMMEDICITY]: {
|
|
138
139
|
label: "Farmacias Medicity",
|
|
139
|
-
|
|
140
|
+
iconPath: "/payment_methods/store.png",
|
|
140
141
|
},
|
|
141
142
|
[PAYMENT_METHOD_APM.RIANXEIRA]: {
|
|
142
143
|
label: "Rianxeira",
|
|
143
|
-
|
|
144
|
+
iconPath: "/payment_methods/store.png",
|
|
144
145
|
},
|
|
145
146
|
[PAYMENT_METHOD_APM.WESTERNUNION]: {
|
|
146
147
|
label: "Western Union",
|
|
147
|
-
|
|
148
|
+
iconPath: "/payment_methods/store.png",
|
|
148
149
|
},
|
|
149
150
|
[PAYMENT_METHOD_APM.ZONAPAGO]: {
|
|
150
151
|
label: "Zona Pago",
|
|
151
|
-
|
|
152
|
+
iconPath: "/payment_methods/store.png",
|
|
152
153
|
},
|
|
153
154
|
[PAYMENT_METHOD_APM.CAJALOSANDES]: {
|
|
154
155
|
label: "Caja Los Andes",
|
|
155
|
-
|
|
156
|
+
iconPath: "/payment_methods/store.png",
|
|
156
157
|
},
|
|
157
158
|
[PAYMENT_METHOD_APM.CAJAPAITA]: {
|
|
158
159
|
label: "Caja Paita",
|
|
159
|
-
|
|
160
|
+
iconPath: "/payment_methods/store.png",
|
|
160
161
|
},
|
|
161
162
|
[PAYMENT_METHOD_APM.CAJASANTA]: {
|
|
162
163
|
label: "Caja Santa",
|
|
163
|
-
|
|
164
|
+
iconPath: "/payment_methods/store.png",
|
|
164
165
|
},
|
|
165
166
|
[PAYMENT_METHOD_APM.CAJASULLANA]: {
|
|
166
167
|
label: "Caja Sullana",
|
|
167
|
-
|
|
168
|
+
iconPath: "/payment_methods/store.png",
|
|
168
169
|
},
|
|
169
170
|
[PAYMENT_METHOD_APM.CAJATRUJILLO]: {
|
|
170
171
|
label: "Caja Trujillo",
|
|
171
|
-
|
|
172
|
+
iconPath: "/payment_methods/store.png",
|
|
172
173
|
},
|
|
173
174
|
[PAYMENT_METHOD_APM.EDPYME]: {
|
|
174
175
|
label: "Edpyme",
|
|
175
|
-
|
|
176
|
+
iconPath: "/payment_methods/store.png",
|
|
176
177
|
},
|
|
177
178
|
[PAYMENT_METHOD_APM.KASNET]: {
|
|
178
179
|
label: "KasNet",
|
|
179
|
-
|
|
180
|
+
iconPath: "/payment_methods/store.png",
|
|
180
181
|
},
|
|
181
182
|
[PAYMENT_METHOD_APM.NORANDINO]: {
|
|
182
183
|
label: "Norandino",
|
|
183
|
-
|
|
184
|
+
iconPath: "/payment_methods/store.png",
|
|
184
185
|
},
|
|
185
186
|
[PAYMENT_METHOD_APM.QAPAQ]: {
|
|
186
187
|
label: "Qapaq",
|
|
187
|
-
|
|
188
|
+
iconPath: "/payment_methods/store.png",
|
|
188
189
|
},
|
|
189
190
|
[PAYMENT_METHOD_APM.RAIZ]: {
|
|
190
191
|
label: "Raiz",
|
|
191
|
-
|
|
192
|
+
iconPath: "/payment_methods/store.png",
|
|
192
193
|
},
|
|
193
194
|
[PAYMENT_METHOD_APM.PAYSER]: {
|
|
194
195
|
label: "Paysera",
|
|
195
|
-
|
|
196
|
+
iconPath: "/payment_methods/store.png",
|
|
196
197
|
},
|
|
197
198
|
[PAYMENT_METHOD_APM.WUNION]: {
|
|
198
199
|
label: "Western Union",
|
|
199
|
-
|
|
200
|
+
iconPath: "/payment_methods/store.png",
|
|
200
201
|
},
|
|
201
202
|
[PAYMENT_METHOD_APM.BANCOCONTINENTAL]: {
|
|
202
203
|
label: "Banco Continental",
|
|
203
|
-
|
|
204
|
+
iconPath: "/payment_methods/store.png",
|
|
204
205
|
},
|
|
205
206
|
[PAYMENT_METHOD_APM.GMONEY]: {
|
|
206
207
|
label: "Go money",
|
|
207
|
-
|
|
208
|
+
iconPath: "/payment_methods/store.png",
|
|
208
209
|
},
|
|
209
210
|
[PAYMENT_METHOD_APM.GOPAY]: {
|
|
210
211
|
label: "Go pay",
|
|
211
|
-
|
|
212
|
+
iconPath: "/payment_methods/store.png",
|
|
212
213
|
},
|
|
213
214
|
[PAYMENT_METHOD_APM.WU]: {
|
|
214
215
|
label: "Western Union",
|
|
215
|
-
|
|
216
|
+
iconPath: "/payment_methods/store.png",
|
|
216
217
|
},
|
|
217
218
|
[PAYMENT_METHOD_APM.PUNTOSHEY]: {
|
|
218
219
|
label: "Puntoshey",
|
|
219
|
-
|
|
220
|
+
iconPath: "/payment_methods/store.png",
|
|
220
221
|
},
|
|
221
222
|
[PAYMENT_METHOD_APM.AMPM]: {
|
|
222
223
|
label: "Ampm",
|
|
223
|
-
|
|
224
|
+
iconPath: "/payment_methods/store.png",
|
|
224
225
|
},
|
|
225
226
|
[PAYMENT_METHOD_APM.JUMBOMARKET]: {
|
|
226
227
|
label: "Jumbomarket",
|
|
227
|
-
|
|
228
|
+
iconPath: "/payment_methods/store.png",
|
|
228
229
|
},
|
|
229
230
|
[PAYMENT_METHOD_APM.SMELPUEBLO]: {
|
|
230
231
|
label: "Smelpueblo",
|
|
231
|
-
|
|
232
|
+
iconPath: "/payment_methods/store.png",
|
|
232
233
|
},
|
|
233
234
|
[PAYMENT_METHOD_APM.BAM]: {
|
|
234
235
|
label: "Bam",
|
|
235
|
-
|
|
236
|
+
iconPath: "/payment_methods/store.png",
|
|
236
237
|
},
|
|
237
238
|
[PAYMENT_METHOD_APM.REFACIL]: {
|
|
238
239
|
label: "Refacil",
|
|
239
|
-
|
|
240
|
+
iconPath: "/payment_methods/store.png",
|
|
240
241
|
},
|
|
241
242
|
[PAYMENT_METHOD_APM.ACYVALORES]: {
|
|
242
243
|
label: "Acyvalores",
|
|
243
|
-
|
|
244
|
+
iconPath: "/payment_methods/store.png",
|
|
244
245
|
},
|
|
245
246
|
};
|
|
246
247
|
|
|
247
248
|
|
|
248
|
-
export const getPaymentMethodDetails = (
|
|
249
|
+
export const getPaymentMethodDetails = (
|
|
250
|
+
scheme_data: string,
|
|
251
|
+
mode: "production" | "sandbox" | "stage" | "development" = "stage",
|
|
252
|
+
) => {
|
|
249
253
|
const scheme: string = clearSpace(scheme_data.toUpperCase());
|
|
250
254
|
const _default = {
|
|
251
|
-
|
|
255
|
+
iconPath: "/payment_methods/store.png",
|
|
252
256
|
label: "",
|
|
253
257
|
};
|
|
254
258
|
// @ts-ignore
|
|
255
|
-
|
|
259
|
+
const details = PAYMENT_METHODS_CATALOG[scheme] || _default;
|
|
260
|
+
return {
|
|
261
|
+
label: details.label,
|
|
262
|
+
icon: `${getAssetBaseUrl(mode)}${details.iconPath}`,
|
|
263
|
+
};
|
|
256
264
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static asset host by environment mode.
|
|
3
|
+
*
|
|
4
|
+
* Production keeps pointing at the legacy CloudFront distribution because
|
|
5
|
+
* merchants running already-published versions of the SDK still resolve their
|
|
6
|
+
* logos and card art from it. Every other mode uses the staging distribution.
|
|
7
|
+
*/
|
|
8
|
+
export const ASSET_BASE_URL_BY_MODE = Object.freeze({
|
|
9
|
+
production: "https://d35a75syrgujp0.cloudfront.net",
|
|
10
|
+
sandbox: "https://static.staging.tonder.io",
|
|
11
|
+
stage: "https://static.staging.tonder.io",
|
|
12
|
+
development: "https://static.staging.tonder.io",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get the static asset base URL for a given mode
|
|
17
|
+
*/
|
|
18
|
+
export function getAssetBaseUrl(
|
|
19
|
+
mode: "production" | "sandbox" | "stage" | "development" = "stage"
|
|
20
|
+
): string {
|
|
21
|
+
return ASSET_BASE_URL_BY_MODE[mode] || ASSET_BASE_URL_BY_MODE["stage"];
|
|
22
|
+
}
|
package/.gitlab-ci.yml
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
image: grupoapok/awscli:18
|
|
2
|
-
|
|
3
|
-
stages:
|
|
4
|
-
- test
|
|
5
|
-
- deploy
|
|
6
|
-
|
|
7
|
-
test:
|
|
8
|
-
stage: test
|
|
9
|
-
only:
|
|
10
|
-
- development
|
|
11
|
-
before_script:
|
|
12
|
-
- npm install
|
|
13
|
-
script:
|
|
14
|
-
- npm run test
|
|
15
|
-
|
|
16
|
-
deploy:
|
|
17
|
-
stage: deploy
|
|
18
|
-
only:
|
|
19
|
-
- tags
|
|
20
|
-
before_script:
|
|
21
|
-
- |
|
|
22
|
-
{
|
|
23
|
-
echo "@tonder.io:registry=https://registry.npmjs.org/"
|
|
24
|
-
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}"
|
|
25
|
-
} | tee -a .npmrc
|
|
26
|
-
script:
|
|
27
|
-
- npm install
|
|
28
|
-
- npm run build
|
|
29
|
-
- npm publish --access=public
|