tonder-web-sdk 1.15.2 → 1.16.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.
Files changed (46) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/.prettierignore +8 -0
  3. package/.prettierrc +10 -0
  4. package/README.md +189 -35
  5. package/eslint.config.mjs +15 -0
  6. package/package.json +21 -4
  7. package/src/classes/3dsHandler.js +58 -62
  8. package/src/classes/BaseInlineCheckout.js +21 -36
  9. package/src/classes/LiteInlineCheckout.js +8 -8
  10. package/src/classes/checkout.js +75 -71
  11. package/src/classes/globalLoader.js +9 -7
  12. package/src/classes/inlineCheckout.js +528 -250
  13. package/src/data/apmApi.js +8 -14
  14. package/src/data/businessApi.js +5 -8
  15. package/src/data/cardApi.js +5 -14
  16. package/src/data/checkoutApi.js +54 -54
  17. package/src/data/customerApi.js +1 -6
  18. package/src/data/index.js +15 -15
  19. package/src/data/openPayApi.js +7 -7
  20. package/src/data/skyflowApi.js +14 -16
  21. package/src/helpers/skyflow.js +210 -119
  22. package/src/helpers/styles.js +56 -27
  23. package/src/helpers/template-skeleton.js +1 -1
  24. package/src/helpers/template.js +984 -541
  25. package/src/helpers/utils.js +152 -58
  26. package/src/helpers/validations.js +34 -35
  27. package/src/index-dev.js +38 -11
  28. package/src/index.html +20 -12
  29. package/src/index.js +19 -13
  30. package/src/shared/catalog/commonLogosCatalog.js +7 -0
  31. package/src/shared/catalog/paymentMethodsCatalog.js +242 -243
  32. package/src/shared/constants/colors.js +15 -0
  33. package/src/shared/constants/displayMode.js +4 -0
  34. package/src/shared/constants/fieldPathNames.js +4 -0
  35. package/src/shared/constants/htmlTonderIds.js +18 -0
  36. package/src/shared/constants/messages.js +10 -9
  37. package/types/card.d.ts +17 -17
  38. package/types/checkout.d.ts +85 -87
  39. package/types/common.d.ts +4 -1
  40. package/types/customer.d.ts +10 -10
  41. package/types/index.d.ts +9 -11
  42. package/types/inlineCheckout.d.ts +81 -61
  43. package/types/liteInlineCheckout.d.ts +78 -83
  44. package/types/paymentMethod.d.ts +17 -17
  45. package/types/transaction.d.ts +94 -94
  46. package/v1/bundle.min.js +3 -3
@@ -1,7 +1,4 @@
1
- import {
2
- buildErrorResponse,
3
- buildErrorResponseFromCatch,
4
- } from "../helpers/utils";
1
+ import { buildErrorResponse, buildErrorResponseFromCatch } from "../helpers/utils";
5
2
 
6
3
  /**
7
4
  * Fetches Alternative Payment Methods (APMs) of a customer.
@@ -23,17 +20,14 @@ export async function fetchCustomerAPMs(
23
20
  try {
24
21
  const queryString = new URLSearchParams(params).toString();
25
22
 
26
- const response = await fetch(
27
- `${baseUrl}/api/v1/payment_methods?${queryString}`,
28
- {
29
- method: "GET",
30
- headers: {
31
- Authorization: `Token ${apiKey}`,
32
- "Content-Type": "application/json",
33
- },
34
- signal,
23
+ const response = await fetch(`${baseUrl}/api/v1/payment_methods?${queryString}`, {
24
+ method: "GET",
25
+ headers: {
26
+ Authorization: `Token ${apiKey}`,
27
+ "Content-Type": "application/json",
35
28
  },
36
- );
29
+ signal,
30
+ });
37
31
 
38
32
  if (response.ok) return await response.json();
39
33
  const res_json = await response.json();
@@ -6,14 +6,11 @@
6
6
  * @returns {Promise<Object>} The business information.
7
7
  */
8
8
  export async function fetchBusiness(baseUrl, apiKey, signal) {
9
- const getBusiness = await fetch(
10
- `${baseUrl}/api/v1/payments/business/${apiKey}`,
11
- {
12
- headers: {
13
- Authorization: `Token ${apiKey}`,
14
- },
15
- signal: signal,
9
+ const getBusiness = await fetch(`${baseUrl}/api/v1/payments/business/${apiKey}`, {
10
+ headers: {
11
+ Authorization: `Token ${apiKey}`,
16
12
  },
17
- );
13
+ signal: signal,
14
+ });
18
15
  return await getBusiness.json();
19
16
  }
@@ -1,8 +1,5 @@
1
- import {
2
- buildErrorResponse,
3
- buildErrorResponseFromCatch,
4
- } from "../helpers/utils";
5
- import {MESSAGES} from "../shared/constants/messages";
1
+ import { buildErrorResponse, buildErrorResponseFromCatch } from "../helpers/utils";
2
+ import { MESSAGES } from "../shared/constants/messages";
6
3
 
7
4
  /**
8
5
  * Saves or updates a customer's card information.
@@ -18,13 +15,7 @@ import {MESSAGES} from "../shared/constants/messages";
18
15
  *
19
16
  * @throws {import("../../types").IApiError} Throws an error object if the save/update operation fails.
20
17
  */
21
- export async function saveCustomerCard(
22
- baseUrl,
23
- customerToken,
24
- secureToken,
25
- businessId,
26
- data,
27
- ) {
18
+ export async function saveCustomerCard(baseUrl, customerToken, secureToken, businessId, data) {
28
19
  try {
29
20
  const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
30
21
  const response = await fetch(url, {
@@ -86,7 +77,7 @@ export async function removeCustomerCard(
86
77
  },
87
78
  });
88
79
 
89
- if(response.status === 204) return MESSAGES.cardSaved;
80
+ if (response.status === 204) return MESSAGES.cardSaved;
90
81
  if (response.ok && "json" in response) return await response.json();
91
82
  const res_json = await response.json();
92
83
 
@@ -112,7 +103,7 @@ export async function fetchCustomerCards(
112
103
  customerToken,
113
104
  secureToken,
114
105
  businessId,
115
- signal= null,
106
+ signal = null,
116
107
  ) {
117
108
  try {
118
109
  const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
@@ -6,22 +6,22 @@
6
6
  * @returns {Promise<Object>} The created order data.
7
7
  */
8
8
  export async function createOrder(baseUrl, apiKey, orderItems) {
9
- const url = `${baseUrl}/api/v1/orders/`;
10
- const data = orderItems;
11
- const response = await fetch(url, {
12
- method: "POST",
13
- headers: {
14
- "Content-Type": "application/json",
15
- Authorization: `Token ${apiKey}`,
16
- },
17
- body: JSON.stringify(data),
18
- });
19
- if (response.status === 201) {
20
- const jsonResponse = await response.json();
21
- return jsonResponse;
22
- } else {
23
- throw new Error(`Error: ${response.statusText}`);
24
- }
9
+ const url = `${baseUrl}/api/v1/orders/`;
10
+ const data = orderItems;
11
+ const response = await fetch(url, {
12
+ method: "POST",
13
+ headers: {
14
+ "Content-Type": "application/json",
15
+ Authorization: `Token ${apiKey}`,
16
+ },
17
+ body: JSON.stringify(data),
18
+ });
19
+ if (response.status === 201) {
20
+ const jsonResponse = await response.json();
21
+ return jsonResponse;
22
+ } else {
23
+ throw new Error(`Error: ${response.statusText}`);
24
+ }
25
25
  }
26
26
 
27
27
  /**
@@ -32,22 +32,22 @@ export async function createOrder(baseUrl, apiKey, orderItems) {
32
32
  * @returns {Promise<Object>} The created payment data.
33
33
  */
34
34
  export async function createPayment(baseUrl, apiKey, paymentItems) {
35
- const url = `${baseUrl}/api/v1/business/${paymentItems.business_pk}/payments/`;
36
- const data = paymentItems;
37
- const response = await fetch(url, {
38
- method: "POST",
39
- headers: {
40
- "Content-Type": "application/json",
41
- Authorization: `Token ${apiKey}`,
42
- },
43
- body: JSON.stringify(data),
44
- });
45
- if (response.status >= 200 && response.status <=299) {
46
- const jsonResponse = await response.json();
47
- return jsonResponse;
48
- } else {
49
- throw new Error(`Error: ${response.statusText}`);
50
- }
35
+ const url = `${baseUrl}/api/v1/business/${paymentItems.business_pk}/payments/`;
36
+ const data = paymentItems;
37
+ const response = await fetch(url, {
38
+ method: "POST",
39
+ headers: {
40
+ "Content-Type": "application/json",
41
+ Authorization: `Token ${apiKey}`,
42
+ },
43
+ body: JSON.stringify(data),
44
+ });
45
+ if (response.status >= 200 && response.status <= 299) {
46
+ const jsonResponse = await response.json();
47
+ return jsonResponse;
48
+ } else {
49
+ throw new Error(`Error: ${response.statusText}`);
50
+ }
51
51
  }
52
52
 
53
53
  /**
@@ -67,26 +67,26 @@ export async function createPayment(baseUrl, apiKey, paymentItems) {
67
67
  * @property {import("../../types").IStartCheckoutErrorResponse} error.details - The response body from the server when an error occurs.
68
68
  */
69
69
  export async function startCheckoutRouter(baseUrl, apiKey, routerItems) {
70
- try {
71
- const url = `${baseUrl}/api/v1/checkout-router/`;
72
- const data = routerItems;
73
- const response = await fetch(url, {
74
- method: "POST",
75
- headers: {
76
- "Content-Type": "application/json",
77
- Authorization: `Token ${apiKey}`,
78
- },
79
- body: JSON.stringify(data),
80
- });
81
- if (response.status >= 200 && response.status <= 299) {
82
- return await response.json();
83
- } else {
84
- const errorResponse = await response.json();
85
- const error = new Error("Failed to start checkout router");
86
- error.details = errorResponse;
87
- throw error;
88
- }
89
- } catch (error) {
90
- throw error
70
+ try {
71
+ const url = `${baseUrl}/api/v1/checkout-router/`;
72
+ const data = routerItems;
73
+ const response = await fetch(url, {
74
+ method: "POST",
75
+ headers: {
76
+ "Content-Type": "application/json",
77
+ Authorization: `Token ${apiKey}`,
78
+ },
79
+ body: JSON.stringify(data),
80
+ });
81
+ if (response.status >= 200 && response.status <= 299) {
82
+ return await response.json();
83
+ } else {
84
+ const errorResponse = await response.json();
85
+ const error = new Error("Failed to start checkout router");
86
+ error.details = errorResponse;
87
+ throw error;
91
88
  }
92
- }
89
+ } catch (error) {
90
+ throw error;
91
+ }
92
+ }
@@ -6,12 +6,7 @@
6
6
  * @param {AbortSignal} signal - The abort signal to cancel the request.
7
7
  * @returns {Promise<Object>} The registered or fetched customer data.
8
8
  */
9
- export async function registerOrFetchCustomer(
10
- baseUrl,
11
- apiKey,
12
- customer,
13
- signal = null,
14
- ) {
9
+ export async function registerOrFetchCustomer(baseUrl, apiKey, customer, signal = null) {
15
10
  const url = `${baseUrl}/api/v1/customer/`;
16
11
  const data = {
17
12
  email: customer.email,
package/src/data/index.js CHANGED
@@ -1,17 +1,17 @@
1
- import { fetchBusiness } from './businessApi';
2
- import { registerOrFetchCustomer } from './customerApi';
3
- import { createOrder } from './checkoutApi';
4
- import { saveCustomerCard, removeCustomerCard, fetchCustomerCards } from './cardApi';
5
- import { fetchCustomerAPMs } from './apmApi';
6
- import { getOpenpayDeviceSessionID } from './openPayApi';
1
+ import { fetchBusiness } from "./businessApi";
2
+ import { registerOrFetchCustomer } from "./customerApi";
3
+ import { createOrder } from "./checkoutApi";
4
+ import { saveCustomerCard, removeCustomerCard, fetchCustomerCards } from "./cardApi";
5
+ import { fetchCustomerAPMs } from "./apmApi";
6
+ import { getOpenpayDeviceSessionID } from "./openPayApi";
7
7
 
8
8
  export {
9
- registerOrFetchCustomer,
10
- createOrder,
11
- saveCustomerCard,
12
- removeCustomerCard,
13
- fetchCustomerCards,
14
- fetchBusiness,
15
- fetchCustomerAPMs,
16
- getOpenpayDeviceSessionID
17
- };
9
+ registerOrFetchCustomer,
10
+ createOrder,
11
+ saveCustomerCard,
12
+ removeCustomerCard,
13
+ fetchCustomerCards,
14
+ fetchBusiness,
15
+ fetchCustomerAPMs,
16
+ getOpenpayDeviceSessionID,
17
+ };
@@ -7,10 +7,10 @@
7
7
  */
8
8
 
9
9
  export async function getOpenpayDeviceSessionID(merchant_id, public_key, signal) {
10
- let openpay = await window.OpenPay;
11
- openpay.setId(merchant_id);
12
- openpay.setApiKey(public_key);
13
- openpay.setSandboxMode(true);
14
- var response = await openpay.deviceData.setup({signal});
15
- return response;
16
- }
10
+ let openpay = await window.OpenPay;
11
+ openpay.setId(merchant_id);
12
+ openpay.setApiKey(public_key);
13
+ openpay.setSandboxMode(true);
14
+ var response = await openpay.deviceData.setup({ signal });
15
+ return response;
16
+ }
@@ -1,18 +1,16 @@
1
+ export async function getVaultToken(baseUrl, apiKey, signal = null) {
2
+ const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
3
+ method: "GET",
4
+ headers: {
5
+ Authorization: `Token ${apiKey}`,
6
+ },
7
+ signal: signal,
8
+ });
1
9
 
2
-
3
- export async function getVaultToken (baseUrl, apiKey, signal = null){
4
- const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
5
- method: 'GET',
6
- headers: {
7
- 'Authorization': `Token ${apiKey}`,
8
- },
9
- signal: signal,
10
- });
11
-
12
- if (response.ok) {
13
- const responseBody = await response.json();
14
- return responseBody.token;
15
- } else {
16
- throw new Error('Failed to retrieve bearer token');
17
- }
10
+ if (response.ok) {
11
+ const responseBody = await response.json();
12
+ return responseBody.token;
13
+ } else {
14
+ throw new Error("Failed to retrieve bearer token");
15
+ }
18
16
  }