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-webview

iOS setup

cd ios && pod install

Quick 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

PropTypeRequiredDescription
publicKeystringYesYour Credo public key (0PUB... for test, 1PUB... for live)
amountnumberYesAmount in lowest unit (kobo/cents)
emailstringYesCustomer email address
visiblebooleanYesControls modal visibility
onSuccess(response) => voidYesCalled when payment completes
onClose() => voidYesCalled when modal closes
callbackUrlstringYesRedirect URL for payment completion detection
currencystringNoNGN, USD, GHS, ZAR (default: NGN)
referencestringNoUnique transaction reference
channelsstring[]No['card', 'bank', 'ussd', 'qr']
metadataobjectNoAdditional 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 (uses api.credodemo.com)
  • Live: Public keys starting with 1PUB (uses api.credocentral.com)

View full API reference

Next steps

Was this page helpful?

Last updated on

On this page