npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@micropaysdk/react-native

v0.2.0

Published

Micropay SDK for React Native - Accept M-Pesa payments in your mobile app

Downloads

24

Readme

@micropaysdk/react-native

Official Micropay SDK for React Native. Accept M-Pesa payments in your mobile app with a beautiful, native UI.

Installation

npm install @micropaysdk/react-native

or

yarn add @micropaysdk/react-native

Quick Start

1. Wrap your app with MicropayProvider

import { MicropayProvider } from '@micropaysdk/react-native';

export default function App() {
  return (
    <MicropayProvider publicKey="pk_test_...">
      <YourApp />
    </MicropayProvider>
  );
}

2. Use the PaymentSheet component

import { useState } from 'react';
import { PaymentSheet, MicropayButton } from '@micropaysdk/react-native';

function CheckoutScreen() {
  const [showPayment, setShowPayment] = useState(false);

  return (
    <>
      <MicropayButton
        amount={500}
        onPress={() => setShowPayment(true)}
      />

      <PaymentSheet
        visible={showPayment}
        onClose={() => setShowPayment(false)}
        amount={500}
        description="Premium Upgrade"
        onSuccess={(intent) => {
          console.log('Payment successful!', intent);
        }}
        onError={(error) => {
          console.error('Payment failed:', error);
        }}
      />
    </>
  );
}

3. Or use the usePayment hook for custom UI

import { usePayment } from '@micropaysdk/react-native';

function CustomPaymentButton({ amount }) {
  const { initiatePayment, status, error } = usePayment();

  const handlePay = async () => {
    try {
      const result = await initiatePayment({
        amount,
        phoneNumber: '254712345678',
        description: 'Game Credits'
      });
      console.log('Success:', result);
    } catch (err) {
      console.error('Failed:', err);
    }
  };

  return (
    <TouchableOpacity onPress={handlePay} disabled={status === 'loading'}>
      <Text>{status === 'loading' ? 'Processing...' : `Pay KES ${amount}`}</Text>
    </TouchableOpacity>
  );
}

Components

MicropayProvider

Wraps your app to provide Micropay functionality.

| Prop | Type | Required | Description | |------|------|----------|-------------| | publicKey | string | Yes | Your Micropay publishable key | | environment | 'sandbox' | 'production' | No | Defaults to 'sandbox' |

PaymentSheet

Pre-built bottom sheet modal for payments.

| Prop | Type | Required | Description | |------|------|----------|-------------| | visible | boolean | Yes | Controls visibility | | onClose | function | Yes | Called when sheet is dismissed | | amount | number | Yes | Payment amount | | currency | string | No | Currency code (default: 'KES') | | description | string | No | Payment description | | onSuccess | function | No | Called with payment intent on success | | onError | function | No | Called with error message on failure | | theme | 'dark' | 'light' | No | UI theme (default: 'dark') |

MicropayButton

Styled payment button.

| Prop | Type | Required | Description | |------|------|----------|-------------| | onPress | function | Yes | Button press handler | | amount | number | No | Amount to display | | label | string | No | Custom button label | | variant | 'primary' | 'outline' | 'ghost' | No | Button style | | size | 'small' | 'medium' | 'large' | No | Button size |

MpesaPhoneInput

Phone number input with country selector.

| Prop | Type | Required | Description | |------|------|----------|-------------| | value | string | Yes | Phone number value | | onChangeText | function | Yes | Text change handler | | defaultCountry | string | No | Country code (default: 'KE') |

Hooks

usePayment()

Returns payment state and methods.

const {
  status,          // 'idle' | 'loading' | 'processing' | 'succeeded' | 'failed'
  error,           // Error message if failed
  paymentIntent,   // Current payment intent object
  isLoading,       // Convenience boolean
  isProcessing,    // Convenience boolean
  isSucceeded,     // Convenience boolean
  isFailed,        // Convenience boolean
  initiatePayment, // Start a new payment
  confirmPayment,  // Confirm an existing intent
  reset            // Reset state for new payment
} = usePayment();

useMicropay()

Access the Micropay client directly.

const { client, publicKey, environment } = useMicropay();

Production Checklist

  • Replace test keys with production keys
  • Handle payment webhooks on your server
  • Test with real M-Pesa sandbox numbers
  • Implement proper error handling
  • Add analytics/logging for payment events

License

MIT