@tonder.io/ionic-lite-sdk 0.0.35-beta.1 → 0.0.35-beta.3
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/prettier.xml +6 -0
- package/.idea/workspace.xml +6 -15
- package/dist/classes/BaseInlineCheckout.d.ts +5 -8
- package/dist/classes/errorResponse.d.ts +1 -1
- package/dist/classes/liteCheckout.d.ts +5 -11
- package/dist/data/businessApi.d.ts +1 -1
- package/dist/data/cardApi.d.ts +1 -1
- package/dist/data/checkoutApi.d.ts +1 -2
- package/dist/data/customerApi.d.ts +1 -1
- package/dist/data/paymentMethodApi.d.ts +1 -1
- package/dist/helpers/utils.d.ts +1 -1
- package/dist/types/commons.d.ts +6 -1
- package/package.json +1 -1
- package/src/classes/BaseInlineCheckout.ts +341 -303
- package/src/classes/errorResponse.ts +1 -1
- package/src/classes/liteCheckout.ts +260 -204
- package/src/data/businessApi.ts +17 -13
- package/src/data/cardApi.ts +70 -63
- package/src/data/checkoutApi.ts +75 -59
- package/src/data/customerApi.ts +27 -27
- package/src/data/openPayApi.ts +12 -7
- package/src/data/paymentMethodApi.ts +32 -29
- package/src/data/skyflowApi.ts +18 -14
- package/src/helpers/mercadopago.ts +14 -14
- package/src/helpers/skyflow.ts +34 -28
- package/src/helpers/utils.ts +51 -39
- package/src/helpers/validations.ts +35 -35
- package/src/shared/catalog/paymentMethodsCatalog.ts +8 -8
- package/src/shared/constants/paymentMethodAPM.ts +59 -59
- package/src/shared/constants/tonderUrl.ts +4 -4
- package/src/types/commons.ts +6 -1
package/src/helpers/utils.ts
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
1
|
import { ErrorResponse } from "../classes/errorResponse";
|
|
2
|
-
import { IErrorResponse } from "../types
|
|
3
|
-
import { PAYMENT_METHOD } from "./constants";
|
|
2
|
+
import { IErrorResponse } from "../types";
|
|
4
3
|
|
|
5
4
|
export const getBrowserInfo = () => {
|
|
6
5
|
const browserInfo = {
|
|
7
|
-
javascript_enabled: true,
|
|
6
|
+
javascript_enabled: true, // Assumed since JavaScript is running
|
|
8
7
|
time_zone: new Date().getTimezoneOffset(),
|
|
9
|
-
language: navigator.language ||
|
|
8
|
+
language: navigator.language || "en-US", // Fallback to 'en-US'
|
|
10
9
|
color_depth: window.screen ? window.screen.colorDepth : null,
|
|
11
|
-
screen_width: window.screen
|
|
12
|
-
|
|
10
|
+
screen_width: window.screen
|
|
11
|
+
? window.screen.width * window.devicePixelRatio || window.screen.width
|
|
12
|
+
: null,
|
|
13
|
+
screen_height: window.screen
|
|
14
|
+
? window.screen.height * window.devicePixelRatio || window.screen.height
|
|
15
|
+
: null,
|
|
13
16
|
user_agent: navigator.userAgent,
|
|
14
17
|
};
|
|
15
18
|
return browserInfo;
|
|
16
|
-
}
|
|
19
|
+
};
|
|
17
20
|
|
|
18
|
-
export const getBusinessId = (merchantData: any) =>{
|
|
19
|
-
return merchantData && "business" in merchantData
|
|
20
|
-
|
|
21
|
+
export const getBusinessId = (merchantData: any) => {
|
|
22
|
+
return merchantData && "business" in merchantData
|
|
23
|
+
? merchantData?.business?.pk
|
|
24
|
+
: "";
|
|
25
|
+
};
|
|
21
26
|
const buildErrorResponseFromCatch = (e: any): ErrorResponse => {
|
|
22
|
-
|
|
23
27
|
const error = new ErrorResponse({
|
|
24
28
|
code: e?.status ? e.status : e.code,
|
|
25
29
|
body: e?.body,
|
|
26
|
-
name: e ? typeof e == "string" ? "catch" : (e as Error).name : "Error",
|
|
30
|
+
name: e ? (typeof e == "string" ? "catch" : (e as Error).name) : "Error",
|
|
27
31
|
message: e ? (typeof e == "string" ? e : (e as Error).message) : "Error",
|
|
28
32
|
stack: typeof e == "string" ? undefined : (e as Error).stack,
|
|
29
|
-
})
|
|
33
|
+
});
|
|
30
34
|
|
|
31
35
|
return error;
|
|
32
|
-
}
|
|
36
|
+
};
|
|
33
37
|
|
|
34
38
|
const buildErrorResponse = async (
|
|
35
39
|
response: Response,
|
|
36
|
-
stack: string | undefined = undefined
|
|
40
|
+
stack: string | undefined = undefined,
|
|
37
41
|
): Promise<ErrorResponse> => {
|
|
38
|
-
let body,
|
|
42
|
+
let body,
|
|
43
|
+
status,
|
|
44
|
+
message = "Error";
|
|
39
45
|
|
|
40
46
|
if (response && "json" in response) {
|
|
41
47
|
body = await response?.json();
|
|
@@ -49,8 +55,8 @@ const buildErrorResponse = async (
|
|
|
49
55
|
message = await response.text();
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
if(body?.detail){
|
|
53
|
-
message = body.detail
|
|
58
|
+
if (body?.detail) {
|
|
59
|
+
message = body.detail;
|
|
54
60
|
}
|
|
55
61
|
const error = new ErrorResponse({
|
|
56
62
|
code: status,
|
|
@@ -58,51 +64,57 @@ const buildErrorResponse = async (
|
|
|
58
64
|
name: status,
|
|
59
65
|
message: message,
|
|
60
66
|
stack,
|
|
61
|
-
} as IErrorResponse)
|
|
67
|
+
} as IErrorResponse);
|
|
62
68
|
|
|
63
69
|
return error;
|
|
64
|
-
}
|
|
70
|
+
};
|
|
65
71
|
|
|
66
72
|
function formatPublicErrorResponse(data: Record<string, any>, error: any) {
|
|
67
|
-
let code = 200
|
|
73
|
+
let code = 200;
|
|
68
74
|
try {
|
|
69
|
-
code = Number(error?.code || 200)
|
|
70
|
-
}catch{}
|
|
75
|
+
code = Number(error?.code || 200);
|
|
76
|
+
} catch {}
|
|
71
77
|
|
|
72
78
|
const default_res = {
|
|
73
79
|
status: "error",
|
|
74
80
|
code,
|
|
75
81
|
message: "",
|
|
76
|
-
detail:
|
|
77
|
-
|
|
82
|
+
detail:
|
|
83
|
+
error?.body?.detail ||
|
|
84
|
+
error?.body?.error ||
|
|
85
|
+
error.body ||
|
|
86
|
+
"Ocurrio un error inesperado.",
|
|
87
|
+
};
|
|
78
88
|
|
|
79
89
|
return {
|
|
80
90
|
...default_res,
|
|
81
|
-
...data
|
|
91
|
+
...data,
|
|
82
92
|
};
|
|
83
93
|
}
|
|
84
94
|
|
|
85
|
-
|
|
86
95
|
const clearSpace = (text: string) => {
|
|
87
|
-
return text.trim().replace(/\s+/g,
|
|
88
|
-
}
|
|
96
|
+
return text.trim().replace(/\s+/g, "");
|
|
97
|
+
};
|
|
89
98
|
|
|
90
99
|
const getCardType = (scheme: string) => {
|
|
91
|
-
if(scheme === "Visa") {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return "https://d35a75syrgujp0.cloudfront.net/cards/
|
|
100
|
+
if (scheme === "Visa") {
|
|
101
|
+
// Check if visa
|
|
102
|
+
return "https://d35a75syrgujp0.cloudfront.net/cards/visa.png";
|
|
103
|
+
} else if (scheme === "Mastercard") {
|
|
104
|
+
// Check if master
|
|
105
|
+
return "https://d35a75syrgujp0.cloudfront.net/cards/mastercard.png";
|
|
106
|
+
} else if (scheme === "American Express") {
|
|
107
|
+
// Check if amex
|
|
108
|
+
return "https://d35a75syrgujp0.cloudfront.net/cards/american_express.png";
|
|
97
109
|
} else {
|
|
98
|
-
return "https://d35a75syrgujp0.cloudfront.net/cards/default_card.png"
|
|
110
|
+
return "https://d35a75syrgujp0.cloudfront.net/cards/default_card.png";
|
|
99
111
|
}
|
|
100
|
-
}
|
|
112
|
+
};
|
|
101
113
|
|
|
102
114
|
export {
|
|
103
115
|
buildErrorResponseFromCatch,
|
|
104
116
|
buildErrorResponse,
|
|
105
117
|
getCardType,
|
|
106
118
|
formatPublicErrorResponse,
|
|
107
|
-
clearSpace
|
|
108
|
-
}
|
|
119
|
+
clearSpace,
|
|
120
|
+
};
|
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
export function validateCardNumber(cardNumber: string) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const regex = /^\d{12,19}$/;
|
|
3
|
+
return regex.test(cardNumber) && luhnCheck(cardNumber);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export function validateCardholderName(name: string) {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const regex = /^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/;
|
|
8
|
+
return regex.test(name);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function validateCVV(cvv: string) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const regex = /^\d{3,4}$/;
|
|
13
|
+
return regex.test(cvv);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function validateExpirationDate(expirationDate: string) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
const regex = /^(0[1-9]|1[0-2])\/\d{2}$/;
|
|
18
|
+
if (!regex.test(expirationDate)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const [month, year] = expirationDate.split("/");
|
|
22
|
+
const currentDate = new Date();
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
const expiration = new Date(`20${year}`, month - 1);
|
|
25
|
+
return expiration >= currentDate;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function validateExpirationMonth(month: string) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const regex = /^(0[1-9]|1[0-2])$/;
|
|
30
|
+
return regex.test(month);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function validateExpirationYear(year: string) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const regex = /^\d{2}$/;
|
|
35
|
+
if (!regex.test(year)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const currentYear = new Date().getFullYear() % 100;
|
|
39
|
+
return parseInt(year, 10) >= currentYear;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const luhnCheck = (num: number | string) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
const arr = `${num}`
|
|
44
|
+
.split("")
|
|
45
|
+
.reverse()
|
|
46
|
+
.map((x) => Number.parseInt(x));
|
|
47
|
+
const lastDigit = arr.shift();
|
|
48
|
+
let sum = arr.reduce(
|
|
49
|
+
(acc, val, i) =>
|
|
50
|
+
i % 2 !== 0 ? acc + val : acc + ((val *= 2) > 9 ? val - 9 : val),
|
|
51
|
+
0,
|
|
52
|
+
);
|
|
53
|
+
sum += lastDigit!;
|
|
54
|
+
return sum % 10 === 0;
|
|
55
55
|
};
|
|
@@ -238,11 +238,11 @@ const PAYMENT_METHODS_CATALOG = {
|
|
|
238
238
|
|
|
239
239
|
|
|
240
240
|
export const getPaymentMethodDetails = (scheme_data: string) => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
241
|
+
const scheme: string = clearSpace(scheme_data.toUpperCase());
|
|
242
|
+
const _default = {
|
|
243
|
+
icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
|
|
244
|
+
label: "",
|
|
245
|
+
};
|
|
246
|
+
// @ts-ignore
|
|
247
|
+
return PAYMENT_METHODS_CATALOG[scheme] || _default;
|
|
248
|
+
};
|
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
const PAYMENT_METHOD_APM = Object.freeze({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
61
|
});
|
|
62
62
|
|
|
63
63
|
export { PAYMENT_METHOD_APM };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const TONDER_URL_BY_MODE = Object.freeze({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
production: "https://app.tonder.io",
|
|
3
|
+
sandbox: "https://sandbox.tonder.io",
|
|
4
|
+
stage: "https://stage.tonder.io",
|
|
5
|
+
development: "http://localhost:8000",
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
export { TONDER_URL_BY_MODE };
|
package/src/types/commons.ts
CHANGED
|
@@ -96,12 +96,17 @@ export interface IInlineCheckoutBaseOptions {
|
|
|
96
96
|
* `baseUrlTonder` is no longer required.
|
|
97
97
|
*/
|
|
98
98
|
baseUrlTonder?: string;
|
|
99
|
-
apiKey: string;
|
|
100
99
|
/**
|
|
101
100
|
* @deprecated This property is deprecated and will be removed in a future release.
|
|
102
101
|
* Use `apiKey` instead, as `apiKeyTonder` is no longer required.
|
|
103
102
|
*/
|
|
104
103
|
apiKeyTonder?: string;
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated This property is deprecated and will be removed in a future release.
|
|
106
|
+
* `signal` is no longer required.
|
|
107
|
+
*/
|
|
108
|
+
signal?: AbortSignal;
|
|
109
|
+
apiKey: string;
|
|
105
110
|
returnUrl: string;
|
|
106
111
|
callBack?: (response: any) => void;
|
|
107
112
|
}
|