React Native Moolre
Accept Moolre payments in a React Native app with a secure, customisable checkout button.
- Secure WebView checkout
- iOS and Android
- Custom callbacks
- Customisable button
- Native device testing
- Production-ready flow
How the SDK works
MoolrePayButton opens the Moolre checkout inside your app’s WebView. Its callback gives your app a payment reference; use that reference to update the screen, then verify the payment from your server before delivering goods, crediting a wallet, or marking an order as paid.
Configure
Pass the amount and merchant details to the button.
Collect payment
The customer completes checkout in the in-app WebView.
Verify on your server
Confirm the returned reference with the Moolre API before fulfilment.
Version, platform, and testing support
| Environment | Support | Notes |
|---|---|---|
| SDK release | v1.0.0 | Install react-native-moolre with react-native-webview. |
| React Native on iOS and Android | Supported | Test checkout in a native app build or on a physical device. |
| Expo Go on iOS and Android | Native-device testing | Use it only for native device testing; do not use Expo web as a checkout test environment. |
| Expo web | Not supported | The SDK uses a native WebView. For browser checkout, use the JavaScript Inline SDK instead. |
Installation
Install the package via yarn or npm. This plugin requires react-native-webview as a peer dependency.
yarn add react-native-moolre react-native-webview# ornpm install react-native-moolre react-native-webviewExpo Go is for native iOS and Android testing. Do not use npx expo start --web to test this SDK; Expo web is not supported. Use a native device or app build for checkout testing.
Quick Start
Import the button and drop it into your component.
import { MoolrePayButton } from 'react-native-moolre';// Inside your component<MoolrePayButton amount={50} publicKey="your_public_key" accountNumber="your_account_number" email="user@example.com" onSuccess={(reference) => { console.log("Payment successful. Ref:", reference); }} onError={({ code, message }) => { console.error(`Payment error [${code}]: ${message}`); }} buttonStyle={{ padding: 12, borderRadius: 8 }} textStyle={{ fontSize: 16 }}/>Example Checkout UI
A complete example of a checkout screen with a product list and the Moolre Pay button.
import React from 'react';import { View, Text, FlatList, SafeAreaView, StyleSheet, Alert,} from 'react-native';import { MoolrePayButton } from 'react-native-moolre';const products = [ { id: '1', name: 'Premium Sneakers', price: 120 }, { id: '2', name: 'T-Shirt', price: 40 }, { id: '3', name: 'Cap', price: 25 },];export default function App() { const total = products.reduce((sum, item) => sum + item.price, 0); return ( <SafeAreaView style={styles.container}> <Text style={styles.heading}>Checkout</Text> <FlatList data={products} keyExtractor={(item) => item.id} renderItem={({ item }) => ( <View style={styles.product}> <Text style={styles.name}>{item.name}</Text> <Text style={styles.price}>GHS {item.price.toFixed(2)}</Text> </View> )} contentContainerStyle={{ paddingBottom: 20 }} /> <Text style={styles.total}>Total: GHS {total.toFixed(2)}</Text> <MoolrePayButton amount={total} publicKey="your_public_key" accountNumber="your_account_number" email="user@example.com" onSuccess={(ref) => Alert.alert('Success', `Payment ref: ${ref}`)} onError={({ code, message }) => Alert.alert(`Error [${code}]`, message) } buttonStyle={styles.button} textStyle={styles.buttonText} /> </SafeAreaView> );}const styles = StyleSheet.create({ container: { flex: 1, padding: 20, justifyContent: 'center' }, heading: { fontSize: 28, fontWeight: 'bold', marginBottom: 20 }, product: { flexDirection: 'row', justifyContent: 'space-between', marginBottom: 10, }, name: { fontSize: 18 }, price: { fontSize: 18, fontWeight: '600' }, total: { fontSize: 20, fontWeight: 'bold', marginTop: 20, marginBottom: 10, }, button: { backgroundColor: '#fff', padding: 15, borderRadius: 10, borderColor: '#FF9900', borderWidth: 1.5, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', }, buttonText: { color: '#111', fontWeight: 'bold', fontSize: 16, },});Props Reference
| Prop | Type | Required | Description |
|---|---|---|---|
| amount | number | Yes | Payment amount in Ghana cedis |
| publicKey | string | Yes | Your Moolre public API key |
| accountNumber | string | Yes | Your Moolre merchant account number |
| currency | string | No | Defaults to "GHS" |
| string | No | Customer email address | |
| callbackUrl | string | No | Optional custom payment redirect callback URL |
| onSuccess | (ref: string) => void | Yes | Triggered on successful payment |
| onError | ({ code, message }) => void | Yes | Triggered on failure or cancellation |
| buttonStyle | ViewStyle | No | Custom styles for the button |
| textStyle | TextStyle | No | Custom styles for the button text |
