React Native SDK
Accept payments in your React Native app with the Credo React Native SDK.
The official React Native SDK for integrating Credo payments into your mobile app.
Installation
npm install react-native-credo-payment react-native-webview
# or
yarn add react-native-credo-payment react-native-webviewiOS setup
cd ios && pod installQuick start
import React, { useState } from 'react';
import { View, Button, Alert } from 'react-native';
import { CredoPayment } from 'react-native-credo-payment';
const PaymentScreen = () => {
const [visible, setVisible] = useState(false);
return (
<View style={{ flex: 1, justifyContent: 'center', padding: 20 }}>
<Button title="Pay Now" onPress={() => setVisible(true)} />
<CredoPayment
publicKey="0PUBxxxxxxxxxxxxxxxxxxxxxxxx"
amount={500000} // NGN 5,000 in kobo
email="customer@example.com"
currency="NGN"
callbackUrl="https://your-website.com/payment/callback"
visible={visible}
onSuccess={(response) => {
console.log('Success:', response.transRef);
setVisible(false);
// Verify transaction on your backend
}}
onClose={() => setVisible(false)}
/>
</View>
);
};Using the hook
import { useCredoPayment } from 'react-native-credo-payment';
const PaymentScreen = () => {
const { visible, openPaymentModal, handleSuccess, handleClose } = useCredoPayment({
onSuccess: (response) => {
console.log('Paid:', response.transRef);
},
});
return (
<>
<Button title="Pay Now" onPress={openPaymentModal} />
<CredoPayment
publicKey="0PUBxxxxxxxxxxxxxxxxxxxxxxxx"
amount={500000}
email="customer@example.com"
callbackUrl="https://your-website.com/payment/callback"
visible={visible}
onSuccess={handleSuccess}
onClose={handleClose}
/>
</>
);
};Props
| Prop | Type | Required | Description |
|---|---|---|---|
publicKey | string | Yes | Your Credo public key (0PUB... for test, 1PUB... for live) |
amount | number | Yes | Amount in lowest unit (kobo/cents) |
email | string | Yes | Customer email address |
visible | boolean | Yes | Controls modal visibility |
onSuccess | (response) => void | Yes | Called when payment completes |
onClose | () => void | Yes | Called when modal closes |
callbackUrl | string | Yes | Redirect URL for payment completion detection |
currency | string | No | NGN, USD, GHS, ZAR (default: NGN) |
reference | string | No | Unique transaction reference |
channels | string[] | No | ['card', 'bank', 'ussd', 'qr'] |
metadata | object | No | Additional transaction data |
Response object
{
transRef: string; // Transaction reference for verification
status: string; // 'pending' - verify on your server
amount: number;
currency: string;
}Important
Always verify the transaction status on your backend using transRef before granting access to goods or services.
Verify transaction
const handleSuccess = async (response) => {
const { transRef } = response;
// Call your backend to verify
const result = await fetch(`https://your-api.com/verify/${transRef}`);
const data = await result.json();
if (data.status === 'successful') {
// Grant access
}
};Backend verification (Node.js example):
const verify = await fetch(
`https://api.credocentral.com/transaction/${transRef}/verify`,
{ headers: { 'Authorization': 'YOUR_SECRET_KEY' } }
);Environments
- Test: Public keys starting with
0PUB(usesapi.credodemo.com) - Live: Public keys starting with
1PUB(usesapi.credocentral.com)
View full API reference
Next steps
Was this page helpful?
Last updated on
