@kwespay/widget 1.0.6 → 1.0.8
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 +156 -0
- package/dist/esm/index.js +338 -359
- package/dist/kwespay-widget.js +339 -360
- package/dist/kwespay-widget.min.js +551 -551
- package/package.json +1 -1
package/Readme.MD
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# @kwespay/widget
|
|
2
|
+
|
|
3
|
+
> Accept crypto payments on any EVM chain with a single JavaScript widget.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@kwespay/widget)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
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
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @kwespay/widget
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or load via CDN (no bundler required):
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<script src="https://unpkg.com/@kwespay/widget/dist/kwespay-widget.min.js"></script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
import KwesPayWidget from "@kwespay/widget";
|
|
36
|
+
|
|
37
|
+
const widget = new KwesPayWidget({
|
|
38
|
+
apiKey: "your_api_key", // from app.kwespay.xyz
|
|
39
|
+
vendorId: "your_vendor_id", // from app.kwespay.xyz
|
|
40
|
+
amount: 10.0,
|
|
41
|
+
currency: "USD",
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
widget.open();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The widget handles everything — wallet connection, network switching, token selection, transaction signing, and success/error states.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const widget = new KwesPayWidget({
|
|
55
|
+
apiKey: "your_api_key", // Required — from app.kwespay.xyz
|
|
56
|
+
vendorId: "your_vendor_id", // Required — from app.kwespay.xyz
|
|
57
|
+
amount: 25.0, // Required — fiat amount to charge
|
|
58
|
+
currency: "USD", // Optional — "USD" (default) or "GHS"
|
|
59
|
+
acceptedTokens: ["USDT", "USDC"], // Optional — restrict accepted tokens
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `acceptedTokens`
|
|
64
|
+
|
|
65
|
+
| Value | Behaviour |
|
|
66
|
+
| ------------------ | ------------------------------------ |
|
|
67
|
+
| `undefined` | All tokens on all supported networks |
|
|
68
|
+
| `"stablecoins"` | USDT, USDC, DAI, BUSD, USDc |
|
|
69
|
+
| `["USDT", "USDC"]` | Only the listed tokens |
|
|
70
|
+
|
|
71
|
+
Token and network availability is also scoped by the permissions set on your API key in the dashboard.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Supported Networks
|
|
76
|
+
|
|
77
|
+
| Network | Chain ID | Type |
|
|
78
|
+
| ------------ | -------- | ------- |
|
|
79
|
+
| Ethereum | 1 | Mainnet |
|
|
80
|
+
| Polygon | 137 | Mainnet |
|
|
81
|
+
| Base | 8453 | Mainnet |
|
|
82
|
+
| Lisk | 1135 | Mainnet |
|
|
83
|
+
| Sepolia | 11155111 | Testnet |
|
|
84
|
+
| Polygon Amoy | 80002 | Testnet |
|
|
85
|
+
| Base Sepolia | 84532 | Testnet |
|
|
86
|
+
| Lisk Sepolia | 4202 | Testnet |
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Methods
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
widget.open(); // Open the payment widget
|
|
94
|
+
widget.close(); // Close the widget
|
|
95
|
+
widget.isOpen(); // Returns boolean
|
|
96
|
+
widget.updateAmount(15.0, "USD"); // Update amount on the fly
|
|
97
|
+
widget.getState(); // Returns current widget and config state
|
|
98
|
+
widget.destroy(); // Remove widget from DOM and clean up
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Events
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
window.addEventListener("kwespay:paymentSuccess", (e) => {
|
|
107
|
+
const {
|
|
108
|
+
transactionHash,
|
|
109
|
+
transactionReference,
|
|
110
|
+
paymentIdBytes32,
|
|
111
|
+
fiatAmount,
|
|
112
|
+
currency,
|
|
113
|
+
token,
|
|
114
|
+
network,
|
|
115
|
+
} = e.detail;
|
|
116
|
+
// fulfil your order here
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
window.addEventListener("kwespay:paymentError", (e) => {
|
|
120
|
+
console.error(e.detail.error, e.detail.errorType);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
window.addEventListener("kwespay:paymentCancelled", (e) => {
|
|
124
|
+
console.log(e.detail.reason); // "user_cancelled_review" | "user_started_over"
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
window.addEventListener("kwespay:widgetOpened", () => {});
|
|
128
|
+
|
|
129
|
+
window.addEventListener("kwespay:widgetClosed", (e) => {
|
|
130
|
+
console.log(e.detail.completedPayment); // boolean
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
window.addEventListener("kwespay:apiKeyValidated", (e) => {
|
|
134
|
+
console.log(e.detail.vendorInfo);
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Wallet Support
|
|
141
|
+
|
|
142
|
+
- **Injected wallets** — MetaMask, Coinbase Wallet, Rabby, and any EIP-6963 compatible wallet
|
|
143
|
+
- **Mobile wallets** — WalletConnect v2 via QR code and deep link
|
|
144
|
+
|
|
145
|
+
## Examples
|
|
146
|
+
|
|
147
|
+
| Example | Stack |
|
|
148
|
+
| -------------------------------------------------------------------- | --------------------- |
|
|
149
|
+
| [Static HTML demo](https://github.com/kwespay/widget-example-static) | Vanilla JS, unpkg CDN |
|
|
150
|
+
| [Next.js demo](https://github.com/kwespay/widget-example-nextjs) | React, npm |
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT © KwesPay
|