@tonder.io/ionic-lite-sdk 0.0.41-beta.1 → 0.0.42-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.gitlab-ci.yml +28 -28
  2. package/README.md +532 -532
  3. package/dist/classes/3dsHandler.d.ts +3 -1
  4. package/dist/classes/BaseInlineCheckout.d.ts +3 -2
  5. package/dist/classes/liteCheckout.d.ts +1 -1
  6. package/dist/data/cardApi.d.ts +3 -3
  7. package/dist/index.js +1 -1
  8. package/dist/types/commons.d.ts +1 -0
  9. package/dist/types/liteInlineCheckout.d.ts +1 -1
  10. package/jest.config.ts +14 -14
  11. package/package.json +41 -41
  12. package/rollup.config.js +16 -16
  13. package/src/classes/3dsHandler.ts +347 -337
  14. package/src/classes/BaseInlineCheckout.ts +424 -415
  15. package/src/classes/errorResponse.ts +16 -16
  16. package/src/classes/liteCheckout.ts +589 -591
  17. package/src/data/api.ts +20 -20
  18. package/src/data/businessApi.ts +18 -18
  19. package/src/data/cardApi.ts +91 -87
  20. package/src/data/checkoutApi.ts +84 -84
  21. package/src/data/customerApi.ts +31 -31
  22. package/src/data/openPayApi.ts +12 -12
  23. package/src/data/paymentMethodApi.ts +37 -37
  24. package/src/data/skyflowApi.ts +20 -20
  25. package/src/helpers/constants.ts +63 -63
  26. package/src/helpers/mercadopago.ts +15 -15
  27. package/src/helpers/skyflow.ts +91 -91
  28. package/src/helpers/utils.ts +120 -120
  29. package/src/helpers/validations.ts +55 -55
  30. package/src/index.ts +12 -12
  31. package/src/shared/catalog/paymentMethodsCatalog.ts +247 -247
  32. package/src/shared/constants/messages.ts +10 -10
  33. package/src/shared/constants/paymentMethodAPM.ts +63 -63
  34. package/src/shared/constants/tonderUrl.ts +8 -8
  35. package/src/types/card.ts +35 -35
  36. package/src/types/checkout.ts +123 -123
  37. package/src/types/commons.ts +143 -142
  38. package/src/types/customer.ts +22 -22
  39. package/src/types/liteInlineCheckout.ts +216 -216
  40. package/src/types/paymentMethod.ts +23 -23
  41. package/src/types/requests.ts +114 -114
  42. package/src/types/responses.ts +192 -192
  43. package/src/types/skyflow.ts +17 -17
  44. package/src/types/transaction.ts +101 -101
  45. package/src/types/validations.d.ts +11 -11
  46. package/tests/classes/liteCheckout.test.ts +57 -57
  47. package/tests/methods/createOrder.test.ts +141 -141
  48. package/tests/methods/createPayment.test.ts +121 -121
  49. package/tests/methods/customerRegister.test.ts +118 -118
  50. package/tests/methods/getBusiness.test.ts +114 -114
  51. package/tests/methods/getCustomerCards.test.ts +112 -112
  52. package/tests/methods/registerCustomerCard.test.ts +117 -117
  53. package/tests/methods/startCheckoutRouter.test.ts +119 -119
  54. package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
  55. package/tests/utils/defaultMock.ts +21 -21
  56. package/tests/utils/mockClasses.ts +659 -659
  57. package/tsconfig.json +18 -18
package/src/data/api.ts CHANGED
@@ -1,21 +1,21 @@
1
- import { buildErrorResponse, buildErrorResponseFromCatch } from "../helpers/utils";
2
-
3
- export async function getCustomerAPMs(baseUrlTonder: string, publicApiKeyTonder: 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 ${publicApiKeyTonder}`,
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
- }
1
+ import { buildErrorResponse, buildErrorResponseFromCatch } from "../helpers/utils";
2
+
3
+ export async function getCustomerAPMs(baseUrlTonder: string, publicApiKeyTonder: 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 ${publicApiKeyTonder}`,
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
21
  }
@@ -1,18 +1,18 @@
1
- import {GetBusinessResponse} from "../types/responses";
2
-
3
- export async function fetchBusiness(
4
- baseUrl: string,
5
- apiKey: string,
6
- signal: AbortSignal,
7
- ): Promise<GetBusinessResponse> {
8
- const getBusiness = await fetch(
9
- `${baseUrl}/api/v1/payments/business/${apiKey}`,
10
- {
11
- headers: {
12
- Authorization: `Token ${apiKey}`,
13
- },
14
- signal: signal,
15
- },
16
- );
17
- return await getBusiness.json();
18
- }
1
+ import {GetBusinessResponse} from "../types/responses";
2
+
3
+ export async function fetchBusiness(
4
+ baseUrl: string,
5
+ apiKey: string,
6
+ signal: AbortSignal,
7
+ ): Promise<GetBusinessResponse> {
8
+ const getBusiness = await fetch(
9
+ `${baseUrl}/api/v1/payments/business/${apiKey}`,
10
+ {
11
+ headers: {
12
+ Authorization: `Token ${apiKey}`,
13
+ },
14
+ signal: signal,
15
+ },
16
+ );
17
+ return await getBusiness.json();
18
+ }
@@ -1,87 +1,91 @@
1
- import {
2
- buildErrorResponse,
3
- buildErrorResponseFromCatch,
4
- } from "../helpers/utils";
5
- import { MESSAGES } from "../shared/constants/messages";
6
- import {ICustomerCardsResponse, ISaveCardResponse, ISaveCardSkyflowRequest} from "../types/card";
7
-
8
- export async function fetchCustomerCards(
9
- baseUrl: string,
10
- customerToken: string,
11
- businessId: string | number,
12
- signal = null,
13
- ): Promise<ICustomerCardsResponse> {
14
- try {
15
- const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
16
- const response = await fetch(url, {
17
- method: "GET",
18
- headers: {
19
- Authorization: `Token ${customerToken}`,
20
- "Content-Type": "application/json",
21
- },
22
- signal,
23
- });
24
- if (response.ok) return await response.json();
25
- const res_json = await response.json();
26
-
27
- throw await buildErrorResponse(response, res_json);
28
- } catch (error) {
29
- throw buildErrorResponseFromCatch(error);
30
- }
31
- }
32
-
33
- export async function saveCustomerCard(
34
- baseUrl: string,
35
- secureToken: string,
36
- customerToken: string,
37
- businessId: string | number,
38
- data: ISaveCardSkyflowRequest,
39
- ): Promise<ISaveCardResponse> {
40
- try {
41
- const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
42
- const response = await fetch(url, {
43
- method: "POST",
44
- headers: {
45
- Authorization: `Bearer ${secureToken}`,
46
- "Content-Type": "application/json",
47
- 'User-token': customerToken,
48
- },
49
- body: JSON.stringify(data),
50
- });
51
-
52
- if (response.ok) return await response.json();
53
-
54
- const res_json = await response.json();
55
-
56
- throw await buildErrorResponse(response, res_json);
57
- } catch (error) {
58
- throw buildErrorResponseFromCatch(error);
59
- }
60
- }
61
-
62
- export async function removeCustomerCard(
63
- baseUrl: string,
64
- customerToken: string,
65
- skyflowId = "",
66
- businessId: string | number,
67
- ): Promise<string> {
68
- try {
69
- const url = `${baseUrl}/api/v1/business/${businessId}/cards/${skyflowId}`;
70
-
71
- const response = await fetch(url, {
72
- method: "DELETE",
73
- headers: {
74
- Authorization: `Token ${customerToken}`,
75
- "Content-Type": "application/json",
76
- },
77
- });
78
-
79
- if (response.status === 204) return MESSAGES.cardSaved;
80
- if (response.ok && "json" in response) return await response.json();
81
- const res_json = await response.json();
82
-
83
- throw await buildErrorResponse(response, res_json);
84
- } catch (error) {
85
- throw buildErrorResponseFromCatch(error);
86
- }
87
- }
1
+ import {
2
+ buildErrorResponse,
3
+ buildErrorResponseFromCatch,
4
+ } from "../helpers/utils";
5
+ import { MESSAGES } from "../shared/constants/messages";
6
+ import {ICustomerCardsResponse, ISaveCardResponse, ISaveCardSkyflowRequest} from "../types/card";
7
+
8
+ export async function fetchCustomerCards(
9
+ baseUrl: string,
10
+ customerToken: string,
11
+ secureToken: string,
12
+ businessId: string | number,
13
+ signal = null,
14
+ ): Promise<ICustomerCardsResponse> {
15
+ try {
16
+ const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
17
+ const response = await fetch(url, {
18
+ method: "GET",
19
+ headers: {
20
+ Authorization: `Token ${secureToken}`,
21
+ "Content-Type": "application/json",
22
+ 'User-token': customerToken,
23
+ },
24
+ signal,
25
+ });
26
+ if (response.ok) return await response.json();
27
+ const res_json = await response.json();
28
+
29
+ throw await buildErrorResponse(response, res_json);
30
+ } catch (error) {
31
+ throw buildErrorResponseFromCatch(error);
32
+ }
33
+ }
34
+
35
+ export async function saveCustomerCard(
36
+ baseUrl: string,
37
+ customerToken: string,
38
+ secureToken: string,
39
+ businessId: string | number,
40
+ data: ISaveCardSkyflowRequest,
41
+ ): Promise<ISaveCardResponse> {
42
+ try {
43
+ const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
44
+ const response = await fetch(url, {
45
+ method: "POST",
46
+ headers: {
47
+ Authorization: `Bearer ${secureToken}`,
48
+ "Content-Type": "application/json",
49
+ 'User-token': customerToken,
50
+ },
51
+ body: JSON.stringify(data),
52
+ });
53
+
54
+ if (response.ok) return await response.json();
55
+
56
+ const res_json = await response.json();
57
+
58
+ throw await buildErrorResponse(response, res_json);
59
+ } catch (error) {
60
+ throw buildErrorResponseFromCatch(error);
61
+ }
62
+ }
63
+
64
+ export async function removeCustomerCard(
65
+ baseUrl: string,
66
+ customerToken: string,
67
+ secureToken: string,
68
+ skyflowId = "",
69
+ businessId: string | number,
70
+ ): Promise<string> {
71
+ try {
72
+ const url = `${baseUrl}/api/v1/business/${businessId}/cards/${skyflowId}`;
73
+
74
+ const response = await fetch(url, {
75
+ method: "DELETE",
76
+ headers: {
77
+ Authorization: `Token ${secureToken}`,
78
+ "Content-Type": "application/json",
79
+ 'User-token': customerToken,
80
+ },
81
+ });
82
+
83
+ if (response.status === 204) return MESSAGES.cardSaved;
84
+ if (response.ok && "json" in response) return await response.json();
85
+ const res_json = await response.json();
86
+
87
+ throw await buildErrorResponse(response, res_json);
88
+ } catch (error) {
89
+ throw buildErrorResponseFromCatch(error);
90
+ }
91
+ }
@@ -1,84 +1,84 @@
1
- import {CreateOrderRequest, CreatePaymentRequest} from "../types/requests";
2
- import {IStartCheckoutIdRequest, IStartCheckoutRequest} from "../types/checkout";
3
-
4
- declare const MP_DEVICE_SESSION_ID: string | undefined;
5
-
6
-
7
- export async function createOrder(
8
- baseUrl: string,
9
- apiKey: string,
10
- orderItems: CreateOrderRequest,
11
- ) {
12
- const url = `${baseUrl}/api/v1/orders/`;
13
- const data = orderItems;
14
- const response = await fetch(url, {
15
- method: "POST",
16
- headers: {
17
- "Content-Type": "application/json",
18
- Authorization: `Token ${apiKey}`,
19
- },
20
- body: JSON.stringify(data),
21
- });
22
- if (response.status === 201) {
23
- return await response.json();
24
- } else {
25
- throw new Error(`Error: ${response.statusText}`);
26
- }
27
- }
28
-
29
- export async function createPayment(
30
- baseUrl: string,
31
- apiKey: string,
32
- paymentItems: CreatePaymentRequest,
33
- ) {
34
- const url = `${baseUrl}/api/v1/business/${paymentItems.business_pk}/payments/`;
35
- const data = paymentItems;
36
- const response = await fetch(url, {
37
- method: "POST",
38
- headers: {
39
- "Content-Type": "application/json",
40
- Authorization: `Token ${apiKey}`,
41
- },
42
- body: JSON.stringify(data),
43
- });
44
- if (response.status >= 200 && response.status <= 299) {
45
- return await response.json();
46
- } else {
47
- throw new Error(`Error: ${response.statusText}`);
48
- }
49
- }
50
-
51
- export async function startCheckoutRouter(
52
- baseUrl: string,
53
- apiKey: string,
54
- routerItems: IStartCheckoutRequest | IStartCheckoutIdRequest,
55
- ) {
56
- try {
57
- const url = `${baseUrl}/api/v1/checkout-router/`;
58
- const data = routerItems;
59
- const response = await fetch(url, {
60
- method: "POST",
61
- headers: {
62
- "Content-Type": "application/json",
63
- Authorization: `Token ${apiKey}`,
64
- },
65
- body: JSON.stringify({
66
- ...data,
67
- ...(typeof MP_DEVICE_SESSION_ID !== "undefined"
68
- ? { mp_device_session_id: MP_DEVICE_SESSION_ID }
69
- : {}),
70
- }),
71
- });
72
- if (response.status >= 200 && response.status <= 299) {
73
- return await response.json();
74
- } else {
75
- const errorResponse = await response.json();
76
- const error = new Error("Failed to start checkout router");
77
- // @ts-ignore
78
- error.details = errorResponse;
79
- throw error;
80
- }
81
- } catch (error) {
82
- throw error;
83
- }
84
- }
1
+ import {CreateOrderRequest, CreatePaymentRequest} from "../types/requests";
2
+ import {IStartCheckoutIdRequest, IStartCheckoutRequest} from "../types/checkout";
3
+
4
+ declare const MP_DEVICE_SESSION_ID: string | undefined;
5
+
6
+
7
+ export async function createOrder(
8
+ baseUrl: string,
9
+ apiKey: string,
10
+ orderItems: CreateOrderRequest,
11
+ ) {
12
+ const url = `${baseUrl}/api/v1/orders/`;
13
+ const data = orderItems;
14
+ const response = await fetch(url, {
15
+ method: "POST",
16
+ headers: {
17
+ "Content-Type": "application/json",
18
+ Authorization: `Token ${apiKey}`,
19
+ },
20
+ body: JSON.stringify(data),
21
+ });
22
+ if (response.status === 201) {
23
+ return await response.json();
24
+ } else {
25
+ throw new Error(`Error: ${response.statusText}`);
26
+ }
27
+ }
28
+
29
+ export async function createPayment(
30
+ baseUrl: string,
31
+ apiKey: string,
32
+ paymentItems: CreatePaymentRequest,
33
+ ) {
34
+ const url = `${baseUrl}/api/v1/business/${paymentItems.business_pk}/payments/`;
35
+ const data = paymentItems;
36
+ const response = await fetch(url, {
37
+ method: "POST",
38
+ headers: {
39
+ "Content-Type": "application/json",
40
+ Authorization: `Token ${apiKey}`,
41
+ },
42
+ body: JSON.stringify(data),
43
+ });
44
+ if (response.status >= 200 && response.status <= 299) {
45
+ return await response.json();
46
+ } else {
47
+ throw new Error(`Error: ${response.statusText}`);
48
+ }
49
+ }
50
+
51
+ export async function startCheckoutRouter(
52
+ baseUrl: string,
53
+ apiKey: string,
54
+ routerItems: IStartCheckoutRequest | IStartCheckoutIdRequest,
55
+ ) {
56
+ try {
57
+ const url = `${baseUrl}/api/v1/checkout-router/`;
58
+ const data = routerItems;
59
+ const response = await fetch(url, {
60
+ method: "POST",
61
+ headers: {
62
+ "Content-Type": "application/json",
63
+ Authorization: `Token ${apiKey}`,
64
+ },
65
+ body: JSON.stringify({
66
+ ...data,
67
+ ...(typeof MP_DEVICE_SESSION_ID !== "undefined"
68
+ ? { mp_device_session_id: MP_DEVICE_SESSION_ID }
69
+ : {}),
70
+ }),
71
+ });
72
+ if (response.status >= 200 && response.status <= 299) {
73
+ return await response.json();
74
+ } else {
75
+ const errorResponse = await response.json();
76
+ const error = new Error("Failed to start checkout router");
77
+ // @ts-ignore
78
+ error.details = errorResponse;
79
+ throw error;
80
+ }
81
+ } catch (error) {
82
+ throw error;
83
+ }
84
+ }
@@ -1,31 +1,31 @@
1
- import {CustomerRegisterResponse} from "../types/responses";
2
-
3
- export async function registerOrFetchCustomer(
4
- baseUrl: string,
5
- apiKey: string,
6
- customer: Record<string, any>,
7
- signal: AbortSignal | null = null,
8
- ): Promise<CustomerRegisterResponse> {
9
- const url = `${baseUrl}/api/v1/customer/`;
10
- const data = {
11
- email: customer.email,
12
- first_name: customer?.firstName,
13
- last_name: customer?.lastName,
14
- phone: customer?.phone,
15
- };
16
- const response = await fetch(url, {
17
- method: "POST",
18
- headers: {
19
- "Content-Type": "application/json",
20
- Authorization: `Token ${apiKey}`,
21
- },
22
- signal: signal,
23
- body: JSON.stringify(data),
24
- });
25
-
26
- if (response.status === 201) {
27
- return await response.json();
28
- } else {
29
- throw new Error(`Error: ${response.statusText}`);
30
- }
31
- }
1
+ import {CustomerRegisterResponse} from "../types/responses";
2
+
3
+ export async function registerOrFetchCustomer(
4
+ baseUrl: string,
5
+ apiKey: string,
6
+ customer: Record<string, any>,
7
+ signal: AbortSignal | null = null,
8
+ ): Promise<CustomerRegisterResponse> {
9
+ const url = `${baseUrl}/api/v1/customer/`;
10
+ const data = {
11
+ email: customer.email,
12
+ first_name: customer?.firstName,
13
+ last_name: customer?.lastName,
14
+ phone: customer?.phone,
15
+ };
16
+ const response = await fetch(url, {
17
+ method: "POST",
18
+ headers: {
19
+ "Content-Type": "application/json",
20
+ Authorization: `Token ${apiKey}`,
21
+ },
22
+ signal: signal,
23
+ body: JSON.stringify(data),
24
+ });
25
+
26
+ if (response.status === 201) {
27
+ return await response.json();
28
+ } else {
29
+ throw new Error(`Error: ${response.statusText}`);
30
+ }
31
+ }
@@ -1,12 +1,12 @@
1
- export async function getOpenpayDeviceSessionID(
2
- merchant_id: string,
3
- public_key: string,
4
- isSandbox: boolean = true,
5
- signal: AbortSignal | null = null,
6
- ): Promise<string> {
7
- let openpay = await window.OpenPay;
8
- openpay.setId(merchant_id);
9
- openpay.setApiKey(public_key);
10
- openpay.setSandboxMode(isSandbox);
11
- return await openpay.deviceData.setup({ signal });
12
- }
1
+ export async function getOpenpayDeviceSessionID(
2
+ merchant_id: string,
3
+ public_key: string,
4
+ isSandbox: boolean = true,
5
+ signal: AbortSignal | null = null,
6
+ ): Promise<string> {
7
+ let openpay = await window.OpenPay;
8
+ openpay.setId(merchant_id);
9
+ openpay.setApiKey(public_key);
10
+ openpay.setSandboxMode(isSandbox);
11
+ return await openpay.deviceData.setup({ signal });
12
+ }
@@ -1,37 +1,37 @@
1
- import {
2
- buildErrorResponse,
3
- buildErrorResponseFromCatch,
4
- } from "../helpers/utils";
5
- import {IPaymentMethodResponse} from "../types/paymentMethod";
6
-
7
- export async function fetchCustomerPaymentMethods(
8
- baseUrl: string,
9
- apiKey: string,
10
- params = {
11
- status: "active",
12
- pagesize: "10000",
13
- },
14
- signal = null,
15
- ): Promise<IPaymentMethodResponse> {
16
- try {
17
- const queryString = new URLSearchParams(params).toString();
18
-
19
- const response = await fetch(
20
- `${baseUrl}/api/v1/payment_methods?${queryString}`,
21
- {
22
- method: "GET",
23
- headers: {
24
- Authorization: `Token ${apiKey}`,
25
- "Content-Type": "application/json",
26
- },
27
- signal,
28
- },
29
- );
30
-
31
- if (response.ok) return await response.json();
32
- const res_json = await response.json();
33
- throw await buildErrorResponse(response, res_json);
34
- } catch (error) {
35
- throw buildErrorResponseFromCatch(error);
36
- }
37
- }
1
+ import {
2
+ buildErrorResponse,
3
+ buildErrorResponseFromCatch,
4
+ } from "../helpers/utils";
5
+ import {IPaymentMethodResponse} from "../types/paymentMethod";
6
+
7
+ export async function fetchCustomerPaymentMethods(
8
+ baseUrl: string,
9
+ apiKey: string,
10
+ params = {
11
+ status: "active",
12
+ pagesize: "10000",
13
+ },
14
+ signal = null,
15
+ ): Promise<IPaymentMethodResponse> {
16
+ try {
17
+ const queryString = new URLSearchParams(params).toString();
18
+
19
+ const response = await fetch(
20
+ `${baseUrl}/api/v1/payment_methods?${queryString}`,
21
+ {
22
+ method: "GET",
23
+ headers: {
24
+ Authorization: `Token ${apiKey}`,
25
+ "Content-Type": "application/json",
26
+ },
27
+ signal,
28
+ },
29
+ );
30
+
31
+ if (response.ok) return await response.json();
32
+ const res_json = await response.json();
33
+ throw await buildErrorResponse(response, res_json);
34
+ } catch (error) {
35
+ throw buildErrorResponseFromCatch(error);
36
+ }
37
+ }
@@ -1,20 +1,20 @@
1
- export async function getVaultToken(
2
- baseUrl: string,
3
- apiKey: string,
4
- signal = null,
5
- ) {
6
- const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
7
- method: "GET",
8
- headers: {
9
- Authorization: `Token ${apiKey}`,
10
- },
11
- signal: signal,
12
- });
13
-
14
- if (response.ok) {
15
- const responseBody = await response.json();
16
- return responseBody.token;
17
- } else {
18
- throw new Error("Failed to retrieve bearer token");
19
- }
20
- }
1
+ export async function getVaultToken(
2
+ baseUrl: string,
3
+ apiKey: string,
4
+ signal = null,
5
+ ) {
6
+ const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
7
+ method: "GET",
8
+ headers: {
9
+ Authorization: `Token ${apiKey}`,
10
+ },
11
+ signal: signal,
12
+ });
13
+
14
+ if (response.ok) {
15
+ const responseBody = await response.json();
16
+ return responseBody.token;
17
+ } else {
18
+ throw new Error("Failed to retrieve bearer token");
19
+ }
20
+ }