All posts

Integrate Paystack in Node.js + Deploy to OneBit in Under 10 Minutes

For Nigerian developers, two realities collide very quickly:

  • You need a reliable local payment gateway like Paystack for naira payments.
  • You want app hosting that doesn't require a foreign card or bill you in dollars.

This guide shows you how to integrate Paystack into a simple Node.js app, configure your Paystack keys as environment variables on OneBit Deploy, and test end-to-end payments in Paystack test mode — all without leaving naira.


1. Prerequisites

Before you start, make sure you have:

  • A Node.js app (Express, Fastify, or plain HTTP) in a GitHub repository.
  • A free OneBit Deploy account at deploy.onebit.ng.
  • A Paystack account with test keys from the Paystack dashboard.

OneBit Deploy is built for Nigerian teams. Billing runs through Paystack in Nigerian naira, so there is no dollar card requirement and no FX markup when you later upgrade from the free plan.

If you have not deployed your Node.js app before, follow the Node.js deploy guide first, then come back to add Paystack.


2. Install a Paystack SDK (or use HTTPS directly)

You can talk to Paystack either via a small Node.js SDK or by making direct HTTPS requests. We'll show the SDK route first.

Option A — Using a Paystack Node.js SDK

Install a lightweight Paystack SDK into your project:

npm install paystack-api
# or
# yarn add paystack-api

Create a helper module to initialise Paystack using your secret key from the environment:

// lib/paystack.js
import Paystack from 'paystack-api';

const paystack = Paystack(process.env.PAYSTACK_SECRET_KEY);

export default paystack;

In test mode, Paystack secret keys usually start with sk_test_.... You will add this value as an environment variable on OneBit later.

Option B — Using direct HTTPS calls

If you prefer not to install an SDK, you can use node-fetch, axios, or the built-in https module to call Paystack's REST API directly. For example, using node-fetch:

npm install node-fetch
// lib/paystack.js
import fetch from 'node-fetch';

const PAYSTACK_SECRET_KEY = process.env.PAYSTACK_SECRET_KEY;

if (!PAYSTACK_SECRET_KEY) {
  throw new Error('PAYSTACK_SECRET_KEY is not set');
}

export async function initializeTransaction({ email, amountInNaira }) {
  const response = await fetch('https://api.paystack.co/transaction/initialize', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${PAYSTACK_SECRET_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      email,
      amount: amountInNaira * 100, // kobo
      currency: 'NGN',
    }),
  });

  if (!response.ok) {
    const errorBody = await response.text();
    throw new Error(`Paystack initialize failed: ${errorBody}`);
  }

  return response.json();
}

export async function verifyTransaction(reference) {
  const response = await fetch(`https://api.paystack.co/transaction/verify/${reference}`, {
    headers: {
      Authorization: `Bearer ${PAYSTACK_SECRET_KEY}`,
    },
  });

  if (!response.ok) {
    const errorBody = await response.text();
    throw new Error(`Paystack verify failed: ${errorBody}`);
  }

  return response.json();
}

3. Configure PAYSTACK keys as environment variables on OneBit

Never hard-code your Paystack keys in your repository. Instead, store them as environment variables, just like DATABASE_URL for a managed PostgreSQL instance.

3.1 Local development

Create a .env file locally (do not commit it) and load it with a library like dotenv:

npm install dotenv
// index.js
import 'dotenv/config';
// ...rest of your app

.env example for test mode:

PAYSTACK_PUBLIC_KEY=pk_test_xxx
PAYSTACK_SECRET_KEY=sk_test_xxx
DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/DATABASE # if using managed Postgres

3.2 Environment variables on OneBit Deploy

On OneBit, you set the same variables in the console:

  1. Log in at deploy.onebit.ng and open your app on Apps.
  2. Go to the Environment tab.
  3. Under Add variable, add these keys (every value is hidden once saved):
    • PAYSTACK_PUBLIC_KEY
    • PAYSTACK_SECRET_KEY
    • DATABASE_URL — if your app uses a managed PostgreSQL database from OneBit Deploy.
  4. Press Add for each — saving restarts the app so it picks up the new values.

Managed PostgreSQL, MySQL, MariaDB and MongoDB are available on OneBit Deploy paid plans. The platform is actively hardening reliability and backups; if your data is critical, continue to take your own exports as well.

At runtime, your Node.js code reads these from process.env.PAYSTACK_PUBLIC_KEY and process.env.PAYSTACK_SECRET_KEY.


4. Implement a basic charge + payment verification endpoint

A common pattern with Paystack is:

  1. Initialise a transaction from your backend.
  2. Redirect the user to Paystack's hosted checkout page.
  3. Verify the payment from your backend using the provided reference.

Below is a minimal Express example using the helper functions from Option B above.

npm install express node-fetch
// index.js
import 'dotenv/config';
import express from 'express';
import { initializeTransaction, verifyTransaction } from './lib/paystack.js';

const app = express();
app.use(express.json());

app.post('/api/paystack/initialize', async (req, res) => {
  const { email, amountInNaira } = req.body;

  try {
    const data = await initializeTransaction({ email, amountInNaira });
    // Return the authorization URL for the frontend to redirect the user
    res.json({ authorizationUrl: data.data.authorization_url, reference: data.data.reference });
  } catch (err) {
    console.error(err);
    res.status(500).json({ error: 'Failed to initialize Paystack transaction' });
  }
});

app.get('/api/paystack/verify', async (req, res) => {
  const { reference } = req.query;

  try {
    const data = await verifyTransaction(reference);

    if (data.data.status === 'success') {
      // TODO: mark order/subscription as paid in your database
      return res.json({ status: 'success', data: data.data });
    }

    res.status(400).json({ status: 'failed', data: data.data });
  } catch (err) {
    console.error(err);
    res.status(500).json({ error: 'Failed to verify Paystack transaction' });
  }
});

app.get('/', (req, res) => {
  res.send('Paystack + OneBit demo is running');
});

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server listening on port ${port}`);
});

This is intentionally simple, but it gives you the two core endpoints you need for Paystack: initialise and verify.


5. Deploy the app to OneBit

Once Paystack is wired into your Node.js app and your keys are set as environment variables, you can deploy.

If you are deploying this app for the first time, follow the full deploy Node.js in Nigeria guide. It covers:

  • Connecting your GitHub repository.
  • Adding it with Add app (the console recognises your Node.js backend by itself).
  • Default build and start commands.
  • Picking a plan (including the free tier) and watching logs until your app is live.

If your app is already deployed, any push to your connected branch (for example, main) will trigger a new build and roll out your Paystack changes automatically.


6. Test end-to-end payments in Paystack test mode

Before switching to live keys, thoroughly test the flow in Paystack test mode.

  1. In the Paystack dashboard, keep your account in test mode and copy the pk_test_... and sk_test_... keys.

  2. Paste them into PAYSTACK_PUBLIC_KEY and PAYSTACK_SECRET_KEY on your OneBit app's Environment tab (and your local .env).

  3. From your frontend or an API client like Postman, call POST /api/paystack/initialize with a test email and amount:

    {
      "email": "[email protected]",
      "amountInNaira": 2000
    }
  4. Redirect the user to the returned authorizationUrl and complete payment using one of Paystack's test cards.

  5. After the hosted checkout redirects back to your app, call GET /api/paystack/verify?reference=... from your frontend or server.

  6. Confirm that your backend marks the payment as successful and (optionally) writes to your database via DATABASE_URL.

Once everything looks good, switch your Paystack dashboard to live mode, update the keys on your OneBit app's Environment tab with your live keys; saving restarts the app with them.


Why OneBit is the natural host for Paystack-backed apps in Nigeria

Most global hosting platforms expect a dollar card and bill you in foreign currency, even when all your revenue is in naira. With OneBit Deploy:

  • Billing is in Nigerian naira via Paystack — the same gateway you're using inside your app.
  • Node.js and Next.js are first-class citizens — auto-detected builds, sensible defaults, and Git-driven deploys.
  • Managed databases are available — including PostgreSQL, MySQL, MariaDB and MongoDB, with reliability and backup features being actively hardened.

The result is a full-stack workflow that stays in naira end to end: your customers pay you in NGN via Paystack, and you pay your hosting bill in NGN via Paystack on OneBit Deploy.


Last updated: August 2026. Always refer to the official Paystack docs for the latest API details and test card numbers.


Ready to ship? Follow the quickstart or read another post.