Skip to content

Commit 49678ee

Browse files
Merge pull request #63 from Flutterwave/dev
Pull deps and bugfixes from the dev branch
2 parents 84cc1ae + d6c387b commit 49678ee

17 files changed

Lines changed: 17889 additions & 16117 deletions

.babelrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
},
99
},
1010
],
11+
'@babel/preset-react',
1112
'@babel/preset-typescript',
1213
],
1314

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ lib-cov
2222
# Coverage directory used by tools like istanbul
2323
coverage
2424
*.lcov
25+
test-report/
2526

2627
# nyc test coverage
2728
.nyc_output

README.md

Lines changed: 182 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Available features include:
3838

3939
1. Flutterwave version 3 API keys
4040
2. Node version >= 6.9.x and npm >= 3.x.x
41-
3. React version >= 14
41+
3. React version >= 15 (including React 19)
42+
4. For Next.js: Version 12+ (both App Router and Pages Router supported)
4243

4344

4445
## Installation
@@ -89,7 +90,8 @@ Add Flutterwave to your projects as a component or a react hook:
8990

9091
1. [As a Component](#components)
9192
2. [Directly in your code](#hooks)
92-
3. [Making recurrent payments](#recurring-payments)
93+
3. [Next.js Applications](#nextjs-applications)
94+
4. [Making recurrent payments](#recurring-payments)
9395

9496

9597
### Components
@@ -186,6 +188,184 @@ export default function App() {
186188
}
187189
```
188190

191+
### Next.js Applications
192+
193+
The Flutterwave React SDK works seamlessly with Next.js applications. Since the library loads external scripts, you must ensure it runs only on the client side.
194+
195+
#### App Router (Next.js 13+)
196+
197+
Add the `'use client'` directive at the top of your payment component:
198+
199+
```javascript
200+
'use client';
201+
202+
import React from 'react';
203+
import { useFlutterwave, closePaymentModal } from 'flutterwave-react-v3';
204+
205+
export default function FlutterwavePayment() {
206+
const config = {
207+
public_key: 'FLWPUBK-**************************-X',
208+
tx_ref: Date.now(),
209+
amount: 100,
210+
currency: 'NGN',
211+
payment_options: 'card,mobilemoney,ussd',
212+
customer: {
213+
email: 'user@gmail.com',
214+
phone_number: '070********',
215+
name: 'john doe',
216+
},
217+
customizations: {
218+
title: 'My Payment',
219+
description: 'Payment for items in cart',
220+
logo: 'https://st2.depositphotos.com/4403291/7418/v/450/depositphotos_74189661-stock-illustration-online-shop-log.jpg',
221+
},
222+
};
223+
224+
const handleFlutterPayment = useFlutterwave(config);
225+
226+
return (
227+
<div>
228+
<h1>Make Payment</h1>
229+
<button
230+
onClick={() => {
231+
handleFlutterPayment({
232+
callback: (response) => {
233+
console.log(response);
234+
closePaymentModal();
235+
},
236+
onClose: () => {},
237+
});
238+
}}
239+
>
240+
Pay with Flutterwave
241+
</button>
242+
</div>
243+
);
244+
}
245+
```
246+
247+
You can also use the FlutterWaveButton component:
248+
249+
```javascript
250+
'use client';
251+
252+
import React from 'react';
253+
import { FlutterWaveButton, closePaymentModal } from 'flutterwave-react-v3';
254+
255+
export default function PaymentButton() {
256+
const config = {
257+
public_key: 'FLWPUBK-**************************-X',
258+
tx_ref: Date.now(),
259+
amount: 100,
260+
currency: 'NGN',
261+
payment_options: 'card,mobilemoney,ussd',
262+
customer: {
263+
email: 'user@gmail.com',
264+
phone_number: '070********',
265+
name: 'john doe',
266+
},
267+
customizations: {
268+
title: 'My store',
269+
description: 'Payment for items in cart',
270+
logo: 'https://st2.depositphotos.com/4403291/7418/v/450/depositphotos_74189661-stock-illustration-online-shop-log.jpg',
271+
},
272+
};
273+
274+
const fwConfig = {
275+
...config,
276+
text: 'Pay with Flutterwave!',
277+
callback: (response) => {
278+
console.log(response);
279+
closePaymentModal();
280+
},
281+
onClose: () => {},
282+
};
283+
284+
return (
285+
<div>
286+
<h1>Checkout</h1>
287+
<FlutterWaveButton {...fwConfig} />
288+
</div>
289+
);
290+
}
291+
```
292+
293+
#### Pages Router (Next.js 12 and below)
294+
295+
Use dynamic imports with SSR disabled:
296+
297+
```javascript
298+
import dynamic from 'next/dynamic';
299+
300+
// Dynamically import the payment component with SSR disabled
301+
const FlutterwavePayment = dynamic(
302+
() => import('../components/FlutterwavePayment'),
303+
{ ssr: false }
304+
);
305+
306+
export default function CheckoutPage() {
307+
return (
308+
<div>
309+
<h1>Checkout</h1>
310+
<FlutterwavePayment />
311+
</div>
312+
);
313+
}
314+
```
315+
316+
Then create your payment component in `components/FlutterwavePayment.js`:
317+
318+
```javascript
319+
import React from 'react';
320+
import { useFlutterwave, closePaymentModal } from 'flutterwave-react-v3';
321+
322+
export default function FlutterwavePayment() {
323+
const config = {
324+
public_key: 'FLWPUBK-**************************-X',
325+
tx_ref: Date.now(),
326+
amount: 100,
327+
currency: 'NGN',
328+
payment_options: 'card,mobilemoney,ussd',
329+
customer: {
330+
email: 'user@gmail.com',
331+
phone_number: '070********',
332+
name: 'john doe',
333+
},
334+
customizations: {
335+
title: 'My Payment',
336+
description: 'Payment for items in cart',
337+
logo: 'https://st2.depositphotos.com/4403291/7418/v/450/depositphotos_74189661-stock-illustration-online-shop-log.jpg',
338+
},
339+
};
340+
341+
const handleFlutterPayment = useFlutterwave(config);
342+
343+
return (
344+
<div>
345+
<button
346+
onClick={() => {
347+
handleFlutterPayment({
348+
callback: (response) => {
349+
console.log(response);
350+
closePaymentModal();
351+
},
352+
onClose: () => {},
353+
});
354+
}}
355+
>
356+
Pay with Flutterwave
357+
</button>
358+
</div>
359+
);
360+
}
361+
```
362+
363+
**Important Notes:**
364+
- Always use the `'use client'` directive when using Next.js App Router (Next.js 13+)
365+
- The Flutterwave script loads client-side only and cannot be server-side rendered
366+
- Ensure payment components are client components, not server components
367+
- For Pages Router, use `dynamic` import with `ssr: false` to prevent server-side rendering errors
368+
189369
### Recurring Payments
190370

191371
Pass the payment plan ID into your payload to make [recurring payments](https://developer.flutterwave.com/docs/recurring-payments/payment-plans).

dist/FWButton.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ interface FlutterWaveButtonProps extends FlutterwaveConfig {
88
children?: React.ReactNode;
99
callback: (response: FlutterWaveResponse) => void;
1010
}
11-
declare const FlutterWaveButton: ({ text, className, children, callback, onClose, disabled, ...config }: FlutterWaveButtonProps) => JSX.Element;
11+
declare const FlutterWaveButton: ({ text, className, children, callback, onClose, disabled, ...config }: FlutterWaveButtonProps) => React.ReactElement;
1212
export default FlutterWaveButton;

example/README.md

Lines changed: 73 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,104 @@
1-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
1+
# Flutterwave React v3 Example
22

3-
## Available Scripts
3+
This example demonstrates how to integrate Flutterwave payment gateway into your React application using the `flutterwave-react-v3` package.
44

5-
In the project directory, you can run:
5+
## Features Demonstrated
66

7-
### `yarn start`
7+
**Three Payment Integration Methods:**
8+
- Custom button with `useFlutterwave` hook
9+
- Pre-built `FlutterWaveButton` component
10+
- Custom styled payment buttons
811

9-
Runs the app in the development mode.<br />
10-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
12+
**Real-time Configuration:**
13+
- Dynamic amount input
14+
- Customer information management
15+
- Live payment preview
1116

12-
The page will reload if you make edits.<br />
13-
You will also see any lint errors in the console.
17+
**Modern UI/UX:**
18+
- Responsive design
19+
- Beautiful gradient backgrounds
20+
- Interactive hover effects
21+
- Mobile-friendly layout
1422

15-
### `yarn test`
23+
## Getting Started
1624

17-
Launches the test runner in the interactive watch mode.<br />
18-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
25+
### Prerequisites
1926

20-
### `yarn build`
27+
- Node.js (v14 or higher)
28+
- npm or yarn
29+
- Flutterwave account ([Sign up here](https://flutterwave.com))
2130

22-
Builds the app for production to the `build` folder.<br />
23-
It correctly bundles React in production mode and optimizes the build for the best performance.
31+
### Installation
2432

25-
The build is minified and the filenames include the hashes.<br />
26-
Your app is ready to be deployed!
33+
1. Install dependencies:
2734

28-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
35+
```bash
36+
npm install
37+
# or
38+
yarn install
39+
```
2940

30-
### `yarn eject`
41+
2. Update your Flutterwave public key in `src/App.js`:
3142

32-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
43+
```javascript
44+
const config = {
45+
public_key: "YOUR_FLUTTERWAVE_PUBLIC_KEY", // Replace with your key
46+
// ... other config
47+
};
48+
```
3349

34-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
50+
### Running the Example
3551

36-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
52+
```bash
53+
npm start
54+
# or
55+
yarn start
56+
```
3757

38-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
58+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
3959

40-
## Learn More
60+
## Test Credentials
4161

42-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
62+
For testing purposes, use these Flutterwave test card details:
4363

44-
To learn React, check out the [React documentation](https://reactjs.org/).
64+
- **Card Number:** 5531 8866 5214 2950
65+
- **CVV:** Any 3 digits
66+
- **Expiry:** Any future date
67+
- **PIN:** 3310
68+
- **OTP:** 12345
4569

46-
### Code Splitting
70+
## Package Information
4771

48-
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
72+
This example uses `flutterwave-react-v3` - the official Flutterwave React package with:
4973

50-
### Analyzing the Bundle Size
74+
- ✅ 100% Test Coverage
75+
- ✅ TypeScript Support
76+
- ✅ React 19 Compatible
77+
- ✅ Multiple Payment Options
78+
- ✅ Comprehensive Documentation
5179

52-
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
80+
## Learn More
81+
82+
- [Flutterwave Documentation](https://developer.flutterwave.com/docs)
83+
- [React Documentation](https://react.dev)
84+
- [Package Repository](https://github.com/Flutterwave/React-v3)
85+
86+
## Available Scripts
5387

54-
### Making a Progressive Web App
88+
### `npm start`
5589

56-
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
90+
Runs the app in development mode at [http://localhost:3000](http://localhost:3000).
5791

58-
### Advanced Configuration
92+
### `npm test`
5993

60-
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
94+
Launches the test runner in interactive watch mode.
6195

62-
### Deployment
96+
### `npm run build`
6397

64-
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
98+
Builds the app for production to the `build` folder.
6599

66-
### `yarn build` fails to minify
100+
## Support
67101

68-
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
102+
For issues or questions:
103+
- [GitHub Issues](https://github.com/Flutterwave/React-v3/issues)
104+
- [Flutterwave Support](https://support.flutterwave.com)

0 commit comments

Comments
 (0)