@tonder.io/ionic-lite-sdk 0.0.35-beta.0 → 0.0.35-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/workspace.xml +2 -2
- package/dist/classes/liteCheckout.d.ts +2 -1
- package/dist/helpers/skyflow.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/types/commons.d.ts +11 -1
- package/dist/types/requests.d.ts +8 -1
- package/package.json +1 -1
- package/src/classes/liteCheckout.ts +21 -2
- package/src/helpers/skyflow.ts +2 -2
- package/src/types/commons.ts +11 -1
- package/src/types/liteInlineCheckout.d.ts +9 -1
- package/src/types/requests.ts +8 -1
- package/tests/utils/mockClasses.ts +3 -4
package/.idea/workspace.xml
CHANGED
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
<updated>1724776429568</updated>
|
|
93
93
|
<workItem from="1724776430626" duration="1847000" />
|
|
94
94
|
<workItem from="1724790840744" duration="239000" />
|
|
95
|
-
<workItem from="1725305433705" duration="
|
|
95
|
+
<workItem from="1725305433705" duration="16640000" />
|
|
96
96
|
</task>
|
|
97
97
|
<servers />
|
|
98
98
|
</component>
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
</line-breakpoint>
|
|
128
128
|
<line-breakpoint enabled="true" type="javascript">
|
|
129
129
|
<url>file://$PROJECT_DIR$/src/classes/liteCheckout.ts</url>
|
|
130
|
-
<line>
|
|
130
|
+
<line>208</line>
|
|
131
131
|
<properties lambdaOrdinal="-1" />
|
|
132
132
|
<option name="timeStamp" value="16" />
|
|
133
133
|
</line-breakpoint>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APM, IInlineCheckoutBaseOptions } from "../types/commons";
|
|
2
|
-
import { CreateOrderRequest, CreatePaymentRequest, RegisterCustomerCardRequest, StartCheckoutRequest, StartCheckoutFullRequest, StartCheckoutIdRequest } from "../types/requests";
|
|
2
|
+
import { CreateOrderRequest, CreatePaymentRequest, RegisterCustomerCardRequest, StartCheckoutRequest, StartCheckoutFullRequest, StartCheckoutIdRequest, TokensRequest } from "../types/requests";
|
|
3
3
|
import { CustomerRegisterResponse, CreateOrderResponse, CreatePaymentResponse, StartCheckoutResponse, RegisterCustomerCardResponse, GetBusinessResponse } from "../types/responses";
|
|
4
4
|
import { ErrorResponse } from "./errorResponse";
|
|
5
5
|
import { BaseInlineCheckout } from "./BaseInlineCheckout";
|
|
@@ -24,6 +24,7 @@ export declare class LiteCheckout extends BaseInlineCheckout implements ILiteInl
|
|
|
24
24
|
removeCustomerCard(skyflowId: string): Promise<string>;
|
|
25
25
|
getCustomerPaymentMethods(): Promise<IPaymentMethod[]>;
|
|
26
26
|
getBusiness(): Promise<GetBusinessResponse>;
|
|
27
|
+
getSkyflowTokens({ vault_id, vault_url, data }: TokensRequest): Promise<any | ErrorResponse>;
|
|
27
28
|
_setCartTotal(total: string): void;
|
|
28
29
|
_checkout({ card, payment_method, isSandbox }: {
|
|
29
30
|
card?: ICardFields | string;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { TokensRequest } from "../types/requests";
|
|
2
1
|
import { ErrorResponse } from "../classes/errorResponse";
|
|
3
|
-
|
|
2
|
+
import { TokensSkyflowRequest } from "../types";
|
|
3
|
+
export declare function getSkyflowTokens({ baseUrl, apiKey, vault_id, vault_url, data, }: TokensSkyflowRequest): Promise<any | ErrorResponse>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"skyflow-js";function e(t,e,o,n){return new(o||(o=Promise))((function(r,i){function s(t){try{d(n.next(t))}catch(t){i(t)}}function a(t){try{d(n.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}d((n=n.apply(t,e||[])).next())}))}function o(t,e,o,n){if("a"===o&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?n:"a"===o?n.call(t):n?n.value:e.get(t)}function n(t,o,n){return e(this,void 0,void 0,(function*(){const e=yield fetch(`${t}/api/v1/payments/business/${o}`,{headers:{Authorization:`Token ${o}`},signal:n});return yield e.json()}))}"function"==typeof SuppressedError&&SuppressedError;class r{constructor({code:t,body:e,name:o,message:n,stack:r}){this.code=t,this.body=e,this.name=o,this.message=n,this.stack=r}}const i=()=>({javascript_enabled:!0,time_zone:(new Date).getTimezoneOffset(),language:navigator.language||"en-US",color_depth:window.screen?window.screen.colorDepth:null,screen_width:window.screen?window.screen.width*window.devicePixelRatio||window.screen.width:null,screen_height:window.screen?window.screen.height*window.devicePixelRatio||window.screen.height:null,user_agent:navigator.userAgent}),s=t=>{var e;return t&&"business"in t?null===(e=null==t?void 0:t.business)||void 0===e?void 0:e.pk:""},a=t=>new r({code:(null==t?void 0:t.status)?t.status:t.code,body:null==t?void 0:t.body,name:t?"string"==typeof t?"catch":t.name:"Error",message:t?"string"==typeof t?t:t.message:"Error",stack:"string"==typeof t?void 0:t.stack}),d=(t,o=void 0)=>e(void 0,void 0,void 0,(function*(){let e,n,i="Error";t&&"json"in t&&(e=yield null==t?void 0:t.json()),t&&"status"in t&&(n=t.status.toString()),!e&&t&&"text"in t&&(i=yield t.text()),(null==e?void 0:e.detail)&&(i=e.detail);return new r({code:n,body:e,name:n,message:i,stack:o})}));function l(t,e){var o,n;let r=200;try{r=Number((null==e?void 0:e.code)||200)}catch(t){}const i={status:"error",code:r,message:"",detail:(null===(o=null==e?void 0:e.body)||void 0===o?void 0:o.detail)||(null===(n=null==e?void 0:e.body)||void 0===n?void 0:n.error)||e.body||"Ocurrio un error inesperado."};return Object.assign(Object.assign({},i),t)}class c{constructor({payload:t=null,apiKey:e,baseUrl:o}){this.localStorageKey="verify_transaction_status_url",this.setPayload=t=>{this.payload=t},this.baseUrl=o,this.apiKey=e,this.payload=t}setStorageItem(t){return localStorage.setItem(this.localStorageKey,JSON.stringify(t))}getStorageItem(){return localStorage.getItem(this.localStorageKey)}removeStorageItem(){return localStorage.removeItem(this.localStorageKey)}saveVerifyTransactionUrl(){var t,e,o,n,r,i;const s=null===(o=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===o?void 0:o.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const t=null===(i=null===(r=null===(n=this.payload)||void 0===n?void 0:n.next_action)||void 0===r?void 0:r.iframe_resources)||void 0===i?void 0:i.verify_transaction_status_url;t?this.saveUrlWithExpiration(t):console.log("No verify_transaction_status_url found")}}saveUrlWithExpiration(t){try{const e={url:t,expires:(new Date).getTime()+12e5};this.setStorageItem(e)}catch(t){console.log("error: ",t)}}getUrlWithExpiration(){const t=this.getStorageItem();if(t){const e=JSON.parse(t);if(!e)return;return(new Date).getTime()>e.expires?(this.removeVerifyTransactionUrl(),null):e.url}return null}removeVerifyTransactionUrl(){return this.removeStorageItem()}getVerifyTransactionUrl(){return this.getStorageItem()}loadIframe(){var t,e,o;if(null===(o=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.iframe_resources)||void 0===o?void 0:o.iframe)return new Promise(((t,e)=>{var o,n,r;const i=null===(r=null===(n=null===(o=this.payload)||void 0===o?void 0:o.next_action)||void 0===n?void 0:n.iframe_resources)||void 0===r?void 0:r.iframe;if(i){this.saveVerifyTransactionUrl();const o=document.createElement("div");o.innerHTML=i,document.body.appendChild(o);const n=document.createElement("script");n.textContent='document.getElementById("tdsMmethodForm").submit();',o.appendChild(n);const r=document.getElementById("tdsMmethodTgtFrame");r?r.onload=()=>t(!0):(console.log("No redirection found"),e(!1))}else console.log("No redirection found"),e(!1)}))}getRedirectUrl(){var t,e,o;return null===(o=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===o?void 0:o.url}redirectToChallenge(){const t=this.getRedirectUrl();t?(this.saveVerifyTransactionUrl(),window.location=t):console.log("No redirection found")}getURLParameters(){const t={},e=new URLSearchParams(window.location.search);for(const[o,n]of e)t[o]=n;return t}handleSuccessTransaction(t){return this.removeVerifyTransactionUrl(),console.log("Transacción autorizada."),t}handleDeclinedTransaction(t){return this.removeVerifyTransactionUrl(),t}handle3dsChallenge(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("form");e.name="frm",e.method="POST",e.action=t.redirect_post_url;const o=document.createElement("input");o.type="hidden",o.name=t.creq,o.value=t.creq,e.appendChild(o);const n=document.createElement("input");n.type="hidden",n.name=t.term_url,n.value=t.TermUrl,e.appendChild(n),document.body.appendChild(e),e.submit(),yield this.verifyTransactionStatus()}))}handleTransactionResponse(t){return e(this,void 0,void 0,(function*(){const e=yield t.json();return"Pending"===e.status&&e.redirect_post_url?yield this.handle3dsChallenge(e):["Success","Authorized"].includes(e.status)?this.handleSuccessTransaction(e):(this.handleDeclinedTransaction(t),e)}))}verifyTransactionStatus(){return e(this,void 0,void 0,(function*(){const t=this.getUrlWithExpiration();if(t){const e=`${this.baseUrl}${t}`;try{const t=yield fetch(e,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`}});return 200!==t.status?(console.error("La verificación de la transacción falló."),this.removeVerifyTransactionUrl(),t):yield this.handleTransactionResponse(t)}catch(t){console.error("Error al verificar la transacción:",t),this.removeVerifyTransactionUrl()}}else console.log("No verify_transaction_status_url found")}))}}const u=Object.freeze({production:"https://app.tonder.io",sandbox:"https://sandbox.tonder.io",stage:"https://stage.tonder.io",development:"http://localhost:8000"});function h(t,o,n){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/checkout-router/`,r=n,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${o}`},body:JSON.stringify(Object.assign(Object.assign({},r),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}))});if(i.status>=200&&i.status<=299)return yield i.json();{const t=yield i.json(),e=new Error("Failed to start checkout router");throw e.details=t,e}}catch(t){throw t}}))}function p(t,o,n=!0,r=null){return e(this,void 0,void 0,(function*(){let e=yield window.OpenPay;return e.setId(t),e.setApiKey(o),e.setSandboxMode(n),yield e.deviceData.setup({signal:r})}))}var m,y,f,g,v,A,_,b;class E{constructor({mode:t="stage",apiKey:e,apiKeyTonder:o,returnUrl:n,callBack:r=(()=>{})}){m.add(this),this.baseUrl="",this.cartTotal="0",this.metadata={},this.card={},this.currency="",y.set(this,void 0),this.apiKeyTonder=e||o||"",this.returnUrl=n,this.callBack=r,this.mode=t,this.baseUrl=u[this.mode]||u.stage,this.abortController=new AbortController,this.process3ds=new c({apiKey:e,baseUrl:this.baseUrl})}configureCheckout(t){"customer"in t&&o(this,m,"m",f).call(this,t.customer)}verify3dsTransaction(){return e(this,void 0,void 0,(function*(){const t=yield this.process3ds.verifyTransactionStatus(),e=yield o(this,m,"m",b).call(this,t);return this.process3ds.setPayload(e),this._handle3dsRedirect(e)}))}payment(t){return new Promise(((n,r)=>e(this,void 0,void 0,(function*(){var e,i;try{o(this,m,"m",f).call(this,t.customer),this._setCartTotal(null===(e=t.cart)||void 0===e?void 0:e.total),o(this,m,"m",g).call(this,null===(i=t.cart)||void 0===i?void 0:i.items),o(this,m,"m",v).call(this,t),o(this,m,"m",A).call(this,t),o(this,m,"m",_).call(this,t);const r=yield this._checkout(t);this.process3ds.setPayload(r),this.callBack&&this.callBack(r);(yield this._handle3dsRedirect(r))&&n(r)}catch(t){r(t)}}))))}_initializeCheckout(){return e(this,void 0,void 0,(function*(){const t=yield this._fetchMerchantData();t&&t.mercado_pago&&t.mercado_pago.active&&function(){try{const t=document.createElement("script");t.src="https://www.mercadopago.com/v2/security.js",t.setAttribute("view",""),t.onload=()=>{console.log("Mercado Pago script loaded successfully.")},t.onerror=t=>{console.error("Error loading Mercado Pago script:",t)},document.head.appendChild(t)}catch(t){console.error("Error attempting to inject Mercado Pago script:",t)}}()}))}_checkout(t){return e(this,void 0,void 0,(function*(){throw new Error("The #checkout method should be implement in child classes.")}))}_setCartTotal(t){throw new Error("The #setCartTotal method should be implement in child classes.")}_getCustomer(t=null){return e(this,void 0,void 0,(function*(){return o(this,y,"f")||function(t,e,o,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?r.call(t,o):r?r.value=o:e.set(t,o)}(this,y,yield function(t,o,n,r=null){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/customer/`,i={email:n.email,first_name:null==n?void 0:n.firstName,last_name:null==n?void 0:n.lastName,phone:null==n?void 0:n.phone},s=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${o}`},signal:r,body:JSON.stringify(i)});if(201===s.status)return yield s.json();throw new Error(`Error: ${s.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,this.customer,t),"f"),o(this,y,"f")}))}_handleCheckout({card:t,payment_method:o,customer:n,isSandbox:r}){return e(this,void 0,void 0,(function*(){const{openpay_keys:s,reference:a,business:d}=this.merchantData,l=Number(this.cartTotal);try{let c;!c&&s.merchant_id&&s.public_key&&(c=yield p(s.merchant_id,s.public_key,r,this.abortController.signal));const{id:u,auth_token:m}=n,y={business:this.apiKeyTonder,client:m,billing_address_id:null,shipping_address_id:null,amount:l,status:"A",reference:a,is_oneclick:!0,items:this.cartItems},f=yield function(t,o,n){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/orders/`,r=n,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${o}`},body:JSON.stringify(r)});if(201===i.status)return yield i.json();throw new Error(`Error: ${i.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,y),g=(new Date).toISOString(),v={business_pk:d.pk,client_id:u,amount:l,date:g,order_id:f.id},A=yield function(t,o,n){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/business/${n.business_pk}/payments/`,r=n,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${o}`},body:JSON.stringify(r)});if(i.status>=200&&i.status<=299)return yield i.json();throw new Error(`Error: ${i.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,v),_=Object.assign({name:this.firstName||"",last_name:this.lastName||"",email_client:this.email,phone_number:this.phone,return_url:this.returnUrl,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:l,title_ship:"shipping",description:"transaction",device_session_id:c||null,token_id:"",order_id:f.id,business_id:d.pk,payment_id:A.pk,source:"sdk",metadata:this.metadata,browser_info:i(),currency:this.currency},o?{payment_method:o}:{card:t}),b=yield h(this.baseUrl,this.apiKeyTonder,_);return b||!1}catch(t){throw console.log(t),t}}))}_fetchMerchantData(){return e(this,void 0,void 0,(function*(){try{return this.merchantData||(this.merchantData=yield n(this.baseUrl,this.apiKeyTonder,this.abortController.signal)),this.merchantData}catch(t){return this.merchantData}}))}_handle3dsRedirect(t){var o,n;return e(this,void 0,void 0,(function*(){if(t&&"next_action"in t?null===(n=null===(o=null==t?void 0:t.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===n?void 0:n.iframe:null)this.process3ds.loadIframe().then((()=>{this.process3ds.verifyTransactionStatus()})).catch((t=>{console.log("Error loading iframe:",t)}));else{if(!this.process3ds.getRedirectUrl())return t;this.process3ds.redirectToChallenge()}}))}}y=new WeakMap,m=new WeakSet,f=function(t){t&&(this.firstName=null==t?void 0:t.firstName,this.lastName=null==t?void 0:t.lastName,this.country=null==t?void 0:t.country,this.address=null==t?void 0:t.street,this.city=null==t?void 0:t.city,this.state=null==t?void 0:t.state,this.postCode=null==t?void 0:t.postCode,this.email=null==t?void 0:t.email,this.phone=null==t?void 0:t.phone,this.customer=t)},g=function(t){this.cartItems=t},v=function(t){this.metadata=null==t?void 0:t.metadata},A=function(t){this.currency=null==t?void 0:t.currency},_=function(t){this.card=null==t?void 0:t.card},b=function(t){var o,n;return e(this,void 0,void 0,(function*(){if("Hard"===(null===(o=null==t?void 0:t.decline)||void 0===o?void 0:o.error_type))return t;if(["Success","Authorized"].includes(null==t?void 0:t.transaction_status))return t;if(t){const e={checkout_id:null===(n=t.checkout)||void 0===n?void 0:n.id};try{return yield h(this.baseUrl,this.apiKeyTonder,e)}catch(t){}return t}}))};const T=Object.freeze({saveCardError:"Ha ocurrido un error guardando la tarjeta. Inténtalo nuevamente.",removeCardError:"Ha ocurrido un error eliminado la tarjeta. Inténtalo nuevamente.",getCardsError:"Ha ocurrido un error obteniendo las tarjetas del customer. Inténtalo nuevamente.",cardExist:"La tarjeta fue registrada previamente.",removedCard:"Card deleted successfully",errorCheckout:"No se ha podido procesar el pago",cardSaved:"Tarjeta registrada con éxito.",getPaymentMethodsError:"Ha ocurrido un error obteniendo las métodos de pago del customer. Inténtalo nuevamente.",getBusinessError:"Ha ocurrido un error obteniendo los datos del comercio. Inténtalo nuevamente."});function O({baseUrl:o,apiKey:n,vault_id:r,vault_url:i,data:s}){return e(this,void 0,void 0,(function*(){const d=t.init({vaultID:r,vaultURL:i,getBearerToken:()=>e(this,void 0,void 0,(function*(){return yield function(t,o,n=null){return e(this,void 0,void 0,(function*(){const e=yield fetch(`${t}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${o}`},signal:n});if(e.ok)return(yield e.json()).token;throw new Error("Failed to retrieve bearer token")}))}(o,n)})),options:{logLevel:t.LogLevel.ERROR,env:t.Env.DEV}}),l=d.container(t.ContainerType.COLLECT),c=yield function(o,n){return e(this,void 0,void 0,(function*(){const r=yield function(o,n){return e(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(o).map((o=>e(this,void 0,void 0,(function*(){return{element:yield n.create({table:"cards",column:o,type:t.ElementType.INPUT_FIELD}),key:o}})))))}))}(o,n);return r?r.map((t=>new Promise((e=>{var n;const r=document.createElement("div");r.hidden=!0,r.id=`id-${t.key}`,null===(n=document.querySelector("body"))||void 0===n||n.appendChild(r),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const n=o[t.key];return t.element.update({value:n}),e(t.element.isMounted())}}),120)}),120)})))):[]}))}(s,l);if((yield Promise.all(c)).some((t=>!t)))throw a(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const t=yield l.collect();if(t)return t.records[0].fields;throw a(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(t){throw a(t)}}))}const S=Object.freeze({SORIANA:"SORIANA",OXXO:"OXXO",SPEI:"SPEI",CODI:"CODI",MERCADOPAGO:"MERCADOPAGO",PAYPAL:"PAYPAL",COMERCIALMEXICANA:"COMERCIALMEXICANA",BANCOMER:"BANCOMER",WALMART:"WALMART",BODEGA:"BODEGA",SAMSCLUB:"SAMSCLUB",SUPERAMA:"SUPERAMA",CALIMAX:"CALIMAX",EXTRA:"EXTRA",CIRCULOK:"CIRCULOK",SEVEN11:"7ELEVEN",TELECOMM:"TELECOMM",BANORTE:"BANORTE",BENAVIDES:"BENAVIDES",DELAHORRO:"DELAHORRO",ELASTURIANO:"ELASTURIANO",WALDOS:"WALDOS",ALSUPER:"ALSUPER",KIOSKO:"KIOSKO",STAMARIA:"STAMARIA",LAMASBARATA:"LAMASBARATA",FARMROMA:"FARMROMA",FARMUNION:"FARMUNION",FARMATODO:"FARMATODO",SFDEASIS:"SFDEASIS",FARM911:"FARM911",FARMECONOMICAS:"FARMECONOMICAS",FARMMEDICITY:"FARMMEDICITY",RIANXEIRA:"RIANXEIRA",WESTERNUNION:"WESTERNUNION",ZONAPAGO:"ZONAPAGO",CAJALOSANDES:"CAJALOSANDES",CAJAPAITA:"CAJAPAITA",CAJASANTA:"CAJASANTA",CAJASULLANA:"CAJASULLANA",CAJATRUJILLO:"CAJATRUJILLO",EDPYME:"EDPYME",KASNET:"KASNET",NORANDINO:"NORANDINO",QAPAQ:"QAPAQ",RAIZ:"RAIZ",PAYSER:"PAYSER",WUNION:"WUNION",BANCOCONTINENTAL:"BANCOCONTINENTAL",GMONEY:"GMONEY",GOPAY:"GOPAY",WU:"WU",PUNTOSHEY:"PUNTOSHEY",AMPM:"AMPM",JUMBOMARKET:"JUMBOMARKET",SMELPUEBLO:"SMELPUEBLO",BAM:"BAM",REFACIL:"REFACIL",ACYVALORES:"ACYVALORES"}),C={[S.SORIANA]:{label:"Soriana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png"},[S.OXXO]:{label:"Oxxo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png"},[S.CODI]:{label:"CoDi",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png"},[S.SPEI]:{label:"SPEI",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png"},[S.PAYPAL]:{label:"Paypal",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png"},[S.COMERCIALMEXICANA]:{label:"Comercial Mexicana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png"},[S.BANCOMER]:{label:"Bancomer",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png"},[S.WALMART]:{label:"Walmart",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png"},[S.BODEGA]:{label:"Bodega Aurrera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png"},[S.SAMSCLUB]:{label:"Sam´s Club",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png"},[S.SUPERAMA]:{label:"Superama",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png"},[S.CALIMAX]:{label:"Calimax",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png"},[S.EXTRA]:{label:"Tiendas Extra",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png"},[S.CIRCULOK]:{label:"Círculo K",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png"},[S.SEVEN11]:{label:"7 Eleven",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png"},[S.TELECOMM]:{label:"Telecomm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png"},[S.BANORTE]:{label:"Banorte",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png"},[S.BENAVIDES]:{label:"Farmacias Benavides",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png"},[S.DELAHORRO]:{label:"Farmacias del Ahorro",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png"},[S.ELASTURIANO]:{label:"El Asturiano",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png"},[S.WALDOS]:{label:"Waldos",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png"},[S.ALSUPER]:{label:"Alsuper",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png"},[S.KIOSKO]:{label:"Kiosko",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png"},[S.STAMARIA]:{label:"Farmacias Santa María",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png"},[S.LAMASBARATA]:{label:"Farmacias la más barata",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png"},[S.FARMROMA]:{label:"Farmacias Roma",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png"},[S.FARMUNION]:{label:"Pago en Farmacias Unión",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png"},[S.FARMATODO]:{label:"Pago en Farmacias Farmatodo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png\t"},[S.SFDEASIS]:{label:"Pago en Farmacias San Francisco de Asís",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png"},[S.FARM911]:{label:"Farmacias 911",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.FARMECONOMICAS]:{label:"Farmacias Economicas",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.FARMMEDICITY]:{label:"Farmacias Medicity",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.RIANXEIRA]:{label:"Rianxeira",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WESTERNUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.ZONAPAGO]:{label:"Zona Pago",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJALOSANDES]:{label:"Caja Los Andes",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJAPAITA]:{label:"Caja Paita",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJASANTA]:{label:"Caja Santa",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJASULLANA]:{label:"Caja Sullana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJATRUJILLO]:{label:"Caja Trujillo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.EDPYME]:{label:"Edpyme",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.KASNET]:{label:"KasNet",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.NORANDINO]:{label:"Norandino",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.QAPAQ]:{label:"Qapaq",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.RAIZ]:{label:"Raiz",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.PAYSER]:{label:"Paysera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.BANCOCONTINENTAL]:{label:"Banco Continental",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.GMONEY]:{label:"Go money",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.GOPAY]:{label:"Go pay",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WU]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.PUNTOSHEY]:{label:"Puntoshey",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.AMPM]:{label:"Ampm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.JUMBOMARKET]:{label:"Jumbomarket",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.SMELPUEBLO]:{label:"Smelpueblo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.BAM]:{label:"Bam",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.REFACIL]:{label:"Refacil",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.ACYVALORES]:{label:"Acyvalores",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"}},j=t=>{const e=t.toUpperCase().trim().replace(/\s+/g,"");return C[e]||{icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",label:""}};var w;class M extends E{constructor({apiKey:t,mode:e,returnUrl:o,callBack:n}){super({mode:e,apiKey:t,returnUrl:o,callBack:n}),this.activeAPMs=[],w.set(this,void 0)}injectCheckout(){return e(this,void 0,void 0,(function*(){yield this._initializeCheckout()}))}getCustomerCards(){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:t}=yield this._getCustomer(),o=yield function(t,o,n,r=null){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${n}/cards/`,i=yield fetch(e,{method:"GET",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,t,this.merchantData.business.pk);return Object.assign(Object.assign({},o),{cards:o.cards.map((t=>{return Object.assign(Object.assign({},t),{icon:(e=t.fields.card_scheme,"Visa"===e?"https://d35a75syrgujp0.cloudfront.net/cards/visa.png":"Mastercard"===e?"https://d35a75syrgujp0.cloudfront.net/cards/mastercard.png":"American Express"===e?"https://d35a75syrgujp0.cloudfront.net/cards/american_express.png":"https://d35a75syrgujp0.cloudfront.net/cards/default_card.png")});var e}))})}catch(t){throw l({message:T.getCardsError},t)}}))}saveCustomerCard(t){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:o}=yield this._getCustomer(),{vault_id:n,vault_url:r,business:i}=this.merchantData,s=yield O({vault_id:n,vault_url:r,data:t,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder});return yield function(t,o,n,r){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${n}/cards/`,i=yield fetch(e,{method:"POST",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,o,null==i?void 0:i.pk,s)}catch(t){throw l({message:T.saveCardError},t)}}))}removeCustomerCard(t){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:o}=yield this._getCustomer(),{business:n}=this.merchantData;return yield function(t,o,n="",r){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${r}/cards/${n}`,i=yield fetch(e,{method:"DELETE",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"}});if(204===i.status)return T.cardSaved;if(i.ok&&"json"in i)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,o,t,null==n?void 0:n.pk)}catch(t){throw l({message:T.removeCardError},t)}}))}getCustomerPaymentMethods(){return e(this,void 0,void 0,(function*(){try{const t=yield function(t,o,n={status:"active",pagesize:"10000"},r=null){return e(this,void 0,void 0,(function*(){try{const e=new URLSearchParams(n).toString(),i=yield fetch(`${t}/api/v1/payment_methods?${e}`,{method:"GET",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,this.apiKeyTonder);return(t&&"results"in t&&t.results.length>0?t.results:[]).filter((t=>"cards"!==t.category.toLowerCase())).map((t=>Object.assign({id:t.pk,payment_method:t.payment_method,priority:t.priority,category:t.category},j(t.payment_method)))).sort(((t,e)=>t.priority-e.priority))}catch(t){throw l({message:T.getPaymentMethodsError},t)}}))}getBusiness(){return e(this,void 0,void 0,(function*(){try{return yield n(this.baseUrl,this.apiKeyTonder,this.abortController.signal)}catch(t){throw l({message:T.getBusinessError},t)}}))}_setCartTotal(t){this.cartTotal=t}_checkout({card:t,payment_method:o,isSandbox:n}){return e(this,void 0,void 0,(function*(){yield this._fetchMerchantData();const e=yield this._getCustomer(this.abortController.signal),{vault_id:r,vault_url:i}=this.merchantData;let s;return o&&""===o&&null!==o||(s="string"==typeof t?{skyflow_id:t}:yield O({vault_id:r,vault_url:i,data:Object.assign(Object.assign({},t),{card_number:t.card_number.replace(/\s+/g,"")}),baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})),yield this._handleCheckout({card:s,payment_method:o,customer:e,isSandbox:n})}))}customerRegister(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/customer/`,o={email:t},n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.abortController.signal,body:JSON.stringify(o)});if(n.ok)return yield n.json();throw yield d(n)}catch(t){throw a(t)}}))}createOrder(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/orders/`,o=t,n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});if(n.ok)return yield n.json();throw yield d(n)}catch(t){throw a(t)}}))}createPayment(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/business/${t.business_pk}/payments/`,o=t,n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});if(n.ok)return yield n.json();throw yield d(n)}catch(t){throw a(t)}}))}startCheckoutRouter(t){return e(this,void 0,void 0,(function*(){const e=yield h(this.baseUrl,this.apiKeyTonder,t);if(yield this.init3DSRedirect(e))return e}))}init3DSRedirect(t){return e(this,void 0,void 0,(function*(){return this.process3ds.setPayload(t),yield this._handle3dsRedirect(t)}))}startCheckoutRouterFull(t){return e(this,void 0,void 0,(function*(){try{const{order:e,total:o,customer:n,skyflowTokens:s,return_url:a,isSandbox:d,metadata:l,currency:c,payment_method:u}=t,m=yield this._fetchMerchantData(),y=yield this.customerRegister(n.email);if(!(y&&"auth_token"in y&&m&&"reference"in m))throw new r({code:"500",body:m,name:"Keys error",message:"Merchant or customer reposne errors"});{const t={business:this.apiKeyTonder,client:y.auth_token,billing_address_id:null,shipping_address_id:null,amount:o,reference:m.reference,is_oneclick:!0,items:e.items},f=yield this.createOrder(t),g=(new Date).toISOString();if(!("id"in f&&"id"in y&&"business"in m))throw new r({code:"500",body:f,name:"Keys error",message:"Order response errors"});{const t={business_pk:m.business.pk,amount:o,date:g,order_id:f.id,client_id:y.id},e=yield this.createPayment(t);let r;const{openpay_keys:v,business:A}=m;v.merchant_id&&v.public_key&&(r=yield p(v.merchant_id,v.public_key,d));const _=Object.assign(Object.assign({name:n.name,last_name:n.lastname,email_client:n.email,phone_number:n.phone,return_url:a,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:o,title_ship:"shipping",description:"transaction",device_session_id:r||null,token_id:"",order_id:"id"in f&&f.id,business_id:A.pk,payment_id:"pk"in e&&e.pk,source:"sdk",metadata:l,browser_info:i(),currency:c},u?{payment_method:u}:{card:s}),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}),b=yield h(this.baseUrl,this.apiKeyTonder,_);if(yield this.init3DSRedirect(b))return b}}}catch(t){throw a(t)}}))}registerCustomerCard(t,o){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const e=yield fetch(`${this.baseUrl}/api/v1/business/${s(this.merchantData)}/cards/`,{method:"POST",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},body:JSON.stringify(Object.assign({},o))});if(e.ok)return yield e.json();throw yield d(e)}catch(t){throw a(t)}}))}deleteCustomerCard(t,o=""){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const e=yield fetch(`${this.baseUrl}/api/v1/business/${s(this.merchantData)}/cards/${o}`,{method:"DELETE",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},signal:this.abortController.signal});if(e.ok)return!0;throw yield d(e)}catch(t){throw a(t)}}))}getActiveAPMs(){return e(this,void 0,void 0,(function*(){try{const t=yield function(t,o,n="?status=active&page_size=10000&country=México",r=null){return e(this,void 0,void 0,(function*(){try{const e=yield fetch(`${t}/api/v1/payment_methods${n}`,{method:"GET",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"},signal:r});if(e.ok)return yield e.json();throw yield d(e)}catch(t){throw a(t)}}))}(this.baseUrl,this.apiKeyTonder),o=t&&t.results&&t.results.length>0?t.results:[];return this.activeAPMs=o.filter((t=>"cards"!==t.category.toLowerCase())).map((t=>Object.assign({id:t.pk,payment_method:t.payment_method,priority:t.priority,category:t.category},j(t.payment_method)))).sort(((t,e)=>t.priority-e.priority)),this.activeAPMs}catch(t){return console.error("Error getting APMS",t),[]}}))}}w=new WeakMap;export{M as LiteCheckout};
|
|
1
|
+
import t from"skyflow-js";function e(t,e,o,n){return new(o||(o=Promise))((function(r,i){function s(t){try{d(n.next(t))}catch(t){i(t)}}function a(t){try{d(n.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}d((n=n.apply(t,e||[])).next())}))}function o(t,e,o,n){if("a"===o&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?n:"a"===o?n.call(t):n?n.value:e.get(t)}function n(t,o,n){return e(this,void 0,void 0,(function*(){const e=yield fetch(`${t}/api/v1/payments/business/${o}`,{headers:{Authorization:`Token ${o}`},signal:n});return yield e.json()}))}"function"==typeof SuppressedError&&SuppressedError;class r{constructor({code:t,body:e,name:o,message:n,stack:r}){this.code=t,this.body=e,this.name=o,this.message=n,this.stack=r}}const i=()=>({javascript_enabled:!0,time_zone:(new Date).getTimezoneOffset(),language:navigator.language||"en-US",color_depth:window.screen?window.screen.colorDepth:null,screen_width:window.screen?window.screen.width*window.devicePixelRatio||window.screen.width:null,screen_height:window.screen?window.screen.height*window.devicePixelRatio||window.screen.height:null,user_agent:navigator.userAgent}),s=t=>{var e;return t&&"business"in t?null===(e=null==t?void 0:t.business)||void 0===e?void 0:e.pk:""},a=t=>new r({code:(null==t?void 0:t.status)?t.status:t.code,body:null==t?void 0:t.body,name:t?"string"==typeof t?"catch":t.name:"Error",message:t?"string"==typeof t?t:t.message:"Error",stack:"string"==typeof t?void 0:t.stack}),d=(t,o=void 0)=>e(void 0,void 0,void 0,(function*(){let e,n,i="Error";t&&"json"in t&&(e=yield null==t?void 0:t.json()),t&&"status"in t&&(n=t.status.toString()),!e&&t&&"text"in t&&(i=yield t.text()),(null==e?void 0:e.detail)&&(i=e.detail);return new r({code:n,body:e,name:n,message:i,stack:o})}));function l(t,e){var o,n;let r=200;try{r=Number((null==e?void 0:e.code)||200)}catch(t){}const i={status:"error",code:r,message:"",detail:(null===(o=null==e?void 0:e.body)||void 0===o?void 0:o.detail)||(null===(n=null==e?void 0:e.body)||void 0===n?void 0:n.error)||e.body||"Ocurrio un error inesperado."};return Object.assign(Object.assign({},i),t)}class c{constructor({payload:t=null,apiKey:e,baseUrl:o}){this.localStorageKey="verify_transaction_status_url",this.setPayload=t=>{this.payload=t},this.baseUrl=o,this.apiKey=e,this.payload=t}setStorageItem(t){return localStorage.setItem(this.localStorageKey,JSON.stringify(t))}getStorageItem(){return localStorage.getItem(this.localStorageKey)}removeStorageItem(){return localStorage.removeItem(this.localStorageKey)}saveVerifyTransactionUrl(){var t,e,o,n,r,i;const s=null===(o=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===o?void 0:o.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const t=null===(i=null===(r=null===(n=this.payload)||void 0===n?void 0:n.next_action)||void 0===r?void 0:r.iframe_resources)||void 0===i?void 0:i.verify_transaction_status_url;t?this.saveUrlWithExpiration(t):console.log("No verify_transaction_status_url found")}}saveUrlWithExpiration(t){try{const e={url:t,expires:(new Date).getTime()+12e5};this.setStorageItem(e)}catch(t){console.log("error: ",t)}}getUrlWithExpiration(){const t=this.getStorageItem();if(t){const e=JSON.parse(t);if(!e)return;return(new Date).getTime()>e.expires?(this.removeVerifyTransactionUrl(),null):e.url}return null}removeVerifyTransactionUrl(){return this.removeStorageItem()}getVerifyTransactionUrl(){return this.getStorageItem()}loadIframe(){var t,e,o;if(null===(o=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.iframe_resources)||void 0===o?void 0:o.iframe)return new Promise(((t,e)=>{var o,n,r;const i=null===(r=null===(n=null===(o=this.payload)||void 0===o?void 0:o.next_action)||void 0===n?void 0:n.iframe_resources)||void 0===r?void 0:r.iframe;if(i){this.saveVerifyTransactionUrl();const o=document.createElement("div");o.innerHTML=i,document.body.appendChild(o);const n=document.createElement("script");n.textContent='document.getElementById("tdsMmethodForm").submit();',o.appendChild(n);const r=document.getElementById("tdsMmethodTgtFrame");r?r.onload=()=>t(!0):(console.log("No redirection found"),e(!1))}else console.log("No redirection found"),e(!1)}))}getRedirectUrl(){var t,e,o;return null===(o=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===o?void 0:o.url}redirectToChallenge(){const t=this.getRedirectUrl();t?(this.saveVerifyTransactionUrl(),window.location=t):console.log("No redirection found")}getURLParameters(){const t={},e=new URLSearchParams(window.location.search);for(const[o,n]of e)t[o]=n;return t}handleSuccessTransaction(t){return this.removeVerifyTransactionUrl(),console.log("Transacción autorizada."),t}handleDeclinedTransaction(t){return this.removeVerifyTransactionUrl(),t}handle3dsChallenge(t){return e(this,void 0,void 0,(function*(){const e=document.createElement("form");e.name="frm",e.method="POST",e.action=t.redirect_post_url;const o=document.createElement("input");o.type="hidden",o.name=t.creq,o.value=t.creq,e.appendChild(o);const n=document.createElement("input");n.type="hidden",n.name=t.term_url,n.value=t.TermUrl,e.appendChild(n),document.body.appendChild(e),e.submit(),yield this.verifyTransactionStatus()}))}handleTransactionResponse(t){return e(this,void 0,void 0,(function*(){const e=yield t.json();return"Pending"===e.status&&e.redirect_post_url?yield this.handle3dsChallenge(e):["Success","Authorized"].includes(e.status)?this.handleSuccessTransaction(e):(this.handleDeclinedTransaction(t),e)}))}verifyTransactionStatus(){return e(this,void 0,void 0,(function*(){const t=this.getUrlWithExpiration();if(t){const e=`${this.baseUrl}${t}`;try{const t=yield fetch(e,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`}});return 200!==t.status?(console.error("La verificación de la transacción falló."),this.removeVerifyTransactionUrl(),t):yield this.handleTransactionResponse(t)}catch(t){console.error("Error al verificar la transacción:",t),this.removeVerifyTransactionUrl()}}else console.log("No verify_transaction_status_url found")}))}}const u=Object.freeze({production:"https://app.tonder.io",sandbox:"https://sandbox.tonder.io",stage:"https://stage.tonder.io",development:"http://localhost:8000"});function h(t,o,n){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/checkout-router/`,r=n,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${o}`},body:JSON.stringify(Object.assign(Object.assign({},r),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}))});if(i.status>=200&&i.status<=299)return yield i.json();{const t=yield i.json(),e=new Error("Failed to start checkout router");throw e.details=t,e}}catch(t){throw t}}))}function p(t,o,n=!0,r=null){return e(this,void 0,void 0,(function*(){let e=yield window.OpenPay;return e.setId(t),e.setApiKey(o),e.setSandboxMode(n),yield e.deviceData.setup({signal:r})}))}var m,y,f,g,v,A,_,b;class E{constructor({mode:t="stage",apiKey:e,apiKeyTonder:o,returnUrl:n,callBack:r=(()=>{})}){m.add(this),this.baseUrl="",this.cartTotal="0",this.metadata={},this.card={},this.currency="",y.set(this,void 0),this.apiKeyTonder=e||o||"",this.returnUrl=n,this.callBack=r,this.mode=t,this.baseUrl=u[this.mode]||u.stage,this.abortController=new AbortController,this.process3ds=new c({apiKey:e,baseUrl:this.baseUrl})}configureCheckout(t){"customer"in t&&o(this,m,"m",f).call(this,t.customer)}verify3dsTransaction(){return e(this,void 0,void 0,(function*(){const t=yield this.process3ds.verifyTransactionStatus(),e=yield o(this,m,"m",b).call(this,t);return this.process3ds.setPayload(e),this._handle3dsRedirect(e)}))}payment(t){return new Promise(((n,r)=>e(this,void 0,void 0,(function*(){var e,i;try{o(this,m,"m",f).call(this,t.customer),this._setCartTotal(null===(e=t.cart)||void 0===e?void 0:e.total),o(this,m,"m",g).call(this,null===(i=t.cart)||void 0===i?void 0:i.items),o(this,m,"m",v).call(this,t),o(this,m,"m",A).call(this,t),o(this,m,"m",_).call(this,t);const r=yield this._checkout(t);this.process3ds.setPayload(r),this.callBack&&this.callBack(r);(yield this._handle3dsRedirect(r))&&n(r)}catch(t){r(t)}}))))}_initializeCheckout(){return e(this,void 0,void 0,(function*(){const t=yield this._fetchMerchantData();t&&t.mercado_pago&&t.mercado_pago.active&&function(){try{const t=document.createElement("script");t.src="https://www.mercadopago.com/v2/security.js",t.setAttribute("view",""),t.onload=()=>{console.log("Mercado Pago script loaded successfully.")},t.onerror=t=>{console.error("Error loading Mercado Pago script:",t)},document.head.appendChild(t)}catch(t){console.error("Error attempting to inject Mercado Pago script:",t)}}()}))}_checkout(t){return e(this,void 0,void 0,(function*(){throw new Error("The #checkout method should be implement in child classes.")}))}_setCartTotal(t){throw new Error("The #setCartTotal method should be implement in child classes.")}_getCustomer(t=null){return e(this,void 0,void 0,(function*(){return o(this,y,"f")||function(t,e,o,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===n?r.call(t,o):r?r.value=o:e.set(t,o)}(this,y,yield function(t,o,n,r=null){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/customer/`,i={email:n.email,first_name:null==n?void 0:n.firstName,last_name:null==n?void 0:n.lastName,phone:null==n?void 0:n.phone},s=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${o}`},signal:r,body:JSON.stringify(i)});if(201===s.status)return yield s.json();throw new Error(`Error: ${s.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,this.customer,t),"f"),o(this,y,"f")}))}_handleCheckout({card:t,payment_method:o,customer:n,isSandbox:r}){return e(this,void 0,void 0,(function*(){const{openpay_keys:s,reference:a,business:d}=this.merchantData,l=Number(this.cartTotal);try{let c;!c&&s.merchant_id&&s.public_key&&(c=yield p(s.merchant_id,s.public_key,r,this.abortController.signal));const{id:u,auth_token:m}=n,y={business:this.apiKeyTonder,client:m,billing_address_id:null,shipping_address_id:null,amount:l,status:"A",reference:a,is_oneclick:!0,items:this.cartItems},f=yield function(t,o,n){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/orders/`,r=n,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${o}`},body:JSON.stringify(r)});if(201===i.status)return yield i.json();throw new Error(`Error: ${i.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,y),g=(new Date).toISOString(),v={business_pk:d.pk,client_id:u,amount:l,date:g,order_id:f.id},A=yield function(t,o,n){return e(this,void 0,void 0,(function*(){const e=`${t}/api/v1/business/${n.business_pk}/payments/`,r=n,i=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${o}`},body:JSON.stringify(r)});if(i.status>=200&&i.status<=299)return yield i.json();throw new Error(`Error: ${i.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,v),_=Object.assign({name:this.firstName||"",last_name:this.lastName||"",email_client:this.email,phone_number:this.phone,return_url:this.returnUrl,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:l,title_ship:"shipping",description:"transaction",device_session_id:c||null,token_id:"",order_id:f.id,business_id:d.pk,payment_id:A.pk,source:"sdk",metadata:this.metadata,browser_info:i(),currency:this.currency},o?{payment_method:o}:{card:t}),b=yield h(this.baseUrl,this.apiKeyTonder,_);return b||!1}catch(t){throw console.log(t),t}}))}_fetchMerchantData(){return e(this,void 0,void 0,(function*(){try{return this.merchantData||(this.merchantData=yield n(this.baseUrl,this.apiKeyTonder,this.abortController.signal)),this.merchantData}catch(t){return this.merchantData}}))}_handle3dsRedirect(t){var o,n;return e(this,void 0,void 0,(function*(){if(t&&"next_action"in t?null===(n=null===(o=null==t?void 0:t.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===n?void 0:n.iframe:null)this.process3ds.loadIframe().then((()=>{this.process3ds.verifyTransactionStatus()})).catch((t=>{console.log("Error loading iframe:",t)}));else{if(!this.process3ds.getRedirectUrl())return t;this.process3ds.redirectToChallenge()}}))}}y=new WeakMap,m=new WeakSet,f=function(t){t&&(this.firstName=null==t?void 0:t.firstName,this.lastName=null==t?void 0:t.lastName,this.country=null==t?void 0:t.country,this.address=null==t?void 0:t.street,this.city=null==t?void 0:t.city,this.state=null==t?void 0:t.state,this.postCode=null==t?void 0:t.postCode,this.email=null==t?void 0:t.email,this.phone=null==t?void 0:t.phone,this.customer=t)},g=function(t){this.cartItems=t},v=function(t){this.metadata=null==t?void 0:t.metadata},A=function(t){this.currency=null==t?void 0:t.currency},_=function(t){this.card=null==t?void 0:t.card},b=function(t){var o,n;return e(this,void 0,void 0,(function*(){if("Hard"===(null===(o=null==t?void 0:t.decline)||void 0===o?void 0:o.error_type))return t;if(["Success","Authorized"].includes(null==t?void 0:t.transaction_status))return t;if(t){const e={checkout_id:null===(n=t.checkout)||void 0===n?void 0:n.id};try{return yield h(this.baseUrl,this.apiKeyTonder,e)}catch(t){}return t}}))};const T=Object.freeze({saveCardError:"Ha ocurrido un error guardando la tarjeta. Inténtalo nuevamente.",removeCardError:"Ha ocurrido un error eliminado la tarjeta. Inténtalo nuevamente.",getCardsError:"Ha ocurrido un error obteniendo las tarjetas del customer. Inténtalo nuevamente.",cardExist:"La tarjeta fue registrada previamente.",removedCard:"Card deleted successfully",errorCheckout:"No se ha podido procesar el pago",cardSaved:"Tarjeta registrada con éxito.",getPaymentMethodsError:"Ha ocurrido un error obteniendo las métodos de pago del customer. Inténtalo nuevamente.",getBusinessError:"Ha ocurrido un error obteniendo los datos del comercio. Inténtalo nuevamente."});function O({baseUrl:o,apiKey:n,vault_id:r,vault_url:i,data:s}){return e(this,void 0,void 0,(function*(){const d=t.init({vaultID:r,vaultURL:i,getBearerToken:()=>e(this,void 0,void 0,(function*(){return yield function(t,o,n=null){return e(this,void 0,void 0,(function*(){const e=yield fetch(`${t}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${o}`},signal:n});if(e.ok)return(yield e.json()).token;throw new Error("Failed to retrieve bearer token")}))}(o,n)})),options:{logLevel:t.LogLevel.ERROR,env:t.Env.DEV}}),l=d.container(t.ContainerType.COLLECT),c=yield function(o,n){return e(this,void 0,void 0,(function*(){const r=yield function(o,n){return e(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(o).map((o=>e(this,void 0,void 0,(function*(){return{element:yield n.create({table:"cards",column:o,type:t.ElementType.INPUT_FIELD}),key:o}})))))}))}(o,n);return r?r.map((t=>new Promise((e=>{var n;const r=document.createElement("div");r.hidden=!0,r.id=`id-${t.key}`,null===(n=document.querySelector("body"))||void 0===n||n.appendChild(r),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const n=o[t.key];return t.element.update({value:n}),e(t.element.isMounted())}}),120)}),120)})))):[]}))}(s,l);if((yield Promise.all(c)).some((t=>!t)))throw a(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const t=yield l.collect();if(t)return t.records[0].fields;throw a(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(t){throw a(t)}}))}const S=Object.freeze({SORIANA:"SORIANA",OXXO:"OXXO",SPEI:"SPEI",CODI:"CODI",MERCADOPAGO:"MERCADOPAGO",PAYPAL:"PAYPAL",COMERCIALMEXICANA:"COMERCIALMEXICANA",BANCOMER:"BANCOMER",WALMART:"WALMART",BODEGA:"BODEGA",SAMSCLUB:"SAMSCLUB",SUPERAMA:"SUPERAMA",CALIMAX:"CALIMAX",EXTRA:"EXTRA",CIRCULOK:"CIRCULOK",SEVEN11:"7ELEVEN",TELECOMM:"TELECOMM",BANORTE:"BANORTE",BENAVIDES:"BENAVIDES",DELAHORRO:"DELAHORRO",ELASTURIANO:"ELASTURIANO",WALDOS:"WALDOS",ALSUPER:"ALSUPER",KIOSKO:"KIOSKO",STAMARIA:"STAMARIA",LAMASBARATA:"LAMASBARATA",FARMROMA:"FARMROMA",FARMUNION:"FARMUNION",FARMATODO:"FARMATODO",SFDEASIS:"SFDEASIS",FARM911:"FARM911",FARMECONOMICAS:"FARMECONOMICAS",FARMMEDICITY:"FARMMEDICITY",RIANXEIRA:"RIANXEIRA",WESTERNUNION:"WESTERNUNION",ZONAPAGO:"ZONAPAGO",CAJALOSANDES:"CAJALOSANDES",CAJAPAITA:"CAJAPAITA",CAJASANTA:"CAJASANTA",CAJASULLANA:"CAJASULLANA",CAJATRUJILLO:"CAJATRUJILLO",EDPYME:"EDPYME",KASNET:"KASNET",NORANDINO:"NORANDINO",QAPAQ:"QAPAQ",RAIZ:"RAIZ",PAYSER:"PAYSER",WUNION:"WUNION",BANCOCONTINENTAL:"BANCOCONTINENTAL",GMONEY:"GMONEY",GOPAY:"GOPAY",WU:"WU",PUNTOSHEY:"PUNTOSHEY",AMPM:"AMPM",JUMBOMARKET:"JUMBOMARKET",SMELPUEBLO:"SMELPUEBLO",BAM:"BAM",REFACIL:"REFACIL",ACYVALORES:"ACYVALORES"}),C={[S.SORIANA]:{label:"Soriana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png"},[S.OXXO]:{label:"Oxxo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png"},[S.CODI]:{label:"CoDi",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png"},[S.SPEI]:{label:"SPEI",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png"},[S.PAYPAL]:{label:"Paypal",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png"},[S.COMERCIALMEXICANA]:{label:"Comercial Mexicana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png"},[S.BANCOMER]:{label:"Bancomer",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png"},[S.WALMART]:{label:"Walmart",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png"},[S.BODEGA]:{label:"Bodega Aurrera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png"},[S.SAMSCLUB]:{label:"Sam´s Club",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png"},[S.SUPERAMA]:{label:"Superama",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png"},[S.CALIMAX]:{label:"Calimax",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png"},[S.EXTRA]:{label:"Tiendas Extra",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png"},[S.CIRCULOK]:{label:"Círculo K",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png"},[S.SEVEN11]:{label:"7 Eleven",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png"},[S.TELECOMM]:{label:"Telecomm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png"},[S.BANORTE]:{label:"Banorte",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png"},[S.BENAVIDES]:{label:"Farmacias Benavides",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png"},[S.DELAHORRO]:{label:"Farmacias del Ahorro",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png"},[S.ELASTURIANO]:{label:"El Asturiano",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png"},[S.WALDOS]:{label:"Waldos",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png"},[S.ALSUPER]:{label:"Alsuper",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png"},[S.KIOSKO]:{label:"Kiosko",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png"},[S.STAMARIA]:{label:"Farmacias Santa María",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png"},[S.LAMASBARATA]:{label:"Farmacias la más barata",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png"},[S.FARMROMA]:{label:"Farmacias Roma",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png"},[S.FARMUNION]:{label:"Pago en Farmacias Unión",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png"},[S.FARMATODO]:{label:"Pago en Farmacias Farmatodo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png\t"},[S.SFDEASIS]:{label:"Pago en Farmacias San Francisco de Asís",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png"},[S.FARM911]:{label:"Farmacias 911",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.FARMECONOMICAS]:{label:"Farmacias Economicas",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.FARMMEDICITY]:{label:"Farmacias Medicity",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.RIANXEIRA]:{label:"Rianxeira",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WESTERNUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.ZONAPAGO]:{label:"Zona Pago",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJALOSANDES]:{label:"Caja Los Andes",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJAPAITA]:{label:"Caja Paita",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJASANTA]:{label:"Caja Santa",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJASULLANA]:{label:"Caja Sullana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.CAJATRUJILLO]:{label:"Caja Trujillo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.EDPYME]:{label:"Edpyme",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.KASNET]:{label:"KasNet",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.NORANDINO]:{label:"Norandino",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.QAPAQ]:{label:"Qapaq",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.RAIZ]:{label:"Raiz",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.PAYSER]:{label:"Paysera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.BANCOCONTINENTAL]:{label:"Banco Continental",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.GMONEY]:{label:"Go money",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.GOPAY]:{label:"Go pay",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.WU]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.PUNTOSHEY]:{label:"Puntoshey",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.AMPM]:{label:"Ampm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.JUMBOMARKET]:{label:"Jumbomarket",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.SMELPUEBLO]:{label:"Smelpueblo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.BAM]:{label:"Bam",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.REFACIL]:{label:"Refacil",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[S.ACYVALORES]:{label:"Acyvalores",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"}},j=t=>{const e=t.toUpperCase().trim().replace(/\s+/g,"");return C[e]||{icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",label:""}};var w;class M extends E{constructor({apiKey:t,mode:e,returnUrl:o,callBack:n}){super({mode:e,apiKey:t,returnUrl:o,callBack:n}),this.activeAPMs=[],w.set(this,void 0)}injectCheckout(){return e(this,void 0,void 0,(function*(){yield this._initializeCheckout()}))}getCustomerCards(){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:t}=yield this._getCustomer(),o=yield function(t,o,n,r=null){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${n}/cards/`,i=yield fetch(e,{method:"GET",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,t,this.merchantData.business.pk);return Object.assign(Object.assign({},o),{cards:o.cards.map((t=>{return Object.assign(Object.assign({},t),{icon:(e=t.fields.card_scheme,"Visa"===e?"https://d35a75syrgujp0.cloudfront.net/cards/visa.png":"Mastercard"===e?"https://d35a75syrgujp0.cloudfront.net/cards/mastercard.png":"American Express"===e?"https://d35a75syrgujp0.cloudfront.net/cards/american_express.png":"https://d35a75syrgujp0.cloudfront.net/cards/default_card.png")});var e}))})}catch(t){throw l({message:T.getCardsError},t)}}))}saveCustomerCard(t){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:o}=yield this._getCustomer(),{vault_id:n,vault_url:r,business:i}=this.merchantData,s=yield O({vault_id:n,vault_url:r,data:t,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder});return yield function(t,o,n,r){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${n}/cards/`,i=yield fetch(e,{method:"POST",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,o,null==i?void 0:i.pk,s)}catch(t){throw l({message:T.saveCardError},t)}}))}removeCustomerCard(t){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:o}=yield this._getCustomer(),{business:n}=this.merchantData;return yield function(t,o,n="",r){return e(this,void 0,void 0,(function*(){try{const e=`${t}/api/v1/business/${r}/cards/${n}`,i=yield fetch(e,{method:"DELETE",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"}});if(204===i.status)return T.cardSaved;if(i.ok&&"json"in i)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,o,t,null==n?void 0:n.pk)}catch(t){throw l({message:T.removeCardError},t)}}))}getCustomerPaymentMethods(){return e(this,void 0,void 0,(function*(){try{const t=yield function(t,o,n={status:"active",pagesize:"10000"},r=null){return e(this,void 0,void 0,(function*(){try{const e=new URLSearchParams(n).toString(),i=yield fetch(`${t}/api/v1/payment_methods?${e}`,{method:"GET",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield d(i,s)}catch(t){throw a(t)}}))}(this.baseUrl,this.apiKeyTonder);return(t&&"results"in t&&t.results.length>0?t.results:[]).filter((t=>"cards"!==t.category.toLowerCase())).map((t=>Object.assign({id:t.pk,payment_method:t.payment_method,priority:t.priority,category:t.category},j(t.payment_method)))).sort(((t,e)=>t.priority-e.priority))}catch(t){throw l({message:T.getPaymentMethodsError},t)}}))}getBusiness(){return e(this,void 0,void 0,(function*(){try{return yield n(this.baseUrl,this.apiKeyTonder,this.abortController.signal)}catch(t){throw l({message:T.getBusinessError},t)}}))}getSkyflowTokens({vault_id:t,vault_url:o,data:n}){return e(this,void 0,void 0,(function*(){return yield O({vault_id:t,vault_url:o,data:n,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})}))}_setCartTotal(t){this.cartTotal=t}_checkout({card:t,payment_method:o,isSandbox:n}){return e(this,void 0,void 0,(function*(){yield this._fetchMerchantData();const e=yield this._getCustomer(this.abortController.signal),{vault_id:r,vault_url:i}=this.merchantData;let s;return o&&""===o&&null!==o||(s="string"==typeof t?{skyflow_id:t}:yield O({vault_id:r,vault_url:i,data:Object.assign(Object.assign({},t),{card_number:t.card_number.replace(/\s+/g,"")}),baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})),yield this._handleCheckout({card:s,payment_method:o,customer:e,isSandbox:n})}))}customerRegister(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/customer/`,o={email:t},n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.abortController.signal,body:JSON.stringify(o)});if(n.ok)return yield n.json();throw yield d(n)}catch(t){throw a(t)}}))}createOrder(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/orders/`,o=t,n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});if(n.ok)return yield n.json();throw yield d(n)}catch(t){throw a(t)}}))}createPayment(t){return e(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/business/${t.business_pk}/payments/`,o=t,n=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});if(n.ok)return yield n.json();throw yield d(n)}catch(t){throw a(t)}}))}startCheckoutRouter(t){return e(this,void 0,void 0,(function*(){const e=yield h(this.baseUrl,this.apiKeyTonder,t);if(yield this.init3DSRedirect(e))return e}))}init3DSRedirect(t){return e(this,void 0,void 0,(function*(){return this.process3ds.setPayload(t),yield this._handle3dsRedirect(t)}))}startCheckoutRouterFull(t){return e(this,void 0,void 0,(function*(){try{const{order:e,total:o,customer:n,skyflowTokens:s,return_url:a,isSandbox:d,metadata:l,currency:c,payment_method:u}=t,m=yield this._fetchMerchantData(),y=yield this.customerRegister(n.email);if(!(y&&"auth_token"in y&&m&&"reference"in m))throw new r({code:"500",body:m,name:"Keys error",message:"Merchant or customer reposne errors"});{const t={business:this.apiKeyTonder,client:y.auth_token,billing_address_id:null,shipping_address_id:null,amount:o,reference:m.reference,is_oneclick:!0,items:e.items},f=yield this.createOrder(t),g=(new Date).toISOString();if(!("id"in f&&"id"in y&&"business"in m))throw new r({code:"500",body:f,name:"Keys error",message:"Order response errors"});{const t={business_pk:m.business.pk,amount:o,date:g,order_id:f.id,client_id:y.id},e=yield this.createPayment(t);let r;const{openpay_keys:v,business:A}=m;v.merchant_id&&v.public_key&&(r=yield p(v.merchant_id,v.public_key,d));const _=Object.assign(Object.assign({name:n.name,last_name:n.lastname,email_client:n.email,phone_number:n.phone,return_url:a,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:o,title_ship:"shipping",description:"transaction",device_session_id:r||null,token_id:"",order_id:"id"in f&&f.id,business_id:A.pk,payment_id:"pk"in e&&e.pk,source:"sdk",metadata:l,browser_info:i(),currency:c},u?{payment_method:u}:{card:s}),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}),b=yield h(this.baseUrl,this.apiKeyTonder,_);if(yield this.init3DSRedirect(b))return b}}}catch(t){throw a(t)}}))}registerCustomerCard(t,o){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const e=yield fetch(`${this.baseUrl}/api/v1/business/${s(this.merchantData)}/cards/`,{method:"POST",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},body:JSON.stringify(Object.assign({},o))});if(e.ok)return yield e.json();throw yield d(e)}catch(t){throw a(t)}}))}deleteCustomerCard(t,o=""){return e(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const e=yield fetch(`${this.baseUrl}/api/v1/business/${s(this.merchantData)}/cards/${o}`,{method:"DELETE",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},signal:this.abortController.signal});if(e.ok)return!0;throw yield d(e)}catch(t){throw a(t)}}))}getActiveAPMs(){return e(this,void 0,void 0,(function*(){try{const t=yield function(t,o,n="?status=active&page_size=10000&country=México",r=null){return e(this,void 0,void 0,(function*(){try{const e=yield fetch(`${t}/api/v1/payment_methods${n}`,{method:"GET",headers:{Authorization:`Token ${o}`,"Content-Type":"application/json"},signal:r});if(e.ok)return yield e.json();throw yield d(e)}catch(t){throw a(t)}}))}(this.baseUrl,this.apiKeyTonder),o=t&&t.results&&t.results.length>0?t.results:[];return this.activeAPMs=o.filter((t=>"cards"!==t.category.toLowerCase())).map((t=>Object.assign({id:t.pk,payment_method:t.payment_method,priority:t.priority,category:t.category},j(t.payment_method)))).sort(((t,e)=>t.priority-e.priority)),this.activeAPMs}catch(t){return console.error("Error getting APMS",t),[]}}))}}w=new WeakMap;export{M as LiteCheckout};
|
package/dist/types/commons.d.ts
CHANGED
|
@@ -82,12 +82,22 @@ export interface IConfigureCheckout {
|
|
|
82
82
|
}
|
|
83
83
|
export interface IInlineCheckoutBaseOptions {
|
|
84
84
|
mode?: "production" | "sandbox" | "stage" | "development";
|
|
85
|
-
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated This property is deprecated and will be removed in a future release.
|
|
87
|
+
* `baseUrlTonder` is no longer required.
|
|
88
|
+
*/
|
|
89
|
+
baseUrlTonder?: string;
|
|
86
90
|
/**
|
|
87
91
|
* @deprecated This property is deprecated and will be removed in a future release.
|
|
88
92
|
* Use `apiKey` instead, as `apiKeyTonder` is no longer required.
|
|
89
93
|
*/
|
|
90
94
|
apiKeyTonder?: string;
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated This property is deprecated and will be removed in a future release.
|
|
97
|
+
* `signal` is no longer required.
|
|
98
|
+
*/
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
apiKey: string;
|
|
91
101
|
returnUrl: string;
|
|
92
102
|
callBack?: (response: any) => void;
|
|
93
103
|
}
|
package/dist/types/requests.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export interface VaultRequest extends SkyflowRecord {
|
|
|
61
61
|
export type RegisterCustomerCardRequest = {
|
|
62
62
|
skyflow_id: string;
|
|
63
63
|
};
|
|
64
|
-
export type
|
|
64
|
+
export type TokensSkyflowRequest = {
|
|
65
65
|
baseUrl: string;
|
|
66
66
|
apiKey: string;
|
|
67
67
|
vault_id: string;
|
|
@@ -70,6 +70,13 @@ export type TokensRequest = {
|
|
|
70
70
|
[key: string]: any;
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
|
+
export type TokensRequest = {
|
|
74
|
+
vault_id: string;
|
|
75
|
+
vault_url: string;
|
|
76
|
+
data: {
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
73
80
|
export type StartCheckoutFullRequest = {
|
|
74
81
|
order: {
|
|
75
82
|
items: IItem[];
|
package/package.json
CHANGED
|
@@ -3,7 +3,15 @@ import {fetchBusiness} from "../data/businessApi";
|
|
|
3
3
|
declare const MP_DEVICE_SESSION_ID: string | undefined;
|
|
4
4
|
|
|
5
5
|
import {APM, Business, IInlineCheckoutBaseOptions, TonderAPM} from "../types/commons";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
CreateOrderRequest,
|
|
8
|
+
CreatePaymentRequest,
|
|
9
|
+
RegisterCustomerCardRequest,
|
|
10
|
+
StartCheckoutRequest,
|
|
11
|
+
StartCheckoutFullRequest,
|
|
12
|
+
StartCheckoutIdRequest,
|
|
13
|
+
TokensRequest
|
|
14
|
+
} from "../types/requests";
|
|
7
15
|
import {
|
|
8
16
|
CustomerRegisterResponse,
|
|
9
17
|
CreateOrderResponse,
|
|
@@ -140,7 +148,6 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
|
|
|
140
148
|
}
|
|
141
149
|
}
|
|
142
150
|
|
|
143
|
-
|
|
144
151
|
async getCustomerPaymentMethods(): Promise<IPaymentMethod[]> {
|
|
145
152
|
try {
|
|
146
153
|
const response = await fetchCustomerAPMs(this.baseUrl, this.apiKeyTonder);
|
|
@@ -183,6 +190,18 @@ export class LiteCheckout extends BaseInlineCheckout implements ILiteInlineCheck
|
|
|
183
190
|
}
|
|
184
191
|
}
|
|
185
192
|
|
|
193
|
+
|
|
194
|
+
// TODO: DEPRECATED
|
|
195
|
+
async getSkyflowTokens({vault_id, vault_url, data}: TokensRequest): Promise<any | ErrorResponse> {
|
|
196
|
+
return await getSkyflowTokens({
|
|
197
|
+
vault_id: vault_id,
|
|
198
|
+
vault_url: vault_url,
|
|
199
|
+
data,
|
|
200
|
+
baseUrl: this.baseUrl,
|
|
201
|
+
apiKey: this.apiKeyTonder,
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
186
205
|
_setCartTotal(total: string) {
|
|
187
206
|
this.cartTotal = total;
|
|
188
207
|
}
|
package/src/helpers/skyflow.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {TokensRequest} from "../types/requests";
|
|
2
1
|
import {ErrorResponse} from "../classes/errorResponse";
|
|
3
2
|
import Skyflow from "skyflow-js";
|
|
4
3
|
import CollectContainer from "skyflow-js/types/core/external/collect/collect-container";
|
|
5
4
|
import {buildErrorResponseFromCatch} from "./utils";
|
|
6
5
|
import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
|
|
7
6
|
import {getVaultToken} from "../data/skyflowApi";
|
|
7
|
+
import {TokensSkyflowRequest} from "../types";
|
|
8
8
|
|
|
9
9
|
export async function getSkyflowTokens({
|
|
10
10
|
baseUrl,
|
|
@@ -12,7 +12,7 @@ export async function getSkyflowTokens({
|
|
|
12
12
|
vault_id,
|
|
13
13
|
vault_url,
|
|
14
14
|
data,
|
|
15
|
-
}:
|
|
15
|
+
}: TokensSkyflowRequest): Promise<any | ErrorResponse> {
|
|
16
16
|
const skyflow = Skyflow.init({
|
|
17
17
|
vaultID: vault_id,
|
|
18
18
|
vaultURL: vault_url,
|
package/src/types/commons.ts
CHANGED
|
@@ -91,12 +91,22 @@ export interface IConfigureCheckout {
|
|
|
91
91
|
|
|
92
92
|
export interface IInlineCheckoutBaseOptions {
|
|
93
93
|
mode?: "production" | "sandbox" | "stage" | "development";
|
|
94
|
-
|
|
94
|
+
/**
|
|
95
|
+
* @deprecated This property is deprecated and will be removed in a future release.
|
|
96
|
+
* `baseUrlTonder` is no longer required.
|
|
97
|
+
*/
|
|
98
|
+
baseUrlTonder?: string;
|
|
95
99
|
/**
|
|
96
100
|
* @deprecated This property is deprecated and will be removed in a future release.
|
|
97
101
|
* Use `apiKey` instead, as `apiKeyTonder` is no longer required.
|
|
98
102
|
*/
|
|
99
103
|
apiKeyTonder?: string;
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated This property is deprecated and will be removed in a future release.
|
|
106
|
+
* `signal` is no longer required.
|
|
107
|
+
*/
|
|
108
|
+
signal?: AbortSignal;
|
|
109
|
+
apiKey: string;
|
|
100
110
|
returnUrl: string;
|
|
101
111
|
callBack?: (response: any) => void;
|
|
102
112
|
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
RegisterCustomerCardRequest,
|
|
12
12
|
StartCheckoutFullRequest,
|
|
13
13
|
StartCheckoutIdRequest,
|
|
14
|
-
StartCheckoutRequest
|
|
14
|
+
StartCheckoutRequest, TokensRequest
|
|
15
15
|
} from "./requests";
|
|
16
16
|
import {
|
|
17
17
|
CreateOrderResponse,
|
|
@@ -177,6 +177,14 @@ export class ILiteInlineCheckout {
|
|
|
177
177
|
* Use the {@link getCustomerPaymentMethods} method
|
|
178
178
|
*/
|
|
179
179
|
async getActiveAPMs(): Promise<APM[]>;
|
|
180
|
+
|
|
181
|
+
// TODO: DEPRECATED
|
|
182
|
+
/**
|
|
183
|
+
* @deprecated This method is deprecated and will be removed in a future release.
|
|
184
|
+
* It is no longer necessary to use this method as customer registration is now automatically handled
|
|
185
|
+
* during the payment process or when using card management methods.
|
|
186
|
+
*/
|
|
187
|
+
async getSkyflowTokens({vault_id, vault_url, data}: TokensRequest): Promise<any | ErrorResponse>
|
|
180
188
|
}
|
|
181
189
|
|
|
182
190
|
|
package/src/types/requests.ts
CHANGED
|
@@ -71,7 +71,7 @@ export type RegisterCustomerCardRequest = {
|
|
|
71
71
|
skyflow_id: string;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export type
|
|
74
|
+
export type TokensSkyflowRequest = {
|
|
75
75
|
baseUrl: string;
|
|
76
76
|
apiKey: string;
|
|
77
77
|
vault_id: string,
|
|
@@ -80,6 +80,13 @@ export type TokensRequest = {
|
|
|
80
80
|
[key: string]: any;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
export type TokensRequest = {
|
|
84
|
+
vault_id: string,
|
|
85
|
+
vault_url: string,
|
|
86
|
+
data: {
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
83
90
|
|
|
84
91
|
export type StartCheckoutFullRequest = {
|
|
85
92
|
order: {
|
|
@@ -4,9 +4,8 @@ import {
|
|
|
4
4
|
CreatePaymentRequest,
|
|
5
5
|
RegisterCustomerCardRequest,
|
|
6
6
|
StartCheckoutRequest,
|
|
7
|
-
TokensRequest,
|
|
8
7
|
StartCheckoutFullRequest,
|
|
9
|
-
StartCheckoutRequestWithCard
|
|
8
|
+
StartCheckoutRequestWithCard, TokensSkyflowRequest
|
|
10
9
|
} from "../../src/types/requests";
|
|
11
10
|
import {
|
|
12
11
|
CreateOrderResponse,
|
|
@@ -556,14 +555,14 @@ export class StartCheckoutFullRequestClass implements StartCheckoutFullRequest {
|
|
|
556
555
|
}
|
|
557
556
|
}
|
|
558
557
|
|
|
559
|
-
export class TokensRequestClass implements
|
|
558
|
+
export class TokensRequestClass implements TokensSkyflowRequest {
|
|
560
559
|
baseUrl!: string;
|
|
561
560
|
apiKey!: string;
|
|
562
561
|
vault_id!: string;
|
|
563
562
|
vault_url!: string;
|
|
564
563
|
data: { [key: string]: any } = {};
|
|
565
564
|
|
|
566
|
-
get mockObject():
|
|
565
|
+
get mockObject(): TokensSkyflowRequest {
|
|
567
566
|
return {
|
|
568
567
|
baseUrl: "",
|
|
569
568
|
apiKey: "",
|