Giter Site home page Giter Site logo

eoeboh / flutterwave-react-v3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danielolamide/flutterwave-react-v3

0.0 0.0 0.0 592 KB

The official React Library for Flutterwave v3 payment APIs.

License: MIT License

JavaScript 19.26% HTML 12.02% CSS 6.48% TypeScript 62.24%

flutterwave-react-v3's Introduction

Flutterwave v3 React Library

Publish React Package npm npm NPM

Table of Contents

About

This is a react package for implementing Flutterwave gateway with different payment methods.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. See references for links to dashboard and API documentation.

Installation

$ npm install flutterwave-react-v3

# or
$ yarn add flutterwave-react-v3


Usage

Hooks

import React from 'react';
import { useFlutterwave, closePaymentModal } from 'flutterwave-react-v3';

export default function App() {
  const config = {
    public_key: 'FLWPUBK-**************************-X',
    tx_ref: Date.now(),
    amount: 100,
    currency: 'NGN',
    payment_options: 'card,mobilemoney,ussd',
    customer: {
      email: '[email protected]',
      phonenumber: '07064586146',
      name: 'joel ugwumadu',
    },
    customizations: {
      title: 'my Payment Title',
      description: 'Payment for items in cart',
      logo: 'https://st2.depositphotos.com/4403291/7418/v/450/depositphotos_74189661-stock-illustration-online-shop-log.jpg',
    },
  };

  const handleFlutterPayment = useFlutterwave(config);

  return (
    <div className="App">
     <h1>Hello Test user</h1>

      <button
        onClick={() => {
          handleFlutterPayment({
            callback: (response) => {
               console.log(response);
                closePaymentModal() // this will close the modal programmatically
            },
            onClose: () => {},
          });
        }}
      >
        Payment with React hooks
      </button>
    </div>
  );
}

Components

import React from 'react';
import { FlutterWaveButton, closePaymentModal } from 'flutterwave-react-v3';

export default function App() {
   const config = {
    public_key: 'FLWPUBK-**************************-X',
    tx_ref: Date.now(),
    amount: 100,
    currency: 'NGN',
    payment_options: 'card,mobilemoney,ussd',
    customer: {
      email: '[email protected]',
      phonenumber: '07064586146',
      name: 'joel ugwumadu',
    },
    customizations: {
      title: 'My store',
      description: 'Payment for items in cart',
      logo: 'https://st2.depositphotos.com/4403291/7418/v/450/depositphotos_74189661-stock-illustration-online-shop-log.jpg',
    },
  };

  const fwConfig = {
    ...config,
    text: 'Pay with Flutterwave!',
    callback: (response) => {
       console.log(response);
      closePaymentModal() // this will close the modal programmatically
    },
    onClose: () => {},
  };

  return (
    <div className="App">
     <h1>Hello Test user</h1>
      <FlutterWaveButton {...fwConfig} />
    </div>
  );
}

Other methods and descriptions:

Method Name Parameters Returns Description
closePaymentModal Null Null This methods allows you to close the payment modal via code.

Please checkout Flutterwave Documentation for other available options you can add to the tag.

Deployment

  • Switch to Live Mode on the Dashboard settings page
  • Use the Live Public API key

Securing Your API key

Even when using a public key, it would still be safe to secure it. Please note that the best way to secure your key is by storing it on the server side! However, your public key can be hidden from direct view on your code by simply taking the following steps:

  1. Create a .env file at the root of your react app directory

  - node_modules
  - public
  - src
  - .env         <-- create it here
  - .gitignore
  - package-lock.json
  - package.json
  1. Assign REACT_APP_ to your API key

Inside the .env file, assign the variable name REACT_APP_ to your API key.

// .env file
REACT_APP_API_KEY=your_api_key
//For example
REACT_APP_FLUTTERWAVE_KEY = 012345
  1. Add the .env file to the .gitignore file

// .gitignore file 

# api keys
.env       <-- add this line

# dependencies
/node_modules

After completing the above process, run a git status on your terminal to ensure the .env file does not show in the log

  1. Reference the API key via the process.env object

In order to confirm you can now access your API key through this object, kindly add a console.log to the reference statement like this:

console.log(process.env.REACT_APP_FLUTTERWAVE_API_KEY)

If your API key shows on your console, then you have successfully accessed your key through the process.env object. If your key does not show, try restarting your react app again.

This enables you hide your API key from direct access on the source code.

Please NOTE: this is not a secure method. To keep your key fully safe, render it from the server side.

Built Using

Contributors

Flutterwave API References

flutterwave-react-v3's People

Contributors

corneliusyaovi avatar korneliosyaovi avatar ugwumadu116 avatar ekene-eze avatar eoeboh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.