@zahlen/checkout-react 0.1.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/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # @zahlen/checkout-react
2
+
3
+ <p align="center">
4
+ <img src="https://img.shields.io/npm/v/@zahlen/checkout-react?style=flat-square" alt="npm version" />
5
+ <img src="https://img.shields.io/npm/l/@zahlen/checkout-react?style=flat-square" alt="license" />
6
+ </p>
7
+
8
+ <p align="center">
9
+ <strong>React components for Zahlen Checkout</strong>
10
+ <br />
11
+ Hooks • Components • Full TypeScript support
12
+ </p>
13
+
14
+ ---
15
+
16
+ ## 🚀 Installation
17
+
18
+ ```bash
19
+ npm install @zahlen/checkout-react @zahlen/checkout
20
+ # or
21
+ yarn add @zahlen/checkout-react @zahlen/checkout
22
+ ```
23
+
24
+ ---
25
+
26
+ ## 📖 Quick Start
27
+
28
+ ### Option 1: Simple Button (Easiest)
29
+
30
+ ```tsx
31
+ import { ZahlenProvider, ZahlenButton } from '@zahlen/checkout-react';
32
+
33
+ function App() {
34
+ return (
35
+ <ZahlenProvider apiKey="pk_live_your_api_key">
36
+ <ProductPage />
37
+ </ZahlenProvider>
38
+ );
39
+ }
40
+
41
+ function ProductPage() {
42
+ return (
43
+ <ZahlenButton
44
+ amount={499900} // ₦4,999 in kobo
45
+ currency="NGN"
46
+ description="Premium Plan"
47
+ onSuccess={(result) => {
48
+ console.log('Paid!', result);
49
+ // Redirect to success page
50
+ }}
51
+ onError={(error) => {
52
+ toast.error(error.message);
53
+ }}
54
+ >
55
+ 💳 Pay ₦4,999
56
+ </ZahlenButton>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### Option 2: useZahlen Hook (Recommended)
62
+
63
+ ```tsx
64
+ import { ZahlenProvider, useZahlen } from '@zahlen/checkout-react';
65
+
66
+ function App() {
67
+ return (
68
+ <ZahlenProvider apiKey="pk_live_your_api_key" theme="dark">
69
+ <ProductPage />
70
+ </ZahlenProvider>
71
+ );
72
+ }
73
+
74
+ function ProductPage() {
75
+ const { openCheckout, isProcessing } = useZahlen();
76
+
77
+ const handleBuy = async () => {
78
+ try {
79
+ const result = await openCheckout({
80
+ amount: 499900,
81
+ currency: 'NGN',
82
+ description: 'Premium Plan',
83
+ });
84
+ console.log('Payment successful!', result);
85
+ router.push('/success');
86
+ } catch (error) {
87
+ console.error('Payment failed:', error);
88
+ }
89
+ };
90
+
91
+ return (
92
+ <button onClick={handleBuy} disabled={isProcessing}>
93
+ {isProcessing ? 'Processing...' : 'Buy Now'}
94
+ </button>
95
+ );
96
+ }
97
+ ```
98
+
99
+ ### Option 3: Controlled Component (Full Control)
100
+
101
+ ```tsx
102
+ import { useState } from 'react';
103
+ import { ZahlenCheckout } from '@zahlen/checkout-react';
104
+ import { Zahlen } from '@zahlen/checkout';
105
+
106
+ // Initialize once at app entry
107
+ Zahlen.init({ apiKey: 'pk_live_your_api_key' });
108
+
109
+ function ProductPage() {
110
+ const [isOpen, setIsOpen] = useState(false);
111
+
112
+ return (
113
+ <>
114
+ <button onClick={() => setIsOpen(true)}>Pay Now</button>
115
+
116
+ <ZahlenCheckout
117
+ open={isOpen}
118
+ onClose={() => setIsOpen(false)}
119
+ amount={499900}
120
+ currency="NGN"
121
+ description="Premium Plan"
122
+ onSuccess={(result) => {
123
+ setIsOpen(false);
124
+ router.push('/success');
125
+ }}
126
+ onError={(error) => {
127
+ console.error(error);
128
+ }}
129
+ />
130
+ </>
131
+ );
132
+ }
133
+ ```
134
+
135
+ ---
136
+
137
+ ## 📚 API Reference
138
+
139
+ ### `<ZahlenProvider>`
140
+
141
+ Wrap your app with this provider to use Zahlen hooks.
142
+
143
+ ```tsx
144
+ <ZahlenProvider
145
+ apiKey="pk_live_xxx" // Required
146
+ theme="dark" // Optional: 'dark' | 'light' | 'auto'
147
+ >
148
+ {children}
149
+ </ZahlenProvider>
150
+ ```
151
+
152
+ ### `useZahlen()`
153
+
154
+ Hook to access Zahlen functionality.
155
+
156
+ ```tsx
157
+ const {
158
+ isInitialized, // boolean - whether SDK is ready
159
+ isProcessing, // boolean - whether payment is in progress
160
+ openCheckout, // (options) => Promise<PaymentResult>
161
+ closeCheckout, // () => void
162
+ setTheme, // (theme) => void
163
+ } = useZahlen();
164
+ ```
165
+
166
+ ### `<ZahlenButton>`
167
+
168
+ Pre-styled checkout button.
169
+
170
+ | Prop | Type | Required | Description |
171
+ |------|------|----------|-------------|
172
+ | `amount` | `number` | ✅ | Amount in smallest unit |
173
+ | `currency` | `string` | ✅ | ISO currency code |
174
+ | `description` | `string` | | Payment description |
175
+ | `customerEmail` | `string` | | Customer email |
176
+ | `metadata` | `object` | | Custom metadata |
177
+ | `onSuccess` | `function` | | Success callback |
178
+ | `onError` | `function` | | Error callback |
179
+ | `onClose` | `function` | | Close callback |
180
+ | `className` | `string` | | CSS class |
181
+ | `style` | `object` | | Inline styles |
182
+ | `disabled` | `boolean` | | Disable button |
183
+
184
+ ### `<ZahlenCheckout>`
185
+
186
+ Controlled checkout component.
187
+
188
+ | Prop | Type | Required | Description |
189
+ |------|------|----------|-------------|
190
+ | `open` | `boolean` | ✅ | Control modal visibility |
191
+ | `onClose` | `function` | ✅ | Close callback |
192
+ | `amount` | `number` | ✅ | Amount in smallest unit |
193
+ | `currency` | `string` | ✅ | ISO currency code |
194
+ | `onSuccess` | `function` | ✅ | Success callback |
195
+ | `onError` | `function` | | Error callback |
196
+ | `description` | `string` | | Payment description |
197
+
198
+ ---
199
+
200
+ ## 🎨 Customization
201
+
202
+ ```tsx
203
+ import { Zahlen } from '@zahlen/checkout';
204
+
205
+ // After init, customize theme
206
+ Zahlen.init({
207
+ apiKey: 'pk_live_xxx',
208
+ customStyles: {
209
+ '--zahlen-primary': '#FF6B6B',
210
+ '--zahlen-bg': '#1A1A2E',
211
+ }
212
+ });
213
+ ```
214
+
215
+ ---
216
+
217
+ ## 📄 License
218
+
219
+ MIT © Zahlen
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";