@snap-pay/elements 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/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ Initial public release. Nine Elements covering the checkout surface:
6
+
7
+ - **PaymentElement** — umbrella that auto-picks Wallet + Card based on the session's allowed providers.
8
+ - **WalletElement** — one radio button per mobile-wallet provider (EVC Plus, Sahal, Zaad, eDahab, Jeeb, Premier Wallet).
9
+ - **CardElement** — cross-origin iframe collecting card fields; issues a sandbox token (`tok_sandbox_*`). Live-mode Mastercard tokenization is deferred to a subsequent release.
10
+ - **ExpressCheckoutElement** — one-tap prominent wallet buttons; emits `submit` on click for the merchant's confirm handler.
11
+ - **PaymentMethodSelector** — tabbed switcher between Wallet and Card; lazy-mounts each tab.
12
+ - **BillingAddressElement** — 7-field form; values flow through `confirmPayment` automatically.
13
+ - **CustomerElement** — name / email / phone form.
14
+ - **OtpElement** — configurable-length code input with paste, auto-advance, backspace-back.
15
+ - **QrElement** — placeholder; emits `failed` on mount until the real QR provider handshake ships.
16
+
17
+ Additional surface:
18
+ - Full Appearance API — spacing, colors, and per-Element rule overrides.
19
+ - Container publishes selection getters (`registerChild`) and form-value getters (`registerValue`) so `confirmPayment` can pick everything up without merchant plumbing.
20
+ - Card element gates live-mode payments at the SDK boundary — merchants using `pk_live_` see a clear error rather than a silent failure.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # @snap-pay/elements
2
+
3
+ Embeddable payment UI components for SNAP checkout. Importing this package registers each Element with `@snap-pay/js`'s factory so `snap.elements(...).create("wallet")` returns an instance.
4
+
5
+ ```bash
6
+ bun add @snap-pay/js @snap-pay/elements
7
+ # or npm/yarn/pnpm
8
+ ```
9
+
10
+ ## Usage — Vanilla JS
11
+
12
+ ```ts
13
+ import { Snap } from "@snap-pay/js";
14
+ import "@snap-pay/elements"; // side effect: registers every element
15
+
16
+ const snap = new Snap("pk_test_…");
17
+ const elements = snap.elements({ clientSecret: sessionId });
18
+
19
+ // The Payment umbrella auto-picks Wallet vs Card based on the session.
20
+ const payment = elements.create("payment");
21
+ payment.mount("#payment-container");
22
+
23
+ document.getElementById("pay")!.addEventListener("click", async () => {
24
+ const result = await snap.confirmPayment({ elements, clientSecret: sessionId });
25
+ console.log(result.status);
26
+ });
27
+ ```
28
+
29
+ ## Available Elements
30
+
31
+ | Element | Purpose |
32
+ |---|---|
33
+ | `payment` | Umbrella — auto-picks Wallet + Card based on the session's allowed providers |
34
+ | `wallet` | Radio button per mobile-wallet provider (EVC Plus, Zaad, Sahal, eDahab, Jeeb, Premier Wallet) |
35
+ | `card` | Cross-origin iframe collecting card fields, issuing a sandbox token (live-mode tokenization deferred) |
36
+ | `express` | One-tap prominent wallet buttons |
37
+ | `paymentMethodSelector` | Tabbed switcher between Wallet and Card |
38
+ | `billingAddress` | Form: name / address / postal / country. Values flow through `confirmPayment` automatically |
39
+ | `customer` | Form: name / email / phone |
40
+ | `otp` | 6-digit code input with paste + auto-advance |
41
+ | `qr` | Placeholder (real QR handshake not yet shipped — emits `failed` on mount) |
42
+
43
+ Every Element implements the same imperative surface:
44
+
45
+ ```ts
46
+ element.mount(target);
47
+ element.on("ready" | "change" | "focus" | "blur" | "failed" | "submit", handler);
48
+ element.off(event, handler);
49
+ element.unmount();
50
+ element.destroy();
51
+ ```
52
+
53
+ Form-collecting elements (BillingAddress, Customer, OTP) also expose `element.getValue()` for imperative reads.
54
+
55
+ ## Appearance
56
+
57
+ ```ts
58
+ snap.elements({
59
+ clientSecret,
60
+ appearance: {
61
+ theme: "light", // "light" | "dark" | "auto"
62
+ primaryColor: "#0066ff",
63
+ borderRadius: "8px",
64
+ spacingUnit: "8px",
65
+ labelColor: "#475569",
66
+ errorColor: "#dc2626",
67
+ // Per-Element overrides
68
+ rules: {
69
+ card: { border: "2px solid #f00" },
70
+ },
71
+ },
72
+ });
73
+ ```
74
+
75
+ ## Card iframe URL
76
+
77
+ The Card Element loads a cross-origin iframe hosted by SNAP. Point at a local dev instance during integration:
78
+
79
+ ```ts
80
+ new Snap("pk_test_…", {
81
+ cardFrameUrl: "http://localhost:3000/elements/card-frame",
82
+ });
83
+ ```
84
+
85
+ ## License
86
+
87
+ MIT