@ozura/elements 1.3.1-next.77 → 1.3.1-next.79
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
CHANGED
|
@@ -28,6 +28,7 @@ Card data is collected inside Ozura-hosted iframes so raw numbers never touch yo
|
|
|
28
28
|
- [vault.createBankToken()](#vaultcreatebanktokenoptions)
|
|
29
29
|
- [vault.reset()](#vaultreset)
|
|
30
30
|
- [vault.destroy()](#vaultdestroy)
|
|
31
|
+
- [vault.getFieldStates()](#vaultgetfieldstates)
|
|
31
32
|
- [vault.debugState()](#vaultdebugstate)
|
|
32
33
|
- [OzElement events](#ozelement-events)
|
|
33
34
|
- [React API](#react-api)
|
|
@@ -36,6 +37,7 @@ Card data is collected inside Ozura-hosted iframes so raw numbers never touch yo
|
|
|
36
37
|
- [Individual field components](#individual-field-components)
|
|
37
38
|
- [OzBankCard](#ozbankcard)
|
|
38
39
|
- [useOzElements()](#useozelements)
|
|
40
|
+
- [useFieldStates()](#usefieldstates)
|
|
39
41
|
- [Styling](#styling)
|
|
40
42
|
- [Per-element styles](#per-element-styles)
|
|
41
43
|
- [Global appearance](#global-appearance)
|
|
@@ -595,6 +597,29 @@ try {
|
|
|
595
597
|
|
|
596
598
|
---
|
|
597
599
|
|
|
600
|
+
### vault.getFieldStates()
|
|
601
|
+
|
|
602
|
+
```ts
|
|
603
|
+
vault.getFieldStates(): FieldStatesSnapshot
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
Returns a snapshot of every created field's current state, keyed by element type. Each entry is `{ empty, complete, valid, error?, cardBrand? }`. Call it whenever you need the latest state — typically from an `OzElement` `change` listener — to gate the submit button, show per-field errors, or display the card brand, without wiring bookkeeping per field.
|
|
607
|
+
|
|
608
|
+
```ts
|
|
609
|
+
cardNumber.on('change', () => {
|
|
610
|
+
const s = vault.getFieldStates();
|
|
611
|
+
// {
|
|
612
|
+
// cardNumber: { empty: false, complete: true, valid: true, cardBrand: 'visa' },
|
|
613
|
+
// cvv: { empty: false, complete: false, valid: false, error: 'Invalid CVV' },
|
|
614
|
+
// }
|
|
615
|
+
payBtn.disabled = !(s.cardNumber?.valid && s.expirationDate?.valid && s.cvv?.valid);
|
|
616
|
+
});
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
Keys exist only for fields you have created (card and bank fields are combined), so access with `?.`. The result is a set of shallow copies — mutating it does not affect the vault. In React/Vue, prefer the reactive [`useFieldStates()`](#usefieldstates) instead of calling this on every change.
|
|
620
|
+
|
|
621
|
+
---
|
|
622
|
+
|
|
598
623
|
### vault.debugState()
|
|
599
624
|
|
|
600
625
|
```ts
|
|
@@ -785,7 +810,7 @@ import { OzBankAccountNumber, OzBankRoutingNumber } from '@ozura/elements/react'
|
|
|
785
810
|
### useOzElements()
|
|
786
811
|
|
|
787
812
|
```ts
|
|
788
|
-
const { createToken, createBankToken, reset, ready, initError, tokenizeCount } = useOzElements();
|
|
813
|
+
const { createToken, createBankToken, reset, ready, initError, tokenizeCount, isComplete, isBankComplete, isTokenizing } = useOzElements();
|
|
789
814
|
```
|
|
790
815
|
|
|
791
816
|
Must be called from inside an `<OzElements>` provider tree.
|
|
@@ -798,11 +823,41 @@ Must be called from inside an `<OzElements>` provider tree.
|
|
|
798
823
|
| `ready` | `boolean` | `true` when the tokenizer **and** all mounted element iframes are ready. Gate your submit button on this. See note below. |
|
|
799
824
|
| `initError` | `Error \| null` | Non-null if `OzVault.create()` failed (e.g. session endpoint unreachable). Render a fallback UI. |
|
|
800
825
|
| `tokenizeCount` | `number` | Number of successful tokenizations in the current session. Resets on session refresh or provider re-init. Useful for tracking calls against `sessionLimit`. |
|
|
826
|
+
| `isComplete` | `boolean` | `true` when every mounted **card** field reports complete and valid. Gate the pay button on it without wiring per-field `onChange`. Reactive — updates as the customer types. |
|
|
827
|
+
| `isBankComplete` | `boolean` | Same as `isComplete`, but for mounted **bank** fields (`OzBankCard` / bank elements). Card and bank completion are tracked independently. |
|
|
828
|
+
| `isTokenizing` | `boolean` | `true` while `createToken()` / `createBankToken()` is in progress (including the transparent wax-key refresh). Keep the pay button disabled to prevent double-submission. |
|
|
801
829
|
|
|
802
830
|
> **`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.
|
|
803
831
|
|
|
804
832
|
---
|
|
805
833
|
|
|
834
|
+
### useFieldStates()
|
|
835
|
+
|
|
836
|
+
```ts
|
|
837
|
+
const fields = useFieldStates();
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
Reactive snapshot of every created field's state, keyed by element type — `{ empty, complete, valid, error?, cardBrand? }` per field. Recomputes on every field change. It is a **standalone hook** (not part of `useOzElements()`), so only the components that need per-field state re-render on input. Must be called inside an `<OzElements>` provider; returns `{}` otherwise.
|
|
841
|
+
|
|
842
|
+
```tsx
|
|
843
|
+
import { useFieldStates } from '@ozura/elements/react';
|
|
844
|
+
|
|
845
|
+
function CardErrors() {
|
|
846
|
+
const fields = useFieldStates();
|
|
847
|
+
return (
|
|
848
|
+
<>
|
|
849
|
+
{fields.cardNumber?.error && <span className="err">{fields.cardNumber.error}</span>}
|
|
850
|
+
{fields.cvv?.error && <span className="err">{fields.cvv.error}</span>}
|
|
851
|
+
{fields.cardNumber?.cardBrand && <BrandIcon brand={fields.cardNumber.cardBrand} />}
|
|
852
|
+
</>
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
```
|
|
856
|
+
|
|
857
|
+
Keys exist only for fields you have created (card and bank combined), so access with `?.`.
|
|
858
|
+
|
|
859
|
+
---
|
|
860
|
+
|
|
806
861
|
## Vue API
|
|
807
862
|
|
|
808
863
|
> 📖 Vue 3 integration using the Composition API. Requires `vue >= 3.3`. No `.vue` SFC files needed in your setup — components work with `<script setup>` or the Options API.
|
|
@@ -885,6 +940,31 @@ Must be called from inside an `<OzElements>` provider tree.
|
|
|
885
940
|
| `initError` | `Ref<Error \| null>` | Non-null if `OzVault.create()` failed. Render a fallback UI. |
|
|
886
941
|
| `tokenizeCount` | `Ref<number>` | Successful tokenizations in the current session. Resets on session refresh. |
|
|
887
942
|
| `reset` | `() => void` | Clear all fields without destroying the vault. Call after a declined payment. |
|
|
943
|
+
| `isComplete` | `ComputedRef<boolean>` | `true` when every mounted **card** field reports complete and valid. Gate the pay button on it. |
|
|
944
|
+
| `isBankComplete` | `ComputedRef<boolean>` | Same as `isComplete`, but for mounted **bank** fields. Tracked independently. |
|
|
945
|
+
| `isTokenizing` | `ComputedRef<boolean>` | `true` while `createToken()` / `createBankToken()` is in progress (incl. wax-key refresh). Keep the pay button disabled. |
|
|
946
|
+
|
|
947
|
+
### useFieldStates()
|
|
948
|
+
|
|
949
|
+
```ts
|
|
950
|
+
const fields = useFieldStates(); // ComputedRef<FieldStatesSnapshot>
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
Reactive snapshot of every created field's state, keyed by element type — `{ empty, complete, valid, error?, cardBrand? }` per field. Returns a `ComputedRef` that recomputes on every field change. Must be called from inside an `<OzElements>` provider tree (throws otherwise).
|
|
954
|
+
|
|
955
|
+
```vue
|
|
956
|
+
<script setup>
|
|
957
|
+
import { useFieldStates } from '@ozura/elements/vue';
|
|
958
|
+
const fields = useFieldStates();
|
|
959
|
+
</script>
|
|
960
|
+
|
|
961
|
+
<template>
|
|
962
|
+
<span v-if="fields.cvv?.error" class="err">{{ fields.cvv.error }}</span>
|
|
963
|
+
<BrandIcon v-if="fields.cardNumber?.cardBrand" :brand="fields.cardNumber.cardBrand" />
|
|
964
|
+
</template>
|
|
965
|
+
```
|
|
966
|
+
|
|
967
|
+
Keys exist only for fields you have created (card and bank combined); access with `?.`.
|
|
888
968
|
|
|
889
969
|
### Field props and events
|
|
890
970
|
|
|
@@ -86,7 +86,7 @@ export interface ElementChangeEvent {
|
|
|
86
86
|
complete: boolean;
|
|
87
87
|
valid: boolean;
|
|
88
88
|
/** Card brand — only present on cardNumber elements */
|
|
89
|
-
cardBrand?:
|
|
89
|
+
cardBrand?: CardBrand;
|
|
90
90
|
/** Parsed month (01-12) — only present on expirationDate elements */
|
|
91
91
|
month?: string;
|
|
92
92
|
/** Parsed 2-digit year — only present on expirationDate elements */
|
|
@@ -86,7 +86,7 @@ export interface ElementChangeEvent {
|
|
|
86
86
|
complete: boolean;
|
|
87
87
|
valid: boolean;
|
|
88
88
|
/** Card brand — only present on cardNumber elements */
|
|
89
|
-
cardBrand?:
|
|
89
|
+
cardBrand?: CardBrand;
|
|
90
90
|
/** Parsed month (01-12) — only present on expirationDate elements */
|
|
91
91
|
month?: string;
|
|
92
92
|
/** Parsed 2-digit year — only present on expirationDate elements */
|
|
@@ -86,7 +86,7 @@ export interface ElementChangeEvent {
|
|
|
86
86
|
complete: boolean;
|
|
87
87
|
valid: boolean;
|
|
88
88
|
/** Card brand — only present on cardNumber elements */
|
|
89
|
-
cardBrand?:
|
|
89
|
+
cardBrand?: CardBrand;
|
|
90
90
|
/** Parsed month (01-12) — only present on expirationDate elements */
|
|
91
91
|
month?: string;
|
|
92
92
|
/** Parsed 2-digit year — only present on expirationDate elements */
|
|
@@ -86,7 +86,7 @@ export interface ElementChangeEvent {
|
|
|
86
86
|
complete: boolean;
|
|
87
87
|
valid: boolean;
|
|
88
88
|
/** Card brand — only present on cardNumber elements */
|
|
89
|
-
cardBrand?:
|
|
89
|
+
cardBrand?: CardBrand;
|
|
90
90
|
/** Parsed month (01-12) — only present on expirationDate elements */
|
|
91
91
|
month?: string;
|
|
92
92
|
/** Parsed 2-digit year — only present on expirationDate elements */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ozura/elements",
|
|
3
|
-
"version": "1.3.1-next.
|
|
3
|
+
"version": "1.3.1-next.79",
|
|
4
4
|
"description": "PCI-compliant card tokenization SDK for the Ozura Vault — collect card data in iframe-isolated fields and tokenize without PCI scope",
|
|
5
5
|
"main": "dist/oz-elements.umd.js",
|
|
6
6
|
"module": "dist/oz-elements.esm.js",
|