@auto-topup/web 0.3.0 → 0.3.1
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 +104 -0
- package/package.json +8 -8
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# @auto-topup/web
|
|
2
|
+
|
|
3
|
+
Auto Topup subscription widget for browsers and any WebView.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @auto-topup/web
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or via CDN (no install):
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script src="https://cdn.jsdelivr.net/npm/@auto-topup/web@0.3.0/dist/retailcode.iife.global.js"></script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage — React / Next.js / Vite
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { RetailcodeTopup } from '@auto-topup/web';
|
|
21
|
+
|
|
22
|
+
RetailcodeTopup.create({
|
|
23
|
+
publicKey: 'pk_live_xxxx',
|
|
24
|
+
msisdn: user.phone,
|
|
25
|
+
container: '#topup-widget',
|
|
26
|
+
theme: { accent: '#0057FF' },
|
|
27
|
+
onSuccess: () => router.push('/success'),
|
|
28
|
+
onClose: () => router.push('/dashboard'),
|
|
29
|
+
}).mount();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Next.js
|
|
33
|
+
|
|
34
|
+
Use `useState` + `useEffect` so the container div is in the DOM before `.mount()` runs:
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
'use client';
|
|
38
|
+
import { useEffect, useState } from 'react';
|
|
39
|
+
import { useRouter } from 'next/navigation';
|
|
40
|
+
import { RetailcodeTopup } from '@auto-topup/web';
|
|
41
|
+
|
|
42
|
+
export default function SomePage() {
|
|
43
|
+
const router = useRouter();
|
|
44
|
+
const [widgetOpen, setWidgetOpen] = useState(false);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!widgetOpen) return;
|
|
48
|
+
RetailcodeTopup.create({
|
|
49
|
+
publicKey: 'pk_live_xxxx',
|
|
50
|
+
msisdn: '08012345678',
|
|
51
|
+
container: '#topup-widget',
|
|
52
|
+
onClose: () => setWidgetOpen(false),
|
|
53
|
+
onSuccess: () => setWidgetOpen(false),
|
|
54
|
+
}).mount();
|
|
55
|
+
}, [widgetOpen]);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<button onClick={() => setWidgetOpen(true)}>Open Topup</button>
|
|
60
|
+
|
|
61
|
+
{widgetOpen && (
|
|
62
|
+
<div id="topup-widget" style={{ position: 'fixed', inset: 0, zIndex: 9999 }} />
|
|
63
|
+
)}
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Usage — Plain HTML / CDN
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<script src="https://cdn.jsdelivr.net/npm/@auto-topup/web@0.3.0/dist/retailcode.iife.global.js"></script>
|
|
73
|
+
|
|
74
|
+
<div id="topup-widget"></div>
|
|
75
|
+
|
|
76
|
+
<script>
|
|
77
|
+
RetailcodeSDK.RetailcodeTopup.create({
|
|
78
|
+
publicKey: 'pk_live_xxxx',
|
|
79
|
+
msisdn: '08012345678',
|
|
80
|
+
container: '#topup-widget',
|
|
81
|
+
theme: { accent: '#0057FF' },
|
|
82
|
+
onSuccess: function(r) { console.log('subscribed', r); },
|
|
83
|
+
onClose: function() { window.location.href = '/'; },
|
|
84
|
+
}).mount();
|
|
85
|
+
</script>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Options
|
|
89
|
+
|
|
90
|
+
| Option | Type | Required | Description |
|
|
91
|
+
|---|---|---|---|
|
|
92
|
+
| `publicKey` | `string` | Yes | Your Retailcode public key |
|
|
93
|
+
| `msisdn` | `string` | Yes | Subscriber phone number |
|
|
94
|
+
| `container` | `string` | Yes | CSS selector for the mount element |
|
|
95
|
+
| `theme.accent` | `string` | No | Hex colour for buttons and accents (default `#0057FF`) |
|
|
96
|
+
| `theme.fontFamily` | `string` | No | Font family override (default `'DM Sans', system-ui`) |
|
|
97
|
+
| `onSuccess` | `() => void` | No | Called after a successful subscription |
|
|
98
|
+
| `onClose` | `() => void` | No | Called when the user dismisses the widget |
|
|
99
|
+
|
|
100
|
+
> **Note:** `onSuccess` and `onClose` are mutually exclusive — only one fires per session.
|
|
101
|
+
|
|
102
|
+
## Full documentation
|
|
103
|
+
|
|
104
|
+
See the [main repository README](https://github.com/FBIS-Tech/auto-topup-sdk).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auto-topup/web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Retailcode SDK — browser widget (Shadow DOM)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/FBIS-Tech/auto-topup-sdk",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
|
-
"scripts": {
|
|
30
|
-
"build": "tsup",
|
|
31
|
-
"dev": "tsup --watch",
|
|
32
|
-
"typecheck": "tsc --noEmit"
|
|
33
|
-
},
|
|
34
29
|
"dependencies": {
|
|
35
|
-
"@auto-topup/core": "
|
|
30
|
+
"@auto-topup/core": "0.3.1"
|
|
36
31
|
},
|
|
37
32
|
"devDependencies": {
|
|
38
33
|
"tsup": "*",
|
|
39
34
|
"typescript": "*"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"dev": "tsup --watch",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|