@valuepay/react
Overview
Official React SDK for ValuePay. Accept payments in your React or Next.js app with minimal setup using the npm package.
This page documents the npm SDK. If you want inline script integration instead, use the React/Next.js (Script) page.
Installation
npm install @valuepay/react
# or
yarn add @valuepay/react
# or
pnpm add @valuepay/reactRequirements
- React >= 16.8.0 (hooks support required)
- React DOM >= 16.8.0
Quick Start
You can integrate the SDK in three ways: drop-in button, hook-based flow, or provider with ref.
Hook Integration
import { useValuePay } from "@valuepay/react";
export default function Checkout() {
const { initialize, isReady, isProcessing } = useValuePay({
publicKey: "KP_your_public_key",
amount: 10000,
customer: { email: "john@example.com", fullName: "John Doe" },
onSuccess: (response) => console.log("Paid!", response),
onCancelled: (response) => console.log("Cancelled", response),
onClose: (response) => console.log("Closed", response),
});
return (
<button onClick={() => initialize()} disabled={!isReady || isProcessing}>
{isProcessing ? "Processing..." : "Pay ₦10,000"}
</button>
);
}Provider with Ref
import { useRef } from "react";
import { ValuePayProvider, ValuePayProviderRef } from "@valuepay/react";
export default function Checkout() {
const payRef = useRef<ValuePayProviderRef>(null);
return (
<>
<ValuePayProvider
ref={payRef}
config={{
publicKey: "KP_your_public_key",
amount: 7500,
customer: { email: "alice@example.com", fullName: "Alice Smith" },
onSuccess: (response) => console.log("Success!", response),
onCancelled: (response) => console.log("Cancelled", response),
}}
/>
<button onClick={() => payRef.current?.initialize()}>Checkout</button>
</>
);
}Redirect Mode
Use redirectUrl to send users to your verification page after checkout.
<ValuePayButton
publicKey="KP_your_public_key"
amount={5000}
customer={{ email: "jane@example.com", fullName: "Jane Doe" }}
redirectUrl="https://yoursite.com/payment/verify"
/>After payment, ValuePay redirects with query params such as ref and status.
API Reference
useValuePay(config: ValuePayConfig)
- initialize(overrides?) => void
- isReady: boolean
- isProcessing: boolean
ValuePayButton
Extends ValuePayConfig and supports optional UI props: text, className, style, containerStyle, containerClassName, disabled, and children.
ValuePayConfig
- publicKey, amount, customer are required
- currency defaults to NGN
- channels defaults to card, transfer, qrcode, ussd
- transactionRef supports custom references (VPS_TX_ is auto-prepended if missing)
- Supports redirectUrl, metaData, customization, and callbacks
ValuePayResponse
Includes ref, transactionRef, status, amount, currency, customer, paymentMethod, validation, and raw payload.
Dynamic Amounts
const { initialize } = useValuePay({
publicKey: "KP_xxx",
amount: 0,
customer: { email: "user@example.com", fullName: "User" },
onSuccess: (res) => console.log(res),
});
initialize({ amount: selectedProduct.price });Payment Channels
- card
- transfer
- qrcode
- ussd
- mobile_money
Checkout Customization
<ValuePayButton
publicKey="KP_xxx"
amount={2000}
customer={{ email: "user@example.com", fullName: "User" }}
customization={{
title: "My Store",
description: "Thanks for shopping with us!",
logoUrl: "https://mystore.com/logo.png",
}}
onSuccess={(res) => console.log(res)}
/>Server Verification
Always verify payments on your server using the ref from the SDK response before fulfilling an order.
const response = await fetch("https://api.valuepayng.com/v1/transactions/verify", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${VALUEPAY_SECRET_KEY}`,
},
body: JSON.stringify({ tx_ref: transactionRef }),
});
const result = await response.json();TypeScript
The package exports first-class types for configuration, responses, channels, status values, hook return type, and component props.
import type {
ValuePayConfig,
ValuePayResponse,
PaymentChannel,
ValuePayStatus,
UseValuePayReturn,
ValuePayButtonProps,
ValuePayProviderProps,
ValuePayProviderRef,
} from "@valuepay/react";Browser and SSR Support
The SDK targets modern browsers and supports SSR frameworks like Next.js (Pages and App Router), Remix, and Gatsby.
DOM access is guarded with runtime checks so it can run safely in server-rendered environments.
Security
- Use only your public key in client-side code.
- Never expose your ValuePay secret key on the frontend.
- Always verify transactions server-side.
- Use HTTPS in production.
- Allow https://www.valuepayng.com in CSP for script-src and frame-src.
Error Handling
<ValuePayButton
publicKey="KP_xxx"
amount={5000}
customer={{ email: "user@example.com", fullName: "User" }}
onError={(error) => {
console.error("Payment SDK error:", error.message);
}}
onSuccess={(res) => console.log(res)}
/>Common causes include script loading failures, CSP blocking, and invalid runtime configuration.
Contributing and Links
GitHub repository: https://github.com/valuepayment/react-sdk
NPM package: https://www.npmjs.com/package/@valuepay/react
# Clone the repository
git clone https://github.com/valuepayment/react-sdk.git
cd react-sdk
# Install dependencies
npm install
# Run tests
npm test
# Lint
npm run lint
# Type check
npm run typecheck
# Build
npm run buildNeed help? Check out the React/Next.js (Script) page or Authentication docs.
ON THIS PAGE
© Copyright 2026