@reevit/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/LICENSE +21 -0
- package/README.md +211 -0
- package/dist/index.d.mts +628 -0
- package/dist/index.d.ts +628 -0
- package/dist/index.js +1636 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1612 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +526 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Reevit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# @reevit/react
|
|
2
|
+
|
|
3
|
+
Unified Payment Widget for React Applications. Accept card and mobile money payments with a single integration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @reevit/react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
The simplest way to integrate Reevit is using the `ReevitCheckout` component.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { ReevitCheckout } from '@reevit/react';
|
|
17
|
+
import '@reevit/react/styles.css';
|
|
18
|
+
|
|
19
|
+
function App() {
|
|
20
|
+
return (
|
|
21
|
+
<ReevitCheckout
|
|
22
|
+
publicKey="pk_test_your_key"
|
|
23
|
+
amount={10000} // Amount in smallest unit (e.g., pesewas for GHS)
|
|
24
|
+
currency="GHS"
|
|
25
|
+
email="customer@example.com"
|
|
26
|
+
onSuccess={(result) => {
|
|
27
|
+
console.log('Payment success!', result);
|
|
28
|
+
alert(`Payment of ${result.currency} ${result.amount/100} successful!`);
|
|
29
|
+
}}
|
|
30
|
+
onError={(error) => {
|
|
31
|
+
console.error('Payment failed:', error.message);
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<button className="my-pay-button">Pay GHS 100.00</button>
|
|
35
|
+
</ReevitCheckout>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Custom Theme
|
|
41
|
+
|
|
42
|
+
You can customize the look and feel of the checkout widget to match your brand.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<ReevitCheckout
|
|
46
|
+
theme={{
|
|
47
|
+
primaryColor: '#6200EE',
|
|
48
|
+
backgroundColor: '#F5F5F5',
|
|
49
|
+
textColor: '#000000',
|
|
50
|
+
borderRadius: '12px',
|
|
51
|
+
fontFamily: "'Segoe UI', Roboto, sans-serif",
|
|
52
|
+
darkMode: true,
|
|
53
|
+
}}
|
|
54
|
+
// ...other props
|
|
55
|
+
>
|
|
56
|
+
<button>Secure Checkout</button>
|
|
57
|
+
</ReevitCheckout>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Advanced Usage: useReevit Hook
|
|
61
|
+
|
|
62
|
+
For full control over the payment flow, use the `useReevit` hook. This allows you to build your own custom UI while Reevit handles the state management and API communication.
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { useReevit } from '@reevit/react';
|
|
66
|
+
|
|
67
|
+
function CustomCheckout() {
|
|
68
|
+
const {
|
|
69
|
+
status, // 'idle' | 'loading' | 'ready' | 'method_selected' | 'processing' | 'success' | 'failed'
|
|
70
|
+
initialize, // Start the process
|
|
71
|
+
selectMethod, // Pick 'card' or 'mobile_money'
|
|
72
|
+
processPayment, // Confirm payment
|
|
73
|
+
error,
|
|
74
|
+
isLoading
|
|
75
|
+
} = useReevit({
|
|
76
|
+
config: {
|
|
77
|
+
publicKey: 'pk_test_xxx',
|
|
78
|
+
amount: 5000,
|
|
79
|
+
currency: 'GHS',
|
|
80
|
+
},
|
|
81
|
+
onSuccess: (res) => console.log('Done!', res),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (status === 'loading') return <Spinner />;
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<div>
|
|
88
|
+
<button onClick={() => initialize()}>Start Checkout</button>
|
|
89
|
+
{status === 'ready' && (
|
|
90
|
+
<>
|
|
91
|
+
<button onClick={() => selectMethod('card')}>Card</button>
|
|
92
|
+
<button onClick={() => selectMethod('mobile_money')}>Mobile Money</button>
|
|
93
|
+
</>
|
|
94
|
+
)}
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Browser Support
|
|
101
|
+
|
|
102
|
+
- Chrome, Firefox, Safari, Edge (latest 2 versions)
|
|
103
|
+
- Mobile Safari and Chrome on Android/iOS
|
|
104
|
+
|
|
105
|
+
## Props Reference
|
|
106
|
+
|
|
107
|
+
| Prop | Type | Description |
|
|
108
|
+
|------|------|-------------|
|
|
109
|
+
| `publicKey` | `string` | **Required**. Your project's public key (pk_test_... or pk_live_...) |
|
|
110
|
+
| `amount` | `number` | **Required**. Amount in the smallest unit (e.g., 500 for 5.00) |
|
|
111
|
+
| `currency` | `string` | **Required**. 3-letter ISO currency code (GHS, NGN, USD, etc.) |
|
|
112
|
+
| `email` | `string` | Customer's email address |
|
|
113
|
+
| `phone` | `string` | Customer's phone number (recommended for Mobile Money) |
|
|
114
|
+
| `reference` | `string` | Your own unique transaction reference |
|
|
115
|
+
| `metadata` | `object` | Key-value pairs to store with the transaction |
|
|
116
|
+
| `paymentMethods` | `string[]` | List of enabled methods: `['card', 'mobile_money', 'bank_transfer']` |
|
|
117
|
+
| `theme` | `ReevitTheme` | Customization options for the widget |
|
|
118
|
+
| `onSuccess` | `function` | Called when the payment is successfully processed |
|
|
119
|
+
| `onError` | `function` | Called when an error occurs |
|
|
120
|
+
| `onClose` | `function` | Called when the user dismisses the widget |
|
|
121
|
+
|
|
122
|
+
## PSP Bridges
|
|
123
|
+
|
|
124
|
+
For advanced use cases, you can use individual PSP bridges directly. These provide React components for each payment processor.
|
|
125
|
+
|
|
126
|
+
### Stripe
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
import { StripeBridge } from '@reevit/react';
|
|
130
|
+
|
|
131
|
+
<StripeBridge
|
|
132
|
+
publishableKey="pk_test_xxx"
|
|
133
|
+
clientSecret="pi_xxx_secret_xxx" // From your backend
|
|
134
|
+
amount={5000}
|
|
135
|
+
currency="USD"
|
|
136
|
+
onSuccess={(result) => console.log('Paid:', result.paymentIntentId)}
|
|
137
|
+
onError={(err) => console.error(err.message)}
|
|
138
|
+
/>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Monnify (Nigeria)
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import { MonnifyBridge } from '@reevit/react';
|
|
145
|
+
|
|
146
|
+
<MonnifyBridge
|
|
147
|
+
apiKey="MK_TEST_xxx"
|
|
148
|
+
contractCode="1234567890"
|
|
149
|
+
amount={5000}
|
|
150
|
+
currency="NGN"
|
|
151
|
+
reference="TXN_12345"
|
|
152
|
+
customerName="John Doe"
|
|
153
|
+
customerEmail="john@example.com"
|
|
154
|
+
isTestMode={true}
|
|
155
|
+
onSuccess={(result) => console.log('Paid:', result.transactionReference)}
|
|
156
|
+
onError={(err) => console.error(err.message)}
|
|
157
|
+
/>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### M-Pesa (Kenya/Tanzania)
|
|
161
|
+
|
|
162
|
+
M-Pesa uses STK Push - the customer receives a prompt on their phone to authorize the payment.
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import { MPesaBridge, useMPesaStatusPolling } from '@reevit/react';
|
|
166
|
+
|
|
167
|
+
function MpesaPayment() {
|
|
168
|
+
const [checkoutId, setCheckoutId] = useState(null);
|
|
169
|
+
|
|
170
|
+
const { startPolling } = useMPesaStatusPolling(
|
|
171
|
+
'/api/mpesa/status',
|
|
172
|
+
checkoutId,
|
|
173
|
+
{
|
|
174
|
+
onSuccess: (result) => console.log('Paid:', result.transactionId),
|
|
175
|
+
onFailed: (err) => console.error(err.message),
|
|
176
|
+
onTimeout: () => console.log('Timed out'),
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<MPesaBridge
|
|
182
|
+
apiEndpoint="/api/mpesa/stk-push"
|
|
183
|
+
phoneNumber="254712345678"
|
|
184
|
+
amount={500}
|
|
185
|
+
currency="KES"
|
|
186
|
+
reference="TXN_12345"
|
|
187
|
+
onInitiated={(id) => {
|
|
188
|
+
setCheckoutId(id);
|
|
189
|
+
startPolling();
|
|
190
|
+
}}
|
|
191
|
+
onSuccess={(result) => console.log('Paid!')}
|
|
192
|
+
onError={(err) => console.error(err.message)}
|
|
193
|
+
/>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Supported PSPs
|
|
199
|
+
|
|
200
|
+
| Provider | Countries | Payment Methods |
|
|
201
|
+
|----------|-----------|-----------------|
|
|
202
|
+
| Paystack | NG, GH, ZA, KE | Card, Mobile Money, Bank |
|
|
203
|
+
| Flutterwave | NG, GH, KE, ZA + | Card, Mobile Money, Bank |
|
|
204
|
+
| Hubtel | GH | Mobile Money |
|
|
205
|
+
| Stripe | Global (50+) | Card, Apple Pay, Google Pay |
|
|
206
|
+
| Monnify | NG | Card, Bank Transfer, USSD |
|
|
207
|
+
| M-Pesa | KE, TZ | Mobile Money (STK Push) |
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
MIT © [Reevit](https://reevit.io)
|