A Unified Payment SDK
# use-africa-pay
use-africa-pay
The Unified Payment SDK for Africa
Integrate Paystack, Flutterwave, Monnify, and Remita with a single, type-safe API.
Created and Maintained by Idorenyin Williams
A unified, type-safe React hook for integrating African payment gateways (Paystack, Flutterwave, Monnify, Remita) into your application.
## Features
- **Unified API**: Switch between providers with a single config change
- **Standardized Responses**: Rich, consistent response objects with customer details, timestamps, and metadata
- **Robust Error Handling**: Custom error types with helpful recovery suggestions
- **Production-Ready Security**: Input sanitization, HTTPS enforcement, error redaction, and timeout protection
- **Lazy Loading**: SDKs loaded only when needed, keeping bundle size small
- **Type-Safe**: Full TypeScript support for configuration and responses
- **4 Major Providers**: Paystack, Flutterwave, Monnify, and Remita
## Installation
```bash
npm install @use-africa-pay/core
# or
pnpm add @use-africa-pay/core
# or
yarn add @use-africa-pay/core
```
## Quick Start
```tsx
import { useAfricaPay, PaystackAdapter } from '@use-africa-pay/core';
const PaymentComponent = () => {
const { initializePayment, loading, error, reset } = useAfricaPay();
const handlePayment = () => {
initializePayment({
provider: 'paystack', // or 'flutterwave', 'monnify', 'remita'
adapter: PaystackAdapter, // Required: Pass the adapter instance
publicKey: 'YOUR_PUBLIC_KEY',
amount: 500000, // Amount in kobo (lowest denomination)
currency: 'NGN',
reference: 'unique_ref_' + Date.now(),
user: {
email: 'customer@example.com',
name: 'John Doe',
phonenumber: '08012345678',
},
metadata: {
custom_field: 'value',
},
onSuccess: (response) => {
console.log('Payment successful:', response);
// Response includes: status, message, reference, transactionId,
// amount, currency, paidAt, customer, provider, metadata, raw
},
onClose: () => {
console.log('Payment closed');
}, …