Chapa
Start here

API Keys and Environments

Understand the difference between Test and Live environments for safe development and production.

Chapa provides two separate environments so you can safely build, test, and deploy your payment integration:

  • Test Mode — for development and QA (no real money)
  • Live Mode — for production (real transactions)

Understanding the difference between these modes is critical to avoid failed payments, invalid keys, and environment-mismatch errors.

Environment Comparison

FeatureTest ModeLive Mode
Real moneyNoYes
API keysCHAPA_TEST_...CHAPA_LIVE_...
Checkout experienceSimulatedReal payment flows
WebhooksTest webhook eventsLive webhook events
Use caseDevelopment & testingProduction

API Keys

Key typeUsed for
PrivateHosted and direct payments, verification, payouts, refunds, subaccounts, balances, payment methods
PublicInline charge, inline validation, HTML checkout service check

Send the appropriate key with Authorization: Bearer <API_KEY>. The API key environment must match the business environment. Keep private keys on your server.

Each environment has its own set of API keys.

Test Key:

CHAPA_TEST_xxxxxxxxxxxxx

Live Key:

CHAPA_LIVE_xxxxxxxxxxxxx

Never mix keys across environments. Using a test key in live mode (or vice versa) will cause authentication or environment errors.

Base URL (Same, Behavior Differs)

Both Test and Live mode use the same API base URL:

https://api.chapa.global

The API key must match your business environment. A mismatch returns HTTP 403 with error code INVALID_VALUE.

Test Mode Behavior

In Test Mode:

  • Payments are simulated
  • No real charges occur
  • You can safely test:
    • Hosted checkout
    • Direct charge
    • Payouts
    • Refunds
    • Webhooks

Ideal Use Cases

  • Local development
  • Staging environments
  • QA testing
  • Automated tests (CI/CD)

Test all payment states:

  • SUCCESS
  • FAILED
  • CANCELLED
  • INCOMPLETE
  • BLOCKED
  • AUTH_NEEDED

Verify:

  • Webhook handling logic
  • Retry behavior
  • Idempotency handling
  • Verification flows

Live Mode Behavior

In Live Mode:

  • Real customers pay real money
  • Payouts move real funds
  • Refunds affect real balances
  • Webhooks reflect real transactions
  • Errors impact real users

Treat Live Mode with production-level care.

Before Switching to Live Mode

We recommend completing the following before switching to Live Mode:

Checklist ItemStatus
Completed full testing in Test ModeRecommended
Verified webhook endpoint is live and reachableRecommended
Enabled required payment methods in the dashboardRecommended
Implemented proper error handling and loggingRecommended
Secured live API keys (secrets manager / env vars)Recommended

Webhooks: Test vs Live

Webhook payloads include a mode field.

Test Mode Webhook:

{
  "mode": "test"
}

Live Mode Webhook:

{
  "mode": "live"
}

Always check the mode field if your system processes both test and live events.

Common Environment Errors

API Key Environment Mismatch

Error MessageMeaning
API key environment does not match business environmentTest key used in live mode or live key used in test mode

Payment Not Found

Usually caused by:

  • Verifying a test transaction using a live key
  • Verifying a live transaction using a test key
  • Mixing references across environments

Deployment Checklist (Live Mode)

Before going live, confirm:

ItemDescription
API keysAll API calls use CHAPA_LIVE_...
Webhook URLProduction-ready and publicly accessible
Webhook handlerIdempotent and handles retries
Payment verificationEnforced before fulfillment
Key storageSensitive keys stored securely
Test logicTest-only logic disabled in production

Best Practices

  • Use separate configs for test and live environments
  • Never hardcode API keys in source code
  • Log environment (test vs live) per transaction
  • Display environment clearly in admin dashboards
  • Restrict live keys to production servers only

Next Steps

On this page