Skip to main content

Concept

This guide will walk you through integrating Flutterwave into your React application using React hooks. You’ll learn how to:
  1. Set up your React app: Install the packages and configure your app to handle payments using React hooks.
  2. Create payment configuration: Define your payment settings, including transaction reference, amount, currency, and customer details.
  3. Handle the payment logic: Use the useFlutterwave hook to initialize and handle the payment process in your React app.

Step 1: Set up your React App

To get started, create a new react project and change into the directory using the following command:

Install the Dependencies

Run the command below to install the required dependencies:

Step 2: Add Payment Configuration

You’ll need a page to show your customers’ orders. Create a src/PrePayment.js file to render the payment details before processing the payment.

Initialize the PrePayment Function

Create a PrePayment function, import the required dependencies, and add data to simulate a real-life scenario.

Define Payment Configuration

Set up the configuration object for the payment. This includes your Flutterwave public key, customer details, payment amount, and payment options.
To get your API key, log into your Flutterwave dashboard and navigate to the API keys section under the Settings menu.

Render the Pre-Payment Page

Update the code to render the payment information and a button for the user to initiate payment.
Here is how your entire src/PrePayment should look like:

Step 3: Handle the Payment Logic

Now, you need a component to manage the routing logic and handle success or errors.

Add the Payment Success Page (PaymentSuccess.js)

First, you need to create a PaymentSuccess.js file that displays a confirmation message and the details of the payment after it has been completed.

Update the Main Component (App.js)

Next, update your App.js file to manage the payment flow and state.

Launch your Development Server

Finally, start your React application to see the changes in your browser.

Next Step

Now that you’ve completed the integration, feel free to explore other Flutterwave features. You can also extend the application by adding custom styles, implementing additional payment options, or incorporating any new features using our React SDK.