@tonder.io/ionic-lite-sdk 0.0.31-beta → 0.0.33-beta

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 (34) hide show
  1. package/.gitlab-ci.yml +28 -28
  2. package/README.md +202 -592
  3. package/dist/classes/3dsHandler.d.ts +36 -0
  4. package/dist/classes/liteCheckout.d.ts +13 -4
  5. package/dist/index.js +1 -1
  6. package/dist/types/requests.d.ts +3 -0
  7. package/dist/types/responses.d.ts +1 -0
  8. package/jest.config.ts +14 -14
  9. package/package.json +38 -38
  10. package/rollup.config.js +16 -16
  11. package/src/classes/3dsHandler.ts +254 -0
  12. package/src/classes/errorResponse.ts +16 -16
  13. package/src/classes/liteCheckout.ts +535 -462
  14. package/src/helpers/utils.ts +12 -12
  15. package/src/index.ts +4 -4
  16. package/src/types/commons.ts +62 -62
  17. package/src/types/requests.ts +93 -89
  18. package/src/types/responses.ts +188 -187
  19. package/src/types/skyflow.ts +17 -17
  20. package/tests/classes/liteCheckout.test.ts +57 -57
  21. package/tests/methods/createOrder.test.ts +142 -142
  22. package/tests/methods/createPayment.test.ts +122 -122
  23. package/tests/methods/customerRegister.test.ts +119 -119
  24. package/tests/methods/getBusiness.test.ts +115 -115
  25. package/tests/methods/getCustomerCards.test.ts +117 -117
  26. package/tests/methods/getOpenpayDeviceSessionID.test.ts +94 -94
  27. package/tests/methods/getSkyflowToken.test.ts +154 -154
  28. package/tests/methods/getVaultToken.test.ts +106 -106
  29. package/tests/methods/registerCustomerCard.test.ts +117 -117
  30. package/tests/methods/startCheckoutRouter.test.ts +119 -119
  31. package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
  32. package/tests/utils/defaultMock.ts +20 -20
  33. package/tests/utils/mockClasses.ts +651 -649
  34. package/tsconfig.json +18 -18
package/README.md CHANGED
@@ -1,592 +1,202 @@
1
- # Tonder SDK
2
-
3
- Tonder SDK Lite to integrate REST service
4
-
5
- ## Installation
6
-
7
- You can install using NPM
8
- ```bash
9
- npm i @tonder.io/ionic-lite-sdk
10
- ```
11
-
12
- or using an script tag
13
- ```html
14
- // TO DO
15
- ```
16
-
17
- Add dependencies to the root of the app (index.html)
18
- ```html
19
- <script src=https://openpay.s3.amazonaws.com/openpay.v1.min.js></script>
20
- <script src=https://openpay.s3.amazonaws.com/openpay-data.v1.min.js></script>
21
- ```
22
-
23
- ## Usage
24
- ## Import LiteCheckout class
25
- ```javascript
26
- import { LiteCheckout } from "@tonder.io/ionic-lite-sdk"
27
- ```
28
- ## Create instance
29
-
30
- ```javascript
31
- const liteCheckout = new LiteCheckout({
32
- signal,
33
- baseUrlTonder,
34
- apiKeyTonder
35
- })
36
- ```
37
-
38
- | Property | Type | Description |
39
- |:---------------:|:-------------:|:-----------------------------------------------------------------------:|
40
- | signal | AborSignal | Signal from AbortController instance if it need cancel request |
41
- | baseUrlTonder | string | Live server: http://stage.tonder.io |
42
- | | | Mock Server: https://stoplight.io/mocks/tonder/tonder-api-v1-2/3152148 |
43
- | apiKeyTonder | string | You can take this from you Tonder Dashboard |
44
- | | | |
45
-
46
- # Class methods
47
-
48
- # Business
49
-
50
- ## Get business
51
-
52
- ```javascript
53
- const merchantData = await liteCheckout.getBusiness();
54
- ```
55
-
56
- ## Return business data
57
-
58
- ```typescript
59
- {
60
- business: {
61
- pk: number,
62
- name: string,
63
- categories: [
64
- {
65
- pk: number,
66
- name: string
67
- }
68
- ],
69
- web: string,
70
- logo: string,
71
- full_logo_url: string,
72
- background_color: string,
73
- primary_color: string,
74
- checkout_mode: boolean,
75
- textCheckoutColor: string,
76
- textDetailsColor: string,
77
- checkout_logo: string
78
- },
79
- openpay_keys: {
80
- merchant_id: string,
81
- public_key: string
82
- },
83
- fintoc_keys: {
84
- public_key: string
85
- },
86
- vault_id: string,
87
- vault_url: string,
88
- reference: number,
89
- is_installments_available: boolean
90
- }
91
- ```
92
-
93
- # OpenPay
94
-
95
- ## Get OpenPay session id
96
-
97
- ```javascript
98
- const { openpay_keys } = merchantData;
99
-
100
- const deviceSessionIdTonder = await liteCheckout.getOpenpayDeviceSessionID(
101
- openpay_keys.merchant_id,
102
- openpay_keys.public_key,
103
- is_sandbox: true
104
- );
105
- ```
106
-
107
- ## Return OpenPay device session id
108
-
109
- string
110
-
111
- # Customer
112
-
113
- ## Get customer authorization token
114
-
115
- ```javascript
116
- const customerEmail = "john.c.calhoun@examplepetstore.com";
117
-
118
- const { auth_token } = await liteCheckout.customerRegister(customerEmail);
119
- ```
120
-
121
- ## Return customer data
122
-
123
- ```typescript
124
- {
125
- id: number,
126
- email: string,
127
- auth_token: string
128
- }
129
- ```
130
-
131
- # Order
132
-
133
- ## Create order
134
-
135
- ```typescript
136
- const cartItems = [
137
- {
138
- description: "Test product description",
139
- quantity: 1,
140
- price_unit: 25,
141
- discount: 0,
142
- taxes: 12,
143
- product_reference: 65421,
144
- name: "Test product",
145
- amount_total: 25
146
- }
147
- ]
148
-
149
- const { reference } = merchantData;
150
-
151
- const orderData = {
152
- business: apiKeyTonder,
153
- client: auth_token,
154
- billing_address_id: null,
155
- shipping_address_id: null,
156
- amount: total,
157
- status: "A",
158
- reference: reference,
159
- is_oneclick: true,
160
- items: cartItems,
161
- };
162
-
163
- const jsonResponseOrder = await liteCheckout.createOrder(
164
- orderData
165
- );
166
- ```
167
-
168
- ## Return order data
169
- ```typescript
170
- {
171
- id: number,
172
- created: string,
173
- amount: string,
174
- status: string,
175
- payment_method?: string,
176
- reference?: string,
177
- is_oneclick: boolean,
178
- items: [
179
- {
180
- description: string,
181
- product_reference: string,
182
- quantity: string,
183
- price_unit: string,
184
- discount: string,
185
- taxes: string,
186
- amount_total: string
187
- }
188
- ],
189
- billing_address?: string,
190
- shipping_address?: string,
191
- client: {
192
- email: string,
193
- name: string,
194
- first_name: string,
195
- last_name: string,
196
- client_profile: {
197
- gender: string,
198
- date_birth?: string,
199
- terms: boolean,
200
- phone: string
201
- }
202
- }
203
- }
204
- ```
205
-
206
- # Payment
207
-
208
- ## Create payment
209
- ```javascript
210
- const now = new Date();
211
- const dateString = now.toISOString();
212
-
213
- const { id: customerId } = await liteCheckout.customerRegister(customerEmail);
214
-
215
- const paymentData = {
216
- business_pk: business.pk,
217
- amount: total,
218
- date: dateString,
219
- order_id: jsonResponseOrder.id,
220
- client_id: customerId,
221
- };
222
-
223
- const jsonResponsePayment = await liteCheckout.createPayment(
224
- paymentData
225
- );
226
- ```
227
-
228
- ## Return payment data
229
- ```javascript
230
- {
231
- pk: number,
232
- order?: string,
233
- amount: string,
234
- status: string,
235
- date: string,
236
- paid_date?: string,
237
- shipping_address: {
238
- street: string,
239
- number: string,
240
- suburb: string,
241
- city: {
242
- name: string
243
- },
244
- state: {
245
- name: string,
246
- country: {
247
- name: string
248
- }
249
- },
250
- zip_code: string
251
- },
252
- shipping_address_id?: string,
253
- billing_address: {
254
- street: string,
255
- number: string,
256
- suburb: string,
257
- city: {
258
- name: string
259
- },
260
- state: {
261
- name: string,
262
- country: {
263
- name: string
264
- }
265
- },
266
- zip_code: string
267
- },
268
- billing_address_id?: string,
269
- client?: string,
270
- customer_order_reference?: string
271
- }
272
- ```
273
-
274
- # Skyflow tokens
275
-
276
- ## Get skyflow payment form tokenized values
277
-
278
- The values of the variable skyflowTokens come from your html form
279
-
280
- ```javascript
281
-
282
- const skyflowFields = {
283
- card_number: this.paymentForm.value.cardNumber,
284
- cvv: this.paymentForm.value.cvv,
285
- expiration_month: this.paymentForm.value.month,
286
- expiration_year: this.paymentForm.value.expirationYear,
287
- cardholder_name: this.paymentForm.value.name
288
- }
289
-
290
- const { vault_id, vault_url } = merchantData;
291
-
292
-
293
- const skyflowTokens = await liteCheckout.getSkyflowTokens({
294
- vault_id: vault_id,
295
- vault_url: vault_url,
296
- data: skyflowFields
297
- })
298
-
299
- ```
300
-
301
- ## Return skyflow tokenized data
302
- ```typescript
303
- {
304
- vaultID: string,
305
- responses: [
306
- {
307
- records: [
308
- {
309
- skyflow_id: string
310
- }
311
- ]
312
- },
313
- {
314
- fields: {
315
- card_number: string,
316
- cardholder_name: string,
317
- cvv: string,
318
- expiration_month: string,
319
- expiration_year: string,
320
- skyflow_id: string
321
- }
322
- }
323
- ]
324
- }
325
- ```
326
-
327
- # Checkout router
328
-
329
- ## Get checkout router data
330
-
331
- ```javascript
332
-
333
- const customerPhone = "+11111111";
334
- const returnUrl = "http://localhost:8100/payment/success";
335
-
336
- const routerData = {
337
- card: skyflowTokens,
338
- name: customerName,
339
- last_name: customerLastName,
340
- email_client: customerEmail,
341
- phone_number: customerPhone,
342
- return_url: returnUrl,
343
- id_product: "no_id",
344
- quantity_product: 1,
345
- id_ship: "0",
346
- instance_id_ship: "0",
347
- amount: total,
348
- title_ship: "shipping",
349
- description: "Transaction from the lite SDK",
350
- device_session_id: deviceSessionIdTonder,
351
- token_id: "",
352
- order_id: jsonResponseOrder.id,
353
- business_id: business.pk,
354
- payment_id: jsonResponsePayment.pk,
355
- source: 'ionic-lite-sdk',
356
- metadata: {
357
- name: "xxxxx"
358
- },
359
- currency: "MXN"
360
- };
361
-
362
- const jsonResponseRouter = await liteCheckout.startCheckoutRouter(
363
- routerData
364
- );
365
-
366
- ```
367
-
368
- ## Return checkout router data
369
-
370
- ```typescript
371
- {
372
- status: 200,
373
- message: "Success",
374
- psp_response: {
375
- id: string,
376
- authorization: number,
377
- operation_type: string,
378
- transaction_type: string,
379
- status: string,
380
- conciliated: boolean,
381
- creation_date: string,
382
- operation_date: string,
383
- description: string,
384
- error_message?: string,
385
- order_id?: string,
386
- card: {
387
- type: string,
388
- brand: string,
389
- address?: string,
390
- card_number: string,
391
- holder_name: string,
392
- expiration_year: string,
393
- expiration_month: string,
394
- allows_charges: boolean,
395
- allows_payouts: boolean,
396
- bank_name: string,
397
- points_type: string,
398
- points_card: boolean,
399
- bank_code: number
400
- },
401
- customer_id: string,
402
- gateway_card_present: string,
403
- amount: number,
404
- fee: {
405
- amount: number,
406
- tax: number,
407
- currency: string
408
- },
409
- payment_method: {
410
- type: string,
411
- url: string
412
- },
413
- currency: string,
414
- method: string,
415
- object: string
416
- },
417
- transaction_status: string,
418
- transaction_id: number,
419
- payment_id: number,
420
- provider: string,
421
- next_action: {
422
- redirect_to_url: {
423
- url: string,
424
- return_url: string,
425
- verify_transaction_status_url: string
426
- }
427
- },
428
- actions: [
429
- {
430
- name: string,
431
- url: string,
432
- method: string
433
- }
434
- ]
435
- }
436
- ```
437
-
438
- ## Take actions on base to the checkout router response
439
-
440
- # Checkout router full
441
-
442
- <font size="4">This method integrate the create order, create payment and checkout router methods into one method, the info required to this method is:</font>
443
-
444
- ```typescript
445
-
446
- const returnUrl = "http://localhost:8100/payment/success";
447
-
448
- let checkoutData = {
449
- customer: {
450
- name: "Jhon",
451
- lastname: "Doe",
452
- email: "john.c.calhoun@examplepetstore.com",
453
- phone: "+58452258525"
454
- },
455
- order: {
456
- items: [
457
- {
458
- description: "Test product description",
459
- quantity: 1,
460
- price_unit: 25,
461
- discount: 1,
462
- taxes: 12,
463
- product_reference: 89456123,
464
- name: "Test product",
465
- amount_total: 25
466
- }
467
- ]
468
- },
469
- return_url: returnUrl,
470
- total: 25,
471
- isSandbox: true,
472
- metadata: {},
473
- currency: "MXN",
474
- skyflowTokens: {
475
- cardholder_name: "",
476
- card_number: "",
477
- expiration_year: "",
478
- expiration_month: "",
479
- cvv: "",
480
- skyflow_id: ""
481
- }
482
- }
483
-
484
- ```
485
-
486
- <font size="4">It is required get the skyflow tokens to add it to the checkout router method, the values of the variable skyflowFields come from your html form</font>
487
-
488
- ```typescript
489
-
490
- const merchantData: any = await liteCheckout.getBusiness();
491
-
492
- const { vault_id, vault_url } = merchantData;
493
-
494
- const skyflowFields = {
495
- card_number: this.paymentForm.value.cardNumber,
496
- cvv: this.paymentForm.value.cvv,
497
- expiration_month: this.paymentForm.value.month,
498
- expiration_year: this.paymentForm.value.expirationYear,
499
- cardholder_name: this.paymentForm.value.name
500
- }
501
-
502
- const skyflowTokens = await liteCheckout.getSkyflowTokens({
503
- vault_id: vault_id,
504
- vault_url: vault_url,
505
- data: skyflowFields
506
- })
507
-
508
- checkoutData.skyflowTokens = skyflowTokens;
509
-
510
- const jsonResponseRouter: any = await liteCheckout.startCheckoutRouterFull(
511
- checkoutData
512
- );
513
-
514
- ```
515
-
516
- <font size="4">The response is the same to the startCheckoutRouter method. Take actions on base to the checkout router response</font>
517
-
518
- # Customer Cards(Register)
519
-
520
- ## Register customer card
521
-
522
- ```typescript
523
-
524
- customer_auth_token: string;
525
-
526
- data: {
527
- skyflow_id: string;
528
- };
529
-
530
- const jsonResponseOrder = await liteCheckout.registerCustomerCard(
531
- customer_auth_token,
532
- data
533
- );
534
- ```
535
-
536
- ## Return register customer card
537
- ```typescript
538
- {
539
- skyflow_id: string;
540
- user_id: number;
541
- }
542
- ```
543
-
544
- # Customer Cards(Get)
545
-
546
- ## Get customer cards
547
-
548
- ```typescript
549
-
550
- customer_auth_token: string;
551
-
552
- query: string = "?ordering=<string>&search=<string>";
553
-
554
- const jsonResponseOrder = await liteCheckout.getCustomerCards(
555
- customer_auth_token,
556
- query
557
- );
558
- ```
559
-
560
- ## Return get customer cards
561
- ```typescript
562
- {
563
- user_id: number,
564
- cards: [
565
- {
566
- fields: {
567
- card_number: string,
568
- cardholder_name: string,
569
- cvv: string,
570
- expiration_month: string,
571
- expiration_year: string,
572
- skyflow_id: string
573
- }
574
- }
575
- ]
576
- }
577
- ```
578
-
579
- ## Delete customer card
580
-
581
- ```typescript
582
-
583
- const deleted: boolean = await liteCheckout.deleteCustomerCard(
584
- customer_auth_token,
585
- skyflow_id
586
- );
587
-
588
- ```
589
-
590
- ## License
591
-
592
- [MIT](https://choosealicense.com/licenses/mit/)
1
+ # Tonder SDK
2
+
3
+ Tonder SDK Lite to integrate REST service
4
+
5
+ ## Installation
6
+
7
+ You can install using NPM
8
+ ```bash
9
+ npm i @tonder.io/ionic-lite-sdk
10
+ ```
11
+
12
+ Add dependencies to the root of the app (index.html)
13
+ ```html
14
+ <script src=https://openpay.s3.amazonaws.com/openpay.v1.min.js></script>
15
+ <script src=https://openpay.s3.amazonaws.com/openpay-data.v1.min.js></script>
16
+ ```
17
+
18
+ ## Usage
19
+ ## Import LiteCheckout class
20
+ ```javascript
21
+ import { LiteCheckout } from "@tonder.io/ionic-lite-sdk"
22
+ ```
23
+ ## Create instance
24
+
25
+ ```javascript
26
+ const liteCheckout = new LiteCheckout({
27
+ signal,
28
+ baseUrlTonder,
29
+ apiKeyTonder
30
+ })
31
+
32
+ // To verify a 3ds transaction you can use the following method
33
+ // It should be called after the injectCheckout method
34
+ // The response status will be one of the following
35
+ // ['Declined', 'Cancelled', 'Failed', 'Success', 'Pending', 'Authorized']
36
+
37
+ inlineCheckout.verify3dsTransaction().then(response => {
38
+ console.log('Verify 3ds response', response)
39
+ })
40
+ ```
41
+
42
+ | Property | Type | Description |
43
+ |:---------------:|:-------------:|:-----------------------------------------------------------------------:|
44
+ | signal | AborSignal | Signal from AbortController instance if it need cancel request |
45
+ | baseUrlTonder | string | Live server: http://stage.tonder.io |
46
+ | | | Mock Server: https://stoplight.io/mocks/tonder/tonder-api-v1-2/3152148 |
47
+ | apiKeyTonder | string | You can take this from you Tonder Dashboard |
48
+ | | | |
49
+
50
+ # Class methods
51
+
52
+ # Checkout router
53
+
54
+ ```typescript
55
+
56
+ const returnUrl = "http://localhost:8100/payment/success";
57
+
58
+ let checkoutData = {
59
+ customer: {
60
+ name: "Jhon",
61
+ lastname: "Doe",
62
+ email: "john.c.calhoun@examplepetstore.com",
63
+ phone: "+58452258525"
64
+ },
65
+ order: {
66
+ items: [
67
+ {
68
+ description: "Test product description",
69
+ quantity: 1,
70
+ price_unit: 25,
71
+ discount: 1,
72
+ taxes: 12,
73
+ product_reference: 89456123,
74
+ name: "Test product",
75
+ amount_total: 25
76
+ }
77
+ ]
78
+ },
79
+ return_url: returnUrl,
80
+ total: 25,
81
+ isSandbox: true,
82
+ metadata: {},
83
+ currency: "MXN",
84
+ skyflowTokens: {
85
+ cardholder_name: "",
86
+ card_number: "",
87
+ expiration_year: "",
88
+ expiration_month: "",
89
+ cvv: "",
90
+ skyflow_id: ""
91
+ }
92
+ }
93
+
94
+ ```
95
+
96
+ <font size="4">It is required get the skyflow tokens to add it to the checkout router method, the values of the variable skyflowFields come from your html form</font>
97
+
98
+ ```typescript
99
+
100
+ const merchantData: any = await liteCheckout.getBusiness();
101
+
102
+ const { vault_id, vault_url } = merchantData;
103
+
104
+ const skyflowFields = {
105
+ card_number: this.paymentForm.value.cardNumber,
106
+ cvv: this.paymentForm.value.cvv,
107
+ expiration_month: this.paymentForm.value.month,
108
+ expiration_year: this.paymentForm.value.expirationYear,
109
+ cardholder_name: this.paymentForm.value.name
110
+ }
111
+
112
+ const skyflowTokens = await liteCheckout.getSkyflowTokens({
113
+ vault_id: vault_id,
114
+ vault_url: vault_url,
115
+ data: skyflowFields
116
+ })
117
+
118
+ checkoutData.skyflowTokens = skyflowTokens;
119
+
120
+ const jsonResponseRouter: any = await liteCheckout.startCheckoutRouterFull(
121
+ checkoutData
122
+ );
123
+
124
+ ```
125
+
126
+ <font size="4">Take actions on base to the checkout router response</font>
127
+
128
+ # Customer Cards(Register)
129
+
130
+ ## Register customer card
131
+
132
+ ```typescript
133
+
134
+ customer_auth_token: string;
135
+
136
+ data: {
137
+ skyflow_id: string;
138
+ };
139
+
140
+ const jsonResponseOrder = await liteCheckout.registerCustomerCard(
141
+ customer_auth_token,
142
+ data
143
+ );
144
+ ```
145
+
146
+ ## Return register customer card
147
+ ```typescript
148
+ {
149
+ skyflow_id: string;
150
+ user_id: number;
151
+ }
152
+ ```
153
+
154
+ # Customer Cards(Get)
155
+
156
+ ## Get customer cards
157
+
158
+ ```typescript
159
+
160
+ customer_auth_token: string;
161
+
162
+ query: string = "?ordering=<string>&search=<string>";
163
+
164
+ const jsonResponseOrder = await liteCheckout.getCustomerCards(
165
+ customer_auth_token,
166
+ query
167
+ );
168
+ ```
169
+
170
+ ## Return get customer cards
171
+ ```typescript
172
+ {
173
+ user_id: number,
174
+ cards: [
175
+ {
176
+ fields: {
177
+ card_number: string,
178
+ cardholder_name: string,
179
+ cvv: string,
180
+ expiration_month: string,
181
+ expiration_year: string,
182
+ skyflow_id: string
183
+ }
184
+ }
185
+ ]
186
+ }
187
+ ```
188
+
189
+ ## Delete customer card
190
+
191
+ ```typescript
192
+
193
+ const deleted: boolean = await liteCheckout.deleteCustomerCard(
194
+ customer_auth_token,
195
+ skyflow_id
196
+ );
197
+
198
+ ```
199
+
200
+ ## License
201
+
202
+ [MIT](https://choosealicense.com/licenses/mit/)