@tonder.io/ionic-lite-sdk 0.0.34-beta.3 → 0.0.35-beta.0

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 (61) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/.idea/workspace.xml +72 -17
  5. package/dist/classes/BaseInlineCheckout.d.ts +48 -0
  6. package/dist/classes/liteCheckout.d.ts +60 -29
  7. package/dist/data/businessApi.d.ts +2 -0
  8. package/dist/data/cardApi.d.ts +4 -0
  9. package/dist/data/checkoutApi.d.ts +5 -0
  10. package/dist/data/customerApi.d.ts +2 -0
  11. package/dist/data/openPayApi.d.ts +1 -0
  12. package/dist/data/paymentMethodApi.d.ts +5 -0
  13. package/dist/data/skyflowApi.d.ts +1 -0
  14. package/dist/helpers/skyflow.d.ts +3 -0
  15. package/dist/helpers/utils.d.ts +8 -4
  16. package/dist/helpers/validations.d.ts +6 -0
  17. package/dist/index.js +1 -1
  18. package/dist/shared/catalog/paymentMethodsCatalog.d.ts +1 -0
  19. package/dist/shared/constants/messages.d.ts +11 -0
  20. package/dist/shared/constants/paymentMethodAPM.d.ts +62 -0
  21. package/dist/shared/constants/tonderUrl.d.ts +7 -0
  22. package/dist/types/card.d.ts +29 -0
  23. package/dist/types/checkout.d.ts +103 -0
  24. package/dist/types/commons.d.ts +27 -0
  25. package/dist/types/customer.d.ts +12 -0
  26. package/dist/types/paymentMethod.d.ts +22 -0
  27. package/dist/types/requests.d.ts +5 -3
  28. package/package.json +1 -1
  29. package/src/classes/BaseInlineCheckout.ts +318 -0
  30. package/src/classes/liteCheckout.ts +254 -280
  31. package/src/data/businessApi.ts +14 -0
  32. package/src/data/cardApi.ts +82 -0
  33. package/src/data/checkoutApi.ts +71 -0
  34. package/src/data/customerApi.ts +31 -0
  35. package/src/data/openPayApi.ts +7 -0
  36. package/src/data/paymentMethodApi.ts +34 -0
  37. package/src/data/skyflowApi.ts +16 -0
  38. package/src/helpers/skyflow.ts +85 -0
  39. package/src/helpers/utils.ts +31 -243
  40. package/src/helpers/validations.ts +55 -0
  41. package/src/shared/catalog/paymentMethodsCatalog.ts +248 -0
  42. package/src/shared/constants/messages.ts +11 -0
  43. package/src/shared/constants/paymentMethodAPM.ts +63 -0
  44. package/src/shared/constants/tonderUrl.ts +8 -0
  45. package/src/types/card.ts +34 -0
  46. package/src/types/checkout.ts +118 -0
  47. package/src/types/commons.ts +32 -0
  48. package/src/types/customer.ts +12 -0
  49. package/src/types/index.d.ts +10 -0
  50. package/src/types/liteInlineCheckout.d.ts +183 -0
  51. package/src/types/paymentMethod.ts +24 -0
  52. package/src/types/requests.ts +5 -3
  53. package/src/types/validations.d.ts +11 -0
  54. package/tests/classes/liteCheckout.test.ts +3 -3
  55. package/tests/methods/getBusiness.test.ts +2 -2
  56. package/tests/methods/getCustomerCards.test.ts +4 -8
  57. package/tests/utils/defaultMock.ts +3 -2
  58. package/tests/utils/mockClasses.ts +4 -0
  59. package/tests/methods/getOpenpayDeviceSessionID.test.ts +0 -95
  60. package/tests/methods/getSkyflowToken.test.ts +0 -155
  61. package/tests/methods/getVaultToken.test.ts +0 -107
@@ -0,0 +1,14 @@
1
+ import {GetBusinessResponse} from "../types/responses";
2
+
3
+ export async function fetchBusiness(baseUrl: string, apiKey: string, signal: AbortSignal): Promise<GetBusinessResponse> {
4
+ const getBusiness = await fetch(
5
+ `${baseUrl}/api/v1/payments/business/${apiKey}`,
6
+ {
7
+ headers: {
8
+ Authorization: `Token ${apiKey}`,
9
+ },
10
+ signal: signal,
11
+ }
12
+ );
13
+ return await getBusiness.json();
14
+ }
@@ -0,0 +1,82 @@
1
+ import {buildErrorResponse, buildErrorResponseFromCatch} from "../helpers/utils";
2
+ import {ICustomerCardsResponse, ISaveCardResponse, ISaveCardSkyflowRequest} from "../types/card";
3
+ import {MESSAGES} from "../shared/constants/messages";
4
+
5
+ export async function fetchCustomerCards(
6
+ baseUrl: string,
7
+ customerToken: string,
8
+ businessId: string | number,
9
+ signal= null,
10
+ ): Promise<ICustomerCardsResponse> {
11
+ try {
12
+ const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
13
+ const response = await fetch(url, {
14
+ method: "GET",
15
+ headers: {
16
+ Authorization: `Token ${customerToken}`,
17
+ "Content-Type": "application/json",
18
+ },
19
+ signal,
20
+ });
21
+ if (response.ok) return await response.json();
22
+ const res_json = await response.json();
23
+
24
+ throw await buildErrorResponse(response, res_json);
25
+ } catch (error) {
26
+ throw buildErrorResponseFromCatch(error);
27
+ }
28
+ }
29
+
30
+ export async function saveCustomerCard(
31
+ baseUrl: string,
32
+ customerToken: string,
33
+ businessId: string | number,
34
+ data: ISaveCardSkyflowRequest,
35
+ ): Promise<ISaveCardResponse> {
36
+ try {
37
+ const url = `${baseUrl}/api/v1/business/${businessId}/cards/`;
38
+ const response = await fetch(url, {
39
+ method: "POST",
40
+ headers: {
41
+ Authorization: `Token ${customerToken}`,
42
+ "Content-Type": "application/json",
43
+ },
44
+ body: JSON.stringify(data),
45
+ });
46
+
47
+ if (response.ok) return await response.json();
48
+
49
+ const res_json = await response.json();
50
+
51
+ throw await buildErrorResponse(response, res_json);
52
+ } catch (error) {
53
+ throw buildErrorResponseFromCatch(error);
54
+ }
55
+ }
56
+
57
+ export async function removeCustomerCard(
58
+ baseUrl: string,
59
+ customerToken: string,
60
+ skyflowId = "",
61
+ businessId: string | number,
62
+ ): Promise<string> {
63
+ try {
64
+ const url = `${baseUrl}/api/v1/business/${businessId}/cards/${skyflowId}`;
65
+
66
+ const response = await fetch(url, {
67
+ method: "DELETE",
68
+ headers: {
69
+ Authorization: `Token ${customerToken}`,
70
+ "Content-Type": "application/json",
71
+ },
72
+ });
73
+
74
+ if(response.status === 204) return MESSAGES.cardSaved;
75
+ if (response.ok && "json" in response) return await response.json();
76
+ const res_json = await response.json();
77
+
78
+ throw await buildErrorResponse(response, res_json);
79
+ } catch (error) {
80
+ throw buildErrorResponseFromCatch(error);
81
+ }
82
+ }
@@ -0,0 +1,71 @@
1
+ declare const MP_DEVICE_SESSION_ID: string | undefined;
2
+
3
+ import {
4
+ CreateOrderRequest,
5
+ CreatePaymentRequest,
6
+ } from "../types/requests";
7
+ import {IStartCheckoutIdRequest, IStartCheckoutRequest} from "../types/checkout";
8
+
9
+
10
+
11
+ export async function createOrder(baseUrl: string, apiKey: string, orderItems: CreateOrderRequest) {
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(baseUrl: string, apiKey: string, paymentItems: CreatePaymentRequest) {
30
+ const url = `${baseUrl}/api/v1/business/${paymentItems.business_pk}/payments/`;
31
+ const data = paymentItems;
32
+ const response = await fetch(url, {
33
+ method: "POST",
34
+ headers: {
35
+ "Content-Type": "application/json",
36
+ Authorization: `Token ${apiKey}`,
37
+ },
38
+ body: JSON.stringify(data),
39
+ });
40
+ if (response.status >= 200 && response.status <=299) {
41
+ return await response.json();
42
+ } else {
43
+ throw new Error(`Error: ${response.statusText}`);
44
+ }
45
+ }
46
+
47
+ export async function startCheckoutRouter(baseUrl: string, apiKey: string, routerItems: IStartCheckoutRequest | IStartCheckoutIdRequest) {
48
+ try {
49
+ const url = `${baseUrl}/api/v1/checkout-router/`;
50
+ const data = routerItems;
51
+ const response = await fetch(url, {
52
+ method: "POST",
53
+ headers: {
54
+ "Content-Type": "application/json",
55
+ Authorization: `Token ${apiKey}`,
56
+ },
57
+ body: JSON.stringify({...data, ...(typeof MP_DEVICE_SESSION_ID !== "undefined" ? {mp_device_session_id: MP_DEVICE_SESSION_ID}:{})}),
58
+ });
59
+ if (response.status >= 200 && response.status <= 299) {
60
+ return await response.json();
61
+ } else {
62
+ const errorResponse = await response.json();
63
+ const error = new Error("Failed to start checkout router");
64
+ // @ts-ignore
65
+ error.details = errorResponse;
66
+ throw error;
67
+ }
68
+ } catch (error) {
69
+ throw error
70
+ }
71
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,7 @@
1
+ export async function getOpenpayDeviceSessionID(merchant_id: string, public_key: string, isSandbox: boolean = true, signal: AbortSignal | null = null): Promise<string> {
2
+ let openpay = await window.OpenPay;
3
+ openpay.setId(merchant_id);
4
+ openpay.setApiKey(public_key);
5
+ openpay.setSandboxMode(isSandbox);
6
+ return await openpay.deviceData.setup({signal});
7
+ }
@@ -0,0 +1,34 @@
1
+ import {buildErrorResponse, buildErrorResponseFromCatch} from "../helpers/utils";
2
+ import {IPaymentMethodResponse} from "../types/paymentMethod";
3
+
4
+ export async function fetchCustomerAPMs(
5
+ baseUrl: string,
6
+ apiKey: string,
7
+ params = {
8
+ status: "active",
9
+ pagesize: "10000",
10
+ },
11
+ signal = null,
12
+ ): Promise<IPaymentMethodResponse> {
13
+ try {
14
+ const queryString = new URLSearchParams(params).toString();
15
+
16
+ const response = await fetch(
17
+ `${baseUrl}/api/v1/payment_methods?${queryString}`,
18
+ {
19
+ method: "GET",
20
+ headers: {
21
+ Authorization: `Token ${apiKey}`,
22
+ "Content-Type": "application/json",
23
+ },
24
+ signal,
25
+ },
26
+ );
27
+
28
+ if (response.ok) return await response.json();
29
+ const res_json = await response.json();
30
+ throw await buildErrorResponse(response, res_json);
31
+ } catch (error) {
32
+ throw buildErrorResponseFromCatch(error);
33
+ }
34
+ }
@@ -0,0 +1,16 @@
1
+ export async function getVaultToken (baseUrl: string, apiKey: string, 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
+ });
9
+
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
+ }
16
+ }
@@ -0,0 +1,85 @@
1
+ import {TokensRequest} from "../types/requests";
2
+ import {ErrorResponse} from "../classes/errorResponse";
3
+ import Skyflow from "skyflow-js";
4
+ import CollectContainer from "skyflow-js/types/core/external/collect/collect-container";
5
+ import {buildErrorResponseFromCatch} from "./utils";
6
+ import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
7
+ import {getVaultToken} from "../data/skyflowApi";
8
+
9
+ export async function getSkyflowTokens({
10
+ baseUrl,
11
+ apiKey,
12
+ vault_id,
13
+ vault_url,
14
+ data,
15
+ }: TokensRequest): Promise<any | ErrorResponse> {
16
+ const skyflow = Skyflow.init({
17
+ vaultID: vault_id,
18
+ vaultURL: vault_url,
19
+ getBearerToken: async () => await getVaultToken(baseUrl, apiKey),
20
+ options: {
21
+ logLevel: Skyflow.LogLevel.ERROR,
22
+ env: Skyflow.Env.DEV,
23
+ },
24
+ });
25
+
26
+ const collectContainer: CollectContainer = skyflow.container(
27
+ Skyflow.ContainerType.COLLECT
28
+ ) as CollectContainer;
29
+
30
+ const fieldPromises = await getFieldsPromise(data, collectContainer);
31
+
32
+ const result = await Promise.all(fieldPromises);
33
+
34
+ const mountFail = result.some((item: boolean) => !item);
35
+
36
+ if (mountFail) {
37
+ throw buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));
38
+ } else {
39
+ try {
40
+ const collectResponseSkyflowTonder = await collectContainer.collect() as any;
41
+ if (collectResponseSkyflowTonder) return collectResponseSkyflowTonder["records"][0]["fields"];
42
+ throw buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))
43
+ } catch (error) {
44
+ throw buildErrorResponseFromCatch(error);
45
+ }
46
+ }
47
+ }
48
+
49
+ async function getFieldsPromise(data: any, collectContainer: CollectContainer): Promise<Promise<boolean>[]> {
50
+ const fields = await getFields(data, collectContainer);
51
+ if (!fields) return [];
52
+
53
+ return fields.map((field: { element: CollectElement, key: string }) => {
54
+ return new Promise((resolve) => {
55
+ const div = document.createElement("div");
56
+ div.hidden = true;
57
+ div.id = `id-${field.key}`;
58
+ document.querySelector(`body`)?.appendChild(div);
59
+ setTimeout(() => {
60
+ field.element.mount(`#id-${field.key}`);
61
+ setInterval(() => {
62
+ if (field.element.isMounted()) {
63
+ const value = data[field.key];
64
+ field.element.update({ value: value });
65
+ return resolve(field.element.isMounted());
66
+ }
67
+ }, 120);
68
+ }, 120);
69
+ });
70
+ })
71
+ }
72
+
73
+ async function getFields(data: any, collectContainer: CollectContainer): Promise<{ element: CollectElement, key: string }[]> {
74
+ return await Promise.all(
75
+ Object.keys(data).map(async (key) => {
76
+ const cardHolderNameElement = await collectContainer.create({
77
+ table: "cards",
78
+ column: key,
79
+ type: Skyflow.ElementType.INPUT_FIELD,
80
+ });
81
+ return { element: cardHolderNameElement, key: key };
82
+ })
83
+ )
84
+ }
85
+
@@ -63,258 +63,46 @@ const buildErrorResponse = async (
63
63
  return error;
64
64
  }
65
65
 
66
- const getPaymentMethodDetails = (scheme_data: string): {icon: string; label: string} => {
67
- const scheme: PAYMENT_METHOD = clearSpace(scheme_data.toUpperCase()) as PAYMENT_METHOD;
68
-
69
- const PAYMENT_METHODS_CATALOG: Partial<Record<PAYMENT_METHOD, { icon: string, label: string }>> = {
70
- [PAYMENT_METHOD.SORIANA]: {
71
- label: "Soriana",
72
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png",
73
- },
74
- [PAYMENT_METHOD.OXXO]: {
75
- label: "Oxxo",
76
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png",
77
- },
78
- [PAYMENT_METHOD.CODI]: {
79
- label: "CoDi",
80
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png",
81
- },
82
- [PAYMENT_METHOD.SPEI]: {
83
- label: "SPEI",
84
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png",
85
- },
86
- [PAYMENT_METHOD.PAYPAL]: {
87
- label: "Paypal",
88
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png",
89
- },
90
- [PAYMENT_METHOD.COMERCIALMEXICANA]: {
91
- label: "Comercial Mexicana",
92
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png",
93
- },
94
- [PAYMENT_METHOD.BANCOMER]: {
95
- label: "Bancomer",
96
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png",
97
- },
98
- [PAYMENT_METHOD.WALMART]: {
99
- label: "Walmart",
100
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png",
101
- },
102
- [PAYMENT_METHOD.BODEGA]: {
103
- label: "Bodega Aurrera",
104
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png",
105
- },
106
- [PAYMENT_METHOD.SAMSCLUB]: {
107
- label: "Sam´s Club",
108
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png",
109
- },
110
- [PAYMENT_METHOD.SUPERAMA]: {
111
- label: "Superama",
112
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png",
113
- },
114
- [PAYMENT_METHOD.CALIMAX]: {
115
- label: "Calimax",
116
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png",
117
- },
118
- [PAYMENT_METHOD.EXTRA]: {
119
- label: "Tiendas Extra",
120
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png",
121
- },
122
- [PAYMENT_METHOD.CIRCULOK]: {
123
- label: "Círculo K",
124
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png",
125
- },
126
- [PAYMENT_METHOD.SEVEN11]: {
127
- label: "7 Eleven",
128
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png",
129
- },
130
- [PAYMENT_METHOD.TELECOMM]: {
131
- label: "Telecomm",
132
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png",
133
- },
134
- [PAYMENT_METHOD.BANORTE]: {
135
- label: "Banorte",
136
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png",
137
- },
138
- [PAYMENT_METHOD.BENAVIDES]: {
139
- label: "Farmacias Benavides",
140
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png",
141
- },
142
- [PAYMENT_METHOD.DELAHORRO]: {
143
- label: "Farmacias del Ahorro",
144
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png",
145
- },
146
- [PAYMENT_METHOD.ELASTURIANO]: {
147
- label: "El Asturiano",
148
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png",
149
- },
150
- [PAYMENT_METHOD.WALDOS]: {
151
- label: "Waldos",
152
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png",
153
- },
154
- [PAYMENT_METHOD.ALSUPER]: {
155
- label: "Alsuper",
156
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png",
157
- },
158
- [PAYMENT_METHOD.KIOSKO]: {
159
- label: "Kiosko",
160
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png",
161
- },
162
- [PAYMENT_METHOD.STAMARIA]: {
163
- label: "Farmacias Santa María",
164
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png",
165
- },
166
- [PAYMENT_METHOD.LAMASBARATA]: {
167
- label: "Farmacias la más barata",
168
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png",
169
- },
170
- [PAYMENT_METHOD.FARMROMA]: {
171
- label: "Farmacias Roma",
172
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png",
173
- },
174
- [PAYMENT_METHOD.FARMUNION]: {
175
- label: "Pago en Farmacias Unión",
176
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png",
177
- },
178
- [PAYMENT_METHOD.FARMATODO]: {
179
- label: "Pago en Farmacias Farmatodo",
180
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png ",
181
- },
182
- [PAYMENT_METHOD.SFDEASIS]: {
183
- label: "Pago en Farmacias San Francisco de Asís",
184
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png",
185
- },
186
- [PAYMENT_METHOD.FARM911]: {
187
- label: "Farmacias 911",
188
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
189
- },
190
- [PAYMENT_METHOD.FARMECONOMICAS]: {
191
- label: "Farmacias Economicas",
192
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
193
- },
194
- [PAYMENT_METHOD.FARMMEDICITY]: {
195
- label: "Farmacias Medicity",
196
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
197
- },
198
- [PAYMENT_METHOD.RIANXEIRA]: {
199
- label: "Rianxeira",
200
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
201
- },
202
- [PAYMENT_METHOD.WESTERNUNION]: {
203
- label: "Western Union",
204
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
205
- },
206
- [PAYMENT_METHOD.ZONAPAGO]: {
207
- label: "Zona Pago",
208
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
209
- },
210
- [PAYMENT_METHOD.CAJALOSANDES]: {
211
- label: "Caja Los Andes",
212
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
213
- },
214
- [PAYMENT_METHOD.CAJAPAITA]: {
215
- label: "Caja Paita",
216
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
217
- },
218
- [PAYMENT_METHOD.CAJASANTA]: {
219
- label: "Caja Santa",
220
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
221
- },
222
- [PAYMENT_METHOD.CAJASULLANA]: {
223
- label: "Caja Sullana",
224
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
225
- },
226
- [PAYMENT_METHOD.CAJATRUJILLO]: {
227
- label: "Caja Trujillo",
228
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
229
- },
230
- [PAYMENT_METHOD.EDPYME]: {
231
- label: "Edpyme",
232
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
233
- },
234
- [PAYMENT_METHOD.KASNET]: {
235
- label: "KasNet",
236
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
237
- },
238
- [PAYMENT_METHOD.NORANDINO]: {
239
- label: "Norandino",
240
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
241
- },
242
- [PAYMENT_METHOD.QAPAQ]: {
243
- label: "Qapaq",
244
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
245
- },
246
- [PAYMENT_METHOD.RAIZ]: {
247
- label: "Raiz",
248
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
249
- },
250
- [PAYMENT_METHOD.PAYSER]: {
251
- label: "Paysera",
252
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
253
- },
254
- [PAYMENT_METHOD.WUNION]: {
255
- label: "Western Union",
256
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
257
- },
258
- [PAYMENT_METHOD.BANCOCONTINENTAL]: {
259
- label: "Banco Continental",
260
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
261
- },
262
- [PAYMENT_METHOD.GMONEY]: {
263
- label: "Go money",
264
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
265
- },
266
- [PAYMENT_METHOD.GOPAY]: {
267
- label: "Go pay",
268
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
269
- },
270
- [PAYMENT_METHOD.WU]: {
271
- label: "Western Union",
272
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
273
- },
274
- [PAYMENT_METHOD.PUNTOSHEY]: {
275
- label: "Puntoshey",
276
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
277
- },
278
- [PAYMENT_METHOD.AMPM]: {
279
- label: "Ampm",
280
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
281
- },
282
- [PAYMENT_METHOD.JUMBOMARKET]: {
283
- label: "Jumbomarket",
284
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
285
- },
286
- [PAYMENT_METHOD.SMELPUEBLO]: {
287
- label: "Smelpueblo",
288
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
289
- },
290
- [PAYMENT_METHOD.BAM]: {
291
- label: "Bam",
292
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
293
- },
294
- [PAYMENT_METHOD.REFACIL]: {
295
- label: "Refacil",
296
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
297
- },
298
- [PAYMENT_METHOD.ACYVALORES]: {
299
- label: "Acyvalores",
300
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
301
- },
302
- };
66
+ function formatPublicErrorResponse(data: Record<string, any>, error: any) {
67
+ let code = 200
68
+ try {
69
+ code = Number(error?.code || 200)
70
+ }catch{}
71
+
72
+ const default_res = {
73
+ status: "error",
74
+ code,
75
+ message: "",
76
+ detail: error?.body?.detail || error?.body?.error || error.body || "Ocurrio un error inesperado."
77
+ }
303
78
 
304
- const _default = {
305
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
306
- label: ""
79
+ return {
80
+ ...default_res,
81
+ ...data
307
82
  };
308
-
309
- return PAYMENT_METHODS_CATALOG[scheme] || _default;
310
83
  }
311
84
 
85
+
312
86
  const clearSpace = (text: string) => {
313
87
  return text.trim().replace(/\s+/g, '');
314
88
  }
315
89
 
90
+ const getCardType = (scheme: string) => {
91
+ if(scheme === "Visa") { // Check if visa
92
+ return "https://d35a75syrgujp0.cloudfront.net/cards/visa.png"
93
+ } else if(scheme === "Mastercard") { // Check if master
94
+ return "https://d35a75syrgujp0.cloudfront.net/cards/mastercard.png"
95
+ } else if (scheme === "American Express") { // Check if amex
96
+ return "https://d35a75syrgujp0.cloudfront.net/cards/american_express.png"
97
+ } else {
98
+ return "https://d35a75syrgujp0.cloudfront.net/cards/default_card.png"
99
+ }
100
+ }
101
+
316
102
  export {
317
103
  buildErrorResponseFromCatch,
318
104
  buildErrorResponse,
319
- getPaymentMethodDetails
105
+ getCardType,
106
+ formatPublicErrorResponse,
107
+ clearSpace
320
108
  }