@tonder.io/ionic-lite-sdk 0.0.57 → 0.0.58

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.
@@ -0,0 +1,63 @@
1
+ import Skyflow from "skyflow-js";
2
+
3
+ const lengthMatchRule = {
4
+ type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
5
+ params: {
6
+ max: 70,
7
+ },
8
+ };
9
+ const regexEmpty = RegExp('^(?!s*$).+');
10
+
11
+ const regexMatchRule = {
12
+ type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
13
+ params: {
14
+ regex: regexEmpty,
15
+ error: 'El campo es requerido', // Optional, default error is 'VALIDATION FAILED'.
16
+ },
17
+ };
18
+
19
+
20
+
21
+ const getErrorField = (
22
+ event: {
23
+ elementType?: string;
24
+ isEmpty?: boolean;
25
+ isFocused?: boolean;
26
+ isValid?: boolean;
27
+ value?: string;
28
+ },
29
+ field: string
30
+ ) => {
31
+ if (event.isEmpty) {
32
+ return 'El campo es requerido';
33
+ } else if (!event.isValid && !event.isEmpty) {
34
+ return `El campo ${field} es inválido`;
35
+ } else {
36
+ return '';
37
+ }
38
+ };
39
+
40
+ const DEFAULT_SKYFLOW_lABELS = {
41
+ name: 'Titular de la tarjeta',
42
+ card_number: 'Número de tarjeta',
43
+ cvv: 'CVC/CVV',
44
+ expiration_month: 'Mes',
45
+ expiration_year: 'Año',
46
+ expiration_date: 'Fecha de expiración',
47
+ };
48
+
49
+ const DEFAULT_SKYFLOW_PLACEHOLDERS = {
50
+ name: 'Nombre como aparece en la tarjeta',
51
+ card_number: '1234 1234 1234 1234',
52
+ cvv: '3-4 dígitos',
53
+ expiration_month: 'MM',
54
+ expiration_year: 'AA',
55
+ };
56
+
57
+ export {
58
+ lengthMatchRule,
59
+ regexMatchRule,
60
+ getErrorField,
61
+ DEFAULT_SKYFLOW_lABELS,
62
+ DEFAULT_SKYFLOW_PLACEHOLDERS,
63
+ };
@@ -0,0 +1,63 @@
1
+ import {CollectInputStylesVariant, CollectLabelStylesVariant} from "../../types/commons";
2
+ import {LabelStyles} from "skyflow-js/types/utils/common";
3
+
4
+ const DEFAULT_SKYFLOW_INPUT_STYLES: CollectInputStylesVariant = {
5
+ base: {
6
+ border: "1px solid #e0e0e0",
7
+ padding: "10px 7px",
8
+ borderRadius: "5px",
9
+ color: "#1d1d1d",
10
+ marginTop: "2px",
11
+ backgroundColor: "white",
12
+ fontFamily: '"Inter", sans-serif',
13
+ fontSize: "16px",
14
+ "&::placeholder": {
15
+ color: "#ccc",
16
+ },
17
+ },
18
+ complete: {
19
+ color: "#4caf50",
20
+ },
21
+ invalid: {
22
+ border: "1px solid #f44336",
23
+ },
24
+ empty: {},
25
+ focus: {},
26
+ global: {
27
+ "@import":
28
+ 'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")',
29
+ },
30
+ };
31
+
32
+ const DEFAULT_SKYFLOW_lABEL_STYLES: LabelStyles = {
33
+ base: {
34
+ fontSize: "12px",
35
+ fontWeight: "500",
36
+ fontFamily: '"Inter", sans-serif'
37
+ },
38
+ };
39
+
40
+ const DEFAULT_SKYFLOW_ERROR_TEXT_STYLES: CollectLabelStylesVariant = {
41
+ base: {
42
+ fontSize: '12px',
43
+ fontWeight: '500',
44
+ fontFamily: '"Inter", sans-serif',
45
+ color: "#f44336",
46
+ },
47
+ }
48
+
49
+ const SKYFLOW_HIDDEN_ERROR_TEXT_STYLES = {
50
+ base: {
51
+ fontSize: '12px',
52
+ fontWeight: '500',
53
+ color: "#f44336",
54
+ fontFamily: '"Inter", sans-serif'
55
+ },
56
+ };
57
+
58
+ export {
59
+ DEFAULT_SKYFLOW_INPUT_STYLES,
60
+ DEFAULT_SKYFLOW_lABEL_STYLES,
61
+ DEFAULT_SKYFLOW_ERROR_TEXT_STYLES,
62
+ SKYFLOW_HIDDEN_ERROR_TEXT_STYLES,
63
+ };
package/src/types/card.ts CHANGED
@@ -33,3 +33,15 @@ export interface ISaveCardRequest {
33
33
  expiration_year: string;
34
34
  cardholder_name: string;
35
35
  }
36
+ export enum CardFieldEnum {
37
+ CARD_NUMBER = 'card_number',
38
+ CVV = 'cvv',
39
+ EXPIRATION_MONTH = 'expiration_month',
40
+ EXPIRATION_YEAR = 'expiration_year',
41
+ CARDHOLDER_NAME = 'cardholder_name',
42
+ }
43
+
44
+ export interface IMountCardFieldsRequest {
45
+ fields: CardFieldEnum[] | { container_id?: string; field: CardFieldEnum}[],
46
+ card_id?: string;
47
+ }
@@ -1,5 +1,13 @@
1
1
  import { ICustomer } from "./customer";
2
2
  import {IProcessPaymentRequest, IStartCheckoutResponse} from "./checkout";
3
+ import CollectorContainer from "skyflow-js/types/core/external/collect/collect-container";
4
+ import ComposableContainer from "skyflow-js/types/core/external/collect/compose-collect-container";
5
+ import RevealContainer from "skyflow-js/types/core/external/reveal/reveal-container";
6
+ import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
7
+ import ComposableElement from "skyflow-js/types/core/external/collect/compose-collect-element";
8
+ import RevealElement from "skyflow-js/types/core/external/reveal/reveal-element";
9
+ import {LabelStyles} from "skyflow-js/types/utils/common";
10
+
3
11
 
4
12
  export type Business = {
5
13
  business: {
@@ -120,9 +128,29 @@ export interface IInlineLiteCheckoutOptions
120
128
  collectorIds?: {
121
129
  tdsIframe?: string
122
130
  }
131
+ customization?: ILiteCustomizationOptions;
132
+ events?: IEvents;
123
133
  }
124
134
 
125
-
135
+ export interface ICardFormEvents {
136
+ cardHolderEvents?: IInputEvents;
137
+ cardNumberEvents?: IInputEvents;
138
+ cvvEvents?: IInputEvents;
139
+ monthEvents?: IInputEvents;
140
+ yearEvents?: IInputEvents;
141
+ }
142
+ export interface IInputEvents {
143
+ onChange?: (event: IEventSecureInput) => void;
144
+ onFocus?: (event: IEventSecureInput) => void;
145
+ onBlur?: (event: IEventSecureInput) => void;
146
+ }
147
+ export interface IEventSecureInput {
148
+ elementType: string;
149
+ isEmpty: boolean;
150
+ isFocused: boolean;
151
+ isValid: boolean;
152
+ }
153
+ export interface IEvents extends ICardFormEvents {}
126
154
  export interface IApiError {
127
155
  code: string;
128
156
  body: Record<string, string> | string;
@@ -140,3 +168,69 @@ export interface IPublicError {
140
168
  export type CustomizationOptions = {
141
169
  redirectOnComplete?: boolean
142
170
  }
171
+
172
+ export interface InCollectorContainer {
173
+ container: CollectorContainer | ComposableContainer | RevealContainer;
174
+ elements: (CollectElement | ComposableElement | RevealElement)[];
175
+ }
176
+
177
+ export interface ILiteCustomizationOptions extends CustomizationOptions {
178
+ styles?: IStyles;
179
+ labels?: IFormLabels;
180
+ placeholders?: IFormPlaceholder;
181
+ }
182
+
183
+ export interface IFormLabels {
184
+ name?: string;
185
+ card_number?: string;
186
+ cvv?: string;
187
+ expiry_date?: string;
188
+ expiration_year?: string;
189
+ expiration_month?: string;
190
+ }
191
+
192
+ export interface IFormPlaceholder {
193
+ name?: string;
194
+ card_number?: string;
195
+ cvv?: string;
196
+ expiration_month?: string;
197
+ expiration_year?: string;
198
+ }
199
+
200
+ export interface IStyles {
201
+ cardForm?: ILiteCardFormStyles;
202
+ }
203
+
204
+ export interface ILiteCardFormStyles extends StylesBaseVariant, IElementStyle {}
205
+
206
+ export interface StylesBaseVariant {
207
+ base?: Record<string, any>;
208
+ }
209
+
210
+ export interface IElementStyle {
211
+ inputStyles?: CollectInputStylesVariant;
212
+ labelStyles?: LabelStyles;
213
+ errorStyles?: StylesBaseVariant;
214
+ }
215
+ export interface StylesFocusVariant {
216
+ focus?: Record<string, any>;
217
+ }
218
+
219
+ export interface CollectInputStylesVariant
220
+ extends StylesBaseVariant,
221
+ StylesFocusVariant {
222
+ complete?: Record<string, any>;
223
+ invalid?: Record<string, any>;
224
+ empty?: Record<string, any>;
225
+ cardIcon?: Record<string, any>;
226
+ dropdownIcon?: Record<string, any>;
227
+ dropdown?: Record<string, any>;
228
+ dropdownListItem?: Record<string, any>;
229
+ global: Record<string, any>;
230
+ }
231
+
232
+ export interface CollectLabelStylesVariant
233
+ extends StylesBaseVariant,
234
+ StylesFocusVariant {
235
+ requiredAsterisk?: Record<string, any>;
236
+ }
@@ -223,5 +223,13 @@ export interface ILiteCheckout {
223
223
  public_key: string,
224
224
  is_sandbox: boolean,
225
225
  ): Promise<string | ErrorResponse>;
226
- }
227
226
 
227
+ /**
228
+ * Displays and renders card input fields in the checkout.
229
+ * Uses the provided configuration to show the required fields in the payment form.
230
+ * @param {import("./card").IMountCardFieldsRequest} event - Configuration for the card fields to render.
231
+ * @returns {Promise<void>} Resolves when the fields have been successfully rendered.
232
+ * @public
233
+ */
234
+ mountCardFields(event: import("./card").IMountCardFieldsRequest): Promise<void>;
235
+ }
@@ -76,7 +76,7 @@ export type TokensSkyflowRequest = {
76
76
  apiKey: string;
77
77
  vault_id: string,
78
78
  vault_url: string,
79
- data: {
79
+ data?: {
80
80
  [key: string]: any;
81
81
  }
82
82
  }
@@ -1,57 +0,0 @@
1
- import "../utils/defaultMock";
2
- import { LiteCheckout } from "../../src";
3
- import { constructorFields } from "../utils/defaultMock";
4
- import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
5
-
6
- declare global {
7
- interface Window {
8
- OpenPay: any;
9
- Skyflow: any;
10
- }
11
- }
12
-
13
- describe("LiteCheckout", () => {
14
- let checkoutConstructor: IInlineLiteCheckoutOptions,
15
- liteCheckout: LiteCheckout,
16
- fetchSpy: jest.SpyInstance,
17
- liteCheckoutSpy: jest.SpyInstance;
18
-
19
- beforeEach(async () => {
20
- window.fetch = jest.fn();
21
-
22
- checkoutConstructor = {
23
- ...constructorFields,
24
- };
25
-
26
- liteCheckout = new LiteCheckout(constructorFields);
27
-
28
- fetchSpy = jest.spyOn(global, "fetch");
29
- });
30
-
31
- afterEach(() => {
32
- jest.restoreAllMocks();
33
- });
34
-
35
- it("Has required properties", () => {
36
- expect(checkoutConstructor).toEqual(constructorFields);
37
- });
38
-
39
- it("Can instance LiteCheckout", () => {
40
- expect(liteCheckout).toBeInstanceOf(LiteCheckout);
41
- expect(liteCheckout.apiKeyTonder).toEqual(constructorFields.apiKey);
42
- expect(liteCheckout.baseUrl).toEqual(constructorFields.baseUrl);
43
- expect(liteCheckout.abortController.signal).toEqual(constructorFields.signal);
44
- });
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
- });
@@ -1,142 +0,0 @@
1
- import "../utils/defaultMock";
2
- import { LiteCheckout } from "../../src";
3
- import { ErrorResponse } from "../../src/classes/errorResponse";
4
- import { constructorFields } from "../utils/defaultMock";
5
- import { OrderResponseClass, OrderClass, OrderEmptyValuesResponse } from "../utils/mockClasses";
6
- import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
7
-
8
- declare global {
9
- interface Window {
10
- OpenPay: any;
11
- Skyflow: any;
12
- }
13
- }
14
-
15
- describe("createOrder", () => {
16
- let checkoutConstructor: IInlineLiteCheckoutOptions,
17
- liteCheckout: LiteCheckout,
18
- fetchSpy: jest.SpyInstance,
19
- liteCheckoutSpy: jest.SpyInstance;
20
-
21
- beforeEach(async () => {
22
- window.fetch = jest.fn();
23
-
24
- checkoutConstructor = {
25
- ...constructorFields,
26
- };
27
-
28
- liteCheckout = new LiteCheckout(constructorFields);
29
-
30
- fetchSpy = jest.spyOn(global, "fetch");
31
- });
32
-
33
- afterEach(() => {
34
- jest.restoreAllMocks();
35
- });
36
-
37
- it("createOrder success", async () => {
38
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
39
-
40
- fetchSpy.mockImplementation(() =>
41
- Promise.resolve({
42
- json: () => Promise.resolve([{ ...new OrderResponseClass() }]),
43
- ok: true,
44
- })
45
- );
46
-
47
- const response = await liteCheckout.createOrder({
48
- ...new OrderClass(),
49
- });
50
-
51
- expect(response).toStrictEqual([{ ...new OrderResponseClass() }]);
52
- expect(liteCheckoutSpy).toHaveBeenCalled();
53
- expect(liteCheckoutSpy).toHaveBeenCalledWith({ ...new OrderClass() });
54
- });
55
-
56
- it("createOrder empty", async () => {
57
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
58
-
59
- fetchSpy.mockImplementation(() =>
60
- Promise.resolve({
61
- json: () => Promise.resolve(),
62
- ok: true,
63
- })
64
- );
65
-
66
- const response = await liteCheckout.createOrder({
67
- ...new OrderClass(),
68
- });
69
- expect(liteCheckoutSpy).toHaveBeenCalled();
70
- expect(liteCheckoutSpy).toHaveReturned();
71
- expect(response).toBeUndefined();
72
- });
73
-
74
- it("createOrder errorResponse", async () => {
75
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
76
-
77
- fetchSpy.mockImplementation(() =>
78
- Promise.resolve({
79
- json: () => Promise.resolve(),
80
- ok: false,
81
- status: 400,
82
- })
83
- );
84
-
85
- let error;
86
-
87
- try {
88
- const response = await liteCheckout.createOrder({
89
- ...new OrderClass(),
90
- })
91
- } catch (e) {
92
- error = e;
93
- }
94
-
95
- expect(liteCheckoutSpy).toHaveBeenCalled();
96
- expect(error).toBeInstanceOf(ErrorResponse);
97
- });
98
-
99
- it("createOrder empty values", async () => {
100
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
101
-
102
- fetchSpy.mockImplementation(() =>
103
- Promise.resolve({
104
- json: () => Promise.resolve(OrderEmptyValuesResponse),
105
- ok: false,
106
- status: 400,
107
- })
108
- );
109
-
110
- let error: ErrorResponse;
111
-
112
- try {
113
- const response = (await liteCheckout.createOrder({
114
- ...new OrderClass(),
115
- })) as ErrorResponse;
116
- } catch (e: any) {
117
- error = e;
118
- expect(error.body).toStrictEqual(OrderEmptyValuesResponse);
119
- }
120
- });
121
-
122
- it("createOrder errorCatch", async () => {
123
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createOrder");
124
-
125
- fetchSpy.mockRejectedValue("error");
126
-
127
- let error: ErrorResponse;
128
-
129
- try {
130
- const response = (await liteCheckout.createOrder({
131
- ...new OrderClass(),
132
- })) as ErrorResponse;
133
- } catch (e: any) {
134
- error = e;
135
- expect(error.message).toStrictEqual("error");
136
- expect(error.name).toStrictEqual("catch");
137
- }
138
-
139
- expect(liteCheckoutSpy).toHaveBeenCalled();
140
- expect(liteCheckoutSpy).rejects.toThrow();
141
- });
142
- });
@@ -1,122 +0,0 @@
1
- import "../utils/defaultMock";
2
- import { LiteCheckout } from "../../src";
3
- import { ErrorResponse } from "../../src/classes/errorResponse";
4
- import { constructorFields } from "../utils/defaultMock";
5
- import { CreatePaymentResponseClass, CreatePaymentRequestClass } from "../utils/mockClasses";
6
- import {IInlineLiteCheckoutOptions} from "../../src/types/commons";
7
-
8
-
9
- declare global {
10
- interface Window {
11
- OpenPay: any;
12
- Skyflow: any;
13
- }
14
- }
15
-
16
- describe("createPayment", () => {
17
- let checkoutConstructor: IInlineLiteCheckoutOptions,
18
- liteCheckout: LiteCheckout,
19
- fetchSpy: jest.SpyInstance,
20
- liteCheckoutSpy: jest.SpyInstance;
21
-
22
- beforeEach(async () => {
23
- window.fetch = jest.fn();
24
-
25
- checkoutConstructor = {
26
- ...constructorFields,
27
- };
28
-
29
- liteCheckout = new LiteCheckout(constructorFields);
30
-
31
- fetchSpy = jest.spyOn(global, "fetch");
32
- });
33
-
34
- afterEach(() => {
35
- jest.restoreAllMocks();
36
- });
37
-
38
- it("createPayment success", async () => {
39
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createPayment");
40
-
41
- fetchSpy.mockImplementation(() =>
42
- Promise.resolve({
43
- json: () => Promise.resolve([{ ...new CreatePaymentResponseClass() }]),
44
- ok: true,
45
- })
46
- );
47
-
48
- const response = await liteCheckout.createPayment({
49
- ...new CreatePaymentRequestClass(),
50
- });
51
-
52
- expect(response).toStrictEqual([{ ...new CreatePaymentResponseClass() }]);
53
- expect(liteCheckoutSpy).toHaveBeenCalled();
54
- expect(liteCheckoutSpy).toHaveBeenCalledWith({
55
- ...new CreatePaymentRequestClass(),
56
- });
57
- });
58
-
59
- it("createPayment empty", async () => {
60
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createPayment");
61
-
62
- fetchSpy.mockImplementation(() =>
63
- Promise.resolve({
64
- json: () => Promise.resolve(),
65
- ok: true,
66
- })
67
- );
68
-
69
- const response = await liteCheckout.createPayment({
70
- ...new CreatePaymentRequestClass(),
71
- });
72
- expect(liteCheckoutSpy).toHaveBeenCalled();
73
- expect(liteCheckoutSpy).toHaveReturned();
74
- expect(response).toBeUndefined();
75
- });
76
-
77
- it("createPayment errorResponse", async () => {
78
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createPayment");
79
-
80
- fetchSpy.mockImplementation(() =>
81
- Promise.resolve({
82
- json: () => Promise.resolve(),
83
- ok: false,
84
- status: 400,
85
- })
86
- );
87
-
88
- let error;
89
-
90
- try {
91
- const response = await liteCheckout.createPayment({
92
- ...new CreatePaymentRequestClass(),
93
- })
94
- } catch (e) {
95
- error = e;
96
- }
97
-
98
- expect(liteCheckoutSpy).toHaveBeenCalled();
99
- expect(error).toBeInstanceOf(ErrorResponse);
100
- });
101
-
102
- it("createPayment errorCatch", async () => {
103
- liteCheckoutSpy = jest.spyOn(liteCheckout, "createPayment");
104
-
105
- fetchSpy.mockRejectedValue("error");
106
-
107
- let error: ErrorResponse;
108
-
109
- try {
110
- const response = (await liteCheckout.createPayment({
111
- ...new CreatePaymentRequestClass(),
112
- })) as ErrorResponse;
113
- } catch (e: any) {
114
- error = e;
115
- expect(error.message).toStrictEqual("error");
116
- expect(error.name).toStrictEqual("catch");
117
- }
118
-
119
- expect(liteCheckoutSpy).toHaveBeenCalled();
120
- expect(liteCheckoutSpy).rejects.toThrow();
121
- });
122
- });