@tonder.io/ionic-lite-sdk 0.0.35-beta.7 → 0.0.36-beta.1
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.
- package/.gitlab-ci.yml +28 -28
- package/README.md +221 -202
- package/dist/classes/errorResponse.d.ts +1 -1
- package/dist/classes/liteCheckout.d.ts +32 -56
- package/dist/data/api.d.ts +1 -1
- package/dist/helpers/utils.d.ts +4 -8
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/types/commons.d.ts +0 -37
- package/dist/types/requests.d.ts +3 -12
- package/dist/types/responses.d.ts +3 -0
- package/jest.config.ts +14 -14
- package/package.json +38 -38
- package/rollup.config.js +16 -16
- package/src/classes/3dsHandler.ts +237 -237
- package/src/classes/errorResponse.ts +16 -16
- package/src/classes/liteCheckout.ts +575 -598
- package/src/data/api.ts +20 -20
- package/src/helpers/constants.ts +63 -63
- package/src/helpers/mercadopago.ts +15 -15
- package/src/helpers/utils.ts +320 -120
- package/src/index.ts +4 -10
- package/src/types/commons.ts +83 -125
- package/src/types/requests.ts +105 -114
- package/src/types/responses.ts +193 -189
- package/src/types/skyflow.ts +17 -17
- package/tests/classes/liteCheckout.test.ts +57 -57
- package/tests/methods/createOrder.test.ts +142 -142
- package/tests/methods/createPayment.test.ts +122 -122
- package/tests/methods/customerRegister.test.ts +119 -119
- package/tests/methods/getBusiness.test.ts +115 -115
- package/tests/methods/getCustomerCards.test.ts +119 -113
- package/tests/methods/getOpenpayDeviceSessionID.test.ts +95 -0
- package/tests/methods/getSkyflowToken.test.ts +155 -0
- package/tests/methods/getVaultToken.test.ts +107 -0
- package/tests/methods/registerCustomerCard.test.ts +117 -117
- package/tests/methods/startCheckoutRouter.test.ts +119 -119
- package/tests/methods/startCheckoutRouterFull.test.ts +138 -138
- package/tests/utils/defaultMock.ts +20 -21
- package/tests/utils/mockClasses.ts +656 -659
- package/tsconfig.json +18 -18
- package/.idea/aws.xml +0 -17
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/prettier.xml +0 -6
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -132
- package/dist/classes/BaseInlineCheckout.d.ts +0 -45
- package/dist/data/businessApi.d.ts +0 -2
- package/dist/data/cardApi.d.ts +0 -4
- package/dist/data/checkoutApi.d.ts +0 -4
- package/dist/data/customerApi.d.ts +0 -2
- package/dist/data/openPayApi.d.ts +0 -1
- package/dist/data/paymentMethodApi.d.ts +0 -5
- package/dist/data/skyflowApi.d.ts +0 -1
- package/dist/helpers/skyflow.d.ts +0 -3
- package/dist/helpers/validations.d.ts +0 -6
- package/dist/shared/catalog/paymentMethodsCatalog.d.ts +0 -1
- package/dist/shared/constants/messages.d.ts +0 -11
- package/dist/shared/constants/paymentMethodAPM.d.ts +0 -62
- package/dist/shared/constants/tonderUrl.d.ts +0 -7
- package/dist/types/card.d.ts +0 -29
- package/dist/types/checkout.d.ts +0 -103
- package/dist/types/customer.d.ts +0 -12
- package/dist/types/paymentMethod.d.ts +0 -22
- package/src/classes/BaseInlineCheckout.ts +0 -356
- package/src/data/businessApi.ts +0 -18
- package/src/data/cardApi.ts +0 -89
- package/src/data/checkoutApi.ts +0 -87
- package/src/data/customerApi.ts +0 -31
- package/src/data/openPayApi.ts +0 -12
- package/src/data/paymentMethodApi.ts +0 -37
- package/src/data/skyflowApi.ts +0 -20
- package/src/helpers/skyflow.ts +0 -91
- package/src/helpers/validations.ts +0 -55
- package/src/shared/catalog/paymentMethodsCatalog.ts +0 -248
- package/src/shared/constants/messages.ts +0 -11
- package/src/shared/constants/paymentMethodAPM.ts +0 -63
- package/src/shared/constants/tonderUrl.ts +0 -8
- package/src/types/card.ts +0 -34
- package/src/types/checkout.ts +0 -118
- package/src/types/customer.ts +0 -12
- package/src/types/index.d.ts +0 -10
- package/src/types/liteInlineCheckout.d.ts +0 -191
- package/src/types/paymentMethod.ts +0 -24
- package/src/types/validations.d.ts +0 -11
|
@@ -1,598 +1,575 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare const MP_DEVICE_SESSION_ID: string | undefined;
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from "../helpers/utils";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
await
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
data
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
},
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
);
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
this.activeAPMs = apms_results
|
|
577
|
-
.filter(
|
|
578
|
-
(apmItem: TonderAPM) => apmItem.category.toLowerCase() !== "cards",
|
|
579
|
-
)
|
|
580
|
-
.map((apmItem: TonderAPM) => {
|
|
581
|
-
const apm: APM = {
|
|
582
|
-
id: apmItem.pk,
|
|
583
|
-
payment_method: apmItem.payment_method,
|
|
584
|
-
priority: apmItem.priority,
|
|
585
|
-
category: apmItem.category,
|
|
586
|
-
...getPaymentMethodDetails(apmItem.payment_method),
|
|
587
|
-
};
|
|
588
|
-
return apm;
|
|
589
|
-
})
|
|
590
|
-
.sort((a: APM, b: APM) => a.priority - b.priority);
|
|
591
|
-
|
|
592
|
-
return this.activeAPMs;
|
|
593
|
-
} catch (e) {
|
|
594
|
-
console.error("Error getting APMS", e);
|
|
595
|
-
return [];
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
1
|
+
import {injectMercadoPagoSecurity} from "../helpers/mercadopago";
|
|
2
|
+
|
|
3
|
+
declare const MP_DEVICE_SESSION_ID: string | undefined;
|
|
4
|
+
|
|
5
|
+
import Skyflow from "skyflow-js";
|
|
6
|
+
import CollectContainer from "skyflow-js/types/core/external/collect/collect-container";
|
|
7
|
+
import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
|
|
8
|
+
import { APM, Business, TonderAPM } from "../types/commons";
|
|
9
|
+
import { CreateOrderRequest, CreatePaymentRequest, RegisterCustomerCardRequest, StartCheckoutRequest, TokensRequest, StartCheckoutFullRequest, StartCheckoutIdRequest } from "../types/requests";
|
|
10
|
+
import { GetSecureTokenResponse, GetBusinessResponse, CustomerRegisterResponse, CreateOrderResponse, CreatePaymentResponse, StartCheckoutResponse, GetVaultTokenResponse, IErrorResponse, GetCustomerCardsResponse, RegisterCustomerCardResponse } from "../types/responses";
|
|
11
|
+
import { ErrorResponse } from "./errorResponse";
|
|
12
|
+
import { buildErrorResponse, buildErrorResponseFromCatch, getBrowserInfo, getPaymentMethodDetails, getBusinessId } from "../helpers/utils";
|
|
13
|
+
import { ThreeDSHandler } from "./3dsHandler";
|
|
14
|
+
import { getCustomerAPMs } from "../data/api";
|
|
15
|
+
|
|
16
|
+
declare global {
|
|
17
|
+
interface Window {
|
|
18
|
+
OpenPay: any;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type LiteCheckoutConstructor = {
|
|
23
|
+
signal: AbortSignal;
|
|
24
|
+
baseUrlTonder: string;
|
|
25
|
+
publicApiKeyTonder: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export class LiteCheckout implements LiteCheckoutConstructor {
|
|
29
|
+
signal: AbortSignal;
|
|
30
|
+
baseUrlTonder: string;
|
|
31
|
+
publicApiKeyTonder: string;
|
|
32
|
+
process3ds: ThreeDSHandler;
|
|
33
|
+
activeAPMs: APM[] = []
|
|
34
|
+
merchantData?: Business | ErrorResponse;
|
|
35
|
+
|
|
36
|
+
constructor({
|
|
37
|
+
signal,
|
|
38
|
+
baseUrlTonder,
|
|
39
|
+
publicApiKeyTonder,
|
|
40
|
+
}: LiteCheckoutConstructor) {
|
|
41
|
+
this.baseUrlTonder = baseUrlTonder;
|
|
42
|
+
this.signal = signal;
|
|
43
|
+
this.publicApiKeyTonder = publicApiKeyTonder;
|
|
44
|
+
this.process3ds = new ThreeDSHandler({
|
|
45
|
+
apiKey: this.publicApiKeyTonder,
|
|
46
|
+
baseUrl: this.baseUrlTonder,
|
|
47
|
+
})
|
|
48
|
+
this.#init()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async #init(){
|
|
52
|
+
this.getActiveAPMs()
|
|
53
|
+
const { mercado_pago } = await this.#fetchMerchantData() as Business
|
|
54
|
+
if (!!mercado_pago && mercado_pago.active){
|
|
55
|
+
injectMercadoPagoSecurity()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getOpenpayDeviceSessionID(
|
|
60
|
+
merchant_id: string,
|
|
61
|
+
public_key: string,
|
|
62
|
+
is_sandbox: boolean
|
|
63
|
+
): Promise<string | ErrorResponse> {
|
|
64
|
+
try {
|
|
65
|
+
let openpay = await window.OpenPay;
|
|
66
|
+
openpay.setId(merchant_id);
|
|
67
|
+
openpay.setApiKey(public_key);
|
|
68
|
+
openpay.setSandboxMode(is_sandbox);
|
|
69
|
+
return await openpay.deviceData.setup({
|
|
70
|
+
signal: this.signal,
|
|
71
|
+
}) as string;
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw buildErrorResponseFromCatch(e);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async #fetchMerchantData() {
|
|
77
|
+
try {
|
|
78
|
+
if (!this.merchantData){
|
|
79
|
+
this.merchantData = await this.getBusiness();
|
|
80
|
+
}
|
|
81
|
+
return this.merchantData
|
|
82
|
+
}catch(e){
|
|
83
|
+
return this.merchantData
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async getBusiness(): Promise<GetBusinessResponse | ErrorResponse> {
|
|
88
|
+
try {
|
|
89
|
+
const getBusiness = await fetch(
|
|
90
|
+
`${this.baseUrlTonder}/api/v1/payments/business/${this.publicApiKeyTonder}`,
|
|
91
|
+
{
|
|
92
|
+
headers: {
|
|
93
|
+
Authorization: `Token ${this.publicApiKeyTonder}`,
|
|
94
|
+
},
|
|
95
|
+
signal: this.signal,
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (getBusiness.ok) return (await getBusiness.json()) as Business;
|
|
100
|
+
|
|
101
|
+
throw await buildErrorResponse(getBusiness);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
throw buildErrorResponseFromCatch(e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async verify3dsTransaction () {
|
|
108
|
+
const result3ds = await this.process3ds.verifyTransactionStatus()
|
|
109
|
+
const resultCheckout = await this.resumeCheckout(result3ds)
|
|
110
|
+
this.process3ds.setPayload(resultCheckout)
|
|
111
|
+
return this.handle3dsRedirect(resultCheckout)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async resumeCheckout(response: any) {
|
|
115
|
+
// Stop the routing process if the transaction is either hard declined or successful
|
|
116
|
+
if (response?.decline?.error_type === "Hard") {
|
|
117
|
+
return response
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (["Success", "Authorized"].includes(response?.transaction_status)) {
|
|
121
|
+
return response;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (response) {
|
|
125
|
+
const routerItems = {
|
|
126
|
+
checkout_id: response?.checkout?.id,
|
|
127
|
+
};
|
|
128
|
+
try {
|
|
129
|
+
const routerResponse = await this.handleCheckoutRouter(
|
|
130
|
+
routerItems
|
|
131
|
+
);
|
|
132
|
+
return routerResponse
|
|
133
|
+
}catch (error){
|
|
134
|
+
// throw error
|
|
135
|
+
}
|
|
136
|
+
return response
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async handle3dsRedirect(response: ErrorResponse | StartCheckoutResponse | false | undefined) {
|
|
141
|
+
const iframe = response && 'next_action' in response ? response?.next_action?.iframe_resources?.iframe:null
|
|
142
|
+
if (iframe) {
|
|
143
|
+
this.process3ds.loadIframe()!.then(() => {
|
|
144
|
+
//TODO: Check if this will be necessary on the frontend side
|
|
145
|
+
// after some the tests in production, since the 3DS process
|
|
146
|
+
// doesn't works properly on the sandbox environment
|
|
147
|
+
// setTimeout(() => {
|
|
148
|
+
// process3ds.verifyTransactionStatus();
|
|
149
|
+
// }, 10000);
|
|
150
|
+
this.process3ds.verifyTransactionStatus();
|
|
151
|
+
}).catch((error: any) => {
|
|
152
|
+
console.log('Error loading iframe:', error)
|
|
153
|
+
})
|
|
154
|
+
} else {
|
|
155
|
+
const redirectUrl = this.process3ds.getRedirectUrl()
|
|
156
|
+
if (redirectUrl) {
|
|
157
|
+
this.process3ds.redirectToChallenge()
|
|
158
|
+
} else {
|
|
159
|
+
return response;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async customerRegister(email: string): Promise<CustomerRegisterResponse | ErrorResponse> {
|
|
165
|
+
try {
|
|
166
|
+
const url = `${this.baseUrlTonder}/api/v1/customer/`;
|
|
167
|
+
const data = { email: email };
|
|
168
|
+
const response = await fetch(url, {
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers: {
|
|
171
|
+
"Content-Type": "application/json",
|
|
172
|
+
Authorization: `Token ${this.publicApiKeyTonder}`,
|
|
173
|
+
},
|
|
174
|
+
signal: this.signal,
|
|
175
|
+
body: JSON.stringify(data),
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
if (response.ok) return await response.json() as CustomerRegisterResponse;
|
|
179
|
+
throw await buildErrorResponse(response);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
throw buildErrorResponseFromCatch(e);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async createOrder(orderItems: CreateOrderRequest): Promise<CreateOrderResponse | ErrorResponse> {
|
|
186
|
+
try {
|
|
187
|
+
const url = `${this.baseUrlTonder}/api/v1/orders/`;
|
|
188
|
+
const data = orderItems;
|
|
189
|
+
const response = await fetch(url, {
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: {
|
|
192
|
+
"Content-Type": "application/json",
|
|
193
|
+
Authorization: `Token ${this.publicApiKeyTonder}`,
|
|
194
|
+
},
|
|
195
|
+
body: JSON.stringify(data),
|
|
196
|
+
});
|
|
197
|
+
if (response.ok) return await response.json() as CreateOrderResponse;
|
|
198
|
+
throw await buildErrorResponse(response);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
throw buildErrorResponseFromCatch(e);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async createPayment(paymentItems: CreatePaymentRequest): Promise<CreatePaymentResponse | ErrorResponse> {
|
|
205
|
+
try {
|
|
206
|
+
const url = `${this.baseUrlTonder}/api/v1/business/${paymentItems.business_pk}/payments/`;
|
|
207
|
+
const data = paymentItems;
|
|
208
|
+
const response = await fetch(url, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
headers: {
|
|
211
|
+
"Content-Type": "application/json",
|
|
212
|
+
Authorization: `Token ${this.publicApiKeyTonder}`,
|
|
213
|
+
},
|
|
214
|
+
body: JSON.stringify(data),
|
|
215
|
+
});
|
|
216
|
+
if (response.ok) return await response.json() as CreatePaymentResponse;
|
|
217
|
+
throw await buildErrorResponse(response);
|
|
218
|
+
} catch (e) {
|
|
219
|
+
throw buildErrorResponseFromCatch(e);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async handleCheckoutRouter(routerData: StartCheckoutRequest | StartCheckoutIdRequest){
|
|
223
|
+
try {
|
|
224
|
+
const url = `${this.baseUrlTonder}/api/v1/checkout-router/`;
|
|
225
|
+
const data = routerData;
|
|
226
|
+
const response = await fetch(url, {
|
|
227
|
+
method: "POST",
|
|
228
|
+
headers: {
|
|
229
|
+
"Content-Type": "application/json",
|
|
230
|
+
Authorization: `Token ${this.publicApiKeyTonder}`,
|
|
231
|
+
},
|
|
232
|
+
body: JSON.stringify({...data, ...(typeof MP_DEVICE_SESSION_ID !== "undefined" ? {mp_device_session_id: MP_DEVICE_SESSION_ID}:{})}),
|
|
233
|
+
});
|
|
234
|
+
if (response.ok) return await response.json() as StartCheckoutResponse;
|
|
235
|
+
throw await buildErrorResponse(response);
|
|
236
|
+
} catch (e) {
|
|
237
|
+
throw buildErrorResponseFromCatch(e);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async startCheckoutRouter(routerData: StartCheckoutRequest | StartCheckoutIdRequest): Promise<StartCheckoutResponse | ErrorResponse | undefined> {
|
|
242
|
+
const checkoutResult = await this.handleCheckoutRouter(routerData);
|
|
243
|
+
const payload = await this.init3DSRedirect(checkoutResult)
|
|
244
|
+
if(payload)
|
|
245
|
+
return checkoutResult;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async startCheckoutRouterFull(routerFullData: StartCheckoutFullRequest): Promise<StartCheckoutResponse | ErrorResponse | undefined> {
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
|
|
252
|
+
const {
|
|
253
|
+
order,
|
|
254
|
+
total,
|
|
255
|
+
customer,
|
|
256
|
+
skyflowTokens,
|
|
257
|
+
return_url,
|
|
258
|
+
isSandbox,
|
|
259
|
+
metadata,
|
|
260
|
+
currency,
|
|
261
|
+
payment_method
|
|
262
|
+
} = routerFullData;
|
|
263
|
+
|
|
264
|
+
const merchantResult = await this.getBusiness();
|
|
265
|
+
|
|
266
|
+
const customerResult : CustomerRegisterResponse | ErrorResponse = await this.customerRegister(customer.email);
|
|
267
|
+
|
|
268
|
+
if(customerResult && "auth_token" in customerResult && merchantResult && "reference" in merchantResult) {
|
|
269
|
+
|
|
270
|
+
const orderData: CreateOrderRequest = {
|
|
271
|
+
business: this.publicApiKeyTonder,
|
|
272
|
+
client: customerResult.auth_token,
|
|
273
|
+
billing_address_id: null,
|
|
274
|
+
shipping_address_id: null,
|
|
275
|
+
amount: total,
|
|
276
|
+
reference: merchantResult.reference,
|
|
277
|
+
is_oneclick: true,
|
|
278
|
+
items: order.items,
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const orderResult = await this.createOrder(orderData);
|
|
282
|
+
|
|
283
|
+
const now = new Date();
|
|
284
|
+
|
|
285
|
+
const dateString = now.toISOString();
|
|
286
|
+
|
|
287
|
+
if("id" in orderResult && "id" in customerResult && "business" in merchantResult) {
|
|
288
|
+
|
|
289
|
+
const paymentItems: CreatePaymentRequest = {
|
|
290
|
+
business_pk: merchantResult.business.pk,
|
|
291
|
+
amount: total,
|
|
292
|
+
date: dateString,
|
|
293
|
+
order_id: orderResult.id,
|
|
294
|
+
client_id: customerResult.id
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const paymentResult = await this.createPayment(
|
|
298
|
+
paymentItems
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
let deviceSessionIdTonder: any;
|
|
302
|
+
|
|
303
|
+
const { openpay_keys, business } = merchantResult
|
|
304
|
+
|
|
305
|
+
if (openpay_keys.merchant_id && openpay_keys.public_key) {
|
|
306
|
+
deviceSessionIdTonder = await this.getOpenpayDeviceSessionID(
|
|
307
|
+
openpay_keys.merchant_id,
|
|
308
|
+
openpay_keys.public_key,
|
|
309
|
+
isSandbox
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const routerItems: StartCheckoutRequest = {
|
|
314
|
+
name: customer.name,
|
|
315
|
+
last_name: customer.lastname,
|
|
316
|
+
email_client: customer.email,
|
|
317
|
+
phone_number: customer.phone,
|
|
318
|
+
return_url: return_url,
|
|
319
|
+
id_product: "no_id",
|
|
320
|
+
quantity_product: 1,
|
|
321
|
+
id_ship: "0",
|
|
322
|
+
instance_id_ship: "0",
|
|
323
|
+
amount: total,
|
|
324
|
+
title_ship: "shipping",
|
|
325
|
+
description: "transaction",
|
|
326
|
+
device_session_id: deviceSessionIdTonder ? deviceSessionIdTonder : null,
|
|
327
|
+
token_id: "",
|
|
328
|
+
order_id: ("id" in orderResult) && orderResult.id,
|
|
329
|
+
business_id: business.pk,
|
|
330
|
+
payment_id: ("pk" in paymentResult) && paymentResult.pk,
|
|
331
|
+
source: 'sdk',
|
|
332
|
+
metadata: metadata,
|
|
333
|
+
browser_info: getBrowserInfo(),
|
|
334
|
+
currency: currency,
|
|
335
|
+
...( !!payment_method
|
|
336
|
+
? {payment_method}
|
|
337
|
+
: {card: skyflowTokens}
|
|
338
|
+
),
|
|
339
|
+
...(typeof MP_DEVICE_SESSION_ID !== "undefined" ? {mp_device_session_id: MP_DEVICE_SESSION_ID}:{})
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const checkoutResult = await this.handleCheckoutRouter(routerItems);
|
|
343
|
+
const payload = await this.init3DSRedirect(checkoutResult)
|
|
344
|
+
if(payload)
|
|
345
|
+
return checkoutResult;
|
|
346
|
+
} else {
|
|
347
|
+
|
|
348
|
+
throw new ErrorResponse({
|
|
349
|
+
code: "500",
|
|
350
|
+
body: orderResult as any,
|
|
351
|
+
name: "Keys error",
|
|
352
|
+
message: "Order response errors"
|
|
353
|
+
} as IErrorResponse)
|
|
354
|
+
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
} else {
|
|
358
|
+
|
|
359
|
+
throw new ErrorResponse({
|
|
360
|
+
code: "500",
|
|
361
|
+
body: merchantResult as any,
|
|
362
|
+
name: "Keys error",
|
|
363
|
+
message: "Merchant or customer reposne errors"
|
|
364
|
+
} as IErrorResponse)
|
|
365
|
+
|
|
366
|
+
}
|
|
367
|
+
} catch (e) {
|
|
368
|
+
|
|
369
|
+
throw buildErrorResponseFromCatch(e);
|
|
370
|
+
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
async init3DSRedirect(checkoutResult: ErrorResponse | StartCheckoutResponse){
|
|
375
|
+
this.process3ds.setPayload(checkoutResult)
|
|
376
|
+
return await this.handle3dsRedirect(checkoutResult)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async getSkyflowTokens({
|
|
380
|
+
vault_id,
|
|
381
|
+
vault_url,
|
|
382
|
+
data,
|
|
383
|
+
}: TokensRequest): Promise<any | ErrorResponse> {
|
|
384
|
+
const skyflow = Skyflow.init({
|
|
385
|
+
vaultID: vault_id,
|
|
386
|
+
vaultURL: vault_url,
|
|
387
|
+
getBearerToken: async () => await this.getVaultToken(),
|
|
388
|
+
options: {
|
|
389
|
+
logLevel: Skyflow.LogLevel.ERROR,
|
|
390
|
+
env: Skyflow.Env.DEV,
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
const collectContainer: CollectContainer = skyflow.container(
|
|
395
|
+
Skyflow.ContainerType.COLLECT
|
|
396
|
+
) as CollectContainer;
|
|
397
|
+
|
|
398
|
+
const fieldPromises = await this.getFieldsPromise(data, collectContainer);
|
|
399
|
+
|
|
400
|
+
const result = await Promise.all(fieldPromises);
|
|
401
|
+
|
|
402
|
+
const mountFail = result.some((item: boolean) => !item);
|
|
403
|
+
|
|
404
|
+
if (mountFail) {
|
|
405
|
+
throw buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));
|
|
406
|
+
} else {
|
|
407
|
+
try {
|
|
408
|
+
const collectResponseSkyflowTonder = await collectContainer.collect() as any;
|
|
409
|
+
if (collectResponseSkyflowTonder) return collectResponseSkyflowTonder["records"][0]["fields"];
|
|
410
|
+
throw buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))
|
|
411
|
+
} catch (error) {
|
|
412
|
+
throw buildErrorResponseFromCatch(error);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async getVaultToken(): Promise<string> {
|
|
418
|
+
try {
|
|
419
|
+
const response = await fetch(`${this.baseUrlTonder}/api/v1/vault-token/`, {
|
|
420
|
+
method: "GET",
|
|
421
|
+
headers: {
|
|
422
|
+
Authorization: `Token ${this.publicApiKeyTonder}`,
|
|
423
|
+
},
|
|
424
|
+
signal: this.signal,
|
|
425
|
+
});
|
|
426
|
+
if (response.ok) return (await response.json() as GetVaultTokenResponse)?.token;
|
|
427
|
+
throw new Error(`HTTPCODE: ${response.status}`)
|
|
428
|
+
} catch (e) {
|
|
429
|
+
throw new Error(`Failed to retrieve bearer token; ${typeof e == "string" ? e : (e as Error).message}`)
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async getFieldsPromise(data: any, collectContainer: CollectContainer): Promise<Promise<boolean>[]> {
|
|
434
|
+
const fields = await this.getFields(data, collectContainer);
|
|
435
|
+
if (!fields) return [];
|
|
436
|
+
|
|
437
|
+
return fields.map((field: { element: CollectElement, key: string }) => {
|
|
438
|
+
return new Promise((resolve) => {
|
|
439
|
+
const div = document.createElement("div");
|
|
440
|
+
div.hidden = true;
|
|
441
|
+
div.id = `id-${field.key}`;
|
|
442
|
+
document.querySelector(`body`)?.appendChild(div);
|
|
443
|
+
setTimeout(() => {
|
|
444
|
+
field.element.mount(`#id-${field.key}`);
|
|
445
|
+
setInterval(() => {
|
|
446
|
+
if (field.element.isMounted()) {
|
|
447
|
+
const value = data[field.key];
|
|
448
|
+
field.element.update({ value: value });
|
|
449
|
+
return resolve(field.element.isMounted());
|
|
450
|
+
}
|
|
451
|
+
}, 120);
|
|
452
|
+
}, 120);
|
|
453
|
+
});
|
|
454
|
+
})
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
async registerCustomerCard(secureToken: string, customerToken: string, data: RegisterCustomerCardRequest): Promise<RegisterCustomerCardResponse | ErrorResponse> {
|
|
458
|
+
try {
|
|
459
|
+
await this.#fetchMerchantData()
|
|
460
|
+
|
|
461
|
+
const response = await fetch(`${this.baseUrlTonder}/api/v1/business/${getBusinessId(this.merchantData)}/cards/`, {
|
|
462
|
+
method: 'POST',
|
|
463
|
+
headers: {
|
|
464
|
+
'Authorization': `Bearer ${secureToken}`,
|
|
465
|
+
'User-token': customerToken,
|
|
466
|
+
'Content-Type': 'application/json'
|
|
467
|
+
},
|
|
468
|
+
signal: this.signal,
|
|
469
|
+
body: JSON.stringify({...data})
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
if (response.ok) return await response.json() as RegisterCustomerCardResponse;
|
|
473
|
+
throw await buildErrorResponse(response);
|
|
474
|
+
} catch (error) {
|
|
475
|
+
throw buildErrorResponseFromCatch(error);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
async getCustomerCards(customerToken: string, bearerToken: string): Promise<GetCustomerCardsResponse | ErrorResponse> {
|
|
480
|
+
try {
|
|
481
|
+
await this.#fetchMerchantData()
|
|
482
|
+
|
|
483
|
+
const response = await fetch(`${this.baseUrlTonder}/api/v1/business/${getBusinessId(this.merchantData)}/cards`, {
|
|
484
|
+
method: 'GET',
|
|
485
|
+
headers: {
|
|
486
|
+
'Authorization': `Bearer ${bearerToken}`,
|
|
487
|
+
'User-Token': customerToken,
|
|
488
|
+
'Content-Type': 'application/json',
|
|
489
|
+
'Accept': 'application/json'
|
|
490
|
+
},
|
|
491
|
+
signal: this.signal,
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
if (response.ok) return await response.json() as GetCustomerCardsResponse;
|
|
495
|
+
throw await buildErrorResponse(response);
|
|
496
|
+
} catch (error) {
|
|
497
|
+
throw buildErrorResponseFromCatch(error);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
async deleteCustomerCard(customerToken: string, skyflowId: string = ""): Promise<Boolean | ErrorResponse> {
|
|
502
|
+
try {
|
|
503
|
+
await this.#fetchMerchantData()
|
|
504
|
+
const response = await fetch(`${this.baseUrlTonder}/api/v1/business/${getBusinessId(this.merchantData)}/cards/${skyflowId}`, {
|
|
505
|
+
method: 'DELETE',
|
|
506
|
+
headers: {
|
|
507
|
+
'Authorization': `Token ${customerToken}`,
|
|
508
|
+
'Content-Type': 'application/json'
|
|
509
|
+
},
|
|
510
|
+
signal: this.signal,
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
if (response.ok) return true;
|
|
514
|
+
throw await buildErrorResponse(response);
|
|
515
|
+
} catch (error) {
|
|
516
|
+
throw buildErrorResponseFromCatch(error);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
private async getFields(data: any, collectContainer: CollectContainer): Promise<{ element: CollectElement, key: string }[]> {
|
|
521
|
+
return await Promise.all(
|
|
522
|
+
Object.keys(data).map(async (key) => {
|
|
523
|
+
const cardHolderNameElement = await collectContainer.create({
|
|
524
|
+
table: "cards",
|
|
525
|
+
column: key,
|
|
526
|
+
type: Skyflow.ElementType.INPUT_FIELD,
|
|
527
|
+
});
|
|
528
|
+
return { element: cardHolderNameElement, key: key };
|
|
529
|
+
})
|
|
530
|
+
)
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
async getActiveAPMs(): Promise<APM[]> {
|
|
534
|
+
try {
|
|
535
|
+
const apms_response = await getCustomerAPMs(this.baseUrlTonder, this.publicApiKeyTonder);
|
|
536
|
+
const apms_results = apms_response && apms_response['results'] && apms_response['results'].length > 0 ? apms_response['results'] : []
|
|
537
|
+
this.activeAPMs = apms_results
|
|
538
|
+
.filter((apmItem: TonderAPM) =>
|
|
539
|
+
apmItem.category.toLowerCase() !== 'cards')
|
|
540
|
+
.map((apmItem: TonderAPM) => {
|
|
541
|
+
const apm: APM = {
|
|
542
|
+
id: apmItem.pk,
|
|
543
|
+
payment_method: apmItem.payment_method,
|
|
544
|
+
priority: apmItem.priority,
|
|
545
|
+
category: apmItem.category,
|
|
546
|
+
...getPaymentMethodDetails(apmItem.payment_method,)
|
|
547
|
+
}
|
|
548
|
+
return apm;
|
|
549
|
+
}).sort((a: APM, b: APM) => a.priority - b.priority);
|
|
550
|
+
|
|
551
|
+
return this.activeAPMs
|
|
552
|
+
} catch (e) {
|
|
553
|
+
console.error("Error getting APMS", e);
|
|
554
|
+
return [];
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
async getSecureToken(token: string): Promise<GetSecureTokenResponse | ErrorResponse> {
|
|
559
|
+
try {
|
|
560
|
+
const response = await fetch(`${this.baseUrlTonder}/api/secure-token/`, {
|
|
561
|
+
method: 'POST',
|
|
562
|
+
headers: {
|
|
563
|
+
'Authorization': `Token ${token}`,
|
|
564
|
+
'Content-Type': 'application/json'
|
|
565
|
+
},
|
|
566
|
+
signal: this.signal,
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
if (response.ok) return await response.json() as GetSecureTokenResponse;
|
|
570
|
+
throw await buildErrorResponse(response);
|
|
571
|
+
} catch (error) {
|
|
572
|
+
throw buildErrorResponseFromCatch(error);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|