1.0.3 • Published 7 months ago

react-native-payfast-plugin v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

React Native Payfast Plugin

React Native Payfast Plugin is a React Native library for Payfast payment gateway integration. It allows you to integrate the Payfast payment gateway into your React Native app with ease. It provides a simple interface to accept in-app payments, generate payment links, and tokenize & update card details.

npm npm GitHub issues [GitHub stars] [GitHub license] Twitter [GitHub contributors] [GitHub last commit] [GitHub pull requests] [GitHub pull requests] [GitHub forks] [GitHub stars] [GitHub watchers]

This is not a Payfast official library.

Check out my other libraries

Table of contents

Getting started

Installation

npm install react-native-payfast-plugin

Expo?

expo install react-native-payfast-plugin

Supported transactions:

  • Once of payment
  • Recurring payment
  • Tokenization

Features:

  • In-app payment
  • Generate payment link
  • Update card details (for tokenized cards)
  • Split payment (coming soon)
  • Charge tokenized card (coming soon)

Usage

In-app payment

import Payfast from 'react-native-payfast-plugin';

...
        <PayFast
            data={{
                merchantDetails: {
                    merchant_id: "10031584",
                    merchant_key: "5n52c1qu5501c",
                    notify_url: "https://webhook.site/f30e4b32-15b5-44e6-ae0b-c75486b8797d",
                },
                customerDetails: {
                    name_first: "First Name",
                    name_last: "Last Name",
                    email_address: "firstname@gmail.com",
                    cell_number: "0885....",
                },
                transactionDetails: {
                    m_payment_id: "1234",
                    amount: "10.00",
                    item_name: "Item Name",
                    item_description: "Item Description",
                },
                transactionOptions: {
                    email_confirmation: 0,
                    confirmation_address: "firstname@gmail.com",
                },
            }}

            sandbox={true}
            passphrase="thisisatestforthe"

            onCancel={(data) => {
                console.log("Payment cancelled: ", data.transaction_id);
            }}

            onMessage={(message) => {
                console.log(message);
            }}

            onSuccess={({ data, transaction_id }) => {
                console.log(transaction_id);
            }}

            onClose={() => {
                console.log("Payment closed");
            }}
        />
        ...

Generate payment link

import { LinkPayment } from "react-native-payfast-plugin";

const link = new LinkPayment(
  {
    merchantDetails: {
      merchant_id: "10031584",
      merchant_key: "5n52c1qu5501c",
      notify_url: "https://webhook.site/f30e4b32-15b5-44e6-ae0b-c75486b8797d",
    },
    customerDetails: {
      name_first: "First Name",
      name_last: "Last Name",
      email_address: "firstname@gmail.com",
      cell_number: "088...",
    },
    transactionDetails: {
      m_payment_id: "1234",
      amount: "10.00",
      item_name: "Item Name",
      item_description: "Item Description",
    },
    transactionOptions: {
      email_confirmation: 0,
      confirmation_address: "firstname4@gmail.com",
    },
  },
  true,
  "thisisatestforthe"
);

// Optional - change to your own urls defaults to https://payfast.io/
link.cancel_url = "https://www.google.com/search?q=cancel";
link.return_url = "https://www.google.com/search?q=success";

const handleLink = async () => {
  link.getLink().then((link) => {
    setLink(link);
  });
};


// In your render function

...
  <Button title="Generate Link" onPress={handleLink} />
  <Text>{link}</Text>
...

Update card details

import { UpdateCard } from "react-native-payfast-plugin";

...
    <UpdateCard
        token="...e90c2-....-....-9ccb-...."
        onComplete={(data) => console.log(data)}
        sandbox={true}
    />
....

Tokenize card details

// Use the same PayFast component as in-app payment on the data prop add the following

    recurringBilling: {
        subscription_type: "2",
    },

Props

PayFast

PropTypeDescription
dataobjectData object for in-app payment
sandboxbooleanSet to true for sandbox mode
passphrasestringPassphrase for sandbox mode
onCancelfunctionCallback function when payment is cancelled
onMessagefunctionCallback function when payment is in progress
onSuccessfunctionCallback function when payment is successful
onClosefunctionCallback function when payment is closed
onCompletefunctionCallback function when card update is complete
data
PropTypeDescription
merchantDetailsobjectMerchant details. See
customerDetailsobjectCustomer details See
transactionDetailsobjectTransaction details See
transactionOptionsobjectTransaction options See
recurringBillingobjectRecurring billing options See

LinkPayment

Same as PayFast data

UpdateCard

PropTypeDescription
tokenstringToken for card to be updated
sandboxbooleanSet to true for sandbox mode
onCompletefunctionCallback function when card update is complete

License

MIT

Author

Axole Maranjana

Twitter Follow GitHub followers Instagram LinkedIn

Help Wanted!

This project is open for contributions. All contributions must be made via pull requests. Feel free to create issues and pull requests.

Credits

Support

Upcoming features and versions

  • Charge tokenized card v1.1.0
  • Get subscription details v1.2.0
  • Cancel subscription v1.3.0
  • Pause subscription v1.4.0
  • Resume subscription v1.5.0
  • Split payment v1.6.0