Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-payfast-checkout

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-payfast-checkout

Integrate Paystack to your React Native mobile app

  • 1.6.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
70
increased by180%
Maintainers
0
Weekly downloads
 
Created
Source

react-native-payfast-checkout

This is a React Native package for integration of Payfast payment gateway into your React Native projects. The package is also compatible with React Native Expo.

screenshot

Features

  • Make once off or repeat payments using a bank card e.g Cheque or Credit Card
  • Save bank card for future use (Tokenization), token sent to your notifyUrl
  • Update saved bank card details
  • Hook/Function to make a payment with saved card / token

Upcoming Features

  • Recurring Billing / Subscriptions

About the package

  • Make a once off payment for any product/service within the app
  • Easy to use package for integrating Payfast payment gateway into your React Native app
  • Written in TypeScript, providing type definitions and improved developer experience
  • Compatible with React Native & React Native Expo

Props

Paystack Props

PropTypeDescriptionRequiredDefault Value
paymentMethodStringSee belowYescc
transactionDetailsObjectSee belowYesN/A
notifyUrlStringWebhook url for outcome notificationNoN/A
sandboxBooleanUsed to set the integration into testing modeYesfalse
signatureBooleanWhether to to use singature or notYesfalse
merchantIdStringPayfast merchant IdYesN/A
merchantKeyStringPayfast merchant keyYesN/A
isVisibleBooleanWhether to show the payment window or notYesN/A
passPhraseStringPhrase to secure the payloadYesN/A
onCloseFunctionFunction to close the payment windowYesN/A

Payment Method

When this field is set, only the SINGLE payment method specified can be used when the customer reaches Payfast. If this field is blank, or not included, then all available payment methods will be shown

Options

OptionDescription
eftEFT
ccCredit card
dcDebit card
mpMasterpass Scan to Pay
mcMobicred
scSCode
ssSnapScan
zpZapper
mtMoreTyme
rcsStore card

Transaction Details

NameTypeDescriptionRequired
customerFirstNameStringCustomer First NameNo
customerLastNameStringCustomer Last NameNo
customerEmailAddressStringCustomer Email addressNo
customerPhoneNumberStringCustomer Phone NumberNo
referenceStringTransaction ReferenceNo
amountFloatTransaction Amount in South African RandsYes
itemNameStringName of item being paid forYes
itemDescriptionStringDescription of the item being paid forNo

How to use the package

Install the latest version of the package Using Yarn

yarn add react-native-payfast-checkout

or Npm

npm install react-native-payfast-checkout

or Expo

npx expo install react-native-payfast-checkout

Use the package in your cart or checkout screen

...
import Payfast from 'react-native-payfast-checkout'
...
const CartScreen = () => {
    ...
    const [showPayfast, setShowPayfast] = useState(false)
    ...
    const transactionDetails = {
        itemName:'iPhone',
        amount: 1500.25
    }
    return <View>
    ...
    <PayFast
        merchantId={process.env.PAYFAST_MERCHANT_ID}
        merchantKey={process.env.PAYFAST_MERCHANT_KEY}
        passPhrase={process.env.PAYFAST_SIGNATURE_PHRASE}
        sandbox
        isVisible={showPayfast}
        onClose={() => setShowPayfast(false)}
        transactionDetails={transactionDetails}
      />
    ...
    </View>
}

export default CartScreen

Adding saving a card for future use

Unfortunately Payfast does not return any details for your saved card, except for the token, therefore you can't show the last 4 digits for the user to remember the card they saved, but the update card screen shows the last 4 digits and the expiry date

...
import {PayFastSaveCard} from 'react-native-payfast-checkout'
...
const PaymentOptionsScreen = () => {

    const [showAddCard, setShowAddCard] = useState(false)
    const [showUpdateCard, setShowUpdateCard] = useState(false)

    const transactionDetails = {
        customerFirstName: 'John',
        customerLastName: 'Doe',
        customerEmailAddress: 'name@email.com',
    }

    return <View>
    ...
    <PayFastSaveCard
        transactionDetails={transactionDetails}
        merchantId={process.env.PAYFAST_MERCHANT_ID}
        merchantKey={process.env.PAYFAST_MERCHANT_KEY}
        passPhrase={process.env.PAYFAST_SIGNATURE_PHRASE}
        notifyUrl=''
        isVisible={showAddCard}
        onClose={(isDone) => {
            // Do things here then
            setShowAddCard(false)
        }}
    />
    ...
    <PayFastUpdateCard
        cardToken=''
        isVisible={showUpdateCard}
        sandbox
        onClose={() => {
            // Do things here
            setShowUpdateCard(false)
        }}
    />
    ...
    </View>
}

export default PaymentOptionsScreen

Using a token in a transaction

...
import { usePayFast } from 'react-native-payfast-checkout'
...

const CheckoutScreen = () => {
    ...
    const { chargeCardToken } = usePayFast({
        merchantId:{process.env.PAYFAST_MERCHANT_ID}
        passPhrase:{process.env.PAYFAST_SIGNATURE_PHRASE}
    })
    ...
    const onCheckout = async( ) => {
        try {
            const { message, pf_payment_id } = await chargeCardToken({
                token:'',
                total:10000 // in cents e.g 10000 = R100,
                reference:'',
                itemName:''
            })
        } catch(error){
            console.log({error})
        }
    }
    ...
    return <View>
    ...
        <Button text='Checkout' onPress={() => onCheckout() } />
    ...
    </View>
}

export default CheckoutScreen

Official Documentation

For more details you can visit the official Payfast documentation page Payfast

Keywords

FAQs

Package last updated on 17 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc