@kwespay/widget 1.0.8 → 1.0.10
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 +105 -12
- package/dist/esm/index--_dPnlv5.js +2553 -0
- package/dist/esm/index-BDgXWGKX.js +2598 -0
- package/dist/esm/index-BL1KrVhv.js +2540 -0
- package/dist/esm/index-BRvdL-Wp.js +3085 -0
- package/dist/esm/index-Bd9oDICQ.js +3085 -0
- package/dist/esm/index-Bu22k5YO.js +2562 -0
- package/dist/esm/{index-338l55OY.js → index-C5OB57Yl.js} +87 -44
- package/dist/esm/index-C7bWyK3p.js +2449 -0
- package/dist/esm/index-CEIKLFls.js +2562 -0
- package/dist/esm/index-CQIWeG1B.js +3083 -0
- package/dist/esm/index-ChlX7kVk.js +2530 -0
- package/dist/esm/index-DKT22_47.js +2601 -0
- package/dist/esm/index-DLb23sAI.js +2562 -0
- package/dist/esm/index-DSz-IL-x.js +2515 -0
- package/dist/esm/index-Dm1jCXcL.js +2540 -0
- package/dist/esm/index-DrZ7hcts.js +2602 -0
- package/dist/esm/index-Ds5OUtZv.js +2552 -0
- package/dist/esm/index-ZsnaJECC.js +3085 -0
- package/dist/esm/index-azjjYn2F.js +2553 -0
- package/dist/esm/index-hxHZv-eJ.js +3085 -0
- package/dist/esm/index.js +1189 -534
- package/dist/index.d.ts +52 -5
- package/dist/kwespay-widget.js +46645 -53961
- package/dist/kwespay-widget.min.js +551 -576
- package/package.json +2 -2
package/Readme.MD
CHANGED
|
@@ -31,20 +31,60 @@ Or load via CDN (no bundler required):
|
|
|
31
31
|
|
|
32
32
|
## Quick Start
|
|
33
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
|
+
|
|
34
64
|
```js
|
|
35
65
|
import KwesPayWidget from "@kwespay/widget";
|
|
36
66
|
|
|
37
67
|
const widget = new KwesPayWidget({
|
|
38
|
-
apiKey: "your_api_key",
|
|
39
|
-
vendorId: "your_vendor_id",
|
|
40
|
-
amount:
|
|
68
|
+
apiKey: "your_api_key",
|
|
69
|
+
vendorId: "your_vendor_id",
|
|
70
|
+
amount: 49.99,
|
|
41
71
|
currency: "USD",
|
|
42
72
|
});
|
|
43
73
|
|
|
44
|
-
|
|
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
|
+
}
|
|
45
84
|
```
|
|
46
85
|
|
|
47
|
-
The widget handles everything — wallet connection, network switching, token
|
|
86
|
+
The widget handles everything — wallet connection, network switching, token
|
|
87
|
+
selection, transaction signing, and success/error states.
|
|
48
88
|
|
|
49
89
|
---
|
|
50
90
|
|
|
@@ -68,7 +108,8 @@ const widget = new KwesPayWidget({
|
|
|
68
108
|
| `"stablecoins"` | USDT, USDC, DAI, BUSD, USDc |
|
|
69
109
|
| `["USDT", "USDC"]` | Only the listed tokens |
|
|
70
110
|
|
|
71
|
-
Token and network availability is also scoped by the permissions set on your
|
|
111
|
+
Token and network availability is also scoped by the permissions set on your
|
|
112
|
+
API key in the dashboard.
|
|
72
113
|
|
|
73
114
|
---
|
|
74
115
|
|
|
@@ -77,6 +118,7 @@ Token and network availability is also scoped by the permissions set on your API
|
|
|
77
118
|
| Network | Chain ID | Type |
|
|
78
119
|
| ------------ | -------- | ------- |
|
|
79
120
|
| Ethereum | 1 | Mainnet |
|
|
121
|
+
| MEZO | 31612 | Mainnet |
|
|
80
122
|
| Polygon | 137 | Mainnet |
|
|
81
123
|
| Base | 8453 | Mainnet |
|
|
82
124
|
| Lisk | 1135 | Mainnet |
|
|
@@ -84,16 +126,55 @@ Token and network availability is also scoped by the permissions set on your API
|
|
|
84
126
|
| Polygon Amoy | 80002 | Testnet |
|
|
85
127
|
| Base Sepolia | 84532 | Testnet |
|
|
86
128
|
| Lisk Sepolia | 4202 | Testnet |
|
|
129
|
+
| MEZO Testnet | 31611 | Testnet |
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
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` |
|
|
87
165
|
|
|
88
166
|
---
|
|
89
167
|
|
|
90
168
|
## Methods
|
|
91
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
|
+
|
|
92
173
|
```js
|
|
93
|
-
widget.open(); // Open the
|
|
174
|
+
widget.open(); // Open the widget — returns a Promise<PaymentResult>
|
|
94
175
|
widget.close(); // Close the widget
|
|
95
176
|
widget.isOpen(); // Returns boolean
|
|
96
|
-
widget.updateAmount(15.0, "USD"); // Update amount
|
|
177
|
+
widget.updateAmount(15.0, "USD"); // Update amount between opens
|
|
97
178
|
widget.getState(); // Returns current widget and config state
|
|
98
179
|
widget.destroy(); // Remove widget from DOM and clean up
|
|
99
180
|
```
|
|
@@ -102,6 +183,10 @@ widget.destroy(); // Remove widget from DOM and clean up
|
|
|
102
183
|
|
|
103
184
|
## Events
|
|
104
185
|
|
|
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.
|
|
189
|
+
|
|
105
190
|
```js
|
|
106
191
|
window.addEventListener("kwespay:paymentSuccess", (e) => {
|
|
107
192
|
const {
|
|
@@ -120,6 +205,12 @@ window.addEventListener("kwespay:paymentError", (e) => {
|
|
|
120
205
|
console.error(e.detail.error, e.detail.errorType);
|
|
121
206
|
});
|
|
122
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
|
+
|
|
123
214
|
window.addEventListener("kwespay:paymentCancelled", (e) => {
|
|
124
215
|
console.log(e.detail.reason); // "user_cancelled_review" | "user_started_over"
|
|
125
216
|
});
|
|
@@ -142,12 +233,14 @@ window.addEventListener("kwespay:apiKeyValidated", (e) => {
|
|
|
142
233
|
- **Injected wallets** — MetaMask, Coinbase Wallet, Rabby, and any EIP-6963 compatible wallet
|
|
143
234
|
- **Mobile wallets** — WalletConnect v2 via QR code and deep link
|
|
144
235
|
|
|
236
|
+
---
|
|
237
|
+
|
|
145
238
|
## Examples
|
|
146
239
|
|
|
147
|
-
| Example
|
|
148
|
-
|
|
|
149
|
-
| [Static HTML demo](https://github.com/kwespay/widget-example-static)
|
|
150
|
-
| [Next.js demo](https://github.com/
|
|
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 |
|
|
151
244
|
|
|
152
245
|
---
|
|
153
246
|
|