@tonder.io/ionic-lite-sdk 0.0.35-beta.8 → 0.0.37-beta.1
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/.gitlab-ci.yml +28 -28
- package/README.md +532 -202
- package/dist/classes/BaseInlineCheckout.d.ts +21 -19
- package/dist/classes/errorResponse.d.ts +1 -1
- package/dist/classes/liteCheckout.d.ts +15 -43
- package/dist/data/api.d.ts +1 -1
- package/dist/data/businessApi.d.ts +1 -1
- package/dist/data/cardApi.d.ts +1 -1
- package/dist/data/checkoutApi.d.ts +2 -1
- package/dist/data/customerApi.d.ts +1 -1
- package/dist/data/paymentMethodApi.d.ts +2 -2
- package/dist/helpers/skyflow.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/card.d.ts +1 -0
- package/dist/types/checkout.d.ts +7 -1
- package/dist/types/commons.d.ts +8 -3
- package/dist/types/customer.d.ts +10 -0
- package/{src → dist}/types/liteInlineCheckout.d.ts +33 -73
- package/dist/types/responses.d.ts +3 -0
- package/jest.config.ts +14 -14
- package/package.json +41 -38
- package/rollup.config.js +16 -16
- package/src/classes/3dsHandler.ts +237 -237
- package/src/classes/BaseInlineCheckout.ts +385 -356
- package/src/classes/errorResponse.ts +16 -16
- package/src/classes/liteCheckout.ts +588 -598
- package/src/data/api.ts +20 -20
- package/src/data/businessApi.ts +18 -18
- package/src/data/cardApi.ts +85 -89
- package/src/data/checkoutApi.ts +84 -87
- package/src/data/customerApi.ts +31 -31
- package/src/data/openPayApi.ts +12 -12
- package/src/data/paymentMethodApi.ts +37 -37
- package/src/data/skyflowApi.ts +20 -20
- package/src/helpers/constants.ts +63 -63
- package/src/helpers/mercadopago.ts +15 -15
- package/src/helpers/skyflow.ts +91 -91
- package/src/helpers/utils.ts +120 -120
- package/src/helpers/validations.ts +55 -55
- package/src/index.ts +12 -10
- package/src/shared/catalog/paymentMethodsCatalog.ts +247 -247
- package/src/shared/constants/messages.ts +10 -10
- package/src/shared/constants/paymentMethodAPM.ts +63 -63
- package/src/shared/constants/tonderUrl.ts +8 -8
- package/src/types/card.ts +35 -34
- package/src/types/checkout.ts +123 -117
- package/src/types/commons.ts +130 -125
- package/src/types/customer.ts +22 -12
- package/src/types/liteInlineCheckout.ts +216 -0
- package/src/types/paymentMethod.ts +23 -23
- package/src/types/requests.ts +114 -114
- package/src/types/responses.ts +193 -189
- package/src/types/skyflow.ts +17 -17
- package/src/types/transaction.ts +101 -101
- package/src/types/validations.d.ts +11 -11
- package/tests/classes/liteCheckout.test.ts +57 -57
- package/tests/methods/createOrder.test.ts +141 -142
- package/tests/methods/createPayment.test.ts +121 -122
- package/tests/methods/customerRegister.test.ts +118 -119
- package/tests/methods/getBusiness.test.ts +114 -115
- package/tests/methods/getCustomerCards.test.ts +112 -113
- package/tests/methods/registerCustomerCard.test.ts +117 -117
- package/tests/methods/startCheckoutRouter.test.ts +119 -119
- package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
- package/tests/utils/defaultMock.ts +21 -21
- package/tests/utils/mockClasses.ts +659 -659
- package/tsconfig.json +18 -18
- package/types/classes/liteCheckout.d.ts +29 -0
- package/types/classes/liteCheckout.js +225 -0
- package/types/classes/liteCheckout.js.map +1 -0
- package/types/helpers/utils.d.ts +3 -0
- package/types/helpers/utils.js +27 -0
- package/types/helpers/utils.js.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.js +6 -0
- package/types/index.js.map +1 -0
- package/.idea/aws.xml +0 -17
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/prettier.xml +0 -6
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -133
- package/src/types/index.d.ts +0 -10
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,
|
|
4
|
-
try {
|
|
5
|
-
const response = await fetch(
|
|
6
|
-
`${baseUrlTonder}/api/v1/payment_methods${query}`,
|
|
7
|
-
{
|
|
8
|
-
method: 'GET',
|
|
9
|
-
headers: {
|
|
10
|
-
Authorization: `Token ${
|
|
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
|
}
|
package/src/data/businessApi.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
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
|
+
}
|
package/src/data/cardApi.ts
CHANGED
|
@@ -1,89 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildErrorResponse,
|
|
3
|
-
buildErrorResponseFromCatch,
|
|
4
|
-
} from "../helpers/utils";
|
|
5
|
-
import {
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} catch (error) {
|
|
87
|
-
throw buildErrorResponseFromCatch(error);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
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
|
+
customerToken: string,
|
|
36
|
+
businessId: string | number,
|
|
37
|
+
data: ISaveCardSkyflowRequest,
|
|
38
|
+
): Promise<ISaveCardResponse> {
|
|
39
|
+
try {
|
|
40
|
+
const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: {
|
|
44
|
+
Authorization: `Token ${customerToken}`,
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(data),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (response.ok) return await response.json();
|
|
51
|
+
|
|
52
|
+
const res_json = await response.json();
|
|
53
|
+
|
|
54
|
+
throw await buildErrorResponse(response, res_json);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw buildErrorResponseFromCatch(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function removeCustomerCard(
|
|
61
|
+
baseUrl: string,
|
|
62
|
+
customerToken: string,
|
|
63
|
+
skyflowId = "",
|
|
64
|
+
businessId: string | number,
|
|
65
|
+
): Promise<string> {
|
|
66
|
+
try {
|
|
67
|
+
const url = `${baseUrl}/api/v1/business/${businessId}/cards/${skyflowId}`;
|
|
68
|
+
|
|
69
|
+
const response = await fetch(url, {
|
|
70
|
+
method: "DELETE",
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: `Token ${customerToken}`,
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (response.status === 204) return MESSAGES.cardSaved;
|
|
78
|
+
if (response.ok && "json" in response) return await response.json();
|
|
79
|
+
const res_json = await response.json();
|
|
80
|
+
|
|
81
|
+
throw await buildErrorResponse(response, res_json);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw buildErrorResponseFromCatch(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/data/checkoutApi.ts
CHANGED
|
@@ -1,87 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
orderItems
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
paymentItems
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
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
|
+
}
|
package/src/data/customerApi.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import {
|
|
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
|
+
}
|
package/src/data/openPayApi.ts
CHANGED
|
@@ -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 {
|
|
6
|
-
|
|
7
|
-
export async function
|
|
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
|
+
}
|
package/src/data/skyflowApi.ts
CHANGED
|
@@ -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
|
+
}
|