@tonder.io/ionic-lite-sdk 0.0.33-beta → 0.0.34-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/3dsHandler.d.ts +0 -3
- package/dist/classes/liteCheckout.d.ts +3 -2
- package/dist/data/api.d.ts +1 -0
- package/dist/helpers/constants.d.ts +62 -0
- package/dist/helpers/utils.d.ts +8 -0
- package/dist/index.js +1 -1
- package/dist/types/commons.d.ts +16 -0
- package/dist/types/requests.d.ts +11 -2
- package/package.json +1 -1
- package/src/classes/3dsHandler.ts +0 -13
- package/src/classes/liteCheckout.ts +59 -73
- package/src/data/api.ts +21 -0
- package/src/helpers/constants.ts +64 -0
- package/src/helpers/utils.ts +303 -0
- package/src/types/commons.ts +18 -0
- package/src/types/requests.ts +15 -3
- package/tests/utils/mockClasses.ts +3 -2
|
@@ -16,9 +16,6 @@ export declare class ThreeDSHandler {
|
|
|
16
16
|
removeStorageItem(): void;
|
|
17
17
|
saveVerifyTransactionUrl(): void;
|
|
18
18
|
saveUrlWithExpiration(url: string): void;
|
|
19
|
-
saveCheckoutId(checkoutId: any): void;
|
|
20
|
-
removeCheckoutId(): void;
|
|
21
|
-
getCurrentCheckoutId(): any;
|
|
22
19
|
getUrlWithExpiration(): any;
|
|
23
20
|
removeVerifyTransactionUrl(): void;
|
|
24
21
|
getVerifyTransactionUrl(): string | null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import CollectContainer from "skyflow-js/types/core/external/collect/collect-container";
|
|
2
|
+
import { APM } from "../types/commons";
|
|
2
3
|
import { CreateOrderRequest, CreatePaymentRequest, RegisterCustomerCardRequest, StartCheckoutRequest, TokensRequest, StartCheckoutFullRequest, StartCheckoutIdRequest } from "../types/requests";
|
|
3
4
|
import { GetBusinessResponse, CustomerRegisterResponse, CreateOrderResponse, CreatePaymentResponse, StartCheckoutResponse, GetCustomerCardsResponse, RegisterCustomerCardResponse } from "../types/responses";
|
|
4
5
|
import { ErrorResponse } from "./errorResponse";
|
|
@@ -20,6 +21,7 @@ export declare class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
20
21
|
apiKeyTonder: string;
|
|
21
22
|
process3ds: ThreeDSHandler;
|
|
22
23
|
successUrl?: string;
|
|
24
|
+
activeAPMs: APM[];
|
|
23
25
|
constructor({ signal, baseUrlTonder, apiKeyTonder, successUrl, }: LiteCheckoutConstructor);
|
|
24
26
|
getOpenpayDeviceSessionID(merchant_id: string, public_key: string, is_sandbox: boolean): Promise<string | ErrorResponse>;
|
|
25
27
|
getBusiness(): Promise<GetBusinessResponse | ErrorResponse>;
|
|
@@ -39,7 +41,6 @@ export declare class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
39
41
|
registerCustomerCard(customerToken: string, data: RegisterCustomerCardRequest): Promise<RegisterCustomerCardResponse | ErrorResponse>;
|
|
40
42
|
getCustomerCards(customerToken: string, query?: string): Promise<GetCustomerCardsResponse | ErrorResponse>;
|
|
41
43
|
deleteCustomerCard(customerToken: string, skyflowId?: string): Promise<Boolean | ErrorResponse>;
|
|
42
|
-
private buildErrorResponseFromCatch;
|
|
43
|
-
private buildErrorResponse;
|
|
44
44
|
private getFields;
|
|
45
|
+
getActiveAPMs(): Promise<APM[]>;
|
|
45
46
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCustomerAPMs(baseUrlTonder: string, apiKeyTonder: string, query?: string, signal?: AbortSignal | null | undefined): Promise<any>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
declare enum PAYMENT_METHOD {
|
|
2
|
+
SORIANA = "SORIANA",
|
|
3
|
+
OXXO = "OXXO",
|
|
4
|
+
SPEI = "SPEI",
|
|
5
|
+
CODI = "CODI",
|
|
6
|
+
MERCADOPAGO = "MERCADOPAGO",
|
|
7
|
+
PAYPAL = "PAYPAL",
|
|
8
|
+
COMERCIALMEXICANA = "COMERCIALMEXICANA",
|
|
9
|
+
BANCOMER = "BANCOMER",
|
|
10
|
+
WALMART = "WALMART",
|
|
11
|
+
BODEGA = "BODEGA",
|
|
12
|
+
SAMSCLUB = "SAMSCLUB",
|
|
13
|
+
SUPERAMA = "SUPERAMA",
|
|
14
|
+
CALIMAX = "CALIMAX",
|
|
15
|
+
EXTRA = "EXTRA",
|
|
16
|
+
CIRCULOK = "CIRCULOK",
|
|
17
|
+
SEVEN11 = "7ELEVEN",
|
|
18
|
+
TELECOMM = "TELECOMM",
|
|
19
|
+
BANORTE = "BANORTE",
|
|
20
|
+
BENAVIDES = "BENAVIDES",
|
|
21
|
+
DELAHORRO = "DELAHORRO",
|
|
22
|
+
ELASTURIANO = "ELASTURIANO",
|
|
23
|
+
WALDOS = "WALDOS",
|
|
24
|
+
ALSUPER = "ALSUPER",
|
|
25
|
+
KIOSKO = "KIOSKO",
|
|
26
|
+
STAMARIA = "STAMARIA",
|
|
27
|
+
LAMASBARATA = "LAMASBARATA",
|
|
28
|
+
FARMROMA = "FARMROMA",
|
|
29
|
+
FARMUNION = "FARMUNION",
|
|
30
|
+
FARMATODO = "FARMATODO",
|
|
31
|
+
SFDEASIS = "SFDEASIS",
|
|
32
|
+
FARM911 = "FARM911",
|
|
33
|
+
FARMECONOMICAS = "FARMECONOMICAS",
|
|
34
|
+
FARMMEDICITY = "FARMMEDICITY",
|
|
35
|
+
RIANXEIRA = "RIANXEIRA",
|
|
36
|
+
WESTERNUNION = "WESTERNUNION",
|
|
37
|
+
ZONAPAGO = "ZONAPAGO",
|
|
38
|
+
CAJALOSANDES = "CAJALOSANDES",
|
|
39
|
+
CAJAPAITA = "CAJAPAITA",
|
|
40
|
+
CAJASANTA = "CAJASANTA",
|
|
41
|
+
CAJASULLANA = "CAJASULLANA",
|
|
42
|
+
CAJATRUJILLO = "CAJATRUJILLO",
|
|
43
|
+
EDPYME = "EDPYME",
|
|
44
|
+
KASNET = "KASNET",
|
|
45
|
+
NORANDINO = "NORANDINO",
|
|
46
|
+
QAPAQ = "QAPAQ",
|
|
47
|
+
RAIZ = "RAIZ",
|
|
48
|
+
PAYSER = "PAYSER",
|
|
49
|
+
WUNION = "WUNION",
|
|
50
|
+
BANCOCONTINENTAL = "BANCOCONTINENTAL",
|
|
51
|
+
GMONEY = "GMONEY",
|
|
52
|
+
GOPAY = "GOPAY",
|
|
53
|
+
WU = "WU",
|
|
54
|
+
PUNTOSHEY = "PUNTOSHEY",
|
|
55
|
+
AMPM = "AMPM",
|
|
56
|
+
JUMBOMARKET = "JUMBOMARKET",
|
|
57
|
+
SMELPUEBLO = "SMELPUEBLO",
|
|
58
|
+
BAM = "BAM",
|
|
59
|
+
REFACIL = "REFACIL",
|
|
60
|
+
ACYVALORES = "ACYVALORES"
|
|
61
|
+
}
|
|
62
|
+
export { PAYMENT_METHOD };
|
package/dist/helpers/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorResponse } from "../classes/errorResponse";
|
|
1
2
|
export declare const getBrowserInfo: () => {
|
|
2
3
|
javascript_enabled: boolean;
|
|
3
4
|
time_zone: number;
|
|
@@ -7,3 +8,10 @@ export declare const getBrowserInfo: () => {
|
|
|
7
8
|
screen_height: number | null;
|
|
8
9
|
user_agent: string;
|
|
9
10
|
};
|
|
11
|
+
declare const buildErrorResponseFromCatch: (e: any) => ErrorResponse;
|
|
12
|
+
declare const buildErrorResponse: (response: Response, stack?: string | undefined) => Promise<ErrorResponse>;
|
|
13
|
+
declare const getPaymentMethodDetails: (scheme_data: string) => {
|
|
14
|
+
icon: string;
|
|
15
|
+
label: string;
|
|
16
|
+
};
|
|
17
|
+
export { buildErrorResponseFromCatch, buildErrorResponse, getPaymentMethodDetails };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"skyflow-js";function t(e,t,i,r){return new(i||(i=Promise))((function(o,n){function s(e){try{d(r.next(e))}catch(e){n(e)}}function a(e){try{d(r.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}d((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class i{constructor({code:e,body:t,name:i,message:r,stack:o}){this.code=e,this.body=t,this.name=i,this.message=r,this.stack=o}}class r{constructor({payload:e=null,apiKey:t,baseUrl:i,successUrl:r}){this.localStorageKey="verify_transaction_status_url",this.setPayload=e=>{this.payload=e},this.baseUrl=i,this.apiKey=t,this.payload=e,this.successUrl=r}setStorageItem(e){return localStorage.setItem(this.localStorageKey,JSON.stringify(e))}getStorageItem(){return localStorage.getItem(this.localStorageKey)}removeStorageItem(){return localStorage.removeItem(this.localStorageKey)}saveVerifyTransactionUrl(){var e,t,i,r,o,n;const s=null===(i=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.redirect_to_url)||void 0===i?void 0:i.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const e=null===(n=null===(o=null===(r=this.payload)||void 0===r?void 0:r.next_action)||void 0===o?void 0:o.iframe_resources)||void 0===n?void 0:n.verify_transaction_status_url;e?this.saveUrlWithExpiration(e):console.log("No verify_transaction_status_url found")}}saveUrlWithExpiration(e){try{const t={url:e,expires:(new Date).getTime()+12e5};this.setStorageItem(t)}catch(e){console.log("error: ",e)}}saveCheckoutId(e){localStorage.setItem("checkout_id",JSON.stringify(e))}removeCheckoutId(){localStorage.removeItem("checkout_id")}getCurrentCheckoutId(){const e=localStorage.getItem("checkout_id");return e?JSON.parse(e):null}getUrlWithExpiration(){const e=this.getStorageItem();if(e){const t=JSON.parse(e);if(!t)return;return(new Date).getTime()>t.expires?(this.removeVerifyTransactionUrl(),null):t.url}return null}removeVerifyTransactionUrl(){return this.removeStorageItem()}getVerifyTransactionUrl(){return this.getStorageItem()}loadIframe(){var e,t,i;if(null===(i=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.iframe_resources)||void 0===i?void 0:i.iframe)return new Promise(((e,t)=>{var i,r,o;const n=null===(o=null===(r=null===(i=this.payload)||void 0===i?void 0:i.next_action)||void 0===r?void 0:r.iframe_resources)||void 0===o?void 0:o.iframe;if(n){this.saveVerifyTransactionUrl();const i=document.createElement("div");i.innerHTML=n,document.body.appendChild(i);const r=document.createElement("script");r.textContent='document.getElementById("tdsMmethodForm").submit();',i.appendChild(r);const o=document.getElementById("tdsMmethodTgtFrame");o?o.onload=()=>e(!0):(console.log("No redirection found"),t(!1))}else console.log("No redirection found"),t(!1)}))}getRedirectUrl(){var e,t,i;return null===(i=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.redirect_to_url)||void 0===i?void 0:i.url}redirectToChallenge(){const e=this.getRedirectUrl();e?(this.saveVerifyTransactionUrl(),window.location=e):console.log("No redirection found")}getURLParameters(){const e={},t=new URLSearchParams(window.location.search);for(const[i,r]of t)e[i]=r;return e}handleSuccessTransaction(e){return this.removeVerifyTransactionUrl(),console.log("Transacción autorizada."),e}handleDeclinedTransaction(e){return this.removeVerifyTransactionUrl(),e}handle3dsChallenge(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("form");t.name="frm",t.method="POST",t.action=e.redirect_post_url;const i=document.createElement("input");i.type="hidden",i.name=e.creq,i.value=e.creq,t.appendChild(i);const r=document.createElement("input");r.type="hidden",r.name=e.term_url,r.value=e.TermUrl,t.appendChild(r),document.body.appendChild(t),t.submit(),yield this.verifyTransactionStatus()}))}handleTransactionResponse(e){return t(this,void 0,void 0,(function*(){const t=yield e.json();return"Pending"===t.status&&t.redirect_post_url?yield this.handle3dsChallenge(t):["Success","Authorized"].includes(t.status)?this.handleSuccessTransaction(t):(this.handleDeclinedTransaction(e),t)}))}verifyTransactionStatus(){return t(this,void 0,void 0,(function*(){const e=this.getUrlWithExpiration();if(e){const t=`${this.baseUrl}${e}`;try{const e=yield fetch(t,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`}});return 200!==e.status?(console.error("La verificación de la transacción falló."),this.removeVerifyTransactionUrl(),e):yield this.handleTransactionResponse(e)}catch(e){console.error("Error al verificar la transacción:",e),this.removeVerifyTransactionUrl()}}else console.log("No verify_transaction_status_url found")}))}}class o{constructor({signal:e,baseUrlTonder:t,apiKeyTonder:i,successUrl:o}){this.baseUrlTonder=t,this.signal=e,this.apiKeyTonder=i,this.successUrl=o,this.process3ds=new r({apiKey:this.apiKeyTonder,baseUrl:this.baseUrlTonder,successUrl:o})}getOpenpayDeviceSessionID(e,i,r){return t(this,void 0,void 0,(function*(){try{let t=yield window.OpenPay;return t.setId(e),t.setApiKey(i),t.setSandboxMode(r),yield t.deviceData.setup({signal:this.signal})}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getBusiness(){return t(this,void 0,void 0,(function*(){try{const e=yield fetch(`${this.baseUrlTonder}/api/v1/payments/business/${this.apiKeyTonder}`,{headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(e.ok)return yield e.json();throw yield this.buildErrorResponse(e)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}verify3dsTransaction(){return t(this,void 0,void 0,(function*(){const e=yield this.process3ds.verifyTransactionStatus(),t=yield this.resumeCheckout(e);return this.process3ds.setPayload(t),t&&"is_route_finished"in t&&"provider"in t&&"tonder"===t.provider?t:this.handle3dsRedirect(t)}))}resumeCheckout(e){return t(this,void 0,void 0,(function*(){if(["Failed","Declined","Cancelled"].includes(null==e?void 0:e.status)){const e={checkout_id:this.process3ds.getCurrentCheckoutId()};return yield this.handleCheckoutRouter(e)}return e}))}handle3dsRedirect(e){var i,r;return t(this,void 0,void 0,(function*(){if(e&&"next_action"in e?null===(r=null===(i=null==e?void 0:e.next_action)||void 0===i?void 0:i.iframe_resources)||void 0===r?void 0:r.iframe:null)this.process3ds.loadIframe().then((()=>{this.process3ds.verifyTransactionStatus()})).catch((e=>{console.log("Error loading iframe:",e)}));else{if(!this.process3ds.getRedirectUrl())return e;this.process3ds.redirectToChallenge()}}))}customerRegister(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/customer/`,i={email:e},r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal,body:JSON.stringify(i)});if(r.ok)return yield r.json();throw yield this.buildErrorResponse(r)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}createOrder(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/orders/`,i=e,r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(i)});if(r.ok)return yield r.json();throw yield this.buildErrorResponse(r)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}createPayment(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/business/${e.business_pk}/payments/`,i=e,r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(i)});if(r.ok)return yield r.json();throw yield this.buildErrorResponse(r)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}handleCheckoutRouter(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/checkout-router/`,i=e,r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(i)});if(r.ok)return yield r.json();throw yield this.buildErrorResponse(r)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}startCheckoutRouter(e){return t(this,void 0,void 0,(function*(){const t=yield this.handleCheckoutRouter(e);if(yield this.init3DSRedirect(t))return t}))}startCheckoutRouterFull(e){return t(this,void 0,void 0,(function*(){try{const{order:t,total:r,customer:o,skyflowTokens:n,return_url:s,isSandbox:a,metadata:d,currency:l}=e,c=yield this.getBusiness(),u=yield this.customerRegister(o.email);if(!(u&&"auth_token"in u&&c&&"reference"in c))throw new i({code:"500",body:c,name:"Keys error",message:"Merchant or customer reposne errors"});{const e={business:this.apiKeyTonder,client:u.auth_token,billing_address_id:null,shipping_address_id:null,amount:r,reference:c.reference,is_oneclick:!0,items:t.items},h=yield this.createOrder(e),y=(new Date).toISOString();if(!("id"in h&&"id"in u&&"business"in c))throw new i({code:"500",body:h,name:"Keys error",message:"Order response errors"});{const e={business_pk:c.business.pk,amount:r,date:y,order_id:h.id,client_id:u.id},t=yield this.createPayment(e);let i;const{openpay_keys:p,business:v}=c;p.merchant_id&&p.public_key&&(i=yield this.getOpenpayDeviceSessionID(p.merchant_id,p.public_key,a));const m={card:n,name:o.name,last_name:o.lastname,email_client:o.email,phone_number:o.phone,return_url:s,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:r,title_ship:"shipping",description:"transaction",device_session_id:i||null,token_id:"",order_id:"id"in h&&h.id,business_id:v.pk,payment_id:"pk"in t&&t.pk,source:"sdk",metadata:d,browser_info:{javascript_enabled:!0,time_zone:(new Date).getTimezoneOffset(),language:navigator.language||"en-US",color_depth:window.screen?window.screen.colorDepth:null,screen_width:window.screen?window.screen.width*window.devicePixelRatio||window.screen.width:null,screen_height:window.screen?window.screen.height*window.devicePixelRatio||window.screen.height:null,user_agent:navigator.userAgent},currency:l},f=yield this.handleCheckoutRouter(m);if(yield this.init3DSRedirect(f))return f}}}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}init3DSRedirect(e){return t(this,void 0,void 0,(function*(){return this.process3ds.setPayload(e),this.process3ds.saveCheckoutId(e&&"checkout_id"in e?e.checkout_id:""),yield this.handle3dsRedirect(e)}))}getSkyflowTokens({vault_id:i,vault_url:r,data:o}){return t(this,void 0,void 0,(function*(){const n=e.init({vaultID:i,vaultURL:r,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield this.getVaultToken()})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}).container(e.ContainerType.COLLECT),s=yield this.getFieldsPromise(o,n);if((yield Promise.all(s)).some((e=>!e)))throw this.buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const e=yield n.collect();if(e)return e.records[0].fields;throw this.buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getVaultToken(){var e;return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(t.ok)return null===(e=yield t.json())||void 0===e?void 0:e.token;throw new Error(`HTTPCODE: ${t.status}`)}catch(e){throw new Error(`Failed to retrieve bearer token; ${"string"==typeof e?e:e.message}`)}}))}getFieldsPromise(e,i){return t(this,void 0,void 0,(function*(){const t=yield this.getFields(e,i);return t?t.map((t=>new Promise((i=>{var r;const o=document.createElement("div");o.hidden=!0,o.id=`id-${t.key}`,null===(r=document.querySelector("body"))||void 0===r||r.appendChild(o),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const r=e[t.key];return t.element.update({value:r}),i(t.element.isMounted())}}),120)}),120)})))):[]}))}registerCustomerCard(e,i){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/`,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal,body:JSON.stringify(i)});if(t.ok)return yield t.json();throw yield this.buildErrorResponse(t)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getCustomerCards(e,i=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${i}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});if(t.ok)return yield t.json();throw yield this.buildErrorResponse(t)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}deleteCustomerCard(e,i=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${i}`,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});if(t.ok)return!0;throw yield this.buildErrorResponse(t)}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}buildErrorResponseFromCatch(e){return new i({code:(null==e?void 0:e.status)?e.status:e.code,body:null==e?void 0:e.body,name:e?"string"==typeof e?"catch":e.name:"Error",message:e?"string"==typeof e?e:e.message:"Error",stack:"string"==typeof e?void 0:e.stack})}buildErrorResponse(e,r=void 0){return t(this,void 0,void 0,(function*(){let t,o,n="Error";e&&"json"in e&&(t=yield null==e?void 0:e.json()),e&&"status"in e&&(o=e.status.toString()),e&&"text"in e&&(n=yield e.text());return new i({code:o,body:t,name:o,message:n,stack:r})}))}getFields(i,r){return t(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(i).map((i=>t(this,void 0,void 0,(function*(){return{element:yield r.create({table:"cards",column:i,type:e.ElementType.INPUT_FIELD}),key:i}})))))}))}}export{o as LiteCheckout};
|
|
1
|
+
import e from"skyflow-js";function t(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{d(o.next(e))}catch(e){i(e)}}function a(e){try{d(o.throw(e))}catch(e){i(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}d((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class n{constructor({code:e,body:t,name:n,message:o,stack:r}){this.code=e,this.body=t,this.name=n,this.message=o,this.stack=r}}var o;!function(e){e.SORIANA="SORIANA",e.OXXO="OXXO",e.SPEI="SPEI",e.CODI="CODI",e.MERCADOPAGO="MERCADOPAGO",e.PAYPAL="PAYPAL",e.COMERCIALMEXICANA="COMERCIALMEXICANA",e.BANCOMER="BANCOMER",e.WALMART="WALMART",e.BODEGA="BODEGA",e.SAMSCLUB="SAMSCLUB",e.SUPERAMA="SUPERAMA",e.CALIMAX="CALIMAX",e.EXTRA="EXTRA",e.CIRCULOK="CIRCULOK",e.SEVEN11="7ELEVEN",e.TELECOMM="TELECOMM",e.BANORTE="BANORTE",e.BENAVIDES="BENAVIDES",e.DELAHORRO="DELAHORRO",e.ELASTURIANO="ELASTURIANO",e.WALDOS="WALDOS",e.ALSUPER="ALSUPER",e.KIOSKO="KIOSKO",e.STAMARIA="STAMARIA",e.LAMASBARATA="LAMASBARATA",e.FARMROMA="FARMROMA",e.FARMUNION="FARMUNION",e.FARMATODO="FARMATODO",e.SFDEASIS="SFDEASIS",e.FARM911="FARM911",e.FARMECONOMICAS="FARMECONOMICAS",e.FARMMEDICITY="FARMMEDICITY",e.RIANXEIRA="RIANXEIRA",e.WESTERNUNION="WESTERNUNION",e.ZONAPAGO="ZONAPAGO",e.CAJALOSANDES="CAJALOSANDES",e.CAJAPAITA="CAJAPAITA",e.CAJASANTA="CAJASANTA",e.CAJASULLANA="CAJASULLANA",e.CAJATRUJILLO="CAJATRUJILLO",e.EDPYME="EDPYME",e.KASNET="KASNET",e.NORANDINO="NORANDINO",e.QAPAQ="QAPAQ",e.RAIZ="RAIZ",e.PAYSER="PAYSER",e.WUNION="WUNION",e.BANCOCONTINENTAL="BANCOCONTINENTAL",e.GMONEY="GMONEY",e.GOPAY="GOPAY",e.WU="WU",e.PUNTOSHEY="PUNTOSHEY",e.AMPM="AMPM",e.JUMBOMARKET="JUMBOMARKET",e.SMELPUEBLO="SMELPUEBLO",e.BAM="BAM",e.REFACIL="REFACIL",e.ACYVALORES="ACYVALORES"}(o||(o={}));const r=e=>new n({code:(null==e?void 0:e.status)?e.status:e.code,body:null==e?void 0:e.body,name:e?"string"==typeof e?"catch":e.name:"Error",message:e?"string"==typeof e?e:e.message:"Error",stack:"string"==typeof e?void 0:e.stack}),i=(e,o=void 0)=>t(void 0,void 0,void 0,(function*(){let t,r,i="Error";e&&"json"in e&&(t=yield null==e?void 0:e.json()),e&&"status"in e&&(r=e.status.toString()),e&&"text"in e&&(i=yield e.text());return new n({code:r,body:t,name:r,message:i,stack:o})})),s=e=>e.trim().replace(/\s+/g,"");class a{constructor({payload:e=null,apiKey:t,baseUrl:n,successUrl:o}){this.localStorageKey="verify_transaction_status_url",this.setPayload=e=>{this.payload=e},this.baseUrl=n,this.apiKey=t,this.payload=e,this.successUrl=o}setStorageItem(e){return localStorage.setItem(this.localStorageKey,JSON.stringify(e))}getStorageItem(){return localStorage.getItem(this.localStorageKey)}removeStorageItem(){return localStorage.removeItem(this.localStorageKey)}saveVerifyTransactionUrl(){var e,t,n,o,r,i;const s=null===(n=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.redirect_to_url)||void 0===n?void 0:n.verify_transaction_status_url;if(s)this.saveUrlWithExpiration(s);else{const e=null===(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;e?this.saveUrlWithExpiration(e):console.log("No verify_transaction_status_url found")}}saveUrlWithExpiration(e){try{const t={url:e,expires:(new Date).getTime()+12e5};this.setStorageItem(t)}catch(e){console.log("error: ",e)}}getUrlWithExpiration(){const e=this.getStorageItem();if(e){const t=JSON.parse(e);if(!t)return;return(new Date).getTime()>t.expires?(this.removeVerifyTransactionUrl(),null):t.url}return null}removeVerifyTransactionUrl(){return this.removeStorageItem()}getVerifyTransactionUrl(){return this.getStorageItem()}loadIframe(){var e,t,n;if(null===(n=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.iframe_resources)||void 0===n?void 0:n.iframe)return new Promise(((e,t)=>{var n,o,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=()=>e(!0):(console.log("No redirection found"),t(!1))}else console.log("No redirection found"),t(!1)}))}getRedirectUrl(){var e,t,n;return null===(n=null===(t=null===(e=this.payload)||void 0===e?void 0:e.next_action)||void 0===t?void 0:t.redirect_to_url)||void 0===n?void 0:n.url}redirectToChallenge(){const e=this.getRedirectUrl();e?(this.saveVerifyTransactionUrl(),window.location=e):console.log("No redirection found")}getURLParameters(){const e={},t=new URLSearchParams(window.location.search);for(const[n,o]of t)e[n]=o;return e}handleSuccessTransaction(e){return this.removeVerifyTransactionUrl(),console.log("Transacción autorizada."),e}handleDeclinedTransaction(e){return this.removeVerifyTransactionUrl(),e}handle3dsChallenge(e){return t(this,void 0,void 0,(function*(){const t=document.createElement("form");t.name="frm",t.method="POST",t.action=e.redirect_post_url;const n=document.createElement("input");n.type="hidden",n.name=e.creq,n.value=e.creq,t.appendChild(n);const o=document.createElement("input");o.type="hidden",o.name=e.term_url,o.value=e.TermUrl,t.appendChild(o),document.body.appendChild(t),t.submit(),yield this.verifyTransactionStatus()}))}handleTransactionResponse(e){return t(this,void 0,void 0,(function*(){const t=yield e.json();return"Pending"===t.status&&t.redirect_post_url?yield this.handle3dsChallenge(t):["Success","Authorized"].includes(t.status)?this.handleSuccessTransaction(t):(this.handleDeclinedTransaction(e),t)}))}verifyTransactionStatus(){return t(this,void 0,void 0,(function*(){const e=this.getUrlWithExpiration();if(e){const t=`${this.baseUrl}${e}`;try{const e=yield fetch(t,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKey}`}});return 200!==e.status?(console.error("La verificación de la transacción falló."),this.removeVerifyTransactionUrl(),e):yield this.handleTransactionResponse(e)}catch(e){console.error("Error al verificar la transacción:",e),this.removeVerifyTransactionUrl()}}else console.log("No verify_transaction_status_url found")}))}}class d{constructor({signal:e,baseUrlTonder:t,apiKeyTonder:n,successUrl:o}){this.activeAPMs=[],this.baseUrlTonder=t,this.signal=e,this.apiKeyTonder=n,this.successUrl=o,this.process3ds=new a({apiKey:this.apiKeyTonder,baseUrl:this.baseUrlTonder,successUrl:o}),this.getActiveAPMs()}getOpenpayDeviceSessionID(e,n,o){return t(this,void 0,void 0,(function*(){try{let t=yield window.OpenPay;return t.setId(e),t.setApiKey(n),t.setSandboxMode(o),yield t.deviceData.setup({signal:this.signal})}catch(e){throw r(e)}}))}getBusiness(){return t(this,void 0,void 0,(function*(){try{const e=yield fetch(`${this.baseUrlTonder}/api/v1/payments/business/${this.apiKeyTonder}`,{headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(e.ok)return yield e.json();throw yield i(e)}catch(e){throw r(e)}}))}verify3dsTransaction(){return t(this,void 0,void 0,(function*(){const e=yield this.process3ds.verifyTransactionStatus(),t=yield this.resumeCheckout(e);return this.process3ds.setPayload(t),t&&"is_route_finished"in t&&"provider"in t&&"tonder"===t.provider?t:this.handle3dsRedirect(t)}))}resumeCheckout(e){var n;return t(this,void 0,void 0,(function*(){if(["Failed","Declined","Cancelled"].includes(null==e?void 0:e.status)){const t={checkout_id:null===(n=e.checkout)||void 0===n?void 0:n.id};return yield this.handleCheckoutRouter(t)}return e}))}handle3dsRedirect(e){var n,o;return t(this,void 0,void 0,(function*(){if(e&&"next_action"in e?null===(o=null===(n=null==e?void 0:e.next_action)||void 0===n?void 0:n.iframe_resources)||void 0===o?void 0:o.iframe:null)this.process3ds.loadIframe().then((()=>{this.process3ds.verifyTransactionStatus()})).catch((e=>{console.log("Error loading iframe:",e)}));else{if(!this.process3ds.getRedirectUrl())return e;this.process3ds.redirectToChallenge()}}))}customerRegister(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/customer/`,n={email:e},o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal,body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield i(o)}catch(e){throw r(e)}}))}createOrder(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/orders/`,n=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield i(o)}catch(e){throw r(e)}}))}createPayment(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/business/${e.business_pk}/payments/`,n=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield i(o)}catch(e){throw r(e)}}))}handleCheckoutRouter(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/checkout-router/`,n=e,o=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(n)});if(o.ok)return yield o.json();throw yield i(o)}catch(e){throw r(e)}}))}startCheckoutRouter(e){return t(this,void 0,void 0,(function*(){const t=yield this.handleCheckoutRouter(e);if(yield this.init3DSRedirect(t))return t}))}startCheckoutRouterFull(e){return t(this,void 0,void 0,(function*(){try{const{order:t,total:o,customer:r,skyflowTokens:i,return_url:s,isSandbox:a,metadata:d,currency:l,payment_method:c}=e,u=yield this.getBusiness(),p=yield this.customerRegister(r.email);if(!(p&&"auth_token"in p&&u&&"reference"in u))throw new n({code:"500",body:u,name:"Keys error",message:"Merchant or customer reposne errors"});{const e={business:this.apiKeyTonder,client:p.auth_token,billing_address_id:null,shipping_address_id:null,amount:o,reference:u.reference,is_oneclick:!0,items:t.items},h=yield this.createOrder(e),y=(new Date).toISOString();if(!("id"in h&&"id"in p&&"business"in u))throw new n({code:"500",body:h,name:"Keys error",message:"Order response errors"});{const e={business_pk:u.business.pk,amount:o,date:y,order_id:h.id,client_id:p.id},t=yield this.createPayment(e);let n;const{openpay_keys:m,business:A}=u;m.merchant_id&&m.public_key&&(n=yield this.getOpenpayDeviceSessionID(m.merchant_id,m.public_key,a));const g=Object.assign({name:r.name,last_name:r.lastname,email_client:r.email,phone_number:r.phone,return_url:s,id_product:"no_id",quantity_product:1,id_ship:"0",instance_id_ship:"0",amount:o,title_ship:"shipping",description:"transaction",device_session_id:n||null,token_id:"",order_id:"id"in h&&h.id,business_id:A.pk,payment_id:"pk"in t&&t.pk,source:"sdk",metadata:d,browser_info:{javascript_enabled:!0,time_zone:(new Date).getTimezoneOffset(),language:navigator.language||"en-US",color_depth:window.screen?window.screen.colorDepth:null,screen_width:window.screen?window.screen.width*window.devicePixelRatio||window.screen.width:null,screen_height:window.screen?window.screen.height*window.devicePixelRatio||window.screen.height:null,user_agent:navigator.userAgent},currency:l},c?{payment_method:c}:{card:i}),f=yield this.handleCheckoutRouter(g);if(yield this.init3DSRedirect(f))return f}}}catch(e){throw r(e)}}))}init3DSRedirect(e){return t(this,void 0,void 0,(function*(){return this.process3ds.setPayload(e),yield this.handle3dsRedirect(e)}))}getSkyflowTokens({vault_id:n,vault_url:o,data:i}){return t(this,void 0,void 0,(function*(){const s=e.init({vaultID:n,vaultURL:o,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield this.getVaultToken()})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}).container(e.ContainerType.COLLECT),a=yield this.getFieldsPromise(i,s);if((yield Promise.all(a)).some((e=>!e)))throw r(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const e=yield s.collect();if(e)return e.records[0].fields;throw r(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(e){throw r(e)}}))}getVaultToken(){var e;return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(t.ok)return null===(e=yield t.json())||void 0===e?void 0:e.token;throw new Error(`HTTPCODE: ${t.status}`)}catch(e){throw new Error(`Failed to retrieve bearer token; ${"string"==typeof e?e:e.message}`)}}))}getFieldsPromise(e,n){return t(this,void 0,void 0,(function*(){const t=yield this.getFields(e,n);return t?t.map((t=>new Promise((n=>{var o;const r=document.createElement("div");r.hidden=!0,r.id=`id-${t.key}`,null===(o=document.querySelector("body"))||void 0===o||o.appendChild(r),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const o=e[t.key];return t.element.update({value:o}),n(t.element.isMounted())}}),120)}),120)})))):[]}))}registerCustomerCard(e,n){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/`,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal,body:JSON.stringify(n)});if(t.ok)return yield t.json();throw yield i(t)}catch(e){throw r(e)}}))}getCustomerCards(e,n=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${n}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});if(t.ok)return yield t.json();throw yield i(t)}catch(e){throw r(e)}}))}deleteCustomerCard(e,n=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${n}`,{method:"DELETE",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});if(t.ok)return!0;throw yield i(t)}catch(e){throw r(e)}}))}getFields(n,o){return t(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(n).map((n=>t(this,void 0,void 0,(function*(){return{element:yield o.create({table:"cards",column:n,type:e.ElementType.INPUT_FIELD}),key:n}})))))}))}getActiveAPMs(){return t(this,void 0,void 0,(function*(){try{const e=yield function(e,n,o="?status=active&page_size=10000&country=México",s=null){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${e}/api/v1/payment_methods${o}`,{method:"GET",headers:{Authorization:`Token ${n}`,"Content-Type":"application/json"},signal:s});if(t.ok)return yield t.json();throw yield i(t)}catch(e){throw r(e)}}))}(this.baseUrlTonder,this.apiKeyTonder),n=e&&e.results&&e.results.length>0?e.results:[];return this.activeAPMs=n.filter((e=>"cards"!==e.category.toLowerCase())).map((e=>Object.assign({id:e.pk,payment_method:e.payment_method,priority:e.priority,category:e.category},(e=>{const t=s(e.toUpperCase());return{[o.SORIANA]:{label:"Soriana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png"},[o.OXXO]:{label:"Oxxo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png"},[o.CODI]:{label:"CoDi",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png"},[o.SPEI]:{label:"SPEI",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png"},[o.PAYPAL]:{label:"Paypal",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png"},[o.COMERCIALMEXICANA]:{label:"Comercial Mexicana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png"},[o.BANCOMER]:{label:"Bancomer",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png"},[o.WALMART]:{label:"Walmart",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png"},[o.BODEGA]:{label:"Bodega Aurrera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png"},[o.SAMSCLUB]:{label:"Sam´s Club",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png"},[o.SUPERAMA]:{label:"Superama",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png"},[o.CALIMAX]:{label:"Calimax",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png"},[o.EXTRA]:{label:"Tiendas Extra",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png"},[o.CIRCULOK]:{label:"Círculo K",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png"},[o.SEVEN11]:{label:"7 Eleven",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png"},[o.TELECOMM]:{label:"Telecomm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png"},[o.BANORTE]:{label:"Banorte",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png"},[o.BENAVIDES]:{label:"Farmacias Benavides",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png"},[o.DELAHORRO]:{label:"Farmacias del Ahorro",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png"},[o.ELASTURIANO]:{label:"El Asturiano",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png"},[o.WALDOS]:{label:"Waldos",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png"},[o.ALSUPER]:{label:"Alsuper",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png"},[o.KIOSKO]:{label:"Kiosko",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png"},[o.STAMARIA]:{label:"Farmacias Santa María",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png"},[o.LAMASBARATA]:{label:"Farmacias la más barata",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png"},[o.FARMROMA]:{label:"Farmacias Roma",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png"},[o.FARMUNION]:{label:"Pago en Farmacias Unión",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png"},[o.FARMATODO]:{label:"Pago en Farmacias Farmatodo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png\t"},[o.SFDEASIS]:{label:"Pago en Farmacias San Francisco de Asís",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png"},[o.FARM911]:{label:"Farmacias 911",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.FARMECONOMICAS]:{label:"Farmacias Economicas",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.FARMMEDICITY]:{label:"Farmacias Medicity",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.RIANXEIRA]:{label:"Rianxeira",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.WESTERNUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.ZONAPAGO]:{label:"Zona Pago",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.CAJALOSANDES]:{label:"Caja Los Andes",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.CAJAPAITA]:{label:"Caja Paita",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.CAJASANTA]:{label:"Caja Santa",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.CAJASULLANA]:{label:"Caja Sullana",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.CAJATRUJILLO]:{label:"Caja Trujillo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.EDPYME]:{label:"Edpyme",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.KASNET]:{label:"KasNet",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.NORANDINO]:{label:"Norandino",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.QAPAQ]:{label:"Qapaq",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.RAIZ]:{label:"Raiz",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.PAYSER]:{label:"Paysera",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.WUNION]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.BANCOCONTINENTAL]:{label:"Banco Continental",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.GMONEY]:{label:"Go money",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.GOPAY]:{label:"Go pay",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.WU]:{label:"Western Union",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.PUNTOSHEY]:{label:"Puntoshey",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.AMPM]:{label:"Ampm",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.JUMBOMARKET]:{label:"Jumbomarket",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.SMELPUEBLO]:{label:"Smelpueblo",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.BAM]:{label:"Bam",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.REFACIL]:{label:"Refacil",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"},[o.ACYVALORES]:{label:"Acyvalores",icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png"}}[t]||{icon:"https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",label:""}})(e.payment_method)))).sort(((e,t)=>e.priority-t.priority)),this.activeAPMs}catch(e){return console.error("Error getting APMS",e),[]}}))}}export{d as LiteCheckout};
|
package/dist/types/commons.d.ts
CHANGED
|
@@ -57,3 +57,19 @@ export type PaymentData = {
|
|
|
57
57
|
items: OrderItem[];
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
|
+
export type TonderAPM = {
|
|
61
|
+
pk: string;
|
|
62
|
+
payment_method: string;
|
|
63
|
+
priority: number;
|
|
64
|
+
category: string;
|
|
65
|
+
unavailable_countries: string[];
|
|
66
|
+
status: string;
|
|
67
|
+
};
|
|
68
|
+
export type APM = {
|
|
69
|
+
id: string;
|
|
70
|
+
payment_method: string;
|
|
71
|
+
priority: number;
|
|
72
|
+
category: string;
|
|
73
|
+
icon: string;
|
|
74
|
+
label: string;
|
|
75
|
+
};
|
package/dist/types/requests.d.ts
CHANGED
|
@@ -18,8 +18,7 @@ export type CreatePaymentRequest = {
|
|
|
18
18
|
order_id?: string | number;
|
|
19
19
|
client_id?: string | number;
|
|
20
20
|
};
|
|
21
|
-
export type
|
|
22
|
-
card: any;
|
|
21
|
+
export type StartCheckoutRequestBase = {
|
|
23
22
|
name: any;
|
|
24
23
|
last_name: string;
|
|
25
24
|
email_client: any;
|
|
@@ -42,6 +41,15 @@ export type StartCheckoutRequest = {
|
|
|
42
41
|
metadata: any;
|
|
43
42
|
currency: string;
|
|
44
43
|
};
|
|
44
|
+
export type StartCheckoutRequestWithCard = StartCheckoutRequestBase & {
|
|
45
|
+
card: any;
|
|
46
|
+
payment_method?: never;
|
|
47
|
+
};
|
|
48
|
+
export type StartCheckoutRequestWithPaymentMethod = StartCheckoutRequestBase & {
|
|
49
|
+
card?: never;
|
|
50
|
+
payment_method: string;
|
|
51
|
+
};
|
|
52
|
+
export type StartCheckoutRequest = StartCheckoutRequestWithCard | StartCheckoutRequestWithPaymentMethod;
|
|
45
53
|
export type StartCheckoutIdRequest = {
|
|
46
54
|
checkout_id: any;
|
|
47
55
|
};
|
|
@@ -83,4 +91,5 @@ export type StartCheckoutFullRequest = {
|
|
|
83
91
|
isSandbox: boolean;
|
|
84
92
|
metadata: any;
|
|
85
93
|
currency: string;
|
|
94
|
+
payment_method?: string;
|
|
86
95
|
};
|
package/package.json
CHANGED
|
@@ -65,19 +65,6 @@ export class ThreeDSHandler {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
saveCheckoutId(checkoutId: any) {
|
|
69
|
-
localStorage.setItem('checkout_id', JSON.stringify(checkoutId))
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
removeCheckoutId() {
|
|
73
|
-
localStorage.removeItem("checkout_id")
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getCurrentCheckoutId() {
|
|
77
|
-
const checkout_id = localStorage.getItem("checkout_id")
|
|
78
|
-
return checkout_id ? JSON.parse(checkout_id):null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
68
|
getUrlWithExpiration() {
|
|
82
69
|
const status = this.getStorageItem();
|
|
83
70
|
if(status) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import Skyflow from "skyflow-js";
|
|
2
2
|
import CollectContainer from "skyflow-js/types/core/external/collect/collect-container";
|
|
3
3
|
import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
|
|
4
|
-
import { Business } from "../types/commons";
|
|
4
|
+
import { APM, Business, TonderAPM } from "../types/commons";
|
|
5
5
|
import { CreateOrderRequest, CreatePaymentRequest, RegisterCustomerCardRequest, StartCheckoutRequest, TokensRequest, StartCheckoutFullRequest, StartCheckoutIdRequest } from "../types/requests";
|
|
6
6
|
import { GetBusinessResponse, CustomerRegisterResponse, CreateOrderResponse, CreatePaymentResponse, StartCheckoutResponse, GetVaultTokenResponse, IErrorResponse, GetCustomerCardsResponse, RegisterCustomerCardResponse } from "../types/responses";
|
|
7
7
|
import { ErrorResponse } from "./errorResponse";
|
|
8
|
-
import { getBrowserInfo } from "../helpers/utils";
|
|
8
|
+
import { buildErrorResponse, buildErrorResponseFromCatch, getBrowserInfo, getPaymentMethodDetails } from "../helpers/utils";
|
|
9
9
|
import { ThreeDSHandler } from "./3dsHandler";
|
|
10
|
+
import { getCustomerAPMs } from "../data/api";
|
|
10
11
|
|
|
11
12
|
declare global {
|
|
12
13
|
interface Window {
|
|
@@ -27,7 +28,7 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
27
28
|
apiKeyTonder: string;
|
|
28
29
|
process3ds: ThreeDSHandler;
|
|
29
30
|
successUrl?: string
|
|
30
|
-
|
|
31
|
+
activeAPMs: APM[] = []
|
|
31
32
|
constructor({
|
|
32
33
|
signal,
|
|
33
34
|
baseUrlTonder,
|
|
@@ -44,6 +45,7 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
44
45
|
baseUrl: this.baseUrlTonder,
|
|
45
46
|
successUrl: successUrl
|
|
46
47
|
})
|
|
48
|
+
this.getActiveAPMs()
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
async getOpenpayDeviceSessionID(
|
|
@@ -60,7 +62,7 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
60
62
|
signal: this.signal,
|
|
61
63
|
}) as string;
|
|
62
64
|
} catch (e) {
|
|
63
|
-
throw
|
|
65
|
+
throw buildErrorResponseFromCatch(e);
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -78,9 +80,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
78
80
|
|
|
79
81
|
if (getBusiness.ok) return (await getBusiness.json()) as Business;
|
|
80
82
|
|
|
81
|
-
throw await
|
|
83
|
+
throw await buildErrorResponse(getBusiness);
|
|
82
84
|
} catch (e) {
|
|
83
|
-
throw
|
|
85
|
+
throw buildErrorResponseFromCatch(e);
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
|
|
@@ -97,8 +99,7 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
97
99
|
async resumeCheckout(response: any) {
|
|
98
100
|
if (["Failed", "Declined", "Cancelled"].includes(response?.status)) {
|
|
99
101
|
const routerItems = {
|
|
100
|
-
|
|
101
|
-
checkout_id: this.process3ds.getCurrentCheckoutId(),
|
|
102
|
+
checkout_id: response.checkout?.id,
|
|
102
103
|
};
|
|
103
104
|
const routerResponse = await this.handleCheckoutRouter(
|
|
104
105
|
routerItems
|
|
@@ -148,9 +149,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
148
149
|
});
|
|
149
150
|
|
|
150
151
|
if (response.ok) return await response.json() as CustomerRegisterResponse;
|
|
151
|
-
throw await
|
|
152
|
+
throw await buildErrorResponse(response);
|
|
152
153
|
} catch (e) {
|
|
153
|
-
throw
|
|
154
|
+
throw buildErrorResponseFromCatch(e);
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
|
|
@@ -167,9 +168,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
167
168
|
body: JSON.stringify(data),
|
|
168
169
|
});
|
|
169
170
|
if (response.ok) return await response.json() as CreateOrderResponse;
|
|
170
|
-
throw await
|
|
171
|
+
throw await buildErrorResponse(response);
|
|
171
172
|
} catch (e) {
|
|
172
|
-
throw
|
|
173
|
+
throw buildErrorResponseFromCatch(e);
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
|
|
@@ -186,9 +187,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
186
187
|
body: JSON.stringify(data),
|
|
187
188
|
});
|
|
188
189
|
if (response.ok) return await response.json() as CreatePaymentResponse;
|
|
189
|
-
throw await
|
|
190
|
+
throw await buildErrorResponse(response);
|
|
190
191
|
} catch (e) {
|
|
191
|
-
throw
|
|
192
|
+
throw buildErrorResponseFromCatch(e);
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
async handleCheckoutRouter(routerData: StartCheckoutRequest | StartCheckoutIdRequest){
|
|
@@ -204,9 +205,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
204
205
|
body: JSON.stringify(data),
|
|
205
206
|
});
|
|
206
207
|
if (response.ok) return await response.json() as StartCheckoutResponse;
|
|
207
|
-
throw await
|
|
208
|
+
throw await buildErrorResponse(response);
|
|
208
209
|
} catch (e) {
|
|
209
|
-
throw
|
|
210
|
+
throw buildErrorResponseFromCatch(e);
|
|
210
211
|
}
|
|
211
212
|
}
|
|
212
213
|
|
|
@@ -229,7 +230,8 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
229
230
|
return_url,
|
|
230
231
|
isSandbox,
|
|
231
232
|
metadata,
|
|
232
|
-
currency
|
|
233
|
+
currency,
|
|
234
|
+
payment_method
|
|
233
235
|
} = routerFullData;
|
|
234
236
|
|
|
235
237
|
const merchantResult = await this.getBusiness();
|
|
@@ -282,7 +284,6 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
282
284
|
}
|
|
283
285
|
|
|
284
286
|
const routerItems: StartCheckoutRequest = {
|
|
285
|
-
card: skyflowTokens,
|
|
286
287
|
name: customer.name,
|
|
287
288
|
last_name: customer.lastname,
|
|
288
289
|
email_client: customer.email,
|
|
@@ -303,7 +304,11 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
303
304
|
source: 'sdk',
|
|
304
305
|
metadata: metadata,
|
|
305
306
|
browser_info: getBrowserInfo(),
|
|
306
|
-
currency: currency
|
|
307
|
+
currency: currency,
|
|
308
|
+
...( !!payment_method
|
|
309
|
+
? {payment_method}
|
|
310
|
+
: {card: skyflowTokens}
|
|
311
|
+
)
|
|
307
312
|
};
|
|
308
313
|
|
|
309
314
|
const checkoutResult = await this.handleCheckoutRouter(routerItems);
|
|
@@ -333,14 +338,13 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
333
338
|
}
|
|
334
339
|
} catch (e) {
|
|
335
340
|
|
|
336
|
-
throw
|
|
341
|
+
throw buildErrorResponseFromCatch(e);
|
|
337
342
|
|
|
338
343
|
}
|
|
339
344
|
}
|
|
340
345
|
|
|
341
346
|
async init3DSRedirect(checkoutResult: ErrorResponse | StartCheckoutResponse){
|
|
342
347
|
this.process3ds.setPayload(checkoutResult)
|
|
343
|
-
this.process3ds.saveCheckoutId(checkoutResult && 'checkout_id' in checkoutResult ? checkoutResult.checkout_id:"")
|
|
344
348
|
return await this.handle3dsRedirect(checkoutResult)
|
|
345
349
|
}
|
|
346
350
|
|
|
@@ -370,14 +374,14 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
370
374
|
const mountFail = result.some((item: boolean) => !item);
|
|
371
375
|
|
|
372
376
|
if (mountFail) {
|
|
373
|
-
throw
|
|
377
|
+
throw buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));
|
|
374
378
|
} else {
|
|
375
379
|
try {
|
|
376
380
|
const collectResponseSkyflowTonder = await collectContainer.collect() as any;
|
|
377
381
|
if (collectResponseSkyflowTonder) return collectResponseSkyflowTonder["records"][0]["fields"];
|
|
378
|
-
throw
|
|
382
|
+
throw buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))
|
|
379
383
|
} catch (error) {
|
|
380
|
-
throw
|
|
384
|
+
throw buildErrorResponseFromCatch(error);
|
|
381
385
|
}
|
|
382
386
|
}
|
|
383
387
|
}
|
|
@@ -435,9 +439,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
435
439
|
});
|
|
436
440
|
|
|
437
441
|
if (response.ok) return await response.json() as RegisterCustomerCardResponse;
|
|
438
|
-
throw await
|
|
442
|
+
throw await buildErrorResponse(response);
|
|
439
443
|
} catch (error) {
|
|
440
|
-
throw
|
|
444
|
+
throw buildErrorResponseFromCatch(error);
|
|
441
445
|
}
|
|
442
446
|
}
|
|
443
447
|
|
|
@@ -453,9 +457,9 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
453
457
|
});
|
|
454
458
|
|
|
455
459
|
if (response.ok) return await response.json() as GetCustomerCardsResponse;
|
|
456
|
-
throw await
|
|
460
|
+
throw await buildErrorResponse(response);
|
|
457
461
|
} catch (error) {
|
|
458
|
-
throw
|
|
462
|
+
throw buildErrorResponseFromCatch(error);
|
|
459
463
|
}
|
|
460
464
|
}
|
|
461
465
|
|
|
@@ -471,53 +475,10 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
471
475
|
});
|
|
472
476
|
|
|
473
477
|
if (response.ok) return true;
|
|
474
|
-
throw await
|
|
478
|
+
throw await buildErrorResponse(response);
|
|
475
479
|
} catch (error) {
|
|
476
|
-
throw
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
private buildErrorResponseFromCatch(e: any): ErrorResponse {
|
|
481
|
-
|
|
482
|
-
const error = new ErrorResponse({
|
|
483
|
-
code: e?.status ? e.status : e.code,
|
|
484
|
-
body: e?.body,
|
|
485
|
-
name: e ? typeof e == "string" ? "catch" : (e as Error).name : "Error",
|
|
486
|
-
message: e ? (typeof e == "string" ? e : (e as Error).message) : "Error",
|
|
487
|
-
stack: typeof e == "string" ? undefined : (e as Error).stack,
|
|
488
|
-
})
|
|
489
|
-
|
|
490
|
-
return error;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
private async buildErrorResponse(
|
|
494
|
-
response: Response,
|
|
495
|
-
stack: string | undefined = undefined
|
|
496
|
-
): Promise<ErrorResponse> {
|
|
497
|
-
|
|
498
|
-
let body, status, message = "Error";
|
|
499
|
-
|
|
500
|
-
if(response && "json" in response) {
|
|
501
|
-
body = await response?.json();
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
if(response && "status" in response) {
|
|
505
|
-
status = response.status.toString();
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
if(response && "text" in response) {
|
|
509
|
-
message = await response.text();
|
|
480
|
+
throw buildErrorResponseFromCatch(error);
|
|
510
481
|
}
|
|
511
|
-
|
|
512
|
-
const error = new ErrorResponse({
|
|
513
|
-
code: status,
|
|
514
|
-
body: body,
|
|
515
|
-
name: status,
|
|
516
|
-
message: message,
|
|
517
|
-
stack,
|
|
518
|
-
} as IErrorResponse)
|
|
519
|
-
|
|
520
|
-
return error;
|
|
521
482
|
}
|
|
522
483
|
|
|
523
484
|
private async getFields(data: any, collectContainer: CollectContainer): Promise<{ element: CollectElement, key: string }[]> {
|
|
@@ -532,4 +493,29 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
532
493
|
})
|
|
533
494
|
)
|
|
534
495
|
}
|
|
496
|
+
|
|
497
|
+
async getActiveAPMs(): Promise<APM[]> {
|
|
498
|
+
try {
|
|
499
|
+
const apms_response = await getCustomerAPMs(this.baseUrlTonder, this.apiKeyTonder);
|
|
500
|
+
const apms_results = apms_response && apms_response['results'] && apms_response['results'].length > 0 ? apms_response['results'] : []
|
|
501
|
+
this.activeAPMs = apms_results
|
|
502
|
+
.filter((apmItem: TonderAPM) =>
|
|
503
|
+
apmItem.category.toLowerCase() !== 'cards')
|
|
504
|
+
.map((apmItem: TonderAPM) => {
|
|
505
|
+
const apm: APM = {
|
|
506
|
+
id: apmItem.pk,
|
|
507
|
+
payment_method: apmItem.payment_method,
|
|
508
|
+
priority: apmItem.priority,
|
|
509
|
+
category: apmItem.category,
|
|
510
|
+
...getPaymentMethodDetails(apmItem.payment_method,)
|
|
511
|
+
}
|
|
512
|
+
return apm;
|
|
513
|
+
}).sort((a: APM, b: APM) => a.priority - b.priority);
|
|
514
|
+
|
|
515
|
+
return this.activeAPMs
|
|
516
|
+
} catch (e) {
|
|
517
|
+
console.error("Error getting APMS", e);
|
|
518
|
+
return [];
|
|
519
|
+
}
|
|
520
|
+
}
|
|
535
521
|
}
|
package/src/data/api.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { buildErrorResponse, buildErrorResponseFromCatch } from "../helpers/utils";
|
|
2
|
+
|
|
3
|
+
export async function getCustomerAPMs(baseUrlTonder: string, apiKeyTonder: string, query: string = "?status=active&page_size=10000&country=México", signal: AbortSignal | null | undefined = null) {
|
|
4
|
+
try {
|
|
5
|
+
const response = await fetch(
|
|
6
|
+
`${baseUrlTonder}/api/v1/payment_methods${query}`,
|
|
7
|
+
{
|
|
8
|
+
method: 'GET',
|
|
9
|
+
headers: {
|
|
10
|
+
Authorization: `Token ${apiKeyTonder}`,
|
|
11
|
+
'Content-Type': 'application/json'
|
|
12
|
+
},
|
|
13
|
+
signal
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (response.ok) return await response.json();
|
|
17
|
+
throw await buildErrorResponse(response);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw buildErrorResponseFromCatch(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
enum PAYMENT_METHOD {
|
|
2
|
+
SORIANA = "SORIANA",
|
|
3
|
+
OXXO = "OXXO",
|
|
4
|
+
SPEI= "SPEI",
|
|
5
|
+
CODI= "CODI",
|
|
6
|
+
MERCADOPAGO= "MERCADOPAGO",
|
|
7
|
+
PAYPAL= "PAYPAL",
|
|
8
|
+
COMERCIALMEXICANA= "COMERCIALMEXICANA",
|
|
9
|
+
BANCOMER= "BANCOMER",
|
|
10
|
+
WALMART= "WALMART",
|
|
11
|
+
BODEGA= "BODEGA",
|
|
12
|
+
SAMSCLUB= "SAMSCLUB",
|
|
13
|
+
SUPERAMA= "SUPERAMA",
|
|
14
|
+
CALIMAX= "CALIMAX",
|
|
15
|
+
EXTRA= "EXTRA",
|
|
16
|
+
CIRCULOK= "CIRCULOK",
|
|
17
|
+
SEVEN11= "7ELEVEN",
|
|
18
|
+
TELECOMM= "TELECOMM",
|
|
19
|
+
BANORTE= "BANORTE",
|
|
20
|
+
BENAVIDES= "BENAVIDES",
|
|
21
|
+
DELAHORRO= "DELAHORRO",
|
|
22
|
+
ELASTURIANO= "ELASTURIANO",
|
|
23
|
+
WALDOS= "WALDOS",
|
|
24
|
+
ALSUPER= "ALSUPER",
|
|
25
|
+
KIOSKO= "KIOSKO",
|
|
26
|
+
STAMARIA= "STAMARIA",
|
|
27
|
+
LAMASBARATA= "LAMASBARATA",
|
|
28
|
+
FARMROMA= "FARMROMA",
|
|
29
|
+
FARMUNION= "FARMUNION",
|
|
30
|
+
FARMATODO= "FARMATODO",
|
|
31
|
+
SFDEASIS= "SFDEASIS",
|
|
32
|
+
FARM911= "FARM911",
|
|
33
|
+
FARMECONOMICAS= "FARMECONOMICAS",
|
|
34
|
+
FARMMEDICITY= "FARMMEDICITY",
|
|
35
|
+
RIANXEIRA= "RIANXEIRA",
|
|
36
|
+
WESTERNUNION= "WESTERNUNION",
|
|
37
|
+
ZONAPAGO= "ZONAPAGO",
|
|
38
|
+
CAJALOSANDES= "CAJALOSANDES",
|
|
39
|
+
CAJAPAITA= "CAJAPAITA",
|
|
40
|
+
CAJASANTA= "CAJASANTA",
|
|
41
|
+
CAJASULLANA= "CAJASULLANA",
|
|
42
|
+
CAJATRUJILLO= "CAJATRUJILLO",
|
|
43
|
+
EDPYME= "EDPYME",
|
|
44
|
+
KASNET= "KASNET",
|
|
45
|
+
NORANDINO= "NORANDINO",
|
|
46
|
+
QAPAQ= "QAPAQ",
|
|
47
|
+
RAIZ= "RAIZ",
|
|
48
|
+
PAYSER= "PAYSER",
|
|
49
|
+
WUNION= "WUNION",
|
|
50
|
+
BANCOCONTINENTAL= "BANCOCONTINENTAL",
|
|
51
|
+
GMONEY= "GMONEY",
|
|
52
|
+
GOPAY= "GOPAY",
|
|
53
|
+
WU= "WU",
|
|
54
|
+
PUNTOSHEY= "PUNTOSHEY",
|
|
55
|
+
AMPM= "AMPM",
|
|
56
|
+
JUMBOMARKET= "JUMBOMARKET",
|
|
57
|
+
SMELPUEBLO= "SMELPUEBLO",
|
|
58
|
+
BAM= "BAM",
|
|
59
|
+
REFACIL= "REFACIL",
|
|
60
|
+
ACYVALORES= "ACYVALORES"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { PAYMENT_METHOD }
|
|
64
|
+
|
package/src/helpers/utils.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { ErrorResponse } from "../classes/errorResponse";
|
|
2
|
+
import { IErrorResponse } from "../types/responses";
|
|
3
|
+
import { PAYMENT_METHOD } from "./constants";
|
|
4
|
+
|
|
1
5
|
export const getBrowserInfo = () => {
|
|
2
6
|
const browserInfo = {
|
|
3
7
|
javascript_enabled: true, // Assumed since JavaScript is running
|
|
@@ -10,3 +14,302 @@ export const getBrowserInfo = () => {
|
|
|
10
14
|
};
|
|
11
15
|
return browserInfo;
|
|
12
16
|
}
|
|
17
|
+
|
|
18
|
+
const buildErrorResponseFromCatch = (e: any): ErrorResponse => {
|
|
19
|
+
|
|
20
|
+
const error = new ErrorResponse({
|
|
21
|
+
code: e?.status ? e.status : e.code,
|
|
22
|
+
body: e?.body,
|
|
23
|
+
name: e ? typeof e == "string" ? "catch" : (e as Error).name : "Error",
|
|
24
|
+
message: e ? (typeof e == "string" ? e : (e as Error).message) : "Error",
|
|
25
|
+
stack: typeof e == "string" ? undefined : (e as Error).stack,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return error;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const buildErrorResponse = async (
|
|
32
|
+
response: Response,
|
|
33
|
+
stack: string | undefined = undefined
|
|
34
|
+
): Promise<ErrorResponse> => {
|
|
35
|
+
|
|
36
|
+
let body, status, message = "Error";
|
|
37
|
+
|
|
38
|
+
if (response && "json" in response) {
|
|
39
|
+
body = await response?.json();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (response && "status" in response) {
|
|
43
|
+
status = response.status.toString();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (response && "text" in response) {
|
|
47
|
+
message = await response.text();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const error = new ErrorResponse({
|
|
51
|
+
code: status,
|
|
52
|
+
body: body,
|
|
53
|
+
name: status,
|
|
54
|
+
message: message,
|
|
55
|
+
stack,
|
|
56
|
+
} as IErrorResponse)
|
|
57
|
+
|
|
58
|
+
return error;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const getPaymentMethodDetails = (scheme_data: string): {icon: string; label: string} => {
|
|
62
|
+
const scheme: PAYMENT_METHOD = clearSpace(scheme_data.toUpperCase()) as PAYMENT_METHOD;
|
|
63
|
+
|
|
64
|
+
const PAYMENT_METHODS_CATALOG: Partial<Record<PAYMENT_METHOD, { icon: string, label: string }>> = {
|
|
65
|
+
[PAYMENT_METHOD.SORIANA]: {
|
|
66
|
+
label: "Soriana",
|
|
67
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png",
|
|
68
|
+
},
|
|
69
|
+
[PAYMENT_METHOD.OXXO]: {
|
|
70
|
+
label: "Oxxo",
|
|
71
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png",
|
|
72
|
+
},
|
|
73
|
+
[PAYMENT_METHOD.CODI]: {
|
|
74
|
+
label: "CoDi",
|
|
75
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png",
|
|
76
|
+
},
|
|
77
|
+
[PAYMENT_METHOD.SPEI]: {
|
|
78
|
+
label: "SPEI",
|
|
79
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png",
|
|
80
|
+
},
|
|
81
|
+
[PAYMENT_METHOD.PAYPAL]: {
|
|
82
|
+
label: "Paypal",
|
|
83
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png",
|
|
84
|
+
},
|
|
85
|
+
[PAYMENT_METHOD.COMERCIALMEXICANA]: {
|
|
86
|
+
label: "Comercial Mexicana",
|
|
87
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png",
|
|
88
|
+
},
|
|
89
|
+
[PAYMENT_METHOD.BANCOMER]: {
|
|
90
|
+
label: "Bancomer",
|
|
91
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png",
|
|
92
|
+
},
|
|
93
|
+
[PAYMENT_METHOD.WALMART]: {
|
|
94
|
+
label: "Walmart",
|
|
95
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png",
|
|
96
|
+
},
|
|
97
|
+
[PAYMENT_METHOD.BODEGA]: {
|
|
98
|
+
label: "Bodega Aurrera",
|
|
99
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png",
|
|
100
|
+
},
|
|
101
|
+
[PAYMENT_METHOD.SAMSCLUB]: {
|
|
102
|
+
label: "Sam´s Club",
|
|
103
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png",
|
|
104
|
+
},
|
|
105
|
+
[PAYMENT_METHOD.SUPERAMA]: {
|
|
106
|
+
label: "Superama",
|
|
107
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png",
|
|
108
|
+
},
|
|
109
|
+
[PAYMENT_METHOD.CALIMAX]: {
|
|
110
|
+
label: "Calimax",
|
|
111
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png",
|
|
112
|
+
},
|
|
113
|
+
[PAYMENT_METHOD.EXTRA]: {
|
|
114
|
+
label: "Tiendas Extra",
|
|
115
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png",
|
|
116
|
+
},
|
|
117
|
+
[PAYMENT_METHOD.CIRCULOK]: {
|
|
118
|
+
label: "Círculo K",
|
|
119
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png",
|
|
120
|
+
},
|
|
121
|
+
[PAYMENT_METHOD.SEVEN11]: {
|
|
122
|
+
label: "7 Eleven",
|
|
123
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png",
|
|
124
|
+
},
|
|
125
|
+
[PAYMENT_METHOD.TELECOMM]: {
|
|
126
|
+
label: "Telecomm",
|
|
127
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png",
|
|
128
|
+
},
|
|
129
|
+
[PAYMENT_METHOD.BANORTE]: {
|
|
130
|
+
label: "Banorte",
|
|
131
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png",
|
|
132
|
+
},
|
|
133
|
+
[PAYMENT_METHOD.BENAVIDES]: {
|
|
134
|
+
label: "Farmacias Benavides",
|
|
135
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png",
|
|
136
|
+
},
|
|
137
|
+
[PAYMENT_METHOD.DELAHORRO]: {
|
|
138
|
+
label: "Farmacias del Ahorro",
|
|
139
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png",
|
|
140
|
+
},
|
|
141
|
+
[PAYMENT_METHOD.ELASTURIANO]: {
|
|
142
|
+
label: "El Asturiano",
|
|
143
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png",
|
|
144
|
+
},
|
|
145
|
+
[PAYMENT_METHOD.WALDOS]: {
|
|
146
|
+
label: "Waldos",
|
|
147
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png",
|
|
148
|
+
},
|
|
149
|
+
[PAYMENT_METHOD.ALSUPER]: {
|
|
150
|
+
label: "Alsuper",
|
|
151
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png",
|
|
152
|
+
},
|
|
153
|
+
[PAYMENT_METHOD.KIOSKO]: {
|
|
154
|
+
label: "Kiosko",
|
|
155
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png",
|
|
156
|
+
},
|
|
157
|
+
[PAYMENT_METHOD.STAMARIA]: {
|
|
158
|
+
label: "Farmacias Santa María",
|
|
159
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png",
|
|
160
|
+
},
|
|
161
|
+
[PAYMENT_METHOD.LAMASBARATA]: {
|
|
162
|
+
label: "Farmacias la más barata",
|
|
163
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png",
|
|
164
|
+
},
|
|
165
|
+
[PAYMENT_METHOD.FARMROMA]: {
|
|
166
|
+
label: "Farmacias Roma",
|
|
167
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png",
|
|
168
|
+
},
|
|
169
|
+
[PAYMENT_METHOD.FARMUNION]: {
|
|
170
|
+
label: "Pago en Farmacias Unión",
|
|
171
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png",
|
|
172
|
+
},
|
|
173
|
+
[PAYMENT_METHOD.FARMATODO]: {
|
|
174
|
+
label: "Pago en Farmacias Farmatodo",
|
|
175
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png ",
|
|
176
|
+
},
|
|
177
|
+
[PAYMENT_METHOD.SFDEASIS]: {
|
|
178
|
+
label: "Pago en Farmacias San Francisco de Asís",
|
|
179
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png",
|
|
180
|
+
},
|
|
181
|
+
[PAYMENT_METHOD.FARM911]: {
|
|
182
|
+
label: "Farmacias 911",
|
|
183
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
184
|
+
},
|
|
185
|
+
[PAYMENT_METHOD.FARMECONOMICAS]: {
|
|
186
|
+
label: "Farmacias Economicas",
|
|
187
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
188
|
+
},
|
|
189
|
+
[PAYMENT_METHOD.FARMMEDICITY]: {
|
|
190
|
+
label: "Farmacias Medicity",
|
|
191
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
192
|
+
},
|
|
193
|
+
[PAYMENT_METHOD.RIANXEIRA]: {
|
|
194
|
+
label: "Rianxeira",
|
|
195
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
196
|
+
},
|
|
197
|
+
[PAYMENT_METHOD.WESTERNUNION]: {
|
|
198
|
+
label: "Western Union",
|
|
199
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
200
|
+
},
|
|
201
|
+
[PAYMENT_METHOD.ZONAPAGO]: {
|
|
202
|
+
label: "Zona Pago",
|
|
203
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
204
|
+
},
|
|
205
|
+
[PAYMENT_METHOD.CAJALOSANDES]: {
|
|
206
|
+
label: "Caja Los Andes",
|
|
207
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
208
|
+
},
|
|
209
|
+
[PAYMENT_METHOD.CAJAPAITA]: {
|
|
210
|
+
label: "Caja Paita",
|
|
211
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
212
|
+
},
|
|
213
|
+
[PAYMENT_METHOD.CAJASANTA]: {
|
|
214
|
+
label: "Caja Santa",
|
|
215
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
216
|
+
},
|
|
217
|
+
[PAYMENT_METHOD.CAJASULLANA]: {
|
|
218
|
+
label: "Caja Sullana",
|
|
219
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
220
|
+
},
|
|
221
|
+
[PAYMENT_METHOD.CAJATRUJILLO]: {
|
|
222
|
+
label: "Caja Trujillo",
|
|
223
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
224
|
+
},
|
|
225
|
+
[PAYMENT_METHOD.EDPYME]: {
|
|
226
|
+
label: "Edpyme",
|
|
227
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
228
|
+
},
|
|
229
|
+
[PAYMENT_METHOD.KASNET]: {
|
|
230
|
+
label: "KasNet",
|
|
231
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
232
|
+
},
|
|
233
|
+
[PAYMENT_METHOD.NORANDINO]: {
|
|
234
|
+
label: "Norandino",
|
|
235
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
236
|
+
},
|
|
237
|
+
[PAYMENT_METHOD.QAPAQ]: {
|
|
238
|
+
label: "Qapaq",
|
|
239
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
240
|
+
},
|
|
241
|
+
[PAYMENT_METHOD.RAIZ]: {
|
|
242
|
+
label: "Raiz",
|
|
243
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
244
|
+
},
|
|
245
|
+
[PAYMENT_METHOD.PAYSER]: {
|
|
246
|
+
label: "Paysera",
|
|
247
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
248
|
+
},
|
|
249
|
+
[PAYMENT_METHOD.WUNION]: {
|
|
250
|
+
label: "Western Union",
|
|
251
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
252
|
+
},
|
|
253
|
+
[PAYMENT_METHOD.BANCOCONTINENTAL]: {
|
|
254
|
+
label: "Banco Continental",
|
|
255
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
256
|
+
},
|
|
257
|
+
[PAYMENT_METHOD.GMONEY]: {
|
|
258
|
+
label: "Go money",
|
|
259
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
260
|
+
},
|
|
261
|
+
[PAYMENT_METHOD.GOPAY]: {
|
|
262
|
+
label: "Go pay",
|
|
263
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
264
|
+
},
|
|
265
|
+
[PAYMENT_METHOD.WU]: {
|
|
266
|
+
label: "Western Union",
|
|
267
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
268
|
+
},
|
|
269
|
+
[PAYMENT_METHOD.PUNTOSHEY]: {
|
|
270
|
+
label: "Puntoshey",
|
|
271
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
272
|
+
},
|
|
273
|
+
[PAYMENT_METHOD.AMPM]: {
|
|
274
|
+
label: "Ampm",
|
|
275
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
276
|
+
},
|
|
277
|
+
[PAYMENT_METHOD.JUMBOMARKET]: {
|
|
278
|
+
label: "Jumbomarket",
|
|
279
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
280
|
+
},
|
|
281
|
+
[PAYMENT_METHOD.SMELPUEBLO]: {
|
|
282
|
+
label: "Smelpueblo",
|
|
283
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
284
|
+
},
|
|
285
|
+
[PAYMENT_METHOD.BAM]: {
|
|
286
|
+
label: "Bam",
|
|
287
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
288
|
+
},
|
|
289
|
+
[PAYMENT_METHOD.REFACIL]: {
|
|
290
|
+
label: "Refacil",
|
|
291
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
292
|
+
},
|
|
293
|
+
[PAYMENT_METHOD.ACYVALORES]: {
|
|
294
|
+
label: "Acyvalores",
|
|
295
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const _default = {
|
|
300
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
301
|
+
label: ""
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
return PAYMENT_METHODS_CATALOG[scheme] || _default;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const clearSpace = (text: string) => {
|
|
308
|
+
return text.trim().replace(/\s+/g, '');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export {
|
|
312
|
+
buildErrorResponseFromCatch,
|
|
313
|
+
buildErrorResponse,
|
|
314
|
+
getPaymentMethodDetails
|
|
315
|
+
}
|
package/src/types/commons.ts
CHANGED
|
@@ -60,3 +60,21 @@ export type PaymentData = {
|
|
|
60
60
|
items: OrderItem[];
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
|
+
|
|
64
|
+
export type TonderAPM = {
|
|
65
|
+
pk: string;
|
|
66
|
+
payment_method: string;
|
|
67
|
+
priority: number;
|
|
68
|
+
category: string;
|
|
69
|
+
unavailable_countries: string[];
|
|
70
|
+
status: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type APM = {
|
|
74
|
+
id: string;
|
|
75
|
+
payment_method: string;
|
|
76
|
+
priority: number;
|
|
77
|
+
category: string;
|
|
78
|
+
icon: string;
|
|
79
|
+
label: string;
|
|
80
|
+
}
|
package/src/types/requests.ts
CHANGED
|
@@ -21,8 +21,7 @@ export type CreatePaymentRequest = {
|
|
|
21
21
|
client_id?: string | number
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export type
|
|
25
|
-
card: any,
|
|
24
|
+
export type StartCheckoutRequestBase = {
|
|
26
25
|
name: any,
|
|
27
26
|
last_name: string,
|
|
28
27
|
email_client: any,
|
|
@@ -43,9 +42,21 @@ export type StartCheckoutRequest = {
|
|
|
43
42
|
source: string,
|
|
44
43
|
browser_info?: any,
|
|
45
44
|
metadata: any,
|
|
46
|
-
currency: string
|
|
45
|
+
currency: string,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type StartCheckoutRequestWithCard = StartCheckoutRequestBase & {
|
|
49
|
+
card: any,
|
|
50
|
+
payment_method?: never,
|
|
47
51
|
}
|
|
48
52
|
|
|
53
|
+
export type StartCheckoutRequestWithPaymentMethod = StartCheckoutRequestBase & {
|
|
54
|
+
card?: never,
|
|
55
|
+
payment_method: string,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type StartCheckoutRequest = StartCheckoutRequestWithCard | StartCheckoutRequestWithPaymentMethod;
|
|
59
|
+
|
|
49
60
|
export type StartCheckoutIdRequest = {
|
|
50
61
|
checkout_id: any
|
|
51
62
|
}
|
|
@@ -91,4 +102,5 @@ export type StartCheckoutFullRequest = {
|
|
|
91
102
|
isSandbox: boolean;
|
|
92
103
|
metadata: any;
|
|
93
104
|
currency: string;
|
|
105
|
+
payment_method?: string;
|
|
94
106
|
}
|
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
RegisterCustomerCardRequest,
|
|
6
6
|
StartCheckoutRequest,
|
|
7
7
|
TokensRequest,
|
|
8
|
-
StartCheckoutFullRequest
|
|
8
|
+
StartCheckoutFullRequest,
|
|
9
|
+
StartCheckoutRequestWithCard
|
|
9
10
|
} from "../../src/types/requests";
|
|
10
11
|
import {
|
|
11
12
|
CreateOrderResponse,
|
|
@@ -312,7 +313,7 @@ export class CreatePaymentResponseClass implements CreatePaymentResponse {
|
|
|
312
313
|
}
|
|
313
314
|
}
|
|
314
315
|
|
|
315
|
-
export class StartCheckoutRequestClass implements
|
|
316
|
+
export class StartCheckoutRequestClass implements StartCheckoutRequestWithCard {
|
|
316
317
|
card: any;
|
|
317
318
|
name: any;
|
|
318
319
|
last_name!: string;
|