@ozura/elements 0.1.0-beta.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1121 -720
- package/dist/frame/element-frame.js +77 -57
- package/dist/frame/element-frame.js.map +1 -1
- package/dist/frame/tokenizer-frame.html +1 -1
- package/dist/frame/tokenizer-frame.js +221 -74
- package/dist/frame/tokenizer-frame.js.map +1 -1
- package/dist/oz-elements.esm.js +870 -231
- package/dist/oz-elements.esm.js.map +1 -1
- package/dist/oz-elements.umd.js +870 -230
- package/dist/oz-elements.umd.js.map +1 -1
- package/dist/react/frame/tokenizerFrame.d.ts +32 -0
- package/dist/react/index.cjs.js +1045 -220
- package/dist/react/index.cjs.js.map +1 -1
- package/dist/react/index.esm.js +1042 -221
- package/dist/react/index.esm.js.map +1 -1
- package/dist/react/react/index.d.ts +165 -8
- package/dist/react/sdk/OzElement.d.ts +34 -3
- package/dist/react/sdk/OzVault.d.ts +104 -4
- package/dist/react/sdk/errors.d.ts +9 -0
- package/dist/react/sdk/index.d.ts +29 -0
- package/dist/react/server/index.d.ts +266 -2
- package/dist/react/types/index.d.ts +94 -16
- package/dist/react/utils/appearance.d.ts +9 -0
- package/dist/react/utils/cardUtils.d.ts +14 -0
- package/dist/react/utils/uuid.d.ts +12 -0
- package/dist/server/frame/tokenizerFrame.d.ts +32 -0
- package/dist/server/index.cjs.js +761 -30
- package/dist/server/index.cjs.js.map +1 -1
- package/dist/server/index.esm.js +757 -31
- package/dist/server/index.esm.js.map +1 -1
- package/dist/server/sdk/OzElement.d.ts +34 -3
- package/dist/server/sdk/OzVault.d.ts +104 -4
- package/dist/server/sdk/errors.d.ts +9 -0
- package/dist/server/sdk/index.d.ts +29 -0
- package/dist/server/server/index.d.ts +266 -2
- package/dist/server/types/index.d.ts +94 -16
- package/dist/server/utils/appearance.d.ts +9 -0
- package/dist/server/utils/cardUtils.d.ts +14 -0
- package/dist/server/utils/uuid.d.ts +12 -0
- package/dist/types/frame/tokenizerFrame.d.ts +32 -0
- package/dist/types/sdk/OzElement.d.ts +34 -3
- package/dist/types/sdk/OzVault.d.ts +104 -4
- package/dist/types/sdk/errors.d.ts +9 -0
- package/dist/types/sdk/index.d.ts +29 -0
- package/dist/types/server/index.d.ts +266 -2
- package/dist/types/types/index.d.ts +94 -16
- package/dist/types/utils/appearance.d.ts +9 -0
- package/dist/types/utils/cardUtils.d.ts +14 -0
- package/dist/types/utils/uuid.d.ts +12 -0
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,720 +1,1121 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
PCI-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
import {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
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
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
-
|
|
685
|
-
|
|
686
|
-
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
1
|
+
# @ozura/elements
|
|
2
|
+
|
|
3
|
+
PCI-isolated card and bank account tokenization SDK for the Ozura Vault.
|
|
4
|
+
|
|
5
|
+
Card data is collected inside Ozura-hosted iframes so raw numbers never touch your JavaScript bundle, your server logs, or your network traffic. The tokenizer communicates directly with the vault using `MessageChannel` port transfers — the merchant page acts as a layout host only.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of contents
|
|
10
|
+
|
|
11
|
+
- [How it works](#how-it-works)
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Quick start — React](#quick-start--react)
|
|
14
|
+
- [Quick start — Vanilla JS](#quick-start--vanilla-js)
|
|
15
|
+
- [Server setup](#server-setup)
|
|
16
|
+
- [Wax key endpoint](#wax-key-endpoint)
|
|
17
|
+
- [Card sale endpoint](#card-sale-endpoint)
|
|
18
|
+
- [Vanilla JS API](#vanilla-js-api)
|
|
19
|
+
- [OzVault.create()](#ozvaultcreate)
|
|
20
|
+
- [vault.createElement()](#vaultcreateelementtypeoptions)
|
|
21
|
+
- [vault.createToken()](#vaultcreatetokenoptions)
|
|
22
|
+
- [vault.createBankElement()](#vaultcreatebankelement)
|
|
23
|
+
- [vault.createBankToken()](#vaultcreatebanktokenoptions)
|
|
24
|
+
- [vault.destroy()](#vaultdestroy)
|
|
25
|
+
- [OzElement events](#ozelement-events)
|
|
26
|
+
- [React API](#react-api)
|
|
27
|
+
- [OzElements provider](#ozelements-provider)
|
|
28
|
+
- [OzCard](#ozcard)
|
|
29
|
+
- [Individual field components](#individual-field-components)
|
|
30
|
+
- [OzBankCard](#ozbankcard)
|
|
31
|
+
- [useOzElements()](#useozelements)
|
|
32
|
+
- [Styling](#styling)
|
|
33
|
+
- [Per-element styles](#per-element-styles)
|
|
34
|
+
- [Global appearance](#global-appearance)
|
|
35
|
+
- [Custom fonts](#custom-fonts)
|
|
36
|
+
- [Billing details](#billing-details)
|
|
37
|
+
- [Error handling](#error-handling)
|
|
38
|
+
- [Server utilities](#server-utilities)
|
|
39
|
+
- [Ozura class](#ozura-class)
|
|
40
|
+
- [Route handler factories](#route-handler-factories)
|
|
41
|
+
- [Local development](#local-development)
|
|
42
|
+
- [Content Security Policy](#content-security-policy)
|
|
43
|
+
- [TypeScript reference](#typescript-reference)
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## How it works
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
Merchant page
|
|
51
|
+
├── OzVault (manages tokenizer iframe + element iframes)
|
|
52
|
+
├── [hidden] tokenizer-frame.html ← Ozura origin
|
|
53
|
+
├── [visible] element-frame.html ← card number ─┐ MessageChannel
|
|
54
|
+
├── [visible] element-frame.html ← expiry ├─ port transfer
|
|
55
|
+
└── [visible] element-frame.html ← CVV ─┘
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
1. `OzVault.create()` mounts a hidden tokenizer iframe and fetches a short-lived **wax key** from your server.
|
|
59
|
+
2. Calling `vault.createElement()` mounts a visible input iframe for each field.
|
|
60
|
+
3. `vault.createToken()` opens a direct `MessageChannel` between each element iframe and the tokenizer iframe. Raw values travel over those ports — they never pass through your JavaScript.
|
|
61
|
+
4. The tokenizer POSTs directly to the vault API over HTTPS and returns a token to your page.
|
|
62
|
+
|
|
63
|
+
Your server only ever sees a token, never card data.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Credentials
|
|
68
|
+
|
|
69
|
+
| Credential | Format | Where it lives | Required for |
|
|
70
|
+
|---|---|---|---|
|
|
71
|
+
| **Vault pub key** | `pk_live_…` or `pk_prod_…` | Frontend env var (safe to expose) | All integrations |
|
|
72
|
+
| **Vault API key** | `key_…` | Server env var — **never in the browser** | Minting wax keys (all integrations) |
|
|
73
|
+
| **Pay API key** | `ak_…` | Server env var only | OzuraPay merchants (card charging) |
|
|
74
|
+
| **Merchant ID** | `ozu_…` | Server env var only | OzuraPay merchants (card charging) |
|
|
75
|
+
|
|
76
|
+
If you are not routing payments through OzuraPay you only need the vault pub key (frontend) and vault API key (backend).
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install @ozura/elements
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
React and React DOM are peer dependencies (optional — only needed for `@ozura/elements/react`):
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm install react react-dom # if not already installed
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Requirements:** Node ≥ 18, React ≥ 17 (React peer).
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Quick start — React
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
// 1. Wrap your checkout in <OzElements>
|
|
100
|
+
import { OzElements, OzCard, useOzElements, createFetchWaxKey } from '@ozura/elements/react';
|
|
101
|
+
|
|
102
|
+
function CheckoutPage() {
|
|
103
|
+
return (
|
|
104
|
+
<OzElements
|
|
105
|
+
pubKey="pk_live_..."
|
|
106
|
+
fetchWaxKey={createFetchWaxKey('/api/mint-wax')}
|
|
107
|
+
>
|
|
108
|
+
<CheckoutForm />
|
|
109
|
+
</OzElements>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 2. Collect card data and tokenize
|
|
114
|
+
function CheckoutForm() {
|
|
115
|
+
const { createToken, ready } = useOzElements();
|
|
116
|
+
|
|
117
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
const { token, cvcSession, billing } = await createToken({
|
|
120
|
+
billing: {
|
|
121
|
+
firstName: 'Jane',
|
|
122
|
+
lastName: 'Smith',
|
|
123
|
+
email: 'jane@example.com',
|
|
124
|
+
address: { line1: '123 Main St', city: 'Austin', state: 'TX', zip: '78701', country: 'US' },
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Send token to your server
|
|
129
|
+
await fetch('/api/charge', {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
headers: { 'Content-Type': 'application/json' },
|
|
132
|
+
body: JSON.stringify({ token, cvcSession, billing }),
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<form onSubmit={handleSubmit}>
|
|
138
|
+
<OzCard onChange={(state) => console.log(state.cardBrand)} />
|
|
139
|
+
<button type="submit" disabled={!ready}>Pay</button>
|
|
140
|
+
</form>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Quick start — Vanilla JS
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { OzVault, createFetchWaxKey } from '@ozura/elements';
|
|
151
|
+
|
|
152
|
+
// Declare state before OzVault.create so the onReady callback isn't in a TDZ
|
|
153
|
+
let readyCount = 0;
|
|
154
|
+
let tokenizerIsReady = false;
|
|
155
|
+
|
|
156
|
+
function checkReady() {
|
|
157
|
+
if (readyCount === 3 && tokenizerIsReady) enablePayButton();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const vault = await OzVault.create({
|
|
161
|
+
pubKey: 'pk_live_...',
|
|
162
|
+
fetchWaxKey: createFetchWaxKey('/api/mint-wax'),
|
|
163
|
+
onReady: () => { tokenizerIsReady = true; checkReady(); }, // tokenizer iframe loaded
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const cardNumberEl = vault.createElement('cardNumber');
|
|
167
|
+
const expiryEl = vault.createElement('expirationDate');
|
|
168
|
+
const cvvEl = vault.createElement('cvv');
|
|
169
|
+
|
|
170
|
+
cardNumberEl.mount('#card-number');
|
|
171
|
+
expiryEl.mount('#expiry');
|
|
172
|
+
cvvEl.mount('#cvv');
|
|
173
|
+
|
|
174
|
+
[cardNumberEl, expiryEl, cvvEl].forEach(el => {
|
|
175
|
+
el.on('ready', () => { readyCount++; checkReady(); });
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
async function pay() {
|
|
179
|
+
const { token, cvcSession, card } = await vault.createToken({
|
|
180
|
+
billing: { firstName: 'Jane', lastName: 'Smith' },
|
|
181
|
+
});
|
|
182
|
+
// POST { token, cvcSession } to your server
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Clean up when done
|
|
186
|
+
vault.destroy();
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
> **Gating the submit button in vanilla JS** requires checking both `vault.isReady` (tokenizer iframe loaded) **and** every element's `ready` event (input iframes loaded). In React, `useOzElements().ready` combines both automatically.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Server setup
|
|
194
|
+
|
|
195
|
+
### Wax key endpoint
|
|
196
|
+
|
|
197
|
+
The SDK calls your `fetchWaxKey` function with a `tokenizationSessionId` UUID. Your backend must exchange it for a wax key from the vault.
|
|
198
|
+
|
|
199
|
+
**Next.js App Router (recommended)**
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
// app/api/mint-wax/route.ts
|
|
203
|
+
import { Ozura, createMintWaxHandler } from '@ozura/elements/server';
|
|
204
|
+
|
|
205
|
+
const ozura = new Ozura({
|
|
206
|
+
merchantId: process.env.MERCHANT_ID!,
|
|
207
|
+
apiKey: process.env.MERCHANT_API_KEY!,
|
|
208
|
+
vaultKey: process.env.VAULT_API_KEY!,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
export const POST = createMintWaxHandler(ozura);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Express**
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import express from 'express';
|
|
218
|
+
import { Ozura, createMintWaxMiddleware } from '@ozura/elements/server';
|
|
219
|
+
|
|
220
|
+
const ozura = new Ozura({ merchantId: '...', apiKey: '...', vaultKey: '...' });
|
|
221
|
+
const app = express();
|
|
222
|
+
|
|
223
|
+
app.use(express.json());
|
|
224
|
+
app.post('/api/mint-wax', createMintWaxMiddleware(ozura));
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**Manual implementation**
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
// POST /api/mint-wax
|
|
231
|
+
const { sessionId } = await req.json();
|
|
232
|
+
const { waxKey } = await ozura.mintWaxKey({
|
|
233
|
+
tokenizationSessionId: sessionId,
|
|
234
|
+
maxTokenizeCalls: 3, // vault enforces this limit; must match VaultOptions.maxTokenizeCalls on the client
|
|
235
|
+
});
|
|
236
|
+
return Response.json({ waxKey });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Card sale endpoint
|
|
240
|
+
|
|
241
|
+
After `createToken()` resolves on the frontend, POST `{ token, cvcSession, billing }` to your server to charge the card.
|
|
242
|
+
|
|
243
|
+
**Next.js App Router**
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
// app/api/charge/route.ts
|
|
247
|
+
import { Ozura, createCardSaleHandler } from '@ozura/elements/server';
|
|
248
|
+
|
|
249
|
+
const ozura = new Ozura({ merchantId: '...', apiKey: '...', vaultKey: '...' });
|
|
250
|
+
|
|
251
|
+
export const POST = createCardSaleHandler(ozura, {
|
|
252
|
+
getAmount: async (body) => {
|
|
253
|
+
const order = await db.orders.findById(body.orderId as string);
|
|
254
|
+
return order.total; // decimal string, e.g. "49.00"
|
|
255
|
+
},
|
|
256
|
+
// getCurrency: async (body) => 'USD', // optional, defaults to "USD"
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Express**
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
app.post('/api/charge', createCardSaleMiddleware(ozura, {
|
|
264
|
+
getAmount: async (body) => {
|
|
265
|
+
const order = await db.orders.findById(body.orderId as string);
|
|
266
|
+
return order.total; // decimal string, e.g. "49.00"
|
|
267
|
+
},
|
|
268
|
+
// getCurrency: async (body) => 'USD', // optional, defaults to "USD"
|
|
269
|
+
}));
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
> `createCardSaleMiddleware` always terminates the request — it does not call `next()` and cannot be composed in a middleware chain.
|
|
273
|
+
|
|
274
|
+
**Manual implementation**
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
const { token, cvcSession, billing } = await req.json();
|
|
278
|
+
const result = await ozura.cardSale({
|
|
279
|
+
token,
|
|
280
|
+
cvcSession,
|
|
281
|
+
amount: '49.00',
|
|
282
|
+
currency: 'USD',
|
|
283
|
+
billing,
|
|
284
|
+
// Take the first IP from the forwarded-for chain; fall back to socket address.
|
|
285
|
+
// req is a Fetch API Request (Next.js App Router / Vercel Edge).
|
|
286
|
+
clientIpAddress: req.headers.get('x-forwarded-for')?.split(',')[0].trim()
|
|
287
|
+
?? req.headers.get('x-real-ip')
|
|
288
|
+
?? '',
|
|
289
|
+
});
|
|
290
|
+
// result.transactionId, result.amount, result.cardLastFour, result.cardBrand
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Vanilla JS API
|
|
296
|
+
|
|
297
|
+
### OzVault.create(options)
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
const vault = await OzVault.create(options: VaultOptions): Promise<OzVault>
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Mounts the hidden tokenizer iframe and fetches the wax key concurrently. Both happen in parallel — by the time `create()` resolves, the iframe may already be ready.
|
|
304
|
+
|
|
305
|
+
| Option | Type | Required | Description |
|
|
306
|
+
|---|---|---|---|
|
|
307
|
+
| `pubKey` | `string` | ✓ | Your public key from the Ozura admin. |
|
|
308
|
+
| `fetchWaxKey` | `(sessionId: string) => Promise<string>` | ✓ | Called with the session ID; must return a wax key string from your server. Use `createFetchWaxKey('/api/mint-wax')` for the common case. |
|
|
309
|
+
| `frameBaseUrl` | `string` | — | Base URL for iframe assets. Defaults to production CDN. Override for local dev (see [Local development](#local-development)). |
|
|
310
|
+
| `fonts` | `FontSource[]` | — | Custom fonts to inject into all element iframes. |
|
|
311
|
+
| `appearance` | `Appearance` | — | Global theme and variable overrides. |
|
|
312
|
+
| `loadTimeoutMs` | `number` | — | Tokenizer iframe load timeout in ms. Default: `10000`. Only takes effect when `onLoadError` is also provided. |
|
|
313
|
+
| `onLoadError` | `() => void` | — | Called if the tokenizer iframe fails to load within `loadTimeoutMs`. |
|
|
314
|
+
| `onWaxRefresh` | `() => void` | — | Called when the SDK silently re-mints an expired wax key mid-tokenization. |
|
|
315
|
+
| `onReady` | `() => void` | — | Called once when the tokenizer iframe has loaded and is ready. Use in vanilla JS to re-check submit-button readiness when the tokenizer becomes ready after all element iframes have already fired. In React, `useOzElements().ready` handles this automatically. |
|
|
316
|
+
| `maxTokenizeCalls` | `number` | — | Maximum successful `createToken` calls per wax key before the key is considered consumed. Default: `3`. Must match `maxTokenizeCalls` in your server-side `mintWaxKey` call. |
|
|
317
|
+
|
|
318
|
+
Throws `OzError` if `fetchWaxKey` rejects, returns an empty string, or returns a non-string value.
|
|
319
|
+
|
|
320
|
+
> **`createFetchWaxKey` retry behavior:** The built-in helper enforces a **10-second per-attempt timeout** and retries **once after 750 ms on pure network failures** (connection refused, DNS failure, offline). HTTP 4xx/5xx errors are never retried — they signal endpoint misconfiguration or invalid credentials and require developer action. Errors are thrown as `OzError` instances so you can inspect `err.errorCode` and `err.retryable`.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
### vault.createElement(type, options?)
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
vault.createElement(type: ElementType, options?: ElementOptions): OzElement
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Creates and returns an element iframe. Call `.mount(target)` to attach it to the DOM.
|
|
331
|
+
|
|
332
|
+
`ElementType`: `'cardNumber'` | `'cvv'` | `'expirationDate'`
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
const cardEl = vault.createElement('cardNumber', {
|
|
336
|
+
placeholder: '1234 5678 9012 3456',
|
|
337
|
+
style: {
|
|
338
|
+
base: { color: '#1a1a1a', fontSize: '16px' },
|
|
339
|
+
focus: { borderColor: '#6366f1' },
|
|
340
|
+
invalid: { color: '#dc2626' },
|
|
341
|
+
complete: { color: '#16a34a' },
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
cardEl.mount('#card-number-container');
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
`ElementOptions`:
|
|
349
|
+
|
|
350
|
+
| Option | Type | Description |
|
|
351
|
+
|---|---|---|
|
|
352
|
+
| `style` | `ElementStyleConfig` | Per-state style overrides. See [Styling](#styling). |
|
|
353
|
+
| `placeholder` | `string` | Placeholder text (max 100 characters). |
|
|
354
|
+
| `disabled` | `boolean` | Disables the input. |
|
|
355
|
+
| `loadTimeoutMs` | `number` | Iframe load timeout in ms. Default: `10000`. |
|
|
356
|
+
|
|
357
|
+
**OzElement methods:**
|
|
358
|
+
|
|
359
|
+
| Method | Description |
|
|
360
|
+
|---|---|
|
|
361
|
+
| `.mount(target)` | Mount the iframe. Accepts a CSS selector string or `HTMLElement`. |
|
|
362
|
+
| `.unmount()` | Remove the iframe from the DOM. The element can be re-mounted. |
|
|
363
|
+
| `.destroy()` | Permanently destroy the element. Cannot be re-mounted. |
|
|
364
|
+
| `.update(options)` | Update placeholder, style, or disabled state without re-mounting. **Merge semantics** — only provided keys are applied; omitted keys retain their values. To reset a property, pass it with an empty string (e.g. `{ style: { base: { color: '' } } }`). To fully reset all styles, destroy and recreate the element. |
|
|
365
|
+
| `.clear()` | Clear the field value. |
|
|
366
|
+
| `.focus()` | Programmatically focus the input. |
|
|
367
|
+
| `.blur()` | Programmatically blur the input. |
|
|
368
|
+
| `.on(event, fn)` | Subscribe to an event. Returns `this` for chaining. |
|
|
369
|
+
| `.off(event, fn)` | Remove an event handler. |
|
|
370
|
+
| `.once(event, fn)` | Subscribe for a single invocation. |
|
|
371
|
+
| `.isReady` | `true` once the iframe has loaded and signalled ready. |
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
### vault.createToken(options?)
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
vault.createToken(options?: TokenizeOptions): Promise<TokenResponse>
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Tokenizes all mounted and ready card elements. Raw values travel directly from element iframes to the tokenizer iframe via `MessageChannel` — they never pass through your page's JavaScript.
|
|
382
|
+
|
|
383
|
+
Returns a `TokenResponse`:
|
|
384
|
+
|
|
385
|
+
```ts
|
|
386
|
+
interface TokenResponse {
|
|
387
|
+
token: string; // Vault token — pass to cardSale
|
|
388
|
+
cvcSession?: string; // CVC session — pass to cardSale
|
|
389
|
+
card?: {
|
|
390
|
+
last4: string; // e.g. "4242"
|
|
391
|
+
brand: string; // e.g. "visa"
|
|
392
|
+
expMonth: string; // e.g. "09"
|
|
393
|
+
expYear: string; // e.g. "2027"
|
|
394
|
+
};
|
|
395
|
+
billing?: BillingDetails; // Normalized billing — only present if billing was passed in
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
> **`cvcSession` is always present on a successful tokenization.** Although the TypeScript type marks it optional, `createToken()` rejects before returning if `cvcSession` is absent — this would indicate a vault misconfiguration. Always forward both `token` and `cvcSession` to your charge endpoint.
|
|
400
|
+
|
|
401
|
+
`TokenizeOptions`:
|
|
402
|
+
|
|
403
|
+
| Option | Type | Description |
|
|
404
|
+
|---|---|---|
|
|
405
|
+
| `billing` | `BillingDetails` | Validated and normalized billing details. Returned in `TokenResponse.billing`. |
|
|
406
|
+
| `firstName` | `string` | **Deprecated.** Pass inside `billing` instead. |
|
|
407
|
+
| `lastName` | `string` | **Deprecated.** Pass inside `billing` instead. |
|
|
408
|
+
|
|
409
|
+
Throws `OzError` if:
|
|
410
|
+
- The vault is not ready (`errorCode: 'unknown'`)
|
|
411
|
+
- A tokenization is already in progress
|
|
412
|
+
- Billing validation fails (`errorCode: 'validation'`)
|
|
413
|
+
- No elements are mounted
|
|
414
|
+
- The vault returns an error (`errorCode` reflects the HTTP status)
|
|
415
|
+
- The request times out after 30 seconds (`errorCode: 'timeout'`) — this timeout is separate from `loadTimeoutMs` and is not configurable
|
|
416
|
+
|
|
417
|
+
**`vault.tokenizeCount`**
|
|
418
|
+
|
|
419
|
+
```ts
|
|
420
|
+
vault.tokenizeCount: number // read-only getter
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
Returns the number of successful `createToken()` / `createBankToken()` calls made against the current wax key. Resets to `0` each time the wax key is refreshed (proactively or reactively). Use this in vanilla JS to display "attempts remaining" feedback or gate the submit button:
|
|
424
|
+
|
|
425
|
+
```ts
|
|
426
|
+
const MAX = 3; // matches maxTokenizeCalls
|
|
427
|
+
const remaining = MAX - vault.tokenizeCount;
|
|
428
|
+
payButton.textContent = `Pay (${remaining} attempt${remaining === 1 ? '' : 's'} remaining)`;
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
In React, use `tokenizeCount` from `useOzElements()` instead — it is a reactive state value and will trigger re-renders automatically.
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
### vault.createBankElement()
|
|
436
|
+
|
|
437
|
+
```ts
|
|
438
|
+
vault.createBankElement(type: BankElementType, options?: ElementOptions): OzElement
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
Creates a bank account element. `BankElementType`: `'accountNumber'` | `'routingNumber'`.
|
|
442
|
+
|
|
443
|
+
```ts
|
|
444
|
+
const accountEl = vault.createBankElement('accountNumber');
|
|
445
|
+
const routingEl = vault.createBankElement('routingNumber');
|
|
446
|
+
accountEl.mount('#account-number');
|
|
447
|
+
routingEl.mount('#routing-number');
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
### vault.createBankToken(options)
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
vault.createBankToken(options: BankTokenizeOptions): Promise<BankTokenResponse>
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Tokenizes the mounted `accountNumber` and `routingNumber` elements. Both must be mounted and ready.
|
|
459
|
+
|
|
460
|
+
```ts
|
|
461
|
+
interface BankTokenizeOptions {
|
|
462
|
+
firstName: string; // Account holder first name (required, max 50 chars)
|
|
463
|
+
lastName: string; // Account holder last name (required, max 50 chars)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
interface BankTokenResponse {
|
|
467
|
+
token: string;
|
|
468
|
+
bank?: {
|
|
469
|
+
last4: string; // Last 4 digits of account number
|
|
470
|
+
routingNumberLast4: string;
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
> **Note:** OzuraPay does not currently support bank account payments. Use the bank token with your own ACH processor. Bank tokens can be passed to any ACH-capable processor directly.
|
|
476
|
+
|
|
477
|
+
> **Card tokens and processors:** Card tokenization returns a `cvcSession` alongside the `token`. OzuraPay's charge API requires `cvcSession`. If you are routing to a non-Ozura processor, pass the `token` directly — your processor's documentation will tell you whether a CVC session token is required.
|
|
478
|
+
|
|
479
|
+
---
|
|
480
|
+
|
|
481
|
+
### vault.destroy()
|
|
482
|
+
|
|
483
|
+
```ts
|
|
484
|
+
vault.destroy(): void
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
Tears down the vault: removes all element and tokenizer iframes, clears the `message` event listener, rejects any pending `createToken()` / `createBankToken()` promises, and cancels active timeout handles. Call this when the checkout component unmounts.
|
|
488
|
+
|
|
489
|
+
```ts
|
|
490
|
+
// React useEffect cleanup — the cancel flag prevents a vault from leaking
|
|
491
|
+
// if the component unmounts before OzVault.create() resolves.
|
|
492
|
+
useEffect(() => {
|
|
493
|
+
let cancelled = false;
|
|
494
|
+
let vault: OzVault | null = null;
|
|
495
|
+
OzVault.create(options).then(v => {
|
|
496
|
+
if (cancelled) { v.destroy(); return; }
|
|
497
|
+
vault = v;
|
|
498
|
+
});
|
|
499
|
+
return () => {
|
|
500
|
+
cancelled = true;
|
|
501
|
+
vault?.destroy();
|
|
502
|
+
};
|
|
503
|
+
}, []);
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
### OzElement events
|
|
509
|
+
|
|
510
|
+
```ts
|
|
511
|
+
element.on('change', (event: ElementChangeEvent) => { ... });
|
|
512
|
+
element.on('focus', () => { ... });
|
|
513
|
+
element.on('blur', () => { ... });
|
|
514
|
+
element.on('ready', () => { ... });
|
|
515
|
+
element.on('loaderror', (payload: { elementType: string; error: string }) => { ... });
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
`ElementChangeEvent`:
|
|
519
|
+
|
|
520
|
+
| Field | Type | Description |
|
|
521
|
+
|---|---|---|
|
|
522
|
+
| `empty` | `boolean` | `true` when the field is empty. |
|
|
523
|
+
| `complete` | `boolean` | `true` when the field has enough digits to be complete. |
|
|
524
|
+
| `valid` | `boolean` | `true` when the value passes all validation (Luhn, expiry date, etc.). |
|
|
525
|
+
| `error` | `string \| undefined` | User-facing error message when `valid` is `false` and the field has been touched. |
|
|
526
|
+
| `cardBrand` | `string \| undefined` | Detected brand — only on `cardNumber` fields (e.g. `"visa"`, `"amex"`). |
|
|
527
|
+
| `month` | `string \| undefined` | Parsed 2-digit month — only on `expirationDate` fields. |
|
|
528
|
+
| `year` | `string \| undefined` | Parsed 2-digit year — only on `expirationDate` fields. |
|
|
529
|
+
|
|
530
|
+
> **Expiry data and PCI scope:** The expiry `onChange` event delivers parsed `month` and `year` to your handler for display purposes (e.g. "Card expires MM/YY"). These are not PANs or CVVs, but they are cardholder data. If your PCI scope requires zero cardholder data on the merchant page, do not read, log, or store these fields.
|
|
531
|
+
|
|
532
|
+
Auto-advance is built in: the vault automatically moves focus from card number → expiry → CVV when each field completes. No additional code required.
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
## React API
|
|
537
|
+
|
|
538
|
+
### OzElements provider
|
|
539
|
+
|
|
540
|
+
```tsx
|
|
541
|
+
import { OzElements, createFetchWaxKey } from '@ozura/elements/react';
|
|
542
|
+
|
|
543
|
+
<OzElements
|
|
544
|
+
pubKey="pk_live_..."
|
|
545
|
+
fetchWaxKey={createFetchWaxKey('/api/mint-wax')}
|
|
546
|
+
appearance={{ theme: 'flat', variables: { colorPrimary: '#6366f1' } }}
|
|
547
|
+
onLoadError={() => setPaymentUnavailable(true)}
|
|
548
|
+
>
|
|
549
|
+
{children}
|
|
550
|
+
</OzElements>
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
All `VaultOptions` are accepted as props. The provider creates a single `OzVault` instance and destroys it on unmount.
|
|
554
|
+
|
|
555
|
+
> **Prop changes and vault lifecycle:** Changing `pubKey`, `frameBaseUrl`, `loadTimeoutMs`, `appearance`, `fonts`, or `maxTokenizeCalls` destroys the current vault and creates a new one — all field iframes will remount. Changing `fetchWaxKey`, `onLoadError`, `onWaxRefresh`, or `onReady` updates the callback in place via refs without recreating the vault.
|
|
556
|
+
|
|
557
|
+
> **One card form per provider:** A vault holds one element per field type (`cardNumber`, `expiry`, `cvv`, etc.). Rendering two `<OzCard>` components under the same `<OzElements>` provider will cause the second to silently replace the first's iframes, breaking the first form. If you genuinely need two independent card forms on the same page, wrap each in its own `<OzElements>` provider with separate `pubKey` / `fetchWaxKey` configurations.
|
|
558
|
+
|
|
559
|
+
---
|
|
560
|
+
|
|
561
|
+
### OzCard
|
|
562
|
+
|
|
563
|
+
Drop-in combined card component. Renders card number, expiry, and CVV with a configurable layout.
|
|
564
|
+
|
|
565
|
+
```tsx
|
|
566
|
+
import { OzCard } from '@ozura/elements/react';
|
|
567
|
+
|
|
568
|
+
<OzCard
|
|
569
|
+
layout="default" // "default" (number on top, expiry+CVV below) | "rows" (stacked)
|
|
570
|
+
onChange={(state) => {
|
|
571
|
+
// state.complete — all three fields complete + valid
|
|
572
|
+
// state.cardBrand — detected brand
|
|
573
|
+
// state.error — first error across all fields
|
|
574
|
+
// state.fields — per-field ElementChangeEvent objects
|
|
575
|
+
}}
|
|
576
|
+
onReady={() => console.log('all card fields loaded')}
|
|
577
|
+
disabled={isSubmitting}
|
|
578
|
+
labels={{ cardNumber: 'Card Number', expiry: 'Expiry', cvv: 'CVV' }}
|
|
579
|
+
placeholders={{ cardNumber: '1234 5678 9012 3456', expiry: 'MM/YY', cvv: '···' }}
|
|
580
|
+
/>
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
`OzCardProps` (full):
|
|
584
|
+
|
|
585
|
+
| Prop | Type | Description |
|
|
586
|
+
|---|---|---|
|
|
587
|
+
| `layout` | `'default' \| 'rows'` | `'default'`: number full-width, expiry+CVV side by side. `'rows'`: all stacked. |
|
|
588
|
+
| `gap` | `number \| string` | Gap between fields. Default: `8` (px). |
|
|
589
|
+
| `style` | `ElementStyleConfig` | Shared style applied to all three inputs. |
|
|
590
|
+
| `styles` | `{ cardNumber?, expiry?, cvv? }` | Per-field overrides merged on top of `style`. |
|
|
591
|
+
| `classNames` | `{ cardNumber?, expiry?, cvv?, row? }` | CSS class names for field wrappers and the expiry+CVV row. |
|
|
592
|
+
| `labels` | `{ cardNumber?, expiry?, cvv? }` | Optional label text above each field. |
|
|
593
|
+
| `labelStyle` | `React.CSSProperties` | Style applied to all `<label>` elements. |
|
|
594
|
+
| `labelClassName` | `string` | Class applied to all `<label>` elements. |
|
|
595
|
+
| `placeholders` | `{ cardNumber?, expiry?, cvv? }` | Custom placeholder text per field. |
|
|
596
|
+
| `hideErrors` | `boolean` | Suppress the built-in error display. Handle via `onChange`. |
|
|
597
|
+
| `errorStyle` | `React.CSSProperties` | Style for the built-in error container. |
|
|
598
|
+
| `errorClassName` | `string` | Class for the built-in error container. |
|
|
599
|
+
| `renderError` | `(error: string) => ReactNode` | Custom error renderer. |
|
|
600
|
+
| `onChange` | `(state: OzCardState) => void` | Fires on any field change. |
|
|
601
|
+
| `onReady` | `() => void` | Fires once all three iframes have loaded. |
|
|
602
|
+
| `onFocus` | `(field: 'cardNumber' \| 'expiry' \| 'cvv') => void` | |
|
|
603
|
+
| `onBlur` | `(field: 'cardNumber' \| 'expiry' \| 'cvv') => void` | |
|
|
604
|
+
| `disabled` | `boolean` | Disable all inputs. |
|
|
605
|
+
| `className` | `string` | Class for the outer wrapper. |
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
### Individual field components
|
|
610
|
+
|
|
611
|
+
For custom layouts where `OzCard` is too opinionated:
|
|
612
|
+
|
|
613
|
+
```tsx
|
|
614
|
+
import { OzCardNumber, OzExpiry, OzCvv } from '@ozura/elements/react';
|
|
615
|
+
|
|
616
|
+
<OzCardNumber onChange={handleChange} placeholder="Card number" />
|
|
617
|
+
<OzExpiry onChange={handleChange} />
|
|
618
|
+
<OzCvv onChange={handleChange} />
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
All accept `OzFieldProps`:
|
|
622
|
+
|
|
623
|
+
| Prop | Type | Description |
|
|
624
|
+
|---|---|---|
|
|
625
|
+
| `style` | `ElementStyleConfig` | Input styles. |
|
|
626
|
+
| `placeholder` | `string` | Placeholder text. |
|
|
627
|
+
| `disabled` | `boolean` | Disables the input. |
|
|
628
|
+
| `loadTimeoutMs` | `number` | Iframe load timeout in ms. |
|
|
629
|
+
| `onChange` | `(event: ElementChangeEvent) => void` | |
|
|
630
|
+
| `onFocus` | `() => void` | |
|
|
631
|
+
| `onBlur` | `() => void` | |
|
|
632
|
+
| `onReady` | `() => void` | |
|
|
633
|
+
| `onLoadError` | `(error: string) => void` | |
|
|
634
|
+
| `className` | `string` | Class for the outer wrapper div. |
|
|
635
|
+
|
|
636
|
+
---
|
|
637
|
+
|
|
638
|
+
### OzBankCard
|
|
639
|
+
|
|
640
|
+
```tsx
|
|
641
|
+
import { OzBankCard } from '@ozura/elements/react';
|
|
642
|
+
|
|
643
|
+
<OzBankCard
|
|
644
|
+
onChange={(state) => {
|
|
645
|
+
// state.complete, state.error, state.fields.accountNumber, state.fields.routingNumber
|
|
646
|
+
}}
|
|
647
|
+
labels={{ accountNumber: 'Account Number', routingNumber: 'Routing Number' }}
|
|
648
|
+
/>
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
Or use individual bank components:
|
|
652
|
+
|
|
653
|
+
```tsx
|
|
654
|
+
import { OzBankAccountNumber, OzBankRoutingNumber } from '@ozura/elements/react';
|
|
655
|
+
|
|
656
|
+
<OzBankAccountNumber onChange={handleChange} />
|
|
657
|
+
<OzBankRoutingNumber onChange={handleChange} />
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
---
|
|
661
|
+
|
|
662
|
+
### useOzElements()
|
|
663
|
+
|
|
664
|
+
```ts
|
|
665
|
+
const { createToken, createBankToken, ready, initError, tokenizeCount } = useOzElements();
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
Must be called from inside an `<OzElements>` provider tree.
|
|
669
|
+
|
|
670
|
+
| Return | Type | Description |
|
|
671
|
+
|---|---|---|
|
|
672
|
+
| `createToken` | `(options?: TokenizeOptions) => Promise<TokenResponse>` | Tokenize mounted card elements. |
|
|
673
|
+
| `createBankToken` | `(options: BankTokenizeOptions) => Promise<BankTokenResponse>` | Tokenize mounted bank elements. |
|
|
674
|
+
| `ready` | `boolean` | `true` when the tokenizer **and** all mounted element iframes are ready. Gate your submit button on this. See note below. |
|
|
675
|
+
| `initError` | `Error \| null` | Non-null if `OzVault.create()` failed (e.g. `fetchWaxKey` threw). Render a fallback UI. |
|
|
676
|
+
| `tokenizeCount` | `number` | Number of successful tokenizations since the last wax key was minted. Resets on wax refresh or provider re-init. Useful for tracking calls against `maxTokenizeCalls`. |
|
|
677
|
+
|
|
678
|
+
> **`ready` vs `vault.isReady`:** `ready` from `useOzElements()` is a composite — it combines `vault.isReady` (tokenizer loaded) with element readiness (all mounted input iframes loaded). `vault.isReady` alone is insufficient for gating a submit button. Always use `ready` from `useOzElements()` in React.
|
|
679
|
+
|
|
680
|
+
---
|
|
681
|
+
|
|
682
|
+
## Styling
|
|
683
|
+
|
|
684
|
+
### Per-element styles
|
|
685
|
+
|
|
686
|
+
Styles apply inside each iframe's `<input>` element. Only an explicit allowlist of CSS properties is accepted (typography, spacing, borders, box-shadow, cursor, transitions). Values containing `url()`, `var()`, `expression()`, `javascript:`, or CSS breakout characters are blocked on both the SDK and iframe sides. Use literal values instead of CSS custom properties (`var(--token)` is rejected).
|
|
687
|
+
|
|
688
|
+
```ts
|
|
689
|
+
const style: ElementStyleConfig = {
|
|
690
|
+
base: {
|
|
691
|
+
color: '#1a1a1a',
|
|
692
|
+
fontSize: '16px',
|
|
693
|
+
fontFamily: '"Inter", sans-serif',
|
|
694
|
+
padding: '10px 12px',
|
|
695
|
+
backgroundColor: '#ffffff',
|
|
696
|
+
borderRadius: '6px',
|
|
697
|
+
border: '1px solid #d1d5db',
|
|
698
|
+
},
|
|
699
|
+
focus: {
|
|
700
|
+
borderColor: '#6366f1',
|
|
701
|
+
boxShadow: '0 0 0 3px rgba(99,102,241,0.15)',
|
|
702
|
+
outline: 'none',
|
|
703
|
+
},
|
|
704
|
+
invalid: {
|
|
705
|
+
borderColor: '#ef4444',
|
|
706
|
+
color: '#dc2626',
|
|
707
|
+
},
|
|
708
|
+
complete: {
|
|
709
|
+
borderColor: '#22c55e',
|
|
710
|
+
},
|
|
711
|
+
placeholder: {
|
|
712
|
+
color: '#9ca3af',
|
|
713
|
+
},
|
|
714
|
+
};
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
State precedence: `placeholder` applies to the `::placeholder` pseudo-element. `focus`, `invalid`, and `complete` merge on top of `base`.
|
|
718
|
+
|
|
719
|
+
### Global appearance
|
|
720
|
+
|
|
721
|
+
Apply a preset theme and/or variable overrides to all elements at once:
|
|
722
|
+
|
|
723
|
+
```ts
|
|
724
|
+
// OzVault.create
|
|
725
|
+
const vault = await OzVault.create({
|
|
726
|
+
pubKey: '...',
|
|
727
|
+
fetchWaxKey: createFetchWaxKey('/api/mint-wax'),
|
|
728
|
+
appearance: {
|
|
729
|
+
theme: 'flat', // 'default' | 'night' | 'flat'
|
|
730
|
+
variables: {
|
|
731
|
+
colorText: '#1a1a1a',
|
|
732
|
+
colorBackground: '#ffffff',
|
|
733
|
+
colorPrimary: '#6366f1', // focus caret + color
|
|
734
|
+
colorDanger: '#dc2626', // invalid state
|
|
735
|
+
colorSuccess: '#16a34a', // complete state
|
|
736
|
+
colorPlaceholder: '#9ca3af',
|
|
737
|
+
fontFamily: '"Inter", sans-serif',
|
|
738
|
+
fontSize: '15px',
|
|
739
|
+
fontWeight: '400',
|
|
740
|
+
padding: '10px 14px',
|
|
741
|
+
letterSpacing: '0.01em',
|
|
742
|
+
},
|
|
743
|
+
},
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
// React provider
|
|
747
|
+
<OzElements pubKey="..." fetchWaxKey={...} appearance={{ theme: 'night' }}>
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
Per-element `style` takes precedence over `appearance` variables.
|
|
751
|
+
|
|
752
|
+
> **`appearance: {}` is not "no theme":** Passing `appearance: {}` or `appearance: { variables: { ... } }` without a `theme` key applies the `'default'` preset as a base. To render elements with no preset styling, omit `appearance` entirely and use per-element `style` overrides.
|
|
753
|
+
>
|
|
754
|
+
> | `appearance` value | Result |
|
|
755
|
+
> |---|---|
|
|
756
|
+
> | *(omitted entirely)* | No preset — element uses minimal built-in defaults |
|
|
757
|
+
> | `{}` | Equivalent to `{ theme: 'default' }` — full default theme applied |
|
|
758
|
+
> | `{ theme: 'night' }` | Night theme |
|
|
759
|
+
> | `{ variables: { colorText: '#333' } }` | Default theme + variable overrides |
|
|
760
|
+
|
|
761
|
+
### Custom fonts
|
|
762
|
+
|
|
763
|
+
Fonts are injected into each iframe so they render inside the input fields:
|
|
764
|
+
|
|
765
|
+
```ts
|
|
766
|
+
fonts: [
|
|
767
|
+
// Google Fonts or any HTTPS CSS URL
|
|
768
|
+
{ cssSrc: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap' },
|
|
769
|
+
|
|
770
|
+
// Custom @font-face
|
|
771
|
+
{
|
|
772
|
+
family: 'BrandFont',
|
|
773
|
+
src: 'url(https://cdn.example.com/brand-font.woff2)',
|
|
774
|
+
weight: '400',
|
|
775
|
+
style: 'normal',
|
|
776
|
+
display: 'swap',
|
|
777
|
+
},
|
|
778
|
+
]
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
Font `src` values must start with `url(https://...)`. HTTP and data URIs are rejected.
|
|
782
|
+
|
|
783
|
+
---
|
|
784
|
+
|
|
785
|
+
## Billing details
|
|
786
|
+
|
|
787
|
+
```ts
|
|
788
|
+
interface BillingDetails {
|
|
789
|
+
firstName: string; // 1–50 characters
|
|
790
|
+
lastName: string; // 1–50 characters
|
|
791
|
+
email?: string; // Valid email, max 50 characters
|
|
792
|
+
phone?: string; // E.164 format, e.g. "+15551234567", max 50 characters
|
|
793
|
+
address?: {
|
|
794
|
+
line1: string; // 1–50 characters
|
|
795
|
+
line2?: string; // Optional, omitted from cardSale if blank
|
|
796
|
+
city: string; // 1–50 characters
|
|
797
|
+
state: string; // For US/CA: normalized to 2-letter abbreviation
|
|
798
|
+
zip: string; // 1–50 characters
|
|
799
|
+
country: string; // ISO 3166-1 alpha-2, e.g. "US"
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
Billing is validated and normalized by both `vault.createToken()` and the server-side handler factories. `TokenResponse.billing` contains the normalized result ready to spread into a `cardSale` call.
|
|
805
|
+
|
|
806
|
+
---
|
|
807
|
+
|
|
808
|
+
## Error handling
|
|
809
|
+
|
|
810
|
+
All SDK errors are instances of `OzError`:
|
|
811
|
+
|
|
812
|
+
```ts
|
|
813
|
+
import { OzError } from '@ozura/elements';
|
|
814
|
+
|
|
815
|
+
try {
|
|
816
|
+
const { token } = await vault.createToken({ billing });
|
|
817
|
+
} catch (err) {
|
|
818
|
+
if (err instanceof OzError) {
|
|
819
|
+
switch (err.errorCode) {
|
|
820
|
+
case 'network': // Connection failure — show retry UI
|
|
821
|
+
case 'timeout': // 30s deadline exceeded — safe to retry
|
|
822
|
+
case 'server': // 5xx from vault — transient, safe to retry
|
|
823
|
+
if (err.retryable) showRetryPrompt();
|
|
824
|
+
break;
|
|
825
|
+
|
|
826
|
+
case 'auth': // Bad pub key / API key — configuration issue
|
|
827
|
+
case 'validation': // Bad card data — show field-level error
|
|
828
|
+
case 'config': // frameBaseUrl not in permitted allowlist
|
|
829
|
+
case 'unknown':
|
|
830
|
+
showError(err.message);
|
|
831
|
+
break;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
`OzError` fields:
|
|
838
|
+
|
|
839
|
+
| Field | Type | Description |
|
|
840
|
+
|---|---|---|
|
|
841
|
+
| `message` | `string` | Human-readable, consumer-facing error message. |
|
|
842
|
+
| `errorCode` | `OzErrorCode` | `'network' \| 'timeout' \| 'auth' \| 'validation' \| 'server' \| 'config' \| 'unknown'` |
|
|
843
|
+
| `raw` | `string` | Raw error string from the vault API, if available. |
|
|
844
|
+
| `retryable` | `boolean` | `true` for `network`, `timeout`, `server`. `false` for `auth`, `validation`, `config`, `unknown`. |
|
|
845
|
+
|
|
846
|
+
> **Wax key expiry is handled automatically.** When a wax key expires or is consumed between initialization and the user clicking Pay, the SDK silently re-mints a fresh key and retries the tokenization once. You will only receive an `auth` error if the re-mint itself fails — for example, if your `/api/mint-wax` backend endpoint is unreachable. A healthy `auth` error in production means your mint endpoint needs attention, not that the user's card is bad.
|
|
847
|
+
|
|
848
|
+
**Error normalisation helpers** (for displaying errors from `cardSale` to users):
|
|
849
|
+
|
|
850
|
+
```ts
|
|
851
|
+
import { normalizeVaultError, normalizeBankVaultError, normalizeCardSaleError } from '@ozura/elements';
|
|
852
|
+
|
|
853
|
+
// Maps vault tokenize error strings to user-facing copy
|
|
854
|
+
const display = normalizeVaultError(err.raw); // card flows
|
|
855
|
+
const display = normalizeBankVaultError(err.raw); // bank/ACH flows
|
|
856
|
+
const display = normalizeCardSaleError(err.message); // cardSale API errors
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
---
|
|
860
|
+
|
|
861
|
+
## Server utilities
|
|
862
|
+
|
|
863
|
+
### Ozura class
|
|
864
|
+
|
|
865
|
+
```ts
|
|
866
|
+
import { Ozura, OzuraError } from '@ozura/elements/server';
|
|
867
|
+
|
|
868
|
+
const ozura = new Ozura({
|
|
869
|
+
merchantId: process.env.MERCHANT_ID!,
|
|
870
|
+
apiKey: process.env.MERCHANT_API_KEY!,
|
|
871
|
+
vaultKey: process.env.VAULT_API_KEY!,
|
|
872
|
+
// apiUrl: 'https://api.ozura.com', // override Pay API URL
|
|
873
|
+
// vaultUrl: 'https://vault.ozura.com', // override vault URL
|
|
874
|
+
timeoutMs: 30000, // default
|
|
875
|
+
retries: 2, // max retry attempts for 5xx/network errors (3 total attempts)
|
|
876
|
+
});
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
**Methods:**
|
|
880
|
+
|
|
881
|
+
```ts
|
|
882
|
+
// Charge a tokenized card
|
|
883
|
+
const result = await ozura.cardSale({
|
|
884
|
+
token: tokenResponse.token,
|
|
885
|
+
cvcSession: tokenResponse.cvcSession,
|
|
886
|
+
amount: '49.00',
|
|
887
|
+
currency: 'USD', // default: 'USD'
|
|
888
|
+
billing: tokenResponse.billing,
|
|
889
|
+
clientIpAddress: '1.2.3.4', // fetch server-side, never from the browser
|
|
890
|
+
// surchargePercent, tipAmount, salesTaxExempt, processor
|
|
891
|
+
});
|
|
892
|
+
// result.transactionId, result.amount, result.cardLastFour, result.cardBrand
|
|
893
|
+
// result.surchargeAmount and result.tipAmount are optional — only present when non-zero
|
|
894
|
+
const surcharge = result.surchargeAmount ?? '0.00';
|
|
895
|
+
const tip = result.tipAmount ?? '0.00';
|
|
896
|
+
|
|
897
|
+
// Mint a wax key (for custom fetchWaxKey implementations)
|
|
898
|
+
const { waxKey, expiresInSeconds } = await ozura.mintWaxKey({
|
|
899
|
+
tokenizationSessionId: sessionId,
|
|
900
|
+
maxTokenizeCalls: 3, // must match VaultOptions.maxTokenizeCalls on the client (default: 3)
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
// Revoke a wax key — call on all three session-end paths
|
|
904
|
+
// Best-effort — never throws. Shortens the exposure window before the vault's ~30 min TTL.
|
|
905
|
+
await ozura.revokeWaxKey(waxKey);
|
|
906
|
+
|
|
907
|
+
// Suggested pattern — wire all three exit paths:
|
|
908
|
+
// 1. Payment success
|
|
909
|
+
const result = await ozura.cardSale({ ... });
|
|
910
|
+
await ozura.revokeWaxKey(waxKey); // key is spent; close the window immediately
|
|
911
|
+
|
|
912
|
+
// 2. User cancels checkout
|
|
913
|
+
router.post('/api/cancel', async (req) => {
|
|
914
|
+
const { waxKey } = await db.session.get(req.sessionId);
|
|
915
|
+
await ozura.revokeWaxKey(waxKey);
|
|
916
|
+
return Response.json({ ok: true });
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
// 3. Page/tab close (best-effort — browser may not deliver this)
|
|
920
|
+
// Use sendBeacon so the request survives navigation / tab close.
|
|
921
|
+
window.addEventListener('visibilitychange', () => {
|
|
922
|
+
if (document.visibilityState === 'hidden') {
|
|
923
|
+
navigator.sendBeacon('/api/cancel', JSON.stringify({ sessionId }));
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
// List transactions
|
|
928
|
+
const { transactions, pagination } = await ozura.listTransactions({
|
|
929
|
+
dateFrom: '2025-01-01',
|
|
930
|
+
dateTo: '2025-12-31',
|
|
931
|
+
transactionType: 'CreditCardSale',
|
|
932
|
+
page: 1,
|
|
933
|
+
limit: 50,
|
|
934
|
+
});
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
**`OzuraError`** (thrown by all `Ozura` methods):
|
|
938
|
+
|
|
939
|
+
```ts
|
|
940
|
+
try {
|
|
941
|
+
await ozura.cardSale(input);
|
|
942
|
+
} catch (err) {
|
|
943
|
+
if (err instanceof OzuraError) {
|
|
944
|
+
err.statusCode; // HTTP status code
|
|
945
|
+
err.message; // Normalized message
|
|
946
|
+
err.raw; // Raw API response string
|
|
947
|
+
err.retryAfter; // Seconds (only present on 429)
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
Rate limits: `cardSale` — 100 req/min per merchant. `listTransactions` — 200 req/min per merchant.
|
|
953
|
+
|
|
954
|
+
> **Retry behavior:** `mintWaxKey` and `listTransactions` retry on 5xx and network errors using exponential backoff (1 s / 2 s / 4 s…) up to `retries + 1` total attempts. **`cardSale` is never retried** — it is a non-idempotent financial operation and the result of a duplicate charge cannot be predicted.
|
|
955
|
+
|
|
956
|
+
---
|
|
957
|
+
|
|
958
|
+
### Route handler factories
|
|
959
|
+
|
|
960
|
+
The server package exports four factory functions covering two runtimes × two endpoints:
|
|
961
|
+
|
|
962
|
+
| Function | Runtime | Endpoint |
|
|
963
|
+
|---|---|---|
|
|
964
|
+
| `createMintWaxHandler` | Fetch API (Next.js App Router, Cloudflare, Vercel Edge) | `POST /api/mint-wax` |
|
|
965
|
+
| `createMintWaxMiddleware` | Express / Connect | `POST /api/mint-wax` |
|
|
966
|
+
| `createCardSaleHandler` | Fetch API | `POST /api/charge` |
|
|
967
|
+
| `createCardSaleMiddleware` | Express / Connect | `POST /api/charge` |
|
|
968
|
+
|
|
969
|
+
`createCardSaleHandler` / `createCardSaleMiddleware` accept a `CardSaleHandlerOptions` object:
|
|
970
|
+
|
|
971
|
+
```ts
|
|
972
|
+
interface CardSaleHandlerOptions {
|
|
973
|
+
/**
|
|
974
|
+
* Required. Return the charge amount as a decimal string.
|
|
975
|
+
* Never trust the amount from the request body — resolve it from your database.
|
|
976
|
+
*/
|
|
977
|
+
getAmount: (body: Record<string, unknown>) => Promise<string>;
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Optional. Return the ISO 4217 currency code. Default: "USD".
|
|
981
|
+
*/
|
|
982
|
+
getCurrency?: (body: Record<string, unknown>) => Promise<string>;
|
|
983
|
+
}
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
Both handler factories validate `Content-Type: application/json`, run `validateBilling()`, extract the client IP from standard proxy headers, and return normalized `{ transactionId, amount, cardLastFour, cardBrand }` on success.
|
|
987
|
+
|
|
988
|
+
---
|
|
989
|
+
|
|
990
|
+
## Local development
|
|
991
|
+
|
|
992
|
+
The repository includes a development server at `dev-server.mjs` that serves the built frame assets and proxies vault API requests:
|
|
993
|
+
|
|
994
|
+
```bash
|
|
995
|
+
npm run dev # build + start dev server on http://localhost:4242
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
Set `frameBaseUrl` to point your vault at the local server:
|
|
999
|
+
|
|
1000
|
+
```ts
|
|
1001
|
+
const vault = await OzVault.create({
|
|
1002
|
+
pubKey: 'pk_test_...',
|
|
1003
|
+
fetchWaxKey: createFetchWaxKey('/api/mint-wax'),
|
|
1004
|
+
frameBaseUrl: 'http://localhost:4242', // local dev only
|
|
1005
|
+
});
|
|
1006
|
+
```
|
|
1007
|
+
|
|
1008
|
+
Or in React:
|
|
1009
|
+
|
|
1010
|
+
```tsx
|
|
1011
|
+
<OzElements
|
|
1012
|
+
pubKey="pk_test_..."
|
|
1013
|
+
fetchWaxKey={createFetchWaxKey('/api/mint-wax')}
|
|
1014
|
+
frameBaseUrl="http://localhost:4242"
|
|
1015
|
+
>
|
|
1016
|
+
```
|
|
1017
|
+
|
|
1018
|
+
Configure environment variables for the dev server:
|
|
1019
|
+
|
|
1020
|
+
```bash
|
|
1021
|
+
VAULT_URL=https://vault-staging.example.com
|
|
1022
|
+
VAULT_API_KEY=vk_test_...
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
---
|
|
1026
|
+
|
|
1027
|
+
## Content Security Policy
|
|
1028
|
+
|
|
1029
|
+
The SDK loads iframes from the Ozura frame origin. Add the following directives to your CSP:
|
|
1030
|
+
|
|
1031
|
+
```
|
|
1032
|
+
frame-src https://elements.ozura.com;
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
If loading custom fonts via `fonts[].cssSrc`, also allow the font stylesheet origin:
|
|
1036
|
+
|
|
1037
|
+
```
|
|
1038
|
+
style-src https://fonts.googleapis.com;
|
|
1039
|
+
font-src https://fonts.gstatic.com;
|
|
1040
|
+
```
|
|
1041
|
+
|
|
1042
|
+
To verify your CSP after a build:
|
|
1043
|
+
|
|
1044
|
+
```bash
|
|
1045
|
+
npm run check:csp
|
|
1046
|
+
```
|
|
1047
|
+
|
|
1048
|
+
---
|
|
1049
|
+
|
|
1050
|
+
## TypeScript reference
|
|
1051
|
+
|
|
1052
|
+
All public types are exported from `@ozura/elements`:
|
|
1053
|
+
|
|
1054
|
+
```ts
|
|
1055
|
+
import type {
|
|
1056
|
+
// Element types
|
|
1057
|
+
ElementType, // 'cardNumber' | 'cvv' | 'expirationDate'
|
|
1058
|
+
BankElementType, // 'accountNumber' | 'routingNumber'
|
|
1059
|
+
ElementOptions,
|
|
1060
|
+
ElementStyleConfig,
|
|
1061
|
+
ElementStyle,
|
|
1062
|
+
ElementChangeEvent,
|
|
1063
|
+
|
|
1064
|
+
// Vault config
|
|
1065
|
+
VaultOptions,
|
|
1066
|
+
FontSource,
|
|
1067
|
+
CssFontSource,
|
|
1068
|
+
CustomFontSource,
|
|
1069
|
+
Appearance,
|
|
1070
|
+
AppearanceVariables,
|
|
1071
|
+
OzTheme, // 'default' | 'night' | 'flat'
|
|
1072
|
+
|
|
1073
|
+
// Tokenization
|
|
1074
|
+
TokenizeOptions,
|
|
1075
|
+
BankTokenizeOptions,
|
|
1076
|
+
TokenResponse,
|
|
1077
|
+
BankTokenResponse,
|
|
1078
|
+
CardMetadata,
|
|
1079
|
+
BankAccountMetadata,
|
|
1080
|
+
|
|
1081
|
+
// Billing
|
|
1082
|
+
BillingDetails,
|
|
1083
|
+
BillingAddress,
|
|
1084
|
+
|
|
1085
|
+
// Card sale
|
|
1086
|
+
CardSaleRequest,
|
|
1087
|
+
CardSaleResponseData,
|
|
1088
|
+
CardSaleApiResponse,
|
|
1089
|
+
|
|
1090
|
+
// Transactions
|
|
1091
|
+
TransactionQueryParams,
|
|
1092
|
+
TransactionQueryPagination,
|
|
1093
|
+
TransactionQueryResponse,
|
|
1094
|
+
TransactionType,
|
|
1095
|
+
TransactionData,
|
|
1096
|
+
CardTransactionData,
|
|
1097
|
+
AchTransactionData,
|
|
1098
|
+
CryptoTransactionData,
|
|
1099
|
+
|
|
1100
|
+
// Errors
|
|
1101
|
+
OzErrorCode,
|
|
1102
|
+
} from '@ozura/elements';
|
|
1103
|
+
```
|
|
1104
|
+
|
|
1105
|
+
Server-specific types are exported from `@ozura/elements/server`:
|
|
1106
|
+
|
|
1107
|
+
```ts
|
|
1108
|
+
import type {
|
|
1109
|
+
OzuraConfig,
|
|
1110
|
+
CardSaleInput,
|
|
1111
|
+
MintWaxKeyOptions,
|
|
1112
|
+
MintWaxKeyResult,
|
|
1113
|
+
ListTransactionsInput,
|
|
1114
|
+
} from '@ozura/elements/server';
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
React-specific types are exported from `@ozura/elements/react`:
|
|
1118
|
+
|
|
1119
|
+
```ts
|
|
1120
|
+
import type { OzFieldProps, OzCardProps, OzCardState, OzBankCardProps, OzBankCardState } from '@ozura/elements/react';
|
|
1121
|
+
```
|