@tonder.io/ionic-lite-sdk 0.0.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 (36) hide show
  1. package/.gitlab-ci.yml +29 -0
  2. package/README.md +496 -0
  3. package/dist/classes/errorResponse.d.ts +9 -0
  4. package/dist/classes/liteCheckout.d.ts +34 -0
  5. package/dist/helpers/utils.d.ts +3 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +1 -0
  8. package/dist/types/commons.d.ts +58 -0
  9. package/dist/types/requests.d.ts +55 -0
  10. package/dist/types/responses.d.ts +177 -0
  11. package/dist/types/skyflow.d.ts +17 -0
  12. package/jest.config.ts +15 -0
  13. package/package.json +34 -0
  14. package/rollup.config.js +17 -0
  15. package/src/classes/errorResponse.ts +17 -0
  16. package/src/classes/liteCheckout.ts +301 -0
  17. package/src/helpers/utils.ts +37 -0
  18. package/src/index.ts +5 -0
  19. package/src/types/commons.ts +61 -0
  20. package/src/types/requests.ts +61 -0
  21. package/src/types/responses.ts +186 -0
  22. package/src/types/skyflow.ts +17 -0
  23. package/tests/classes/liteCheckout.test.ts +57 -0
  24. package/tests/methods/createOrder.test.ts +106 -0
  25. package/tests/methods/createPayment.test.ts +109 -0
  26. package/tests/methods/customerRegister.test.ts +106 -0
  27. package/tests/methods/getBusiness.test.ts +102 -0
  28. package/tests/methods/getCustomerCards.test.ts +105 -0
  29. package/tests/methods/getOpenpayDeviceSessionID.test.ts +95 -0
  30. package/tests/methods/getSkyflowToken.test.ts +137 -0
  31. package/tests/methods/getVaultToken.test.ts +107 -0
  32. package/tests/methods/registerCustomerCard.test.ts +105 -0
  33. package/tests/methods/startCheckoutRouter.test.ts +107 -0
  34. package/tests/utils/defaultMock.ts +21 -0
  35. package/tests/utils/mockClasses.ts +540 -0
  36. package/tsconfig.json +19 -0
@@ -0,0 +1,107 @@
1
+ import "../utils/defaultMock";
2
+ import { LiteCheckout } from "../../src";
3
+ import { ErrorResponse } from "../../src/classes/errorResponse";
4
+ import { LiteCheckoutConstructor } from "../../src/classes/liteCheckout";
5
+ import { IErrorResponse } from "../../src/types/responses";
6
+ import { constructorFields } from "../utils/defaultMock";
7
+ import { StartCheckoutResponseClass, StartCheckoutRequestClass, CreatePaymentRequestClass } from "../utils/mockClasses";
8
+
9
+ declare global {
10
+ interface Window {
11
+ OpenPay: any;
12
+ Skyflow: any;
13
+ }
14
+ }
15
+
16
+ describe("startCheckoutRouter", () => {
17
+ let checkoutConstructor: LiteCheckoutConstructor,
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("startCheckoutRouter success", async () => {
39
+ liteCheckoutSpy = jest.spyOn(liteCheckout, "startCheckoutRouter");
40
+
41
+ fetchSpy.mockImplementation(() =>
42
+ Promise.resolve({
43
+ json: () => Promise.resolve([{ ...new StartCheckoutResponseClass() }]),
44
+ ok: true,
45
+ })
46
+ );
47
+
48
+ const response = await liteCheckout.startCheckoutRouter({
49
+ ...new StartCheckoutRequestClass(),
50
+ });
51
+ expect(response).toStrictEqual([{ ...new StartCheckoutResponseClass() }]);
52
+ expect(liteCheckoutSpy).toHaveBeenCalled();
53
+ expect(liteCheckoutSpy).toHaveBeenCalledWith({
54
+ ...new CreatePaymentRequestClass(),
55
+ });
56
+ });
57
+
58
+ it("startCheckoutRouter empty", async () => {
59
+ liteCheckoutSpy = jest.spyOn(liteCheckout, "startCheckoutRouter");
60
+
61
+ fetchSpy.mockImplementation(() =>
62
+ Promise.resolve({
63
+ json: () => Promise.resolve(),
64
+ ok: true,
65
+ })
66
+ );
67
+
68
+ const response = await liteCheckout.startCheckoutRouter({
69
+ ...new StartCheckoutRequestClass(),
70
+ });
71
+ expect(liteCheckoutSpy).toHaveBeenCalled();
72
+ expect(liteCheckoutSpy).toHaveReturned();
73
+ expect(response).toBeUndefined();
74
+ });
75
+
76
+ it("startCheckoutRouter errorResponse", async () => {
77
+ liteCheckoutSpy = jest.spyOn(liteCheckout, "startCheckoutRouter");
78
+
79
+ fetchSpy.mockImplementation(() =>
80
+ Promise.resolve({
81
+ json: () => Promise.resolve(),
82
+ ok: false,
83
+ status: 400,
84
+ })
85
+ );
86
+
87
+ const response = (await liteCheckout.startCheckoutRouter({
88
+ ...new StartCheckoutRequestClass(),
89
+ })) as IErrorResponse;
90
+ expect(response.code).toStrictEqual("400");
91
+ expect(response).toBeInstanceOf(ErrorResponse);
92
+ });
93
+
94
+ it("startCheckoutRouter errorCatch", async () => {
95
+ liteCheckoutSpy = jest.spyOn(liteCheckout, "startCheckoutRouter");
96
+
97
+ fetchSpy.mockRejectedValue("error");
98
+
99
+ const response = (await liteCheckout.startCheckoutRouter({
100
+ ...new StartCheckoutRequestClass(),
101
+ })) as IErrorResponse;
102
+ expect(liteCheckoutSpy).toHaveBeenCalled();
103
+ expect(response.message).toStrictEqual("error");
104
+ expect(response.name).toStrictEqual("catch");
105
+ expect(liteCheckoutSpy).rejects.toThrow();
106
+ });
107
+ });
@@ -0,0 +1,21 @@
1
+ jest.setMock("skyflow-js", {
2
+ OpenPay: jest.fn(),
3
+ init: jest.fn().mockImplementation(() => ({
4
+ container: () => ({
5
+ collect: () => ({
6
+ records: [{ fields: "1234" }],
7
+ }),
8
+ }),
9
+ })),
10
+ LogLevel: { ERROR: "ERROR" },
11
+ Env: { DEV: "DEV" },
12
+ ContainerType: { COLLECT: "COLLECT" },
13
+ });
14
+
15
+ const abortSignal = new AbortController().signal;
16
+
17
+ export const constructorFields = {
18
+ signal: abortSignal,
19
+ baseUrlTonder: "",
20
+ apiKeyTonder: "",
21
+ };
@@ -0,0 +1,540 @@
1
+ import { Business, OrderItem } from "../../src/types/commons";
2
+ import {
3
+ CreateOrderRequest,
4
+ CreatePaymentRequest,
5
+ RegisterCustomerCardRequest,
6
+ StartCheckoutRequest,
7
+ TokensRequest,
8
+ } from "../../src/types/requests";
9
+ import {
10
+ CreateOrderResponse,
11
+ CreatePaymentResponse,
12
+ GetBusinessResponse,
13
+ GetCustomerCardsResponse,
14
+ RegisterCustomerCardResponse,
15
+ StartCheckoutResponse,
16
+ } from "../../src/types/responses";
17
+
18
+ export class BusinessClass implements Business {
19
+ business!: {
20
+ pk: number;
21
+ name: string;
22
+ categories: [{ pk: number; name: string }];
23
+ web: string;
24
+ logo: string;
25
+ full_logo_url: string;
26
+ background_color: string;
27
+ primary_color: string;
28
+ checkout_mode: boolean;
29
+ textCheckoutColor: string;
30
+ textDetailsColor: string;
31
+ checkout_logo: string;
32
+ };
33
+ openpay_keys!: { merchant_id: string; public_key: string };
34
+ fintoc_keys!: { public_key: string };
35
+ vault_id!: string;
36
+ vault_url!: string;
37
+ reference!: number;
38
+ is_installments_available!: boolean;
39
+
40
+ get mockObject(): GetBusinessResponse {
41
+ return {
42
+ business: {
43
+ pk: 1234, // Número de ejemplo
44
+ name: 'Mock Business Name',
45
+ categories: [
46
+ { pk: 5678, name: 'Mock Category 1' },
47
+ { pk: 9012, name: 'Mock Category 2' }
48
+ ],
49
+ web: 'https://www.mockbusiness.com',
50
+ logo: 'assets/images/mock-logo.png',
51
+ full_logo_url: 'https://www.mockbusiness.com/logo.png',
52
+ background_color: '#f5f5f5',
53
+ primary_color: '#007bff',
54
+ checkout_mode: true,
55
+ textCheckoutColor: '#333333',
56
+ textDetailsColor: '#666666',
57
+ checkout_logo: 'assets/images/checkout-logo.png',
58
+ },
59
+ vault_id: 'mock-vault-id-123',
60
+ vault_url: 'https://mock-vault.com',
61
+ reference: 987654,
62
+ is_installments_available: true,
63
+ openpay_keys: { merchant_id: "", public_key: "" },
64
+ fintoc_keys: { public_key: "" }
65
+ }
66
+ }
67
+ }
68
+
69
+ export class OrderClass implements CreateOrderRequest {
70
+ business!: string;
71
+ client!: string;
72
+ billing_address_id!: string;
73
+ shipping_address_id!: string;
74
+ amount!: number;
75
+ status!: string;
76
+ reference!: string;
77
+ is_oneclick!: boolean;
78
+ items!: OrderItem[];
79
+
80
+ get mockObject(): CreateOrderRequest {
81
+ return {
82
+ business: "The business pk",
83
+ client: "Client auth token",
84
+ billing_address_id: "The billing address",
85
+ shipping_address_id: "The shipping address",
86
+ amount: 25,
87
+ status: "PENDING",
88
+ reference: "XXXXXXX",
89
+ is_oneclick: false,
90
+ items: [
91
+ { ...new OrderItemClass() }
92
+ ]
93
+ }
94
+
95
+ }
96
+ }
97
+
98
+ export class OrderItemClass implements OrderItem {
99
+ description!: string;
100
+ quantity!: number;
101
+ price_unit!: number;
102
+ discount!: number;
103
+ taxes!: number;
104
+ product_reference!: number;
105
+ name!: string;
106
+ amount_total!: number;
107
+
108
+ get mockObject(): OrderItem {
109
+ return {
110
+ description: "string",
111
+ quantity: 0,
112
+ price_unit: 0,
113
+ discount: 0,
114
+ taxes: 0,
115
+ product_reference: 0,
116
+ name: "string",
117
+ amount_total: 0,
118
+ }
119
+
120
+ }
121
+ }
122
+
123
+ export class OrderResponseClass implements CreateOrderResponse {
124
+ id!: number;
125
+ created!: string;
126
+ amount!: string;
127
+ status!: string;
128
+ payment_method?: string | undefined;
129
+ reference?: string | undefined;
130
+ is_oneclick!: boolean;
131
+ items!: [
132
+ {
133
+ description: string;
134
+ product_reference: string;
135
+ quantity: string;
136
+ price_unit: string;
137
+ discount: string;
138
+ taxes: string;
139
+ amount_total: string;
140
+ }
141
+ ];
142
+ billing_address?: string | undefined;
143
+ shipping_address?: string | undefined;
144
+ client!: {
145
+ email: string;
146
+ name: string;
147
+ first_name: string;
148
+ last_name: string;
149
+ client_profile: {
150
+ gender: string;
151
+ date_birth?: string | undefined;
152
+ terms: boolean;
153
+ phone: string;
154
+ };
155
+ };
156
+
157
+ get mockObject(): CreateOrderResponse {
158
+ return {
159
+ id: 12345,
160
+ created: '2024-02-01T10:42:00Z',
161
+ amount: '123.45',
162
+ status: 'APPROVED',
163
+ payment_method: 'CREDIT_CARD',
164
+ reference: 'PAYMENT_REF_12345',
165
+ is_oneclick: true,
166
+ items: [
167
+ {
168
+ description: 'Mock Item 1',
169
+ product_reference: 'PRD-123',
170
+ quantity: '2',
171
+ price_unit: '50.00',
172
+ discount: '5.00',
173
+ taxes: '10.90',
174
+ amount_total: '105.90',
175
+ },
176
+ {
177
+ description: 'Mock Item 2',
178
+ product_reference: 'PRD-456',
179
+ quantity: '1',
180
+ price_unit: '73.45',
181
+ discount: '0.00',
182
+ taxes: '6.55',
183
+ amount_total: '79.00',
184
+ },
185
+ ],
186
+ billing_address: 'Mock Street 123, Mock City',
187
+ shipping_address: 'Mock Avenue 456, Mock Town',
188
+ client: {
189
+ email: 'mockuser@example.com',
190
+ name: 'Mock User',
191
+ first_name: 'Mock',
192
+ last_name: 'User',
193
+ client_profile: {
194
+ gender: 'M',
195
+ date_birth: '1990-01-01',
196
+ terms: true,
197
+ phone: '+1234567890',
198
+ },
199
+ },
200
+ }
201
+ }
202
+ }
203
+
204
+ export class CreatePaymentRequestClass implements CreatePaymentRequest {
205
+ business_pk!: string;
206
+ amount!: number;
207
+ date!: string;
208
+ order!: string;
209
+
210
+ get mockObject(): CreatePaymentRequest {
211
+ const now = new Date();
212
+ const dateString = now.toISOString();
213
+ return {
214
+ business_pk: "NNNNNNNNNN",
215
+ amount: 25,
216
+ date: dateString,
217
+ order: "XXXXX"
218
+ };
219
+ }
220
+ }
221
+
222
+ export class CreatePaymentResponseClass implements CreatePaymentResponse {
223
+ pk!: number;
224
+ order?: string | undefined;
225
+ amount!: string;
226
+ status!: string;
227
+ date!: string;
228
+ paid_date?: string | undefined;
229
+ shipping_address!: {
230
+ street: string;
231
+ number: string;
232
+ suburb: string;
233
+ city: { name: string };
234
+ state: { name: string; country: { name: string } };
235
+ zip_code: string;
236
+ };
237
+ shipping_address_id?: string | undefined;
238
+ billing_address!: {
239
+ street: string;
240
+ number: string;
241
+ suburb: string;
242
+ city: { name: string };
243
+ state: { name: string; country: { name: string } };
244
+ zip_code: string;
245
+ };
246
+ billing_address_id?: string | undefined;
247
+ client?: string | undefined;
248
+ customer_order_reference?: string | undefined;
249
+
250
+ get mockObject(): CreatePaymentResponse {
251
+ return {
252
+ pk: 45678,
253
+ order: "ORDER-98765",
254
+ amount: "250.00",
255
+ status: "PENDING",
256
+ date: "2024-02-01T14:29:05Z",
257
+ paid_date: "",
258
+ shipping_address: {
259
+ street: "Mock Street 123",
260
+ number: "10",
261
+ suburb: "Mock Suburb",
262
+ city: { name: "Mock City" },
263
+ state: { name: "Mock State", country: { name: "Mock Country" } },
264
+ zip_code: "12345",
265
+ },
266
+ shipping_address_id: "",
267
+ billing_address: {
268
+ street: "Mock Street 456",
269
+ number: "20",
270
+ suburb: "Mock Suburb 2",
271
+ city: { name: "Mock City 2" },
272
+ state: { name: "Mock State 2", country: { name: "Mock Country 2" } },
273
+ zip_code: "54321",
274
+ },
275
+ billing_address_id: "",
276
+ client: "CLIENT-123",
277
+ customer_order_reference: "REF-ABC123",
278
+ };
279
+ }
280
+ }
281
+
282
+ export class StartCheckoutRequestClass implements StartCheckoutRequest {
283
+ card: any;
284
+ name: any;
285
+ last_name!: string;
286
+ email_client: any;
287
+ phone_number: any;
288
+ return_url!: string;
289
+ id_product!: string;
290
+ quantity_product!: number;
291
+ id_ship!: string;
292
+ instance_id_ship!: string;
293
+ amount: any;
294
+ title_ship!: string;
295
+ description!: string;
296
+ device_session_id: any;
297
+ token_id!: string;
298
+ order_id: any;
299
+ business_id: any;
300
+ payment_id: any;
301
+ source!: string;
302
+
303
+ get mockObject(): StartCheckoutRequest {
304
+ return {
305
+ card: " any",
306
+ name: " any",
307
+ last_name: " string",
308
+ email_client: " any",
309
+ phone_number: " any",
310
+ return_url: " string",
311
+ id_product: " string",
312
+ quantity_product: 0,
313
+ id_ship: " string",
314
+ instance_id_ship: " string",
315
+ amount: " any",
316
+ title_ship: " string",
317
+ description: " string",
318
+ device_session_id: " any",
319
+ token_id: " string",
320
+ order_id: " any",
321
+ business_id: " any",
322
+ payment_id: " any",
323
+ source: " string",
324
+ };
325
+ }
326
+ }
327
+
328
+ export class StartCheckoutResponseClass implements StartCheckoutResponse {
329
+ status!: number;
330
+ message!: string;
331
+ psp_response!: {
332
+ id: string;
333
+ authorization: number;
334
+ operation_type: string;
335
+ transaction_type: string;
336
+ status: string;
337
+ conciliated: boolean;
338
+ creation_date: string;
339
+ operation_date: string;
340
+ description: string;
341
+ error_message?: string;
342
+ order_id?: string;
343
+ card: {
344
+ type: string;
345
+ brand: string;
346
+ address?: string;
347
+ card_number: string;
348
+ holder_name: string;
349
+ expiration_year: string;
350
+ expiration_month: string;
351
+ allows_charges: boolean;
352
+ allows_payouts: boolean;
353
+ bank_name: string;
354
+ points_type: string;
355
+ points_card: boolean;
356
+ bank_code: number;
357
+ };
358
+ customer_id: string;
359
+ gateway_card_present: string;
360
+ amount: number;
361
+ fee: {
362
+ amount: number;
363
+ tax: number;
364
+ currency: string;
365
+ };
366
+ payment_method: {
367
+ type: string;
368
+ url: string;
369
+ };
370
+ currency: string;
371
+ method: string;
372
+ object: string;
373
+ };
374
+ transaction_status!: string;
375
+ transaction_id!: number;
376
+ payment_id!: number;
377
+ provider!: string;
378
+ next_action!: {
379
+ redirect_to_url: {
380
+ url: string;
381
+ return_url: string;
382
+ verify_transaction_status_url: string;
383
+ };
384
+ };
385
+ actions!: {
386
+ name: string;
387
+ url: string;
388
+ method: string;
389
+ }[];
390
+
391
+ get mockObject(): StartCheckoutResponse {
392
+ return {
393
+ status: 200, // Representa un estado exitoso
394
+ message: "Payment processing initiated",
395
+ transaction_status: "PENDING",
396
+ transaction_id: 1234567890,
397
+ payment_id: 9876543210,
398
+ provider: "STRIPE",
399
+ next_action: {
400
+ redirect_to_url: {
401
+ url: "https://www.mock-payment-provider.com/checkout",
402
+ return_url: "https://your-app.com/payment-confirmation",
403
+ verify_transaction_status_url:
404
+ "https://api.mock-payment-provider.com/transactions/1234567890/status",
405
+ },
406
+ },
407
+ psp_response: {
408
+ id: " string",
409
+ authorization: 0,
410
+ operation_type: " string",
411
+ transaction_type: " string",
412
+ status: " string",
413
+ conciliated: false,
414
+ creation_date: " string",
415
+ operation_date: " string",
416
+ description: " string",
417
+ error_message: " string",
418
+ order_id: " string",
419
+ card: {
420
+ type: " string",
421
+ brand: " string",
422
+ address: " string",
423
+ card_number: " string",
424
+ holder_name: " string",
425
+ expiration_year: " string",
426
+ expiration_month: " string",
427
+ allows_charges: false,
428
+ allows_payouts: false,
429
+ bank_name: " string",
430
+ points_type: " string",
431
+ points_card: false,
432
+ bank_code: 0,
433
+ },
434
+ customer_id: " string",
435
+ gateway_card_present: " string",
436
+ amount: 0,
437
+ fee: {
438
+ amount: 0,
439
+ tax: 0,
440
+ currency: " string",
441
+ },
442
+ payment_method: {
443
+ type: " string",
444
+ url: " string",
445
+ },
446
+ currency: " string",
447
+ method: " string",
448
+ object: " string",
449
+ },
450
+ actions: [
451
+ {
452
+ name: "Check status",
453
+ url: "https://api.mock-payment-provider.com/transactions/1234567890/status",
454
+ method: "GET",
455
+ },
456
+ {
457
+ name: "Cancel payment",
458
+ url: "https://api.mock-payment-provider.com/transactions/1234567890/cancel",
459
+ method: "POST",
460
+ },
461
+ ],
462
+ };
463
+ }
464
+ }
465
+
466
+ export class TokensRequestClass implements TokensRequest {
467
+ vault_id!: string;
468
+ vault_url!: string;
469
+ data: { [key: string]: any } = {};
470
+
471
+ get mockObject(): TokensRequest {
472
+ return {
473
+ vault_id: "string",
474
+ vault_url: "string",
475
+ data: {
476
+ fields: [],
477
+ },
478
+ };
479
+ }
480
+ }
481
+
482
+ export class RegisterCustomerCardResponseClass
483
+ implements RegisterCustomerCardResponse {
484
+ skyflow_id!: string;
485
+ user_id!: number;
486
+
487
+ get mockObject(): RegisterCustomerCardResponse {
488
+ return {
489
+ skyflow_id: "string",
490
+ user_id: 0,
491
+ };
492
+ }
493
+ }
494
+
495
+ export class RegisterCustomerCardRequestClass
496
+ implements RegisterCustomerCardRequest {
497
+ skyflow_id!: string;
498
+
499
+ get mockObject(): RegisterCustomerCardRequest {
500
+ return {
501
+ skyflow_id: "",
502
+ };
503
+ }
504
+ }
505
+
506
+ export class GetCustomerCardsResponseClass implements GetCustomerCardsResponse {
507
+ user_id!: number;
508
+ cards!: {
509
+ records: {
510
+ fields: {
511
+ card_number: string;
512
+ cardholder_name: string;
513
+ cvv: string;
514
+ expiration_month: string;
515
+ expiration_year: string;
516
+ skyflow_id: string;
517
+ };
518
+ }[];
519
+ };
520
+
521
+ get mockObject(): GetCustomerCardsResponse {
522
+ return {
523
+ user_id: 0,
524
+ cards: {
525
+ records: [
526
+ {
527
+ fields: {
528
+ card_number: "string",
529
+ cardholder_name: "string",
530
+ cvv: "string",
531
+ expiration_month: "string",
532
+ expiration_year: "string",
533
+ skyflow_id: "string",
534
+ },
535
+ },
536
+ ],
537
+ },
538
+ };
539
+ }
540
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+
4
+ /* Language and Environment */
5
+ "target": "es2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
6
+
7
+ /* Modules */
8
+ "module": "esnext", /* Specify what module code is generated. */
9
+ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
10
+ /* Emit */
11
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
12
+ "outDir": "./dist", /* Specify an output folder for all emitted files. */
13
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
14
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
15
+ /* Type Checking */
16
+ "strict": true,
17
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
18
+ }
19
+ }