McTaba Labs logo
Software EngineeringThe WhiteboardProjectsEventsMasterclassesWebinarsLearn
Book Call

500+ developers already in the community

Get answers, find accountability partners, and stay ahead

Join Discord →
McTaba Labs logo

Educating 1 million students in tech by 2030.

Programs

  • HighSchool Graduates Launchpad
  • AI & Business Automation
  • Corporate Training
  • McTaba Story & Mission
  • Full-Stack Curriculum
  • Course Pricing & Plans
  • Frequently Asked Questions

Resources

  • Join Discord Community
  • Tech Events in Nairobi
  • Masterclasses
  • Free Resources
  • Learn
  • Campus
  • Africa Tech Talent Report
  • Partner With Us
  • Start a Project
  • Our Work

Contact Us

  • 124 Manyani East Road, Lavington, Nairobi
  • +254727795603
  • Book a Discovery Call

Office Hours:

Mon-Fri: 9am - 2pm EAT

Sat: 10am - 12pm EAT

© 2027 McTaba Labs - A product of Edtech Industries. All rights reserved.

Privacy PolicyTerms of ServiceRefund Policy
  1. Learn
  2. Paystack for African Developers
  3. Staging Environments and Separate Paystack Accounts
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Staging Environments and Separate Paystack Accounts

Use Paystack test mode for staging — your test API keys (sk_test_...) are free, unlimited, and fully isolated from live transactions. Configure your staging deployment with test API keys in environment variables. Register a separate webhook URL pointing at your staging server in the Paystack dashboard. Keep staging and production subaccounts, plans, and split codes completely separate — they are not shared between test and live modes.

In this article

  1. 1. Environment Configuration for Staging
  2. 2. Staging Webhook Configuration
  3. 3. Learn More

Environment Configuration for Staging

# .env.staging — never commit this
PAYSTACK_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PAYSTACK_PUBLIC_KEY=pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
NODE_ENV=staging
DATABASE_URL=postgresql://user:pass@staging-db:5432/myapp_staging

# .env.production — never commit this
PAYSTACK_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PAYSTACK_PUBLIC_KEY=pk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
NODE_ENV=production
DATABASE_URL=postgresql://user:pass@prod-db:5432/myapp

In your code, validate the environment at startup:

// startup validation
var secretKey = process.env.PAYSTACK_SECRET_KEY;
if (!secretKey) throw new Error('PAYSTACK_SECRET_KEY is not set');
if (process.env.NODE_ENV === 'production' && !secretKey.startsWith('sk_live_')) {
  throw new Error('Production environment is using a test key — deployment blocked');
}
if (process.env.NODE_ENV === 'staging' && secretKey.startsWith('sk_live_')) {
  throw new Error('Staging environment is using a live key — configuration error');
}

Staging Webhook Configuration

In the Paystack dashboard:

  1. Go to Settings → API Keys & Webhooks
  2. In Test mode, set Test Webhook URL to your staging webhook endpoint: https://staging.yourapp.com/webhook/paystack
  3. In Live mode, set Live Webhook URL to your production webhook: https://yourapp.com/webhook/paystack

Use the same webhook handler code for both — the validation logic (HMAC check) and event processing are identical. The only difference is which secret key is used for the HMAC check (test key in staging, live key in production).

For local development where your staging URL is not publicly accessible, use ngrok:

ngrok http 3000
# Set the ngrok URL as temporary Test Webhook URL in Paystack dashboard
# Update it each time ngrok restarts (random URL)

Get weekly developer tips

Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.

No spam. Unsubscribe anytime.

Learn More

This guide is part of the Paystack testing guide.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Paystack test mode is your staging environment — no separate Paystack account needed unless you want full team isolation.
  • ✓Register a separate webhook URL for test mode in the Paystack dashboard: Settings → API Keys & Webhooks → Test Webhook URL.
  • ✓Store environment variables separately: .env.production (live keys) vs .env.staging (test keys) — never mix them.
  • ✓Subaccounts, plans, and customers created in test mode are invisible in live mode and vice versa — recreate them in each mode.
  • ✓When your staging environment receives a webhook, verify the x-paystack-signature matches your test secret key — use the same validation code as production.
  • ✓Protect staging with HTTP basic auth to prevent public access and accidental test transactions from real users.

Frequently Asked Questions

Do I need a separate Paystack account for staging?
No — Paystack test mode on your existing account is sufficient for staging. Test and live are fully isolated within the same Paystack account. You would only need a separate Paystack account if you wanted completely separate dashboard access control (e.g., staging team should never see live transactions at all).
Can I accidentally send real money in staging?
No — as long as your staging environment uses sk_test_ and pk_test_ keys. Test keys can only process test cards. Real card numbers will be rejected. The guard at startup (checking key prefix) provides an extra layer of protection.
How do I test webhooks in staging if my server is on a private network?
Use a tunneling tool: ngrok (free tier works), Cloudflare Tunnel, or localtunnel. These expose your local server over a public HTTPS URL that Paystack can reach. For permanent staging environments (e.g., a Vercel preview deployment), register that deployment URL directly in the Paystack dashboard.
Should staging use a copy of the production database or a separate database?
Always use a completely separate staging database — never connect staging to production data. Staging payment tests write to the database; if that database were production, test records would mix with real customer records. The staging database can be seeded with anonymised production data snapshots, but it must remain isolated.

Learn Paystack Integration

KES 2,999

The definitive guide to building payment systems with Paystack — from your first transaction to production-grade payment infrastructure across Africa. 9 modules, 47 lessons. Free preview available.

Start Paystack Course

Not ready? Create Free Account

Keep reading

Testing Paystack Integrations: The Complete Guide

A complete guide to testing Paystack integrations at every level: test mode, test cards, unit tests with mocks, integration tests, end-to-end flows with Playwright, webhook simulation, contract testing, CI pipelines, staging environments, load testing, and coverage targets for payment code.

Read more

Simulating Declined Cards on Paystack

A card decline is one of the most common failure states in a payment flow, and your application must handle it gracefully. This guide shows how to simulate specific card declines in Paystack test mode and how to verify your decline handling code works correctly.

Read more

Mocking the Paystack API in PHPUnit

PHPUnit tests for Paystack integrations in Laravel or PHP can run without any network calls using Laravel's Http::fake() or Mockery. This guide shows how to mock Paystack responses, test webhook handlers, and verify your payment logic in isolation.

Read more

Contract Testing Your Paystack Webhook Handler

Contract testing verifies that your webhook handler correctly handles the exact payload structure Paystack sends. If Paystack adds or renames a field, contract tests catch the mismatch before it reaches production. This guide shows how to write contract tests for Paystack webhook events.

Read more

Paystack Inline Script Not Loading

The Paystack Inline JS script fails to load when the URL is wrong, your Content Security Policy blocks it, an ad blocker intercepts it, or the network request fails. This guide covers every cause and shows you how to build a fallback so payments work even when the script is blocked.

Read more

Explore related topics

M-Pesa & African Stack

M-Pesa Daraja API tutorials, USSD development, and WhatsApp Business API guides. The African Stack that global bootcamps do not teach.

Learn to Code in Kenya

Everything a Kenyan needs to know before writing their first line of code. Career paths, real costs, hardware requirements, and honest answers about what it takes.

Learning to Code

Roadmaps, language guides, and practical advice for learning to code and launching a programming career.

Breaking Into Tech

Practical, no-nonsense guides for anyone looking to start or change their career in tech. From choosing your first language to acing interviews.

The African Stack: Skills for This Market

The skills that make Kenyan developers hard to replace: M-Pesa, USSD, WhatsApp, fintech, and building for the African market.

Bonaventure Ogeto

Bonaventure Ogeto

Founder, McTaba Labs

Bonaventure is the founder of McTaba Labs, a coding bootcamp in Nairobi, Kenya. He has spent years building products for the African market and mentoring the next generation of developers across the continent.