4.6.7 • Published 5 months ago

react-native-paystack-webview v4.6.7

Weekly downloads
39
License
MIT
Repository
-
Last release
5 months ago

This package lets you accept payments with Paystack in a snap! Just install, add your keys, and you’re good to go—no headaches here! Plus, it’s officially endorsed by Paystack, so you know you’re in good hands. Payment processing has never been this easy!

Installation

Add react-native-paystack-webview to your project by running;

npm install react-native-paystack-webview

or

yarn add react-native-paystack-webview

Additional Setup

To ensure everything works smoothly, install and configure the required dependency, react-native-webview:

yarn add react-native-webview

for iOS:

cd iOS && pod install && cd ..

for expo applications run;

npx expo install react-native-webview

That’s it! You’re all set.

Usage

Basic Example
import React from 'react';
import  { Paystack }  from 'react-native-paystack-webview';
import { View } from 'react-native';

function Pay() {
  return (
    <View style={{ flex: 1 }}>
      <Paystack  
        paystackKey="your-public-key-here"
        amount={'25000.00'}
        billingEmail="paystackwebview@something.com"
        activityIndicatorColor="green"
        onCancel={(e) => {
          // handle response here
        }}
        onSuccess={(res) => {
          // handle response here
        }}
        autoStart={true}
      />
    </View>
  );
}
Using Refs

You can also use a ref to start a transaction. Here’s how:

import React, { useRef } from 'react';
import  { Paystack , paystackProps}  from 'react-native-paystack-webview';
import { View, TouchableOpacity,Text } from 'react-native';

function Pay(){
  const paystackWebViewRef = useRef<paystackProps.PayStackRef>(); 

  return (
    <View style={{flex: 1}}>
      <Paystack
        paystackKey="your-public-key-here"
        billingEmail="paystackwebview@something.com"
        amount={'25000.00'}
        onCancel={(e) => {
          // handle response here
        }}
        onSuccess={(res) => {
          // handle response here
        }}
        ref={paystackWebViewRef}
      />

        <TouchableOpacity onPress={()=> paystackWebViewRef.current.startTransaction()}>
          <Text>Pay Now</Text>
        </TouchableOpacity>
      </View>
  );
}

API Reference

Nameuse/descriptionextra
paystackKeyPublic or Private paystack key(visit paystack.com to get yours)nill
amountAmount to be paidnill
activityIndicatorColorcolor of loaderdefault: green
billingEmail(required by paystack)Billers emaildefault: nill
billingMobileBillers mobiledefault: nill
billingNameBillers Namedefault: nill
planSpecify plan code generated from the Paystack Dashboard or API to create a subscription to a predefined plan by the transaction. The plan code is a unique code given to every plan, it is used to identify a particular plan. Here's an example of usage: plan: "PLANCODE". The PLANCODE comes in the format PLN_xxxxxxxxxx NOTE: This would invalidate/override the value provided in amountdefault: nill
invoice_limitSpecify the number of times to charge customer during subscription to plan (integer). Works together with the plan propdefault: nill
subaccountSpecify subaccount code generated from the Paystack Dashboard or API to enable Split Payment on the transaction. Here's an example of usage: subaccount: "SUB_ACCOUNTCODE"default: nill
split_codeSpecify split_code generated from the Paystack Dashboard under Transaction Splits menu or API to enable Multi-Split Payment on the transaction. According to Paystack's documentation available here, Multi-split enables merchants to split the settlement for a transaction across their payout account, and one or more subaccounts. Here's an example of usage: split_code: "SPL_xxxxxxx"default: nill
splitSpecify split object to enable Dynamic Multi-Split Payment on the transaction. According to Paystack's documentation available here, Sometimes, you can't determine a split configuration until later in the purchase flow. With dynamic splits, you can create splits on the fly. The Structure is defined in the Dynamic Multi-Split Structure belowdefault: nill
channelsSpecify payment options available to users. Available channel options are: "card", "bank", "ussd", "qr", "mobile_money", "bank_transfer", "eft", "apple_pay". Here's an example of usage: channels={["card","ussd"]}default: ["card"]
onCancelcallback function if user cancels or payment transaction could not be verified. In a case of not being verified, transactionRef number is also returned in the callbackdefault: nill
onSuccesscallback function if transaction was successful and verified (it will also return the transactionRef number in the callback )default: nill
autoStartAuto start payment once page is openeddefault: false
refNumberReference number, if you have already generated onedefault: ''+Math.floor((Math.random() * 1000000000) + 1)
handleWebViewMessageWill be called when a WebView receives a messagedefault: true
modalPropsCan be used to extend the root modal props for example to handle closing like so modalProps={{ onRequestClose: () => paystackWebViewRef.current.endTransaction() }}default: nill

Meta Props

NameDescriptionRequired?Default Value
cart_idA unique identifier for the cart. Can be either a string or a number.NOundefined
custom_fieldsAn array of custom fields for adding additional metadata to the transaction. If not passed, a default custom field is created using the firstName, lastName, and billingName.NO[{ display_name: '${firstName + ' ' + lastName}', variable_name: '${billingName}', value: '' }]
cancel_actionA string specifying the action to take if a transaction is canceled.NOundefined
custom_filtersCustom filters to restrict or specify transaction options, such as:NOundefined
- recurring: A boolean to indicate if the transaction is recurring.
- banks: An array of bank codes for supported banks.
- card_brands: Supported card brands, e.g., 'verve', 'visa', 'mastercard'.
- supported_mobile_money_providers: Supported mobile money providers, e.g., 'mtn', 'atl', 'vod'.

Refs

Nameuse/descriptionextra
startTransactionFunction triggered to start a transaction . Example usage: paystackWebViewRef.current.startTransaction()default: nill
endTransactionFunction triggered to ends a transaction . Example usage: paystackWebViewRef.current.endTransaction()default: nill

Dynamic Multi-Split Payment Object structure

Nameuse/descriptionrequired?
typeDynamic Multi-Split type. Value can be flat or percentageYES
bearer_typeDefines who bears the charges. Value can be all, all-proportional, account or subaccountYES
subaccountsAn array of subaccount object as defined below. e.g. {"subaccount": 'ACCT_xxxxxx', "share": 60}YES
bearer_subaccountSubaccount code of the bearerof the transaction. It should be specified if bearer_type is subaccountNO
referenceUnique reference of the split. Can be defined by the userNO

Dynamic Multi-Split Payment Sub-Account Object structure

Nameuse/descriptionrequired?
subaccountSpecify subaccount code generated from the Paystack Dashboard or API to enable Split Payment on the transaction. Here's an example of usage: subaccount: "SUB_ACCOUNTCODE"YES
shareDefines the amount in percentage (integer) or value (decimal allowed) depending on the type of multi-split definedYES

Contributions

Want to help improve this package? Read how to contribute and feel free to submit your PR!

Licensing

This project is licensed under the MIT License.

Related Projects

Video Tutorial

Sponsorship

Thanks to Our Superheroes ✨

A huge shoutout to our amazing contributors! Your efforts make this project better every day. Check out the (emoji key) for what each contribution means:

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

4.6.7

5 months ago

4.6.6

5 months ago

4.6.3

5 months ago

4.6.2

5 months ago

4.6.5

5 months ago

4.6.4

5 months ago

4.5.0

5 months ago

4.4.0

5 months ago

4.3.1

8 months ago

4.6.1

5 months ago

4.6.0

5 months ago

4.3.0

8 months ago

4.1.2

8 months ago

4.2.0

8 months ago

4.0.5

9 months ago

4.0.6

9 months ago

4.1.0

8 months ago

4.1.1

8 months ago

4.1.4

1 year ago

4.0.4

1 year ago

4.0.1

4 years ago

4.0.0

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.0.8

5 years ago

3.1.9

5 years ago

3.0.9

5 years ago

3.0.7

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.3

5 years ago

1.0.1

5 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago