Code Monkey home page Code Monkey logo

react-ravepayment's Introduction

react-ravepayment

A React library wrapper for implementing ReavePay Payment Gateway

Demo

Alt text

Installation

npm install react-ravepayment --save

or

yarn add react-ravepayment --save

Usage

Hooks

import React, { Component } from "react";
import { useRavePayment } from "react-ravepayment";

const config = {
  txref: "rave-123456",
  customer_email: "[email protected]",
  customer_phone: "234099940409",
  amount: 2000,
  PBFPubKey: "FLWPUBK-XXXXXXXXXXXXXXXXXXXXXXXXXX-X",
  production: false,
};

const App = () => {
  const { initializePayment } = useRavePayment(config);
  return (
    <div>
      <button onClick={() => initializePayment()}>Pay 2000</button>
    </div>
  );
};

export default App;

Components

import React, { Component } from "react";
import { RaveProvider, RavePaymentButton } from "react-ravepayment";

const config = {
  txref: "rave-123456",
  customer_email: "[email protected]",
  customer_phone: "234099940409",
  amount: 2000,
  PBFPubKey: "FLWPUBK-XXXXXXXXXXXXXXXXXXXXXXXXXX-X",
  production: false,
  onSuccess: () => {},
  onClose: () => {}
};

const App = () => {
  return (
    <div>
      <RaveProvider {...config}>
        <RavePaymentButton>Pay 2000</RavePaymentButton>
      </RaveProvider>
    </div>
  );
};

export default App;

For more usage example check

API

See the API reference.

Deployment

WHEN DEPLOYING TO PRODUCTION/LIVE SYSTEM, take note of the following;

  1. Change isProduction attribute in the component tag to true i.e isProduction={true}
  2. Change RavePay PUBLIC KEY
  3. Ensure you implement webhooks to receive automatic updates when a transaction happens.

Contribution

  1. Fork it!
  2. Create your feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Some commit message'
  4. Push to the branch: git push origin feature-name
  5. Submit a pull request ๐Ÿ˜‰๐Ÿ˜‰

This project follows the all-contributors specification. Contributions of any kind welcome!

Issues

Looking to contribute? Look for the Good First Issue label.

๐Ÿ› Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

License

MIT

react-ravepayment's People

Contributors

anjolabassey avatar devifeoma avatar gladchinda avatar iamraphson avatar lkbr avatar quadriphobs1 avatar temiadesina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-ravepayment's Issues

Does not allow for dynamically adding amount

since the config object is used by the useRavePayment hook, there is no way to change the amount after the hook is called. And we cant also defer the calling of the hook until we have accepted the amount from the user since react hooks are supposed to be called at the top level of the functional component. Please let me know if you need more details to understand my context.

Redirect Url does not work

I have added the redirect_url to the config like this;

const redirectUrl = window.location.path + WATCH + '/' + singleEvent.event.sessionId + '/' + singleEvent.event.sessionToken;

const config = {
                                    PBFPubKey: process.env.REACT_APP_RAVE_PUBLIC_KEY,
                                    customer_email: this.props.auth.user.email,
                                    customer_phone: '',
                                    amount: singleEvent.event.eventPrice,
                                    currency: 'UGX',
                                    redirectUrl: redirectUrl,
                                    txref: singleEvent.id,
                                    production: true,
                                    payment_options: [
                                        'card',
                                        'mpesa',
                                        'mobilemoneyghana',
                                        'mobilemoneyuganda',
                                        'mobilemoneyrwanda',
                                        'mobilemoneyzambia',
                                        'mobilemoneytanzania',
                                        'barter'],
                                    onSuccess: () => {},
                                    onClose: () => console.log('Closed this transaction!!!'),
                                }

When I run the payment, it succeeds but it doesn't redirect to that page, which is what the user is paying to access.

Any help? I'm using class components.

Props not updated on RavePayment component

There seems to be a bug on the <RavePayment> component that prevents props from being updated after the component is first mounted.

A close observation of the component shows that the error can be attributed to the following:

Constructor

constructor(props) {
    super(props);
    this.payWithRave = this.payWithRave.bind(this);
    this.loadScript = this.loadScript.bind(this);
    this.state = {
      scriptLoaded: null,
      text: this.props.text || "Make Payment",
      class: this.props.class || "",
      metadata: this.props.metadata || [{}],
      currency: this.props.currency || "NGN",
      country: this.props.country || "NG",
      customer_firstname: this.props.customer_firstname || "",
      customer_phone: this.props.customer_phone || "",
      customer_lastname: this.props.customer_lastname || "",
      custom_title: this.props.custom_title || "",
      custom_description: this.props.custom_description || "",
      custom_logo: this.props.custom_logo || "",
      subaccounts: this.props.subaccounts || [{}], //splits payments into subaccounts provided
      payment_method: this.props.payment_method || "both", //falls back to card and account if none is specified
      payment_plan: this.props.payment_plan || "", //the id of your payment plan
      redirect_url: this.props.redirect_url || "", //calls this url after successful payment
      hosted_payment: this.props.hosted_payment //opens the modal in a new page
    };
}

PayWithRave

  payWithRave() {
    this.state.scriptLoaded &&
      this.state.scriptLoaded.then(() => {
        window.getpaidSetup({
          customer_email: this.props.email,
          amount: this.props.amount,
          txref: this.props.reference,
          PBFPubKey: this.props.ravePubKey,
          onclose: () => this.props.close(),
          callback: response => this.props.callback(response),
          meta: this.state.metadata,
          currency: this.state.currency,
          country: this.state.country,
          customer_firstname: this.state.customer_firstname,
          customer_phone: this.state.customer_phone,
          customer_lastname: this.state.customer_lastname,
          custom_title: this.state.custom_title,
          custom_description: this.state.custom_description,
          custom_logo: this.state.custom_logo,
          subaccounts: this.state.subaccounts,
          payment_method: this.state.payment_method,
          payment_plan: this.state.payment_plan,
          redirect_url: this.state.redirect_url,
          hosted_payment: this.state.hosted_payment
        });
      });
  }

TypeError: __webpack_require__.i(...) is not a function

When i use Component or Function both case in give this error


useRaveScript
webpack:///~/react-ravepayment/dist/index.es.js:60
useRavePayment
webpack:///~/react-ravepayment/dist/index.es.js:122
new
webpack:///src/components/Booking/Payment/FlutterWave.js:19
http://localhost:3001/assets/vendor.js:338561:24
instantiate
webpack:///~/react-proxy/modules/createClassProxy.js:103
flutterwave (http://localhost:3001/assets/vendor.js:338576:22),
mountIndeterminateComponent
webpack:///~/react-dom/cjs/react-dom.development.js:13381
beginWork
webpack:///~/react-dom/cjs/react-dom.development.js:13821
performUnitOfWork
webpack:///~/react-dom/cjs/react-dom.development.js:15864
workLoop
webpack:///~/react-dom/cjs/react-dom.development.js:15903

Publish 3.0.0 to npm

Hey - thanks for making this, super helpful for quickly pulling in Flutterwave to my app!

Small request - I'm using typescript and saw that you've merged a PR that includes type definitions but the current published version (2.0.8) on NPMJS doesn't include that yet. Would you mind publishing the newer 3.0.0 version please?

Thanks!

Cannot post after redirect

How do I handle cannot post after redirecting? It handles the payment well but what after completing the payment
It says cannot post?

Currency Type Declaration

Your union type declaration for Currency has no string and so it cannot be passed as a config parameter in the object declaration to useRavePayment hook.

Amount is not formatted in button

The Amount on the button component is not formatted with comma to show distinctively, the amount that is to be paid.

example N3000 should be N3,000

Not working in production

The latest version (^3.0.0) is not working in production mode, it keeps saying "invalid public key" even after passing isProduction=true. I had to revert back to the previous version

Uncaught TypeError: Cannot set property 'textContent' of null

After a successful payment, I keep seeing this error in the console

scripts.min.js:1 Uncaught TypeError: Cannot set property 'textContent' of null
at scripts.min.js:1

The bad thing is that it keeps console logging the same error as long as the site is open

Screenshot (27)

onClose and onSuccess callbacks not working

None of those callbacks are working.
This is the error for onCLose
VM3500 flwpbf-inline.js:56 Uncaught TypeError: hideIframe is not a function
at closePopup (VM3500 flwpbf-inline.js:56)
at Object.message_handlers.closeiframe (VM3500 flwpbf-inline.js:246)
at VM3500 flwpbf-inline.js:279

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.