@tonder.io/ionic-lite-sdk 0.0.35-beta.12 → 0.0.35-beta.14
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 +7 -44
- package/dist/classes/BaseInlineCheckout.d.ts +5 -1
- package/dist/data/paymentMethodApi.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/classes/BaseInlineCheckout.ts +58 -8
- package/src/classes/liteCheckout.ts +22 -24
- package/src/data/paymentMethodApi.ts +1 -1
- package/src/index.ts +2 -0
- package/src/types/liteInlineCheckout.d.ts +0 -10
package/.idea/workspace.xml
CHANGED
|
@@ -5,51 +5,13 @@
|
|
|
5
5
|
</component>
|
|
6
6
|
<component name="ChangeListManager">
|
|
7
7
|
<list default="true" id="49ce0c58-6ae2-4b0a-9ac0-48692c69c15e" name="Changes" comment="">
|
|
8
|
-
<change afterPath="$PROJECT_DIR$/.idea/
|
|
9
|
-
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
|
|
10
|
-
<change afterPath="$PROJECT_DIR$/.idea/prettier.xml" afterDir="false" />
|
|
11
|
-
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
|
12
|
-
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
13
|
-
<change afterPath="$PROJECT_DIR$/src/classes/BaseInlineCheckout.ts" afterDir="false" />
|
|
14
|
-
<change afterPath="$PROJECT_DIR$/src/data/businessApi.ts" afterDir="false" />
|
|
15
|
-
<change afterPath="$PROJECT_DIR$/src/data/cardApi.ts" afterDir="false" />
|
|
16
|
-
<change afterPath="$PROJECT_DIR$/src/data/checkoutApi.ts" afterDir="false" />
|
|
17
|
-
<change afterPath="$PROJECT_DIR$/src/data/customerApi.ts" afterDir="false" />
|
|
18
|
-
<change afterPath="$PROJECT_DIR$/src/data/openPayApi.ts" afterDir="false" />
|
|
19
|
-
<change afterPath="$PROJECT_DIR$/src/data/paymentMethodApi.ts" afterDir="false" />
|
|
20
|
-
<change afterPath="$PROJECT_DIR$/src/data/skyflowApi.ts" afterDir="false" />
|
|
21
|
-
<change afterPath="$PROJECT_DIR$/src/helpers/skyflow.ts" afterDir="false" />
|
|
22
|
-
<change afterPath="$PROJECT_DIR$/src/helpers/validations.ts" afterDir="false" />
|
|
23
|
-
<change afterPath="$PROJECT_DIR$/src/shared/catalog/paymentMethodsCatalog.ts" afterDir="false" />
|
|
24
|
-
<change afterPath="$PROJECT_DIR$/src/shared/constants/messages.ts" afterDir="false" />
|
|
25
|
-
<change afterPath="$PROJECT_DIR$/src/shared/constants/paymentMethodAPM.ts" afterDir="false" />
|
|
26
|
-
<change afterPath="$PROJECT_DIR$/src/shared/constants/tonderUrl.ts" afterDir="false" />
|
|
27
|
-
<change afterPath="$PROJECT_DIR$/src/types/card.ts" afterDir="false" />
|
|
28
|
-
<change afterPath="$PROJECT_DIR$/src/types/checkout.ts" afterDir="false" />
|
|
29
|
-
<change afterPath="$PROJECT_DIR$/src/types/customer.ts" afterDir="false" />
|
|
30
|
-
<change afterPath="$PROJECT_DIR$/src/types/index.d.ts" afterDir="false" />
|
|
31
|
-
<change afterPath="$PROJECT_DIR$/src/types/liteInlineCheckout.d.ts" afterDir="false" />
|
|
32
|
-
<change afterPath="$PROJECT_DIR$/src/types/paymentMethod.ts" afterDir="false" />
|
|
33
|
-
<change afterPath="$PROJECT_DIR$/src/types/transaction.ts" afterDir="false" />
|
|
34
|
-
<change afterPath="$PROJECT_DIR$/src/types/validations.d.ts" afterDir="false" />
|
|
35
|
-
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
|
8
|
+
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
36
9
|
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
|
|
37
10
|
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
38
|
-
<change beforePath="$PROJECT_DIR$/src/classes/
|
|
11
|
+
<change beforePath="$PROJECT_DIR$/src/classes/BaseInlineCheckout.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/classes/BaseInlineCheckout.ts" afterDir="false" />
|
|
39
12
|
<change beforePath="$PROJECT_DIR$/src/classes/liteCheckout.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/classes/liteCheckout.ts" afterDir="false" />
|
|
40
|
-
<change beforePath="$PROJECT_DIR$/src/
|
|
41
|
-
<change beforePath="$PROJECT_DIR$/src/helpers/utils.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/helpers/utils.ts" afterDir="false" />
|
|
13
|
+
<change beforePath="$PROJECT_DIR$/src/data/paymentMethodApi.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/paymentMethodApi.ts" afterDir="false" />
|
|
42
14
|
<change beforePath="$PROJECT_DIR$/src/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.ts" afterDir="false" />
|
|
43
|
-
<change beforePath="$PROJECT_DIR$/src/types/commons.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/types/commons.ts" afterDir="false" />
|
|
44
|
-
<change beforePath="$PROJECT_DIR$/src/types/requests.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/types/requests.ts" afterDir="false" />
|
|
45
|
-
<change beforePath="$PROJECT_DIR$/tests/classes/liteCheckout.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/tests/classes/liteCheckout.test.ts" afterDir="false" />
|
|
46
|
-
<change beforePath="$PROJECT_DIR$/tests/methods/getBusiness.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/tests/methods/getBusiness.test.ts" afterDir="false" />
|
|
47
|
-
<change beforePath="$PROJECT_DIR$/tests/methods/getCustomerCards.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/tests/methods/getCustomerCards.test.ts" afterDir="false" />
|
|
48
|
-
<change beforePath="$PROJECT_DIR$/tests/methods/getOpenpayDeviceSessionID.test.ts" beforeDir="false" />
|
|
49
|
-
<change beforePath="$PROJECT_DIR$/tests/methods/getSkyflowToken.test.ts" beforeDir="false" />
|
|
50
|
-
<change beforePath="$PROJECT_DIR$/tests/methods/getVaultToken.test.ts" beforeDir="false" />
|
|
51
|
-
<change beforePath="$PROJECT_DIR$/tests/utils/defaultMock.ts" beforeDir="false" afterPath="$PROJECT_DIR$/tests/utils/defaultMock.ts" afterDir="false" />
|
|
52
|
-
<change beforePath="$PROJECT_DIR$/tests/utils/mockClasses.ts" beforeDir="false" afterPath="$PROJECT_DIR$/tests/utils/mockClasses.ts" afterDir="false" />
|
|
53
15
|
</list>
|
|
54
16
|
<option name="SHOW_DIALOG" value="false" />
|
|
55
17
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -107,7 +69,8 @@
|
|
|
107
69
|
<workItem from="1724790840744" duration="239000" />
|
|
108
70
|
<workItem from="1725305433705" duration="21026000" />
|
|
109
71
|
<workItem from="1725333899382" duration="2939000" />
|
|
110
|
-
<workItem from="1725337022494" duration="
|
|
72
|
+
<workItem from="1725337022494" duration="3671000" />
|
|
73
|
+
<workItem from="1725378545854" duration="2349000" />
|
|
111
74
|
</task>
|
|
112
75
|
<servers />
|
|
113
76
|
</component>
|
|
@@ -130,7 +93,7 @@
|
|
|
130
93
|
<breakpoints>
|
|
131
94
|
<line-breakpoint enabled="true" type="javascript">
|
|
132
95
|
<url>file://$PROJECT_DIR$/src/classes/liteCheckout.ts</url>
|
|
133
|
-
<line>
|
|
96
|
+
<line>227</line>
|
|
134
97
|
<option name="timeStamp" value="16" />
|
|
135
98
|
</line-breakpoint>
|
|
136
99
|
<line-breakpoint enabled="true" type="javascript">
|
|
@@ -140,7 +103,7 @@
|
|
|
140
103
|
</line-breakpoint>
|
|
141
104
|
<line-breakpoint enabled="true" type="javascript">
|
|
142
105
|
<url>file://$PROJECT_DIR$/src/classes/liteCheckout.ts</url>
|
|
143
|
-
<line>
|
|
106
|
+
<line>231</line>
|
|
144
107
|
<option name="timeStamp" value="18" />
|
|
145
108
|
</line-breakpoint>
|
|
146
109
|
</breakpoints>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ThreeDSHandler } from "./3dsHandler";
|
|
2
2
|
import { ErrorResponse } from "./errorResponse";
|
|
3
|
-
import { Business, ICustomer, IItem, IInlineCheckoutBaseOptions, IConfigureCheckout, IProcessPaymentRequest, IStartCheckoutResponse, StartCheckoutResponse } from "../types";
|
|
3
|
+
import { Business, ICustomer, IItem, IInlineCheckoutBaseOptions, IConfigureCheckout, IProcessPaymentRequest, IStartCheckoutResponse, StartCheckoutResponse, ICustomerCardsResponse, ISaveCardResponse, ISaveCardSkyflowRequest, IPaymentMethodResponse } from "../types";
|
|
4
4
|
export declare class BaseInlineCheckout {
|
|
5
5
|
#private;
|
|
6
6
|
baseUrl: string;
|
|
@@ -34,5 +34,9 @@ export declare class BaseInlineCheckout {
|
|
|
34
34
|
isSandbox?: boolean;
|
|
35
35
|
}): Promise<any>;
|
|
36
36
|
_fetchMerchantData(): Promise<Business | undefined>;
|
|
37
|
+
_getCustomerCards(authToken: string, businessId: string | number): Promise<ICustomerCardsResponse>;
|
|
38
|
+
_saveCustomerCard(authToken: string, businessId: string | number, skyflowTokens: ISaveCardSkyflowRequest): Promise<ISaveCardResponse>;
|
|
39
|
+
_removeCustomerCard(authToken: string, businessId: string | number, skyflowId: string): Promise<string>;
|
|
40
|
+
_fetchCustomerAPMs(): Promise<IPaymentMethodResponse>;
|
|
37
41
|
_handle3dsRedirect(response: ErrorResponse | StartCheckoutResponse | false | undefined): Promise<false | ErrorResponse | StartCheckoutResponse | undefined>;
|
|
38
42
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPaymentMethodResponse } from "../types";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function fetchCustomerPaymentMethods(baseUrl: string, apiKey: string, params?: {
|
|
3
3
|
status: string;
|
|
4
4
|
pagesize: string;
|
|
5
5
|
}, signal?: null): Promise<IPaymentMethodResponse>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { LiteCheckout } from './classes/liteCheckout';
|
|
2
|
+
import { BaseInlineCheckout } from './classes/BaseInlineCheckout';
|
|
2
3
|
import { validateCVV, validateCardNumber, validateExpirationMonth, validateCardholderName, validateExpirationYear } from './helpers/validations';
|
|
3
|
-
export { LiteCheckout, validateCVV, validateCardNumber, validateCardholderName, validateExpirationMonth, validateExpirationYear };
|
|
4
|
+
export { LiteCheckout, BaseInlineCheckout, validateCVV, validateCardNumber, validateCardholderName, validateExpirationMonth, validateExpirationYear };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{get as t}from"lodash";import e from"skyflow-js";function n(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{d(o.next(t))}catch(t){i(t)}}function a(t){try{d(o.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}d((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function r(t,e,o){return n(this,void 0,void 0,(function*(){const n=yield fetch(`${t}/api/v1/payments/business/${e}`,{headers:{Authorization:`Token ${e}`},signal:o});return yield n.json()}))}"function"==typeof SuppressedError&&SuppressedError;class i{constructor({code:t,body:e,name:n,message:o,stack:r}){this.code=t,this.body=e,this.name=n,this.message=o,this.stack=r}}const s=()=>({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}),a=t=>{var e;return t&&"business"in t?null===(e=null==t?void 0:t.business)||void 0===e?void 0:e.pk:""},d=t=>new i({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}),c=(t,e=void 0)=>n(void 0,void 0,void 0,(function*(){let n,o,r="Error";t&&"json"in t&&(n=yield null==t?void 0:t.json()),t&&"status"in t&&(o=t.status.toString()),!n&&t&&"text"in t&&(r=yield t.text()),(null==n?void 0:n.detail)&&(r=n.detail);return new i({code:o,body:n,name:o,message:r,stack:e})}));function l(t,e){var n,o;let r=200;try{r=Number((null==e?void 0:e.code)||200)}catch(t){}const i={status:"error",code:r,message:"",detail:(null===(n=null==e?void 0:e.body)||void 0===n?void 0:n.detail)||(null===(o=null==e?void 0:e.body)||void 0===o?void 0:o.error)||e.body||"Ocurrio un error inesperado."};return Object.assign(Object.assign({},i),t)}class u{constructor({payload:t=null,apiKey:e,baseUrl:n}){this.localStorageKey="verify_transaction_status_url",this.setPayload=t=>{this.payload=t},this.baseUrl=n,this.apiKey=e,this.payload=t}setStorageItem(t){return localStorage.setItem(this.localStorageKey,JSON.stringify(t))}getStorageItem(){return localStorage.getItem(this.localStorageKey)}removeStorageItem(){return localStorage.removeItem(this.localStorageKey)}saveVerifyTransactionUrl(){var t,e,n,o,r,i;const s=null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===n?void 0:n.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const t=null===(i=null===(r=null===(o=this.payload)||void 0===o?void 0:o.next_action)||void 0===r?void 0:r.iframe_resources)||void 0===i?void 0:i.verify_transaction_status_url;t?this.saveUrlWithExpiration(t):console.log("No verify_transaction_status_url found")}}saveUrlWithExpiration(t){try{const e={url:t,expires:(new Date).getTime()+12e5};this.setStorageItem(e)}catch(t){console.log("error: ",t)}}getUrlWithExpiration(){const t=this.getStorageItem();if(t){const e=JSON.parse(t);if(!e)return;return(new Date).getTime()>e.expires?(this.removeVerifyTransactionUrl(),null):e.url}return null}removeVerifyTransactionUrl(){return this.removeStorageItem()}getVerifyTransactionUrl(){return this.getStorageItem()}loadIframe(){var t,e,n;if(null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.iframe_resources)||void 0===n?void 0:n.iframe)return new Promise(((t,e)=>{var n,o,r;const i=null===(r=null===(o=null===(n=this.payload)||void 0===n?void 0:n.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===r?void 0:r.iframe;if(i){this.saveVerifyTransactionUrl();const n=document.createElement("div");n.innerHTML=i,document.body.appendChild(n);const o=document.createElement("script");o.textContent='document.getElementById("tdsMmethodForm").submit();',n.appendChild(o);const r=document.getElementById("tdsMmethodTgtFrame");r?r.onload=()=>t(!0):(console.log("No redirection found"),e(!1))}else console.log("No redirection found"),e(!1)}))}getRedirectUrl(){var t,e,n;return null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===n?void 0:n.url}redirectToChallenge(){const t=this.getRedirectUrl();t?(this.saveVerifyTransactionUrl(),window.location=t):console.log("No redirection found")}getURLParameters(){const t={},e=new URLSearchParams(window.location.search);for(const[n,o]of e)t[n]=o;return t}handleSuccessTransaction(t){return this.removeVerifyTransactionUrl(),console.log("Transacción autorizada."),t}handleDeclinedTransaction(t){return this.removeVerifyTransactionUrl(),t}handle3dsChallenge(t){return n(this,void 0,void 0,(function*(){const e=document.createElement("form");e.name="frm",e.method="POST",e.action=t.redirect_post_url;const n=document.createElement("input");n.type="hidden",n.name=t.creq,n.value=t.creq,e.appendChild(n);const o=document.createElement("input");o.type="hidden",o.name=t.term_url,o.value=t.TermUrl,e.appendChild(o),document.body.appendChild(e),e.submit(),yield this.verifyTransactionStatus()}))}handleTransactionResponse(t){return n(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 n(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 h=Object.freeze({production:"https://app.tonder.io",sandbox:"https://sandbox.tonder.io",stage:"https://stage.tonder.io",development:"http://localhost:8000"});function p(t,e,o){return n(this,void 0,void 0,(function*(){try{const n=`${t}/api/v1/checkout-router/`,r=o,i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${e}`},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 m(t,e,o=!0,r=null){return n(this,void 0,void 0,(function*(){let n=yield window.OpenPay;return n.setId(t),n.setApiKey(e),n.setSandboxMode(o),yield n.deviceData.setup({signal:r})}))}var y,f,g,v,A,_,b,E;class T{constructor({mode:t="stage",apiKey:e,apiKeyTonder:n,returnUrl:o,callBack:r=(()=>{})}){y.add(this),this.baseUrl="",this.cartTotal="0",this.metadata={},this.card={},this.currency="",f.set(this,void 0),this.apiKeyTonder=e||n||"",this.returnUrl=o,this.callBack=r,this.mode=t,this.baseUrl=h[this.mode]||h.stage,this.abortController=new AbortController,this.process3ds=new u({apiKey:e,baseUrl:this.baseUrl})}configureCheckout(t){"customer"in t&&o(this,y,"m",g).call(this,t.customer)}verify3dsTransaction(){return n(this,void 0,void 0,(function*(){const t=yield this.process3ds.verifyTransactionStatus(),e=yield o(this,y,"m",E).call(this,t);return this.process3ds.setPayload(e),this._handle3dsRedirect(e)}))}payment(t){return new Promise(((e,r)=>n(this,void 0,void 0,(function*(){var n,i;try{o(this,y,"m",g).call(this,t.customer),this._setCartTotal(null===(n=t.cart)||void 0===n?void 0:n.total),o(this,y,"m",v).call(this,null===(i=t.cart)||void 0===i?void 0:i.items),o(this,y,"m",A).call(this,t),o(this,y,"m",_).call(this,t),o(this,y,"m",b).call(this,t);const r=yield this._checkout(t);this.process3ds.setPayload(r),this.callBack&&this.callBack(r);(yield this._handle3dsRedirect(r))&&e(r)}catch(t){r(t)}}))))}_initializeCheckout(){return n(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 n(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 n(this,void 0,void 0,(function*(){return o(this,f,"f")||function(t,e,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===o?r.call(t,n):r?r.value=n:e.set(t,n)}(this,f,yield function(t,e,o,r=null){return n(this,void 0,void 0,(function*(){const n=`${t}/api/v1/customer/`,i={email:o.email,first_name:null==o?void 0:o.firstName,last_name:null==o?void 0:o.lastName,phone:null==o?void 0:o.phone},s=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${e}`},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,f,"f")}))}_handleCheckout({card:e,payment_method:o,customer:r,isSandbox:i}){return n(this,void 0,void 0,(function*(){const{openpay_keys:a,reference:d,business:c}=this.merchantData,l=Number(this.cartTotal);try{let u;!u&&a.merchant_id&&a.public_key&&(u=yield m(a.merchant_id,a.public_key,i,this.abortController.signal));const{id:h,auth_token:y}=r,f={business:this.apiKeyTonder,client:y,billing_address_id:null,shipping_address_id:null,amount:l,status:"A",reference:d,is_oneclick:!0,items:this.cartItems},g=yield function(t,e,o){return n(this,void 0,void 0,(function*(){const n=`${t}/api/v1/orders/`,r=o,i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${e}`},body:JSON.stringify(r)});if(201===i.status)return yield i.json();throw new Error(`Error: ${i.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,f),v=(new Date).toISOString(),A={business_pk:c.pk,client_id:h,amount:l,date:v,order_id:g.id},_=yield function(t,e,o){return n(this,void 0,void 0,(function*(){const n=`${t}/api/v1/business/${o.business_pk}/payments/`,r=o,i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${e}`},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,A),b=Object.assign({name:t(this.customer,"firstName",t(this.customer,"name","")),last_name:t(this.customer,"lastName",t(this.customer,"lastname","")),email_client:t(this.customer,"email",""),phone_number:t(this.customer,"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:u||null,token_id:"",order_id:g.id,business_id:c.pk,payment_id:_.pk,source:"sdk",metadata:this.metadata,browser_info:s(),currency:this.currency},o?{payment_method:o}:{card:e}),E=yield p(this.baseUrl,this.apiKeyTonder,b);return E||!1}catch(t){throw console.log(t),t}}))}_fetchMerchantData(){return n(this,void 0,void 0,(function*(){try{return this.merchantData||(this.merchantData=yield r(this.baseUrl,this.apiKeyTonder,this.abortController.signal)),this.merchantData}catch(t){return this.merchantData}}))}_handle3dsRedirect(t){var e,o;return n(this,void 0,void 0,(function*(){if(t&&"next_action"in t?null===(o=null===(e=null==t?void 0:t.next_action)||void 0===e?void 0:e.iframe_resources)||void 0===o?void 0:o.iframe:null)this.process3ds.loadIframe().then((()=>{this.process3ds.verifyTransactionStatus()})).catch((t=>{console.log("Error loading iframe:",t)}));else{if(!this.process3ds.getRedirectUrl())return t;this.process3ds.redirectToChallenge()}}))}}f=new WeakMap,y=new WeakSet,g=function(t){t&&(this.customer=t)},v=function(t){this.cartItems=t},A=function(t){this.metadata=null==t?void 0:t.metadata},_=function(t){this.currency=null==t?void 0:t.currency},b=function(t){this.card=null==t?void 0:t.card},E=function(t){var e,o;return n(this,void 0,void 0,(function*(){if("Hard"===(null===(e=null==t?void 0:t.decline)||void 0===e?void 0:e.error_type))return t;if(["Success","Authorized"].includes(null==t?void 0:t.transaction_status))return t;if(t){const e={checkout_id:null===(o=t.checkout)||void 0===o?void 0:o.id};try{return yield p(this.baseUrl,this.apiKeyTonder,e)}catch(t){}return t}}))};const O=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 S({baseUrl:t,apiKey:o,vault_id:r,vault_url:i,data:s}){return n(this,void 0,void 0,(function*(){const a=e.init({vaultID:r,vaultURL:i,getBearerToken:()=>n(this,void 0,void 0,(function*(){return yield function(t,e,o=null){return n(this,void 0,void 0,(function*(){const n=yield fetch(`${t}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${e}`},signal:o});if(n.ok)return(yield n.json()).token;throw new Error("Failed to retrieve bearer token")}))}(t,o)})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}),c=a.container(e.ContainerType.COLLECT),l=yield function(t,o){return n(this,void 0,void 0,(function*(){const r=yield function(t,o){return n(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(t).map((t=>n(this,void 0,void 0,(function*(){return{element:yield o.create({table:"cards",column:t,type:e.ElementType.INPUT_FIELD}),key:t}})))))}))}(t,o);return r?r.map((e=>new Promise((n=>{var o;const r=document.createElement("div");r.hidden=!0,r.id=`id-${e.key}`,null===(o=document.querySelector("body"))||void 0===o||o.appendChild(r),setTimeout((()=>{e.element.mount(`#id-${e.key}`),setInterval((()=>{if(e.element.isMounted()){const o=t[e.key];return e.element.update({value:o}),n(e.element.isMounted())}}),120)}),120)})))):[]}))}(s,c);if((yield Promise.all(l)).some((t=>!t)))throw d(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const t=yield c.collect();if(t)return t.records[0].fields;throw d(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(t){throw d(t)}}))}const C=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"}),j={[C.SORIANA]:{label:"Soriana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png"},[C.OXXO]:{label:"Oxxo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png"},[C.CODI]:{label:"CoDi",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png"},[C.SPEI]:{label:"SPEI",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png"},[C.PAYPAL]:{label:"Paypal",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png"},[C.COMERCIALMEXICANA]:{label:"Comercial Mexicana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png"},[C.BANCOMER]:{label:"Bancomer",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png"},[C.WALMART]:{label:"Walmart",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png"},[C.BODEGA]:{label:"Bodega Aurrera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png"},[C.SAMSCLUB]:{label:"Sam´s Club",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png"},[C.SUPERAMA]:{label:"Superama",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png"},[C.CALIMAX]:{label:"Calimax",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png"},[C.EXTRA]:{label:"Tiendas Extra",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png"},[C.CIRCULOK]:{label:"Círculo K",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png"},[C.SEVEN11]:{label:"7 Eleven",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png"},[C.TELECOMM]:{label:"Telecomm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png"},[C.BANORTE]:{label:"Banorte",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png"},[C.BENAVIDES]:{label:"Farmacias Benavides",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png"},[C.DELAHORRO]:{label:"Farmacias del Ahorro",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png"},[C.ELASTURIANO]:{label:"El Asturiano",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png"},[C.WALDOS]:{label:"Waldos",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png"},[C.ALSUPER]:{label:"Alsuper",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png"},[C.KIOSKO]:{label:"Kiosko",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png"},[C.STAMARIA]:{label:"Farmacias Santa María",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png"},[C.LAMASBARATA]:{label:"Farmacias la más barata",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png"},[C.FARMROMA]:{label:"Farmacias Roma",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png"},[C.FARMUNION]:{label:"Pago en Farmacias Unión",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png"},[C.FARMATODO]:{label:"Pago en Farmacias Farmatodo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png\t"},[C.SFDEASIS]:{label:"Pago en Farmacias San Francisco de Asís",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png"},[C.FARM911]:{label:"Farmacias 911",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.FARMECONOMICAS]:{label:"Farmacias Economicas",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.FARMMEDICITY]:{label:"Farmacias Medicity",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.RIANXEIRA]:{label:"Rianxeira",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.WESTERNUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.ZONAPAGO]:{label:"Zona Pago",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.CAJALOSANDES]:{label:"Caja Los Andes",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.CAJAPAITA]:{label:"Caja Paita",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.CAJASANTA]:{label:"Caja Santa",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.CAJASULLANA]:{label:"Caja Sullana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.CAJATRUJILLO]:{label:"Caja Trujillo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.EDPYME]:{label:"Edpyme",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.KASNET]:{label:"KasNet",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.NORANDINO]:{label:"Norandino",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.QAPAQ]:{label:"Qapaq",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.RAIZ]:{label:"Raiz",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.PAYSER]:{label:"Paysera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.WUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.BANCOCONTINENTAL]:{label:"Banco Continental",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.GMONEY]:{label:"Go money",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.GOPAY]:{label:"Go pay",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.WU]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.PUNTOSHEY]:{label:"Puntoshey",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.AMPM]:{label:"Ampm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.JUMBOMARKET]:{label:"Jumbomarket",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.SMELPUEBLO]:{label:"Smelpueblo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.BAM]:{label:"Bam",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.REFACIL]:{label:"Refacil",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[C.ACYVALORES]:{label:"Acyvalores",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"}},w=t=>{const e=t.toUpperCase().trim().replace(/\s+/g,"");return j[e]||{icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",label:""}};class R extends T{constructor({apiKey:t,mode:e,returnUrl:n,callBack:o}){super({mode:e,apiKey:t,returnUrl:n,callBack:o}),this.activeAPMs=[]}injectCheckout(){return n(this,void 0,void 0,(function*(){yield this._initializeCheckout()}))}getCustomerCards(){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:t}=yield this._getCustomer(),e=yield function(t,e,o,r=null){return n(this,void 0,void 0,(function*(){try{const n=`${t}/api/v1/business/${o}/cards/`,i=yield fetch(n,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield c(i,s)}catch(t){throw d(t)}}))}(this.baseUrl,t,this.merchantData.business.pk);return Object.assign(Object.assign({},e),{cards:e.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:O.getCardsError},t)}}))}saveCustomerCard(t){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:e}=yield this._getCustomer(),{vault_id:o,vault_url:r,business:i}=this.merchantData,s=yield S({vault_id:o,vault_url:r,data:t,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder});return yield function(t,e,o,r){return n(this,void 0,void 0,(function*(){try{const n=`${t}/api/v1/business/${o}/cards/`,i=yield fetch(n,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(i.ok)return yield i.json();const s=yield i.json();throw yield c(i,s)}catch(t){throw d(t)}}))}(this.baseUrl,e,null==i?void 0:i.pk,s)}catch(t){throw l({message:O.saveCardError},t)}}))}removeCustomerCard(t){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:e}=yield this._getCustomer(),{business:o}=this.merchantData;return yield function(t,e,o="",r){return n(this,void 0,void 0,(function*(){try{const n=`${t}/api/v1/business/${r}/cards/${o}`,i=yield fetch(n,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"}});if(204===i.status)return O.cardSaved;if(i.ok&&"json"in i)return yield i.json();const s=yield i.json();throw yield c(i,s)}catch(t){throw d(t)}}))}(this.baseUrl,e,t,null==o?void 0:o.pk)}catch(t){throw l({message:O.removeCardError},t)}}))}getCustomerPaymentMethods(){return n(this,void 0,void 0,(function*(){try{const t=yield function(t,e,o={status:"active",pagesize:"10000"},r=null){return n(this,void 0,void 0,(function*(){try{const n=new URLSearchParams(o).toString(),i=yield fetch(`${t}/api/v1/payment_methods?${n}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield c(i,s)}catch(t){throw d(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},w(t.payment_method)))).sort(((t,e)=>t.priority-e.priority))}catch(t){throw l({message:O.getPaymentMethodsError},t)}}))}getBusiness(){return n(this,void 0,void 0,(function*(){try{return yield r(this.baseUrl,this.apiKeyTonder,this.abortController.signal)}catch(t){throw l({message:O.getBusinessError},t)}}))}getOpenpayDeviceSessionID(t,e,o){return n(this,void 0,void 0,(function*(){try{return yield m(t,e,o)}catch(t){throw d(t)}}))}getSkyflowTokens({vault_id:t,vault_url:e,data:o}){return n(this,void 0,void 0,(function*(){return yield S({vault_id:t,vault_url:e,data:o,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})}))}_setCartTotal(t){this.cartTotal=t}_checkout({card:t,payment_method:e,isSandbox:o}){return n(this,void 0,void 0,(function*(){yield this._fetchMerchantData();const n=yield this._getCustomer(this.abortController.signal),{vault_id:r,vault_url:i}=this.merchantData;let s;return e&&""===e&&null!==e||(s="string"==typeof t?{skyflow_id:t}:yield S({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:e,customer:n,isSandbox:o})}))}customerRegister(t){return n(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/customer/`,n={email:t},o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.abortController.signal,body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield c(o)}catch(t){throw d(t)}}))}createOrder(t){return n(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/orders/`,n=t,o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield c(o)}catch(t){throw d(t)}}))}createPayment(t){return n(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/business/${t.business_pk}/payments/`,n=t,o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield c(o)}catch(t){throw d(t)}}))}startCheckoutRouter(t){return n(this,void 0,void 0,(function*(){const e=yield p(this.baseUrl,this.apiKeyTonder,t);if(yield this.init3DSRedirect(e))return e}))}init3DSRedirect(t){return n(this,void 0,void 0,(function*(){return this.process3ds.setPayload(t),yield this._handle3dsRedirect(t)}))}startCheckoutRouterFull(t){return n(this,void 0,void 0,(function*(){try{const{order:e,total:n,customer:o,skyflowTokens:r,return_url:a,isSandbox:d,metadata:c,currency:l,payment_method:u}=t,h=yield this._fetchMerchantData(),y=yield this.customerRegister(o.email);if(!(y&&"auth_token"in y&&h&&"reference"in h))throw new i({code:"500",body:h,name:"Keys error",message:"Merchant or customer reposne errors"});{const t={business:this.apiKeyTonder,client:y.auth_token,billing_address_id:null,shipping_address_id:null,amount:n,reference:h.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 h))throw new i({code:"500",body:f,name:"Keys error",message:"Order response errors"});{const t={business_pk:h.business.pk,amount:n,date:g,order_id:f.id,client_id:y.id},e=yield this.createPayment(t);let i;const{openpay_keys:v,business:A}=h;v.merchant_id&&v.public_key&&(i=yield m(v.merchant_id,v.public_key,d));const _=Object.assign(Object.assign({name:o.name,last_name:o.lastname,email_client:o.email,phone_number:o.phone,return_url:a,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:n,title_ship:"shipping",description:"transaction",device_session_id:i||null,token_id:"",order_id:"id"in f&&f.id,business_id:A.pk,payment_id:"pk"in e&&e.pk,source:"sdk",metadata:c,browser_info:s(),currency:l},u?{payment_method:u}:{card:r}),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}),b=yield p(this.baseUrl,this.apiKeyTonder,_);if(yield this.init3DSRedirect(b))return b}}}catch(t){throw d(t)}}))}registerCustomerCard(t,e){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const n=yield fetch(`${this.baseUrl}/api/v1/business/${a(this.merchantData)}/cards/`,{method:"POST",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},body:JSON.stringify(Object.assign({},e))});if(n.ok)return yield n.json();throw yield c(n)}catch(t){throw d(t)}}))}deleteCustomerCard(t,e=""){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const n=yield fetch(`${this.baseUrl}/api/v1/business/${a(this.merchantData)}/cards/${e}`,{method:"DELETE",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},signal:this.abortController.signal});if(n.ok)return!0;throw yield c(n)}catch(t){throw d(t)}}))}getActiveAPMs(){return n(this,void 0,void 0,(function*(){try{const t=yield function(t,e,o="?status=active&page_size=10000&country=México",r=null){return n(this,void 0,void 0,(function*(){try{const n=yield fetch(`${t}/api/v1/payment_methods${o}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:r});if(n.ok)return yield n.json();throw yield c(n)}catch(t){throw d(t)}}))}(this.baseUrl,this.apiKeyTonder),e=t&&t.results&&t.results.length>0?t.results:[];return this.activeAPMs=e.filter((t=>"cards"!==t.category.toLowerCase())).map((t=>Object.assign({id:t.pk,payment_method:t.payment_method,priority:t.priority,category:t.category},w(t.payment_method)))).sort(((t,e)=>t.priority-e.priority)),this.activeAPMs}catch(t){return console.error("Error getting APMS",t),[]}}))}}function M(t){return/^\d{12,19}$/.test(t)&&P(t)}function I(t){return/^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/.test(t)}function N(t){return/^\d{3,4}$/.test(t)}function k(t){return/^(0[1-9]|1[0-2])$/.test(t)}function U(t){if(!/^\d{2}$/.test(t))return!1;const e=(new Date).getFullYear()%100;return parseInt(t,10)>=e}const P=t=>{const e=`${t}`.split("").reverse().map((t=>Number.parseInt(t))),n=e.shift();let o=e.reduce(((t,e,n)=>n%2!=0?t+e:t+((e*=2)>9?e-9:e)),0);return o+=n,o%10==0};export{R as LiteCheckout,N as validateCVV,M as validateCardNumber,I as validateCardholderName,k as validateExpirationMonth,U as validateExpirationYear};
|
|
1
|
+
import{get as t}from"lodash";import e from"skyflow-js";function n(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{d(o.next(t))}catch(t){i(t)}}function a(t){try{d(o.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}d((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function r(t,e,o){return n(this,void 0,void 0,(function*(){const n=yield fetch(`${t}/api/v1/payments/business/${e}`,{headers:{Authorization:`Token ${e}`},signal:o});return yield n.json()}))}"function"==typeof SuppressedError&&SuppressedError;class i{constructor({code:t,body:e,name:n,message:o,stack:r}){this.code=t,this.body=e,this.name=n,this.message=o,this.stack=r}}const s=()=>({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}),a=t=>{var e;return t&&"business"in t?null===(e=null==t?void 0:t.business)||void 0===e?void 0:e.pk:""},d=t=>new i({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}),c=(t,e=void 0)=>n(void 0,void 0,void 0,(function*(){let n,o,r="Error";t&&"json"in t&&(n=yield null==t?void 0:t.json()),t&&"status"in t&&(o=t.status.toString()),!n&&t&&"text"in t&&(r=yield t.text()),(null==n?void 0:n.detail)&&(r=n.detail);return new i({code:o,body:n,name:o,message:r,stack:e})}));function l(t,e){var n,o;let r=200;try{r=Number((null==e?void 0:e.code)||200)}catch(t){}const i={status:"error",code:r,message:"",detail:(null===(n=null==e?void 0:e.body)||void 0===n?void 0:n.detail)||(null===(o=null==e?void 0:e.body)||void 0===o?void 0:o.error)||e.body||"Ocurrio un error inesperado."};return Object.assign(Object.assign({},i),t)}class u{constructor({payload:t=null,apiKey:e,baseUrl:n}){this.localStorageKey="verify_transaction_status_url",this.setPayload=t=>{this.payload=t},this.baseUrl=n,this.apiKey=e,this.payload=t}setStorageItem(t){return localStorage.setItem(this.localStorageKey,JSON.stringify(t))}getStorageItem(){return localStorage.getItem(this.localStorageKey)}removeStorageItem(){return localStorage.removeItem(this.localStorageKey)}saveVerifyTransactionUrl(){var t,e,n,o,r,i;const s=null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===n?void 0:n.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const t=null===(i=null===(r=null===(o=this.payload)||void 0===o?void 0:o.next_action)||void 0===r?void 0:r.iframe_resources)||void 0===i?void 0:i.verify_transaction_status_url;t?this.saveUrlWithExpiration(t):console.log("No verify_transaction_status_url found")}}saveUrlWithExpiration(t){try{const e={url:t,expires:(new Date).getTime()+12e5};this.setStorageItem(e)}catch(t){console.log("error: ",t)}}getUrlWithExpiration(){const t=this.getStorageItem();if(t){const e=JSON.parse(t);if(!e)return;return(new Date).getTime()>e.expires?(this.removeVerifyTransactionUrl(),null):e.url}return null}removeVerifyTransactionUrl(){return this.removeStorageItem()}getVerifyTransactionUrl(){return this.getStorageItem()}loadIframe(){var t,e,n;if(null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.iframe_resources)||void 0===n?void 0:n.iframe)return new Promise(((t,e)=>{var n,o,r;const i=null===(r=null===(o=null===(n=this.payload)||void 0===n?void 0:n.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===r?void 0:r.iframe;if(i){this.saveVerifyTransactionUrl();const n=document.createElement("div");n.innerHTML=i,document.body.appendChild(n);const o=document.createElement("script");o.textContent='document.getElementById("tdsMmethodForm").submit();',n.appendChild(o);const r=document.getElementById("tdsMmethodTgtFrame");r?r.onload=()=>t(!0):(console.log("No redirection found"),e(!1))}else console.log("No redirection found"),e(!1)}))}getRedirectUrl(){var t,e,n;return null===(n=null===(e=null===(t=this.payload)||void 0===t?void 0:t.next_action)||void 0===e?void 0:e.redirect_to_url)||void 0===n?void 0:n.url}redirectToChallenge(){const t=this.getRedirectUrl();t?(this.saveVerifyTransactionUrl(),window.location=t):console.log("No redirection found")}getURLParameters(){const t={},e=new URLSearchParams(window.location.search);for(const[n,o]of e)t[n]=o;return t}handleSuccessTransaction(t){return this.removeVerifyTransactionUrl(),console.log("Transacción autorizada."),t}handleDeclinedTransaction(t){return this.removeVerifyTransactionUrl(),t}handle3dsChallenge(t){return n(this,void 0,void 0,(function*(){const e=document.createElement("form");e.name="frm",e.method="POST",e.action=t.redirect_post_url;const n=document.createElement("input");n.type="hidden",n.name=t.creq,n.value=t.creq,e.appendChild(n);const o=document.createElement("input");o.type="hidden",o.name=t.term_url,o.value=t.TermUrl,e.appendChild(o),document.body.appendChild(e),e.submit(),yield this.verifyTransactionStatus()}))}handleTransactionResponse(t){return n(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 n(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 h=Object.freeze({production:"https://app.tonder.io",sandbox:"https://sandbox.tonder.io",stage:"https://stage.tonder.io",development:"http://localhost:8000"});function p(t,e,o){return n(this,void 0,void 0,(function*(){try{const n=`${t}/api/v1/checkout-router/`,r=o,i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${e}`},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 m(t,e,o=!0,r=null){return n(this,void 0,void 0,(function*(){let n=yield window.OpenPay;return n.setId(t),n.setApiKey(e),n.setSandboxMode(o),yield n.deviceData.setup({signal:r})}))}const y=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."});var f,g,v,_,A,b,E,T;class C{constructor({mode:t="stage",apiKey:e,apiKeyTonder:n,returnUrl:o,callBack:r=(()=>{})}){f.add(this),this.baseUrl="",this.cartTotal="0",this.metadata={},this.card={},this.currency="",g.set(this,void 0),this.apiKeyTonder=e||n||"",this.returnUrl=o,this.callBack=r,this.mode=t,this.baseUrl=h[this.mode]||h.stage,this.abortController=new AbortController,this.process3ds=new u({apiKey:e,baseUrl:this.baseUrl})}configureCheckout(t){"customer"in t&&o(this,f,"m",v).call(this,t.customer)}verify3dsTransaction(){return n(this,void 0,void 0,(function*(){const t=yield this.process3ds.verifyTransactionStatus(),e=yield o(this,f,"m",T).call(this,t);return this.process3ds.setPayload(e),this._handle3dsRedirect(e)}))}payment(t){return new Promise(((e,r)=>n(this,void 0,void 0,(function*(){var n,i;try{o(this,f,"m",v).call(this,t.customer),this._setCartTotal(null===(n=t.cart)||void 0===n?void 0:n.total),o(this,f,"m",_).call(this,null===(i=t.cart)||void 0===i?void 0:i.items),o(this,f,"m",A).call(this,t),o(this,f,"m",b).call(this,t),o(this,f,"m",E).call(this,t);const r=yield this._checkout(t);this.process3ds.setPayload(r),this.callBack&&this.callBack(r);(yield this._handle3dsRedirect(r))&&e(r)}catch(t){r(t)}}))))}_initializeCheckout(){return n(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 n(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 n(this,void 0,void 0,(function*(){return o(this,g,"f")||function(t,e,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===o?r.call(t,n):r?r.value=n:e.set(t,n)}(this,g,yield function(t,e,o,r=null){return n(this,void 0,void 0,(function*(){const n=`${t}/api/v1/customer/`,i={email:o.email,first_name:null==o?void 0:o.firstName,last_name:null==o?void 0:o.lastName,phone:null==o?void 0:o.phone},s=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${e}`},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,g,"f")}))}_handleCheckout({card:e,payment_method:o,customer:r,isSandbox:i}){return n(this,void 0,void 0,(function*(){const{openpay_keys:a,reference:d,business:c}=this.merchantData,l=Number(this.cartTotal);try{let u;!u&&a.merchant_id&&a.public_key&&(u=yield m(a.merchant_id,a.public_key,i,this.abortController.signal));const{id:h,auth_token:y}=r,f={business:this.apiKeyTonder,client:y,billing_address_id:null,shipping_address_id:null,amount:l,status:"A",reference:d,is_oneclick:!0,items:this.cartItems},g=yield function(t,e,o){return n(this,void 0,void 0,(function*(){const n=`${t}/api/v1/orders/`,r=o,i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${e}`},body:JSON.stringify(r)});if(201===i.status)return yield i.json();throw new Error(`Error: ${i.statusText}`)}))}(this.baseUrl,this.apiKeyTonder,f),v=(new Date).toISOString(),_={business_pk:c.pk,client_id:h,amount:l,date:v,order_id:g.id},A=yield function(t,e,o){return n(this,void 0,void 0,(function*(){const n=`${t}/api/v1/business/${o.business_pk}/payments/`,r=o,i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${e}`},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,_),b=Object.assign({name:t(this.customer,"firstName",t(this.customer,"name","")),last_name:t(this.customer,"lastName",t(this.customer,"lastname","")),email_client:t(this.customer,"email",""),phone_number:t(this.customer,"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:u||null,token_id:"",order_id:g.id,business_id:c.pk,payment_id:A.pk,source:"sdk",metadata:this.metadata,browser_info:s(),currency:this.currency},o?{payment_method:o}:{card:e}),E=yield p(this.baseUrl,this.apiKeyTonder,b);return E||!1}catch(t){throw console.log(t),t}}))}_fetchMerchantData(){return n(this,void 0,void 0,(function*(){try{return this.merchantData||(this.merchantData=yield r(this.baseUrl,this.apiKeyTonder,this.abortController.signal)),this.merchantData}catch(t){return this.merchantData}}))}_getCustomerCards(t,e){return n(this,void 0,void 0,(function*(){return yield function(t,e,o,r=null){return n(this,void 0,void 0,(function*(){try{const n=`${t}/api/v1/business/${o}/cards/`,i=yield fetch(n,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield c(i,s)}catch(t){throw d(t)}}))}(this.baseUrl,t,e)}))}_saveCustomerCard(t,e,o){return n(this,void 0,void 0,(function*(){return yield function(t,e,o,r){return n(this,void 0,void 0,(function*(){try{const n=`${t}/api/v1/business/${o}/cards/`,i=yield fetch(n,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(i.ok)return yield i.json();const s=yield i.json();throw yield c(i,s)}catch(t){throw d(t)}}))}(this.baseUrl,t,e,o)}))}_removeCustomerCard(t,e,o){return n(this,void 0,void 0,(function*(){return yield function(t,e,o="",r){return n(this,void 0,void 0,(function*(){try{const n=`${t}/api/v1/business/${r}/cards/${o}`,i=yield fetch(n,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"}});if(204===i.status)return y.cardSaved;if(i.ok&&"json"in i)return yield i.json();const s=yield i.json();throw yield c(i,s)}catch(t){throw d(t)}}))}(this.baseUrl,t,o,e)}))}_fetchCustomerAPMs(){return n(this,void 0,void 0,(function*(){return yield function(t,e,o={status:"active",pagesize:"10000"},r=null){return n(this,void 0,void 0,(function*(){try{const n=new URLSearchParams(o).toString(),i=yield fetch(`${t}/api/v1/payment_methods?${n}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:r});if(i.ok)return yield i.json();const s=yield i.json();throw yield c(i,s)}catch(t){throw d(t)}}))}(this.baseUrl,this.apiKeyTonder)}))}_handle3dsRedirect(t){var e,o;return n(this,void 0,void 0,(function*(){if(t&&"next_action"in t?null===(o=null===(e=null==t?void 0:t.next_action)||void 0===e?void 0:e.iframe_resources)||void 0===o?void 0:o.iframe:null)this.process3ds.loadIframe().then((()=>{this.process3ds.verifyTransactionStatus()})).catch((t=>{console.log("Error loading iframe:",t)}));else{if(!this.process3ds.getRedirectUrl())return t;this.process3ds.redirectToChallenge()}}))}}function O({baseUrl:t,apiKey:o,vault_id:r,vault_url:i,data:s}){return n(this,void 0,void 0,(function*(){const a=e.init({vaultID:r,vaultURL:i,getBearerToken:()=>n(this,void 0,void 0,(function*(){return yield function(t,e,o=null){return n(this,void 0,void 0,(function*(){const n=yield fetch(`${t}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${e}`},signal:o});if(n.ok)return(yield n.json()).token;throw new Error("Failed to retrieve bearer token")}))}(t,o)})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}),c=a.container(e.ContainerType.COLLECT),l=yield function(t,o){return n(this,void 0,void 0,(function*(){const r=yield function(t,o){return n(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(t).map((t=>n(this,void 0,void 0,(function*(){return{element:yield o.create({table:"cards",column:t,type:e.ElementType.INPUT_FIELD}),key:t}})))))}))}(t,o);return r?r.map((e=>new Promise((n=>{var o;const r=document.createElement("div");r.hidden=!0,r.id=`id-${e.key}`,null===(o=document.querySelector("body"))||void 0===o||o.appendChild(r),setTimeout((()=>{e.element.mount(`#id-${e.key}`),setInterval((()=>{if(e.element.isMounted()){const o=t[e.key];return e.element.update({value:o}),n(e.element.isMounted())}}),120)}),120)})))):[]}))}(s,c);if((yield Promise.all(l)).some((t=>!t)))throw d(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const t=yield c.collect();if(t)return t.records[0].fields;throw d(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(t){throw d(t)}}))}g=new WeakMap,f=new WeakSet,v=function(t){t&&(this.customer=t)},_=function(t){this.cartItems=t},A=function(t){this.metadata=null==t?void 0:t.metadata},b=function(t){this.currency=null==t?void 0:t.currency},E=function(t){this.card=null==t?void 0:t.card},T=function(t){var e,o;return n(this,void 0,void 0,(function*(){if("Hard"===(null===(e=null==t?void 0:t.decline)||void 0===e?void 0:e.error_type))return t;if(["Success","Authorized"].includes(null==t?void 0:t.transaction_status))return t;if(t){const e={checkout_id:null===(o=t.checkout)||void 0===o?void 0:o.id};try{return yield p(this.baseUrl,this.apiKeyTonder,e)}catch(t){}return 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"}),j={[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"}},w=t=>{const e=t.toUpperCase().trim().replace(/\s+/g,"");return j[e]||{icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",label:""}};class M extends C{constructor({apiKey:t,mode:e,returnUrl:n,callBack:o}){super({mode:e,apiKey:t,returnUrl:n,callBack:o}),this.activeAPMs=[]}injectCheckout(){return n(this,void 0,void 0,(function*(){yield this._initializeCheckout()}))}getCustomerCards(){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:t}=yield this._getCustomer(),e=yield this._getCustomerCards(t,this.merchantData.business.pk);return Object.assign(Object.assign({},e),{cards:e.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:y.getCardsError},t)}}))}saveCustomerCard(t){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:e}=yield this._getCustomer(),{vault_id:n,vault_url:o,business:r}=this.merchantData,i=yield O({vault_id:n,vault_url:o,data:t,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder});return yield this._saveCustomerCard(e,null==r?void 0:r.pk,i)}catch(t){throw l({message:y.saveCardError},t)}}))}removeCustomerCard(t){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const{auth_token:e}=yield this._getCustomer(),{business:n}=this.merchantData;return yield this._removeCustomerCard(e,null==n?void 0:n.pk,t)}catch(t){throw l({message:y.removeCardError},t)}}))}getCustomerPaymentMethods(){return n(this,void 0,void 0,(function*(){try{const t=yield this._fetchCustomerAPMs();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},w(t.payment_method)))).sort(((t,e)=>t.priority-e.priority))}catch(t){throw l({message:y.getPaymentMethodsError},t)}}))}getBusiness(){return n(this,void 0,void 0,(function*(){try{return yield r(this.baseUrl,this.apiKeyTonder,this.abortController.signal)}catch(t){throw l({message:y.getBusinessError},t)}}))}getOpenpayDeviceSessionID(t,e,o){return n(this,void 0,void 0,(function*(){try{return yield m(t,e,o)}catch(t){throw d(t)}}))}getSkyflowTokens({vault_id:t,vault_url:e,data:o}){return n(this,void 0,void 0,(function*(){return yield O({vault_id:t,vault_url:e,data:o,baseUrl:this.baseUrl,apiKey:this.apiKeyTonder})}))}_setCartTotal(t){this.cartTotal=t}_checkout({card:t,payment_method:e,isSandbox:o}){return n(this,void 0,void 0,(function*(){yield this._fetchMerchantData();const n=yield this._getCustomer(this.abortController.signal),{vault_id:r,vault_url:i}=this.merchantData;let s;return e&&""===e&&null!==e||(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:e,customer:n,isSandbox:o})}))}customerRegister(t){return n(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/customer/`,n={email:t},o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.abortController.signal,body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield c(o)}catch(t){throw d(t)}}))}createOrder(t){return n(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/orders/`,n=t,o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield c(o)}catch(t){throw d(t)}}))}createPayment(t){return n(this,void 0,void 0,(function*(){try{const e=`${this.baseUrl}/api/v1/business/${t.business_pk}/payments/`,n=t,o=yield fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield c(o)}catch(t){throw d(t)}}))}startCheckoutRouter(t){return n(this,void 0,void 0,(function*(){const e=yield p(this.baseUrl,this.apiKeyTonder,t);if(yield this.init3DSRedirect(e))return e}))}init3DSRedirect(t){return n(this,void 0,void 0,(function*(){return this.process3ds.setPayload(t),yield this._handle3dsRedirect(t)}))}startCheckoutRouterFull(t){return n(this,void 0,void 0,(function*(){try{const{order:e,total:n,customer:o,skyflowTokens:r,return_url:a,isSandbox:d,metadata:c,currency:l,payment_method:u}=t,h=yield this._fetchMerchantData(),y=yield this.customerRegister(o.email);if(!(y&&"auth_token"in y&&h&&"reference"in h))throw new i({code:"500",body:h,name:"Keys error",message:"Merchant or customer reposne errors"});{const t={business:this.apiKeyTonder,client:y.auth_token,billing_address_id:null,shipping_address_id:null,amount:n,reference:h.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 h))throw new i({code:"500",body:f,name:"Keys error",message:"Order response errors"});{const t={business_pk:h.business.pk,amount:n,date:g,order_id:f.id,client_id:y.id},e=yield this.createPayment(t);let i;const{openpay_keys:v,business:_}=h;v.merchant_id&&v.public_key&&(i=yield m(v.merchant_id,v.public_key,d));const A=Object.assign(Object.assign({name:o.name,last_name:o.lastname,email_client:o.email,phone_number:o.phone,return_url:a,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:n,title_ship:"shipping",description:"transaction",device_session_id:i||null,token_id:"",order_id:"id"in f&&f.id,business_id:_.pk,payment_id:"pk"in e&&e.pk,source:"sdk",metadata:c,browser_info:s(),currency:l},u?{payment_method:u}:{card:r}),"undefined"!=typeof MP_DEVICE_SESSION_ID?{mp_device_session_id:MP_DEVICE_SESSION_ID}:{}),b=yield p(this.baseUrl,this.apiKeyTonder,A);if(yield this.init3DSRedirect(b))return b}}}catch(t){throw d(t)}}))}registerCustomerCard(t,e){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const n=yield fetch(`${this.baseUrl}/api/v1/business/${a(this.merchantData)}/cards/`,{method:"POST",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},body:JSON.stringify(Object.assign({},e))});if(n.ok)return yield n.json();throw yield c(n)}catch(t){throw d(t)}}))}deleteCustomerCard(t,e=""){return n(this,void 0,void 0,(function*(){try{yield this._fetchMerchantData();const n=yield fetch(`${this.baseUrl}/api/v1/business/${a(this.merchantData)}/cards/${e}`,{method:"DELETE",headers:{Authorization:`Token ${t}`,"Content-Type":"application/json"},signal:this.abortController.signal});if(n.ok)return!0;throw yield c(n)}catch(t){throw d(t)}}))}getActiveAPMs(){return n(this,void 0,void 0,(function*(){try{const t=yield function(t,e,o="?status=active&page_size=10000&country=México",r=null){return n(this,void 0,void 0,(function*(){try{const n=yield fetch(`${t}/api/v1/payment_methods${o}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:r});if(n.ok)return yield n.json();throw yield c(n)}catch(t){throw d(t)}}))}(this.baseUrl,this.apiKeyTonder),e=t&&t.results&&t.results.length>0?t.results:[];return this.activeAPMs=e.filter((t=>"cards"!==t.category.toLowerCase())).map((t=>Object.assign({id:t.pk,payment_method:t.payment_method,priority:t.priority,category:t.category},w(t.payment_method)))).sort(((t,e)=>t.priority-e.priority)),this.activeAPMs}catch(t){return console.error("Error getting APMS",t),[]}}))}}function R(t){return/^\d{12,19}$/.test(t)&&P(t)}function I(t){return/^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/.test(t)}function N(t){return/^\d{3,4}$/.test(t)}function k(t){return/^(0[1-9]|1[0-2])$/.test(t)}function U(t){if(!/^\d{2}$/.test(t))return!1;const e=(new Date).getFullYear()%100;return parseInt(t,10)>=e}const P=t=>{const e=`${t}`.split("").reverse().map((t=>Number.parseInt(t))),n=e.shift();let o=e.reduce(((t,e,n)=>n%2!=0?t+e:t+((e*=2)>9?e-9:e)),0);return o+=n,o%10==0};export{C as BaseInlineCheckout,M as LiteCheckout,N as validateCVV,R as validateCardNumber,I as validateCardholderName,k as validateExpirationMonth,U as validateExpirationYear};
|
package/package.json
CHANGED
|
@@ -21,8 +21,18 @@ import {
|
|
|
21
21
|
IStartCheckoutResponse,
|
|
22
22
|
StartCheckoutResponse,
|
|
23
23
|
ICardFields,
|
|
24
|
+
ICustomerCardsResponse,
|
|
25
|
+
ISaveCardResponse,
|
|
26
|
+
ISaveCardSkyflowRequest,
|
|
27
|
+
IPaymentMethodResponse,
|
|
24
28
|
} from "../types";
|
|
25
|
-
import { get } from "lodash"
|
|
29
|
+
import { get } from "lodash";
|
|
30
|
+
import {
|
|
31
|
+
fetchCustomerCards,
|
|
32
|
+
removeCustomerCard,
|
|
33
|
+
saveCustomerCard,
|
|
34
|
+
} from "../data/cardApi";
|
|
35
|
+
import { fetchCustomerPaymentMethods } from "../data/paymentMethodApi";
|
|
26
36
|
export class BaseInlineCheckout {
|
|
27
37
|
baseUrl = "";
|
|
28
38
|
cartTotal = "0";
|
|
@@ -33,8 +43,8 @@ export class BaseInlineCheckout {
|
|
|
33
43
|
callBack?: ((response: any) => void) | undefined;
|
|
34
44
|
merchantData?: Business;
|
|
35
45
|
abortController: AbortController;
|
|
36
|
-
|
|
37
|
-
customer?: ICustomer | {email: string};
|
|
46
|
+
|
|
47
|
+
customer?: ICustomer | { email: string };
|
|
38
48
|
|
|
39
49
|
cartItems?: IItem[];
|
|
40
50
|
metadata = {};
|
|
@@ -197,10 +207,14 @@ export class BaseInlineCheckout {
|
|
|
197
207
|
|
|
198
208
|
// Checkout router
|
|
199
209
|
const routerItems = {
|
|
200
|
-
name: get(this.customer,"firstName",get(this.customer,"name","")),
|
|
201
|
-
last_name: get(
|
|
202
|
-
|
|
203
|
-
|
|
210
|
+
name: get(this.customer, "firstName", get(this.customer, "name", "")),
|
|
211
|
+
last_name: get(
|
|
212
|
+
this.customer,
|
|
213
|
+
"lastName",
|
|
214
|
+
get(this.customer, "lastname", ""),
|
|
215
|
+
),
|
|
216
|
+
email_client: get(this.customer, "email", ""),
|
|
217
|
+
phone_number: get(this.customer, "phone", ""),
|
|
204
218
|
return_url: this.returnUrl,
|
|
205
219
|
id_product: "no_id",
|
|
206
220
|
quantity_product: 1,
|
|
@@ -253,7 +267,43 @@ export class BaseInlineCheckout {
|
|
|
253
267
|
}
|
|
254
268
|
}
|
|
255
269
|
|
|
256
|
-
|
|
270
|
+
async _getCustomerCards(
|
|
271
|
+
authToken: string,
|
|
272
|
+
businessId: string | number,
|
|
273
|
+
): Promise<ICustomerCardsResponse> {
|
|
274
|
+
return await fetchCustomerCards(this.baseUrl, authToken, businessId);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async _saveCustomerCard(
|
|
278
|
+
authToken: string,
|
|
279
|
+
businessId: string | number,
|
|
280
|
+
skyflowTokens: ISaveCardSkyflowRequest,
|
|
281
|
+
): Promise<ISaveCardResponse> {
|
|
282
|
+
return await saveCustomerCard(
|
|
283
|
+
this.baseUrl,
|
|
284
|
+
authToken,
|
|
285
|
+
businessId,
|
|
286
|
+
skyflowTokens,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async _removeCustomerCard(
|
|
291
|
+
authToken: string,
|
|
292
|
+
businessId: string | number,
|
|
293
|
+
skyflowId: string,
|
|
294
|
+
): Promise<string> {
|
|
295
|
+
return await removeCustomerCard(
|
|
296
|
+
this.baseUrl,
|
|
297
|
+
authToken,
|
|
298
|
+
skyflowId,
|
|
299
|
+
businessId,
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
async _fetchCustomerAPMs(): Promise<IPaymentMethodResponse> {
|
|
303
|
+
return await fetchCustomerPaymentMethods(this.baseUrl, this.apiKeyTonder);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
#handleCustomer(customer: ICustomer | { email: string }) {
|
|
257
307
|
if (!customer) return;
|
|
258
308
|
|
|
259
309
|
this.customer = customer;
|
|
@@ -12,14 +12,8 @@ import {
|
|
|
12
12
|
} from "../helpers/utils";
|
|
13
13
|
import { getCustomerAPMs } from "../data/api";
|
|
14
14
|
import { BaseInlineCheckout } from "./BaseInlineCheckout";
|
|
15
|
-
import {
|
|
16
|
-
fetchCustomerCards,
|
|
17
|
-
removeCustomerCard,
|
|
18
|
-
saveCustomerCard,
|
|
19
|
-
} from "../data/cardApi";
|
|
20
15
|
import { MESSAGES } from "../shared/constants/messages";
|
|
21
16
|
import { getSkyflowTokens } from "../helpers/skyflow";
|
|
22
|
-
import { fetchCustomerAPMs } from "../data/paymentMethodApi";
|
|
23
17
|
import { startCheckoutRouter } from "../data/checkoutApi";
|
|
24
18
|
import { getOpenpayDeviceSessionID } from "../data/openPayApi";
|
|
25
19
|
import { getPaymentMethodDetails } from "../shared/catalog/paymentMethodsCatalog";
|
|
@@ -46,6 +40,7 @@ import {
|
|
|
46
40
|
CreatePaymentResponse,
|
|
47
41
|
CreateOrderResponse,
|
|
48
42
|
RegisterCustomerCardRequest,
|
|
43
|
+
ISaveCardSkyflowRequest,
|
|
49
44
|
} from "../types";
|
|
50
45
|
|
|
51
46
|
declare global {
|
|
@@ -71,8 +66,7 @@ export class LiteCheckout extends BaseInlineCheckout {
|
|
|
71
66
|
try {
|
|
72
67
|
await this._fetchMerchantData();
|
|
73
68
|
const { auth_token } = await this._getCustomer();
|
|
74
|
-
const response = await
|
|
75
|
-
this.baseUrl,
|
|
69
|
+
const response = await this._getCustomerCards(
|
|
76
70
|
auth_token,
|
|
77
71
|
this.merchantData!.business.pk,
|
|
78
72
|
);
|
|
@@ -94,13 +88,15 @@ export class LiteCheckout extends BaseInlineCheckout {
|
|
|
94
88
|
}
|
|
95
89
|
}
|
|
96
90
|
|
|
97
|
-
async saveCustomerCard(
|
|
91
|
+
public async saveCustomerCard(
|
|
92
|
+
card: ISaveCardRequest,
|
|
93
|
+
): Promise<ISaveCardResponse> {
|
|
98
94
|
try {
|
|
99
95
|
await this._fetchMerchantData();
|
|
100
96
|
const { auth_token } = await this._getCustomer();
|
|
101
97
|
const { vault_id, vault_url, business } = this.merchantData!;
|
|
102
98
|
|
|
103
|
-
const skyflowTokens = await getSkyflowTokens({
|
|
99
|
+
const skyflowTokens: ISaveCardSkyflowRequest = await getSkyflowTokens({
|
|
104
100
|
vault_id: vault_id,
|
|
105
101
|
vault_url: vault_url,
|
|
106
102
|
data: card,
|
|
@@ -108,8 +104,7 @@ export class LiteCheckout extends BaseInlineCheckout {
|
|
|
108
104
|
apiKey: this.apiKeyTonder,
|
|
109
105
|
});
|
|
110
106
|
|
|
111
|
-
return await
|
|
112
|
-
this.baseUrl,
|
|
107
|
+
return await this._saveCustomerCard(
|
|
113
108
|
auth_token,
|
|
114
109
|
business?.pk,
|
|
115
110
|
skyflowTokens,
|
|
@@ -124,17 +119,16 @@ export class LiteCheckout extends BaseInlineCheckout {
|
|
|
124
119
|
}
|
|
125
120
|
}
|
|
126
121
|
|
|
127
|
-
async removeCustomerCard(skyflowId: string): Promise<string> {
|
|
122
|
+
public async removeCustomerCard(skyflowId: string): Promise<string> {
|
|
128
123
|
try {
|
|
129
124
|
await this._fetchMerchantData();
|
|
130
125
|
const { auth_token } = await this._getCustomer();
|
|
131
126
|
const { business } = this.merchantData!;
|
|
132
127
|
|
|
133
|
-
return await
|
|
134
|
-
this.baseUrl,
|
|
128
|
+
return await this._removeCustomerCard(
|
|
135
129
|
auth_token,
|
|
136
|
-
skyflowId,
|
|
137
130
|
business?.pk,
|
|
131
|
+
skyflowId,
|
|
138
132
|
);
|
|
139
133
|
} catch (error) {
|
|
140
134
|
throw formatPublicErrorResponse(
|
|
@@ -146,9 +140,9 @@ export class LiteCheckout extends BaseInlineCheckout {
|
|
|
146
140
|
}
|
|
147
141
|
}
|
|
148
142
|
|
|
149
|
-
async getCustomerPaymentMethods(): Promise<IPaymentMethod[]> {
|
|
143
|
+
public async getCustomerPaymentMethods(): Promise<IPaymentMethod[]> {
|
|
150
144
|
try {
|
|
151
|
-
const response = await
|
|
145
|
+
const response = await this._fetchCustomerAPMs();
|
|
152
146
|
|
|
153
147
|
const apms_results =
|
|
154
148
|
response && "results" in response && response["results"].length > 0
|
|
@@ -178,7 +172,7 @@ export class LiteCheckout extends BaseInlineCheckout {
|
|
|
178
172
|
}
|
|
179
173
|
}
|
|
180
174
|
|
|
181
|
-
async getBusiness(): Promise<GetBusinessResponse> {
|
|
175
|
+
public async getBusiness(): Promise<GetBusinessResponse> {
|
|
182
176
|
try {
|
|
183
177
|
return await fetchBusiness(
|
|
184
178
|
this.baseUrl,
|
|
@@ -197,18 +191,22 @@ export class LiteCheckout extends BaseInlineCheckout {
|
|
|
197
191
|
|
|
198
192
|
// TODO: DEPRECATED
|
|
199
193
|
async getOpenpayDeviceSessionID(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
194
|
+
merchant_id: string,
|
|
195
|
+
public_key: string,
|
|
196
|
+
is_sandbox: boolean,
|
|
203
197
|
): Promise<string | ErrorResponse> {
|
|
204
198
|
try {
|
|
205
|
-
return await getOpenpayDeviceSessionID(
|
|
199
|
+
return await getOpenpayDeviceSessionID(
|
|
200
|
+
merchant_id,
|
|
201
|
+
public_key,
|
|
202
|
+
is_sandbox,
|
|
203
|
+
);
|
|
206
204
|
} catch (e) {
|
|
207
205
|
throw buildErrorResponseFromCatch(e);
|
|
208
206
|
}
|
|
209
207
|
}
|
|
210
208
|
|
|
211
|
-
|
|
209
|
+
// TODO: DEPRECATED
|
|
212
210
|
async getSkyflowTokens({
|
|
213
211
|
vault_id,
|
|
214
212
|
vault_url,
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { LiteCheckout } from './classes/liteCheckout'
|
|
2
|
+
import { BaseInlineCheckout } from './classes/BaseInlineCheckout'
|
|
2
3
|
import { validateCVV, validateCardNumber, validateExpirationMonth, validateCardholderName, validateExpirationYear } from './helpers/validations'
|
|
3
4
|
|
|
4
5
|
export {
|
|
5
6
|
LiteCheckout,
|
|
7
|
+
BaseInlineCheckout,
|
|
6
8
|
validateCVV,
|
|
7
9
|
validateCardNumber,
|
|
8
10
|
validateCardholderName,
|
|
@@ -120,7 +120,6 @@ export class LiteCheckout {
|
|
|
120
120
|
*/
|
|
121
121
|
getBusiness(): Promise<GetBusinessResponse>;
|
|
122
122
|
|
|
123
|
-
// TODO: DEPRECATED
|
|
124
123
|
/**
|
|
125
124
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
126
125
|
* It is no longer necessary to use this method as customer registration is now automatically handled
|
|
@@ -130,7 +129,6 @@ export class LiteCheckout {
|
|
|
130
129
|
email: string,
|
|
131
130
|
): Promise<CustomerRegisterResponse | ErrorResponse>;
|
|
132
131
|
|
|
133
|
-
// TODO: DEPRECATED
|
|
134
132
|
/**
|
|
135
133
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
136
134
|
* It is no longer necessary to use this method as order creation is now automatically
|
|
@@ -140,7 +138,6 @@ export class LiteCheckout {
|
|
|
140
138
|
orderItems: CreateOrderRequest,
|
|
141
139
|
): Promise<CreateOrderResponse | ErrorResponse>;
|
|
142
140
|
|
|
143
|
-
// TODO: DEPRECATED
|
|
144
141
|
/**
|
|
145
142
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
146
143
|
* It is no longer necessary to use this method as payment creation is now automatically
|
|
@@ -150,7 +147,6 @@ export class LiteCheckout {
|
|
|
150
147
|
paymentItems: CreatePaymentRequest,
|
|
151
148
|
): Promise<CreatePaymentResponse | ErrorResponse>;
|
|
152
149
|
|
|
153
|
-
// TODO: DEPRECATED
|
|
154
150
|
/**
|
|
155
151
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
156
152
|
* Use the {@link payment} method
|
|
@@ -159,7 +155,6 @@ export class LiteCheckout {
|
|
|
159
155
|
routerData: StartCheckoutRequest | StartCheckoutIdRequest,
|
|
160
156
|
): Promise<StartCheckoutResponse | ErrorResponse | undefined>;
|
|
161
157
|
|
|
162
|
-
// TODO: DEPRECATED
|
|
163
158
|
/**
|
|
164
159
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
165
160
|
* Use the {@link payment} method
|
|
@@ -168,7 +163,6 @@ export class LiteCheckout {
|
|
|
168
163
|
routerFullData: StartCheckoutFullRequest,
|
|
169
164
|
): Promise<StartCheckoutResponse | ErrorResponse | undefined>;
|
|
170
165
|
|
|
171
|
-
// TODO: DEPRECATED
|
|
172
166
|
/**
|
|
173
167
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
174
168
|
* Use the {@link saveCustomerCard} method
|
|
@@ -178,7 +172,6 @@ export class LiteCheckout {
|
|
|
178
172
|
data: RegisterCustomerCardRequest,
|
|
179
173
|
): Promise<RegisterCustomerCardResponse | ErrorResponse>;
|
|
180
174
|
|
|
181
|
-
// TODO: DEPRECATED
|
|
182
175
|
/**
|
|
183
176
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
184
177
|
* Use the {@link removeCustomerCard} method
|
|
@@ -188,14 +181,12 @@ export class LiteCheckout {
|
|
|
188
181
|
skyflowId: string,
|
|
189
182
|
): Promise<Boolean | ErrorResponse>;
|
|
190
183
|
|
|
191
|
-
// TODO: DEPRECATED
|
|
192
184
|
/**
|
|
193
185
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
194
186
|
* Use the {@link getCustomerPaymentMethods} method
|
|
195
187
|
*/
|
|
196
188
|
getActiveAPMs(): Promise<APM[]>;
|
|
197
189
|
|
|
198
|
-
// TODO: DEPRECATED
|
|
199
190
|
/**
|
|
200
191
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
201
192
|
* It is no longer necessary to use this method as customer registration is now automatically handled
|
|
@@ -207,7 +198,6 @@ export class LiteCheckout {
|
|
|
207
198
|
data,
|
|
208
199
|
}: TokensRequest): Promise<any | ErrorResponse>;
|
|
209
200
|
|
|
210
|
-
// TODO: DEPRECATED
|
|
211
201
|
/**
|
|
212
202
|
* @deprecated This method is deprecated and will be removed in a future release.
|
|
213
203
|
* It is no longer necessary to use this method is now automatically handled
|