Developer Tools
React Native

React Native Library

The BudPay React Native Library lets you accept payments in iOS and Android apps built with React Native. The payment modal runs in a WebView, so customers pay without leaving your app.


Installation

Install @budpay/react-native with npm or yarn:

npm install @budpay/react-native

or

yarn add @budpay/react-native

Install the WebView Dependency

The library depends on react-native-webview. Install it in your project:

yarn add react-native-webview

For iOS:

cd ios && pod install && cd ..

For Expo applications:

expo install react-native-webview

Usage: Open Automatically

Set autoStart to true to open the payment modal as soon as the component mounts:

import React from 'react';
import { BudPay } from '@budpay/react-native';
import { View } from 'react-native';
 
const Pay = () => {
  const handleCancel = (data) => {
    console.log(data, 'data');
  };
  
  const handleComplete = (data) => {
    console.log(data, 'data complete');
  };
  
  return (
    <View style={{ flex: 1 }}>
      <BudPay
        api_key="pk_test_xxxxxxxx" // Your BudPay public key, from Settings > API Credentials in your dashboard
        amount={1000}
        currency="NGN"
        reference={`ORDER_${Date.now()}`} // A unique reference from your system
        email="customer@example.com"
        first_name="Ada"
        last_name="Okafor"
        phone="08012345678"
        onCancel={handleCancel}
        onComplete={handleComplete}
        autoStart={true}
      />
    </View>
  );
}
 
export default Pay;

Usage: Open From a Button

To open the modal on demand, attach a ref to the component and call startTransaction(), for example from your own pay button:

import { useRef } from 'react';
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
import { BudPay } from '@budpay/react-native';
import type { BudPayRef } from '@budpay/react-native';
 
const Pay = () => {
  const handleCancel = (data) => {
    console.log(data, 'data');
  };
  
  const handleComplete = (data) => {
    console.log(data, 'data complete');
  };
  
  const budpayRef = useRef<BudPayRef | null>(null);
 
  return (
    <View style={styles.container}>
      <BudPay
        api_key="pk_test_xxxxxxxx" // Your BudPay public key, from Settings > API Credentials in your dashboard
        amount={1000}
        currency="NGN"
        reference={`ORDER_${Date.now()}`} // A unique reference from your system
        email="customer@example.com"
        first_name="Ada"
        last_name="Okafor"
        phone="08012345678"
        onCancel={handleCancel}
        onComplete={handleComplete}
        ref={budpayRef}
        autoStart={false}
      />
 
      <TouchableOpacity
        style={styles.payBtn}
        onPress={() => budpayRef.current?.startTransaction()}
      >
        <Text style={styles.txt}>Pay with BudPay</Text>
      </TouchableOpacity>
    </View>
  );
}
 
const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  payBtn: {
    padding: 16,
    backgroundColor: '#007AFF',
    borderRadius: 8,
  },
  txt: {
    color: '#fff',
    textAlign: 'center',
    fontSize: 16,
  },
});
 
export default Pay;

Props

PropTypeRequiredDescription
api_keystringYesYour BudPay public key, e.g. "pk_test_1234567890". Find it in your dashboard under Settings > API Credentials.
amountnumberYesAmount to charge, e.g., 1000
currencystringYesCurrency to charge in, e.g., "NGN"
referencestringNoUnique reference for the transaction, e.g., "BUD_1234567890"
emailstringYesCustomer email
first_namestringYesCustomer first name
last_namestringYesCustomer last name
phonestringYesCustomer phone
callback_urlstringNoURL to redirect to after payment, e.g., "https://yourwebsite.com/callback"
onCompletefunctionNoCallback function to execute after payment is successful, e.g., (response) => { console.log(response) }
onCancelfunctionNoCallback function to execute after payment is cancelled, e.g., (response) => { console.log(response) }
activityIndicatorColorstringNoLoader color
activityIndicatorSizestringNoLoader size, e.g., "small", "large"
debugbooleanNoEnables debug mode, e.g., true

The onComplete and onCancel callbacks only tell you the modal has closed. Always verify the transaction on your server with the reference before giving value to the customer.