Want to accept payments online? Whether you're building an e-commerce store, a SaaS platform, or a donation page, integrating a payment gateway like Paystack or Stripe is essential. In this guide, we’ll walk you through the step-by-step process of integrating these gateways into your web app so you can securely process payments.
- Choosing the Right Payment Gateway
Before integrating, consider:
Paystack – Best for businesses in Africa (Nigeria, Ghana, South Africa, etc.)
Stripe – Ideal for global businesses with a wider range of features
Both support card payments, bank transfers, USSD, and mobile money.
- Setting Up a Paystack Integration
Step 1: Create a Paystack Account
Sign up at Paystack
Get your Public and Secret API Keys from the dashboard
Step 2: Install Paystack in Your React/Next.js App
npm install react-paystack
Step 3: Create a Payment Component
import React from "react";
import { PaystackButton } from "react-paystack";
const PayButton = ({ email, amount }: { email: string; amount: number }) => {
const publicKey = "your-paystack-public-key"; // Replace with your key
const onSuccess = (reference: any) => alert("Payment Successful!");
const onClose = () => alert("Payment Canceled!");
const paystackProps = {
email,
amount: amount * 100, // Convert Naira to Kobo
publicKey,
text: "Pay Now",
onSuccess,
onClose,
};
return <PaystackButton {...paystackProps} />;
};
export default PayButton;
Step 4: Add to Checkout Page
import PayButton from "../components/PayButton";
const Checkout = () => {
return (
<div>
<h1>Checkout</h1>
<PayButton email="customer@example.com" amount={5000} />
</div>
);
};
export default Checkout;
✅ Done! Now you can accept payments with Paystack.
- Setting Up a Stripe Integration
Step 1: Create a Stripe Account
Sign up at Stripe
Get your Publishable and Secret Keys
Step 2: Install Stripe SDK
npm install @stripe/react-stripe-js @stripe/stripe-js
Step 3: Set Up Stripe Context
import { Elements } from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";
import CheckoutForm from "../components/CheckoutForm";
const stripePromise = loadStripe("your-stripe-public-key");
const Checkout = () => (
<Elements stripe={stripePromise}>
<CheckoutForm />
</Elements>
);
export default Checkout;
Step 4: Create Checkout Form
import { CardElement, useStripe, useElements } from "@stripe/react-stripe-js";
const CheckoutForm = () => {
const stripe = useStripe();
const elements = useElements();
const handleSubmit = async (event: any) => {
event.preventDefault();
if (!stripe || !elements) return;
const { error, paymentIntent } = await stripe.confirmCardPayment(
"your-client-secret",
{
payment_method: {
card: elements.getElement(CardElement)!,
},
}
);
if (error) alert(error.message);
else alert("Payment successful!");
};
return (
<form onSubmit={handleSubmit}>
<CardElement />
<button type="submit" disabled={!stripe}>Pay</button>
</form>
);
};
export default CheckoutForm;
✅ Done! Your Stripe integration is live.
- Comparing Paystack vs Stripe
Conclusion
Both Paystack and Stripe offer powerful tools to accept payments online. If you’re targeting African markets, Paystack is your best choice. For global payments, go with Stripe.
Top comments (0)