@kwespay/widget 1.0.7 → 1.0.9

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
@@ -1,12 +1,20 @@
1
1
  # @kwespay/widget
2
2
 
3
- > Accept crypto payments in 3 lines of code drop-in JavaScript widget for EVM chains.
3
+ > Accept crypto payments on any EVM chain with a single JavaScript widget.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@kwespay/widget)](https://www.npmjs.com/package/@kwespay/widget)
6
6
  [![license](https://img.shields.io/npm/l/@kwespay/widget)](LICENSE)
7
7
 
8
8
  ---
9
9
 
10
+ ## Get Started
11
+
12
+ 1. Create a merchant account at [app.kwespay.xyz](https://app.kwespay.xyz)
13
+ 2. Grab your **API Key** and **Vendor ID** from the dashboard
14
+ 3. Install the widget and start accepting payments
15
+
16
+ ---
17
+
10
18
  ## Installation
11
19
 
12
20
  ```bash
@@ -23,20 +31,60 @@ Or load via CDN (no bundler required):
23
31
 
24
32
  ## Quick Start
25
33
 
34
+ ### One-liner (recommended)
35
+
36
+ The `kwespay()` function is the simplest way to integrate. It handles widget
37
+ creation, amount updates, and cleanup automatically — one `await` and you're done.
38
+
39
+ ```js
40
+ import { kwespay } from "@kwespay/widget";
41
+
42
+ try {
43
+ const result = await kwespay({
44
+ apiKey: "your_api_key", // from app.kwespay.xyz
45
+ vendorId: "your_vendor_id", // from app.kwespay.xyz
46
+ amount: 49.99,
47
+ currency: "USD",
48
+ });
49
+
50
+ console.log("Payment confirmed:", result.transactionHash);
51
+ // fulfil your order here
52
+ } catch (err) {
53
+ if (err.code !== "USER_CANCELLED") {
54
+ console.error("Payment failed:", err.message);
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### Class-based (full lifecycle control)
60
+
61
+ If you need to manage the widget instance yourself — for example, to call
62
+ `updateAmount()` or `destroy()` explicitly — use the class directly.
63
+
26
64
  ```js
27
65
  import KwesPayWidget from "@kwespay/widget";
28
66
 
29
67
  const widget = new KwesPayWidget({
30
68
  apiKey: "your_api_key",
31
69
  vendorId: "your_vendor_id",
32
- amount: 10.0,
70
+ amount: 49.99,
33
71
  currency: "USD",
34
72
  });
35
73
 
36
- widget.open();
74
+ try {
75
+ const result = await widget.open();
76
+ console.log("Payment confirmed:", result.transactionHash);
77
+ } catch (err) {
78
+ if (err.code !== "USER_CANCELLED") {
79
+ console.error("Payment failed:", err.message);
80
+ }
81
+ } finally {
82
+ widget.destroy();
83
+ }
37
84
  ```
38
85
 
39
- That's it. The widget handles wallet connection, network switching, token selection, transaction signing, and success/error states.
86
+ The widget handles everything — wallet connection, network switching, token
87
+ selection, transaction signing, and success/error states.
40
88
 
41
89
  ---
42
90
 
@@ -44,11 +92,11 @@ That's it. The widget handles wallet connection, network switching, token select
44
92
 
45
93
  ```js
46
94
  const widget = new KwesPayWidget({
47
- apiKey: "your_api_key", // Required — your KwesPay API key
48
- vendorId: "your_vendor_id", // Required — your merchant identifier
95
+ apiKey: "your_api_key", // Required — from app.kwespay.xyz
96
+ vendorId: "your_vendor_id", // Required — from app.kwespay.xyz
49
97
  amount: 25.0, // Required — fiat amount to charge
50
98
  currency: "USD", // Optional — "USD" (default) or "GHS"
51
- acceptedTokens: ["USDT", "USDC"], // Optional — restrict tokens. Pass "stablecoins" to allow all stables
99
+ acceptedTokens: ["USDT", "USDC"], // Optional — restrict accepted tokens
52
100
  });
53
101
  ```
54
102
 
@@ -60,7 +108,8 @@ const widget = new KwesPayWidget({
60
108
  | `"stablecoins"` | USDT, USDC, DAI, BUSD, USDc |
61
109
  | `["USDT", "USDC"]` | Only the listed tokens |
62
110
 
63
- Tokens are also scoped by your API key's network/token permissions set in the KwesPay dashboard.
111
+ Token and network availability is also scoped by the permissions set on your
112
+ API key in the dashboard.
64
113
 
65
114
  ---
66
115
 
@@ -69,6 +118,7 @@ Tokens are also scoped by your API key's network/token permissions set in the Kw
69
118
  | Network | Chain ID | Type |
70
119
  | ------------ | -------- | ------- |
71
120
  | Ethereum | 1 | Mainnet |
121
+ | MEZO | 31612 | Mainnet |
72
122
  | Polygon | 137 | Mainnet |
73
123
  | Base | 8453 | Mainnet |
74
124
  | Lisk | 1135 | Mainnet |
@@ -76,27 +126,66 @@ Tokens are also scoped by your API key's network/token permissions set in the Kw
76
126
  | Polygon Amoy | 80002 | Testnet |
77
127
  | Base Sepolia | 84532 | Testnet |
78
128
  | Lisk Sepolia | 4202 | Testnet |
129
+ | MEZO Testnet | 31611 | Testnet |
130
+
131
+ ---
79
132
 
80
- Network and token availability in the widget is automatically filtered by your API key's permitted scope.
133
+ ## Payment Result
134
+
135
+ Both `kwespay()` and `widget.open()` resolve with the same result object:
136
+
137
+ ```ts
138
+ {
139
+ transactionHash: string; // On-chain transaction hash
140
+ transactionReference: string; // KwesPay internal payment reference
141
+ paymentIdBytes32: string; // On-chain payment ID (bytes32)
142
+ transactionStatus: "completed" | "unconfirmed";
143
+ fiatAmount: number; // Charged fiat amount
144
+ currency: string; // e.g. "USD"
145
+ token: string; // e.g. "USDC"
146
+ network: string; // e.g. "polygon"
147
+ }
148
+ ```
149
+
150
+ `"unconfirmed"` means the transaction is confirmed on-chain but the KwesPay
151
+ backend did not acknowledge it within the polling window. The payment is still
152
+ valid — reconcile it via the `kwespay:paymentUnconfirmed` event or your backend.
153
+
154
+ ### Error codes
155
+
156
+ The returned Promise rejects with an `Error` whose `.code` is one of:
157
+
158
+ | Code | Meaning |
159
+ | ------------------ | ------------------------------------------------- |
160
+ | `USER_CANCELLED` | User closed the widget without completing payment |
161
+ | `USER_REJECTED` | User rejected the transaction in their wallet |
162
+ | `SESSION_EXPIRED` | Wallet session timed out mid-payment |
163
+ | `WIDGET_DESTROYED` | `widget.destroy()` was called mid-payment |
164
+ | `UNKNOWN` | Unexpected error — check `err.message` |
81
165
 
82
166
  ---
83
167
 
84
168
  ## Methods
85
169
 
170
+ These are available on a `KwesPayWidget` instance. When using `kwespay()` you
171
+ don't need to call any of them — they are managed for you.
172
+
86
173
  ```js
87
- widget.open(); // Opens the payment widget
88
- widget.close(); // Closes the widget
174
+ widget.open(); // Open the widget — returns a Promise<PaymentResult>
175
+ widget.close(); // Close the widget
89
176
  widget.isOpen(); // Returns boolean
90
- widget.updateAmount(15.0, "USD"); // Update amount without re-creating the widget
91
- widget.getState(); // Returns current widget + config state
92
- widget.destroy(); // Removes widget from DOM and cleans up
177
+ widget.updateAmount(15.0, "USD"); // Update amount between opens
178
+ widget.getState(); // Returns current widget and config state
179
+ widget.destroy(); // Remove widget from DOM and clean up
93
180
  ```
94
181
 
95
182
  ---
96
183
 
97
184
  ## Events
98
185
 
99
- Listen for widget lifecycle and payment events on the `window`:
186
+ DOM events are dispatched on `window` for every significant widget action.
187
+ These fire regardless of whether you use `kwespay()` or the class directly,
188
+ and are useful for analytics, logging, or non-`async` integrations.
100
189
 
101
190
  ```js
102
191
  window.addEventListener("kwespay:paymentSuccess", (e) => {
@@ -109,18 +198,25 @@ window.addEventListener("kwespay:paymentSuccess", (e) => {
109
198
  token,
110
199
  network,
111
200
  } = e.detail;
112
- // Fulfil the order
201
+ // fulfil your order here
113
202
  });
114
203
 
115
204
  window.addEventListener("kwespay:paymentError", (e) => {
116
205
  console.error(e.detail.error, e.detail.errorType);
117
206
  });
118
207
 
208
+ window.addEventListener("kwespay:paymentUnconfirmed", (e) => {
209
+ // On-chain tx succeeded but backend confirmation timed out.
210
+ // Safe to treat as paid — reconcile async on your backend.
211
+ console.log(e.detail.transactionReference, e.detail.transactionHash);
212
+ });
213
+
119
214
  window.addEventListener("kwespay:paymentCancelled", (e) => {
120
215
  console.log(e.detail.reason); // "user_cancelled_review" | "user_started_over"
121
216
  });
122
217
 
123
218
  window.addEventListener("kwespay:widgetOpened", () => {});
219
+
124
220
  window.addEventListener("kwespay:widgetClosed", (e) => {
125
221
  console.log(e.detail.completedPayment); // boolean
126
222
  });
@@ -134,23 +230,17 @@ window.addEventListener("kwespay:apiKeyValidated", (e) => {
134
230
 
135
231
  ## Wallet Support
136
232
 
137
- - **Injected wallets** (MetaMask, Coinbase Wallet, Rabby, etc.) via EIP-6963
138
- - **Mobile wallets** via WalletConnect v2 (QR code + deep link)
233
+ - **Injected wallets** MetaMask, Coinbase Wallet, Rabby, and any EIP-6963 compatible wallet
234
+ - **Mobile wallets** WalletConnect v2 via QR code and deep link
139
235
 
140
236
  ---
141
237
 
142
238
  ## Examples
143
239
 
144
- | Example | Stack |
145
- | -------------------------------------------------------------------- | --------------------- |
146
- | [Static HTML demo](https://github.com/kwespay/widget-example-static) | Vanilla JS, unpkg CDN |
147
- | [Next.js demo](https://github.com/kwespay/widget-example-nextjs) | React, npm |
148
-
149
- ---
150
-
151
- ## Fee Model
152
-
153
- KwesPay uses a **customer-pays-fee** architecture. The fee is calculated by the backend and signed into the payment payload — the merchant always receives the exact `amount` specified. Fee details are shown to the customer before they confirm the transaction.
240
+ | Example | Stack |
241
+ | ----------------------------------------------------------------------- | --------------------- |
242
+ | [Static HTML demo](https://github.com/kwespay/widget-example-static) | Vanilla JS, unpkg CDN |
243
+ | [Next.js demo](https://github.com/Kwespay/Kwespay-embedded-widget-demo) | Next.js, React, npm |
154
244
 
155
245
  ---
156
246