@tonder.io/ionic-lite-sdk 0.0.34-beta.2 → 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 +74 -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 +35 -245
  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
+
@@ -35,7 +35,6 @@ const buildErrorResponse = async (
35
35
  response: Response,
36
36
  stack: string | undefined = undefined
37
37
  ): Promise<ErrorResponse> => {
38
-
39
38
  let body, status, message = "Error";
40
39
 
41
40
  if (response && "json" in response) {
@@ -46,10 +45,13 @@ const buildErrorResponse = async (
46
45
  status = response.status.toString();
47
46
  }
48
47
 
49
- if (response && "text" in response) {
48
+ if (!body && response && "text" in response) {
50
49
  message = await response.text();
51
50
  }
52
51
 
52
+ if(body?.detail){
53
+ message = body.detail
54
+ }
53
55
  const error = new ErrorResponse({
54
56
  code: status,
55
57
  body: body,
@@ -61,258 +63,46 @@ const buildErrorResponse = async (
61
63
  return error;
62
64
  }
63
65
 
64
- const getPaymentMethodDetails = (scheme_data: string): {icon: string; label: string} => {
65
- const scheme: PAYMENT_METHOD = clearSpace(scheme_data.toUpperCase()) as PAYMENT_METHOD;
66
-
67
- const PAYMENT_METHODS_CATALOG: Partial<Record<PAYMENT_METHOD, { icon: string, label: string }>> = {
68
- [PAYMENT_METHOD.SORIANA]: {
69
- label: "Soriana",
70
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/soriana.png",
71
- },
72
- [PAYMENT_METHOD.OXXO]: {
73
- label: "Oxxo",
74
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxo.png",
75
- },
76
- [PAYMENT_METHOD.CODI]: {
77
- label: "CoDi",
78
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/codi.png",
79
- },
80
- [PAYMENT_METHOD.SPEI]: {
81
- label: "SPEI",
82
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/spei.png",
83
- },
84
- [PAYMENT_METHOD.PAYPAL]: {
85
- label: "Paypal",
86
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/paypal.png",
87
- },
88
- [PAYMENT_METHOD.COMERCIALMEXICANA]: {
89
- label: "Comercial Mexicana",
90
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/comercial_exicana.png",
91
- },
92
- [PAYMENT_METHOD.BANCOMER]: {
93
- label: "Bancomer",
94
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/bancomer.png",
95
- },
96
- [PAYMENT_METHOD.WALMART]: {
97
- label: "Walmart",
98
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/walmart.png",
99
- },
100
- [PAYMENT_METHOD.BODEGA]: {
101
- label: "Bodega Aurrera",
102
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/bodega_aurrera.png",
103
- },
104
- [PAYMENT_METHOD.SAMSCLUB]: {
105
- label: "Sam´s Club",
106
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/sams_club.png",
107
- },
108
- [PAYMENT_METHOD.SUPERAMA]: {
109
- label: "Superama",
110
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/superama.png",
111
- },
112
- [PAYMENT_METHOD.CALIMAX]: {
113
- label: "Calimax",
114
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/calimax.png",
115
- },
116
- [PAYMENT_METHOD.EXTRA]: {
117
- label: "Tiendas Extra",
118
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/tiendas_extra.png",
119
- },
120
- [PAYMENT_METHOD.CIRCULOK]: {
121
- label: "Círculo K",
122
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png",
123
- },
124
- [PAYMENT_METHOD.SEVEN11]: {
125
- label: "7 Eleven",
126
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png",
127
- },
128
- [PAYMENT_METHOD.TELECOMM]: {
129
- label: "Telecomm",
130
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/telecomm.png",
131
- },
132
- [PAYMENT_METHOD.BANORTE]: {
133
- label: "Banorte",
134
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/banorte.png",
135
- },
136
- [PAYMENT_METHOD.BENAVIDES]: {
137
- label: "Farmacias Benavides",
138
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_benavides.png",
139
- },
140
- [PAYMENT_METHOD.DELAHORRO]: {
141
- label: "Farmacias del Ahorro",
142
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_ahorro.png",
143
- },
144
- [PAYMENT_METHOD.ELASTURIANO]: {
145
- label: "El Asturiano",
146
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/asturiano.png",
147
- },
148
- [PAYMENT_METHOD.WALDOS]: {
149
- label: "Waldos",
150
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/waldos.png",
151
- },
152
- [PAYMENT_METHOD.ALSUPER]: {
153
- label: "Alsuper",
154
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/al_super.png",
155
- },
156
- [PAYMENT_METHOD.KIOSKO]: {
157
- label: "Kiosko",
158
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/kiosko.png",
159
- },
160
- [PAYMENT_METHOD.STAMARIA]: {
161
- label: "Farmacias Santa María",
162
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_santa_maria.png",
163
- },
164
- [PAYMENT_METHOD.LAMASBARATA]: {
165
- label: "Farmacias la más barata",
166
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_barata.png",
167
- },
168
- [PAYMENT_METHOD.FARMROMA]: {
169
- label: "Farmacias Roma",
170
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_roma.png",
171
- },
172
- [PAYMENT_METHOD.FARMUNION]: {
173
- label: "Pago en Farmacias Unión",
174
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_union.png",
175
- },
176
- [PAYMENT_METHOD.FARMATODO]: {
177
- label: "Pago en Farmacias Farmatodo",
178
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_farmatodo.png ",
179
- },
180
- [PAYMENT_METHOD.SFDEASIS]: {
181
- label: "Pago en Farmacias San Francisco de Asís",
182
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/farmacias_san_francisco.png",
183
- },
184
- [PAYMENT_METHOD.FARM911]: {
185
- label: "Farmacias 911",
186
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
187
- },
188
- [PAYMENT_METHOD.FARMECONOMICAS]: {
189
- label: "Farmacias Economicas",
190
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
191
- },
192
- [PAYMENT_METHOD.FARMMEDICITY]: {
193
- label: "Farmacias Medicity",
194
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
195
- },
196
- [PAYMENT_METHOD.RIANXEIRA]: {
197
- label: "Rianxeira",
198
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
199
- },
200
- [PAYMENT_METHOD.WESTERNUNION]: {
201
- label: "Western Union",
202
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
203
- },
204
- [PAYMENT_METHOD.ZONAPAGO]: {
205
- label: "Zona Pago",
206
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
207
- },
208
- [PAYMENT_METHOD.CAJALOSANDES]: {
209
- label: "Caja Los Andes",
210
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
211
- },
212
- [PAYMENT_METHOD.CAJAPAITA]: {
213
- label: "Caja Paita",
214
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
215
- },
216
- [PAYMENT_METHOD.CAJASANTA]: {
217
- label: "Caja Santa",
218
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
219
- },
220
- [PAYMENT_METHOD.CAJASULLANA]: {
221
- label: "Caja Sullana",
222
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
223
- },
224
- [PAYMENT_METHOD.CAJATRUJILLO]: {
225
- label: "Caja Trujillo",
226
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
227
- },
228
- [PAYMENT_METHOD.EDPYME]: {
229
- label: "Edpyme",
230
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
231
- },
232
- [PAYMENT_METHOD.KASNET]: {
233
- label: "KasNet",
234
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
235
- },
236
- [PAYMENT_METHOD.NORANDINO]: {
237
- label: "Norandino",
238
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
239
- },
240
- [PAYMENT_METHOD.QAPAQ]: {
241
- label: "Qapaq",
242
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
243
- },
244
- [PAYMENT_METHOD.RAIZ]: {
245
- label: "Raiz",
246
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
247
- },
248
- [PAYMENT_METHOD.PAYSER]: {
249
- label: "Paysera",
250
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
251
- },
252
- [PAYMENT_METHOD.WUNION]: {
253
- label: "Western Union",
254
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
255
- },
256
- [PAYMENT_METHOD.BANCOCONTINENTAL]: {
257
- label: "Banco Continental",
258
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
259
- },
260
- [PAYMENT_METHOD.GMONEY]: {
261
- label: "Go money",
262
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
263
- },
264
- [PAYMENT_METHOD.GOPAY]: {
265
- label: "Go pay",
266
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
267
- },
268
- [PAYMENT_METHOD.WU]: {
269
- label: "Western Union",
270
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
271
- },
272
- [PAYMENT_METHOD.PUNTOSHEY]: {
273
- label: "Puntoshey",
274
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
275
- },
276
- [PAYMENT_METHOD.AMPM]: {
277
- label: "Ampm",
278
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
279
- },
280
- [PAYMENT_METHOD.JUMBOMARKET]: {
281
- label: "Jumbomarket",
282
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
283
- },
284
- [PAYMENT_METHOD.SMELPUEBLO]: {
285
- label: "Smelpueblo",
286
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
287
- },
288
- [PAYMENT_METHOD.BAM]: {
289
- label: "Bam",
290
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
291
- },
292
- [PAYMENT_METHOD.REFACIL]: {
293
- label: "Refacil",
294
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
295
- },
296
- [PAYMENT_METHOD.ACYVALORES]: {
297
- label: "Acyvalores",
298
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
299
- },
300
- };
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
+ }
301
78
 
302
- const _default = {
303
- icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/store.png",
304
- label: ""
79
+ return {
80
+ ...default_res,
81
+ ...data
305
82
  };
306
-
307
- return PAYMENT_METHODS_CATALOG[scheme] || _default;
308
83
  }
309
84
 
85
+
310
86
  const clearSpace = (text: string) => {
311
87
  return text.trim().replace(/\s+/g, '');
312
88
  }
313
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
+
314
102
  export {
315
103
  buildErrorResponseFromCatch,
316
104
  buildErrorResponse,
317
- getPaymentMethodDetails
105
+ getCardType,
106
+ formatPublicErrorResponse,
107
+ clearSpace
318
108
  }