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. Logging Payments Without Logging Secrets
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Logging Payments Without Logging Secrets

Safe to log: transaction reference, amount, status, customer email, gateway_response, channel, ip_address. Never log: your Paystack secret key, authorization_code (store encrypted instead), full card numbers (you should never see these), CVV, or the raw Authorization header from your outbound API requests. Mask sensitive values in logs using a sanitize function before writing to any log store.

In this article

  1. 1. What to Log and What Never to Log
  2. 2. Sanitizing Logs Before Writing
  3. 3. Learn More

What to Log and What Never to Log

DataLog?Reason
Transaction referenceYesCore debug identifier
Amount (in kobo)YesNeeded for reconciliation
Status (success/failed)YesTrack payment outcomes
Customer emailYes (masked)Use "u***@gmail.com" format
gateway_responseYesDebug declined cards
channelYesDebug payment method issues
ip_addressYesFraud detection
Paystack secret keyNeverFull account compromise
Authorization header (outbound)NeverContains secret key
authorization_codeNever in plaintextToken for charging card again
Card number (PAN)NeverYou should never see this anyway
CVVNeverYou should never see this

Sanitizing Logs Before Writing

// logger.js — safe payment event logging

function maskEmail(email) {
  if (!email || !email.includes('@')) return email;
  var [local, domain] = email.split('@');
  return local[0] + '***@' + domain;
}

function sanitizePaystackResponse(data) {
  // Only extract the fields you need — never spread the whole object
  return {
    reference: data.reference,
    amount: data.amount,
    status: data.status,
    gateway_response: data.gateway_response,
    channel: data.channel,
    ip_address: data.ip_address,
    customer_email: maskEmail(data.customer?.email),
    // Deliberately excluded: authorization.authorization_code, authorization.bin (full)
  };
}

// In your webhook handler
if (event.event === 'charge.success') {
  var safeData = sanitizePaystackResponse(event.data);
  console.log(JSON.stringify({ event: 'charge.success', ...safeData }));
  // Safe — none of the sensitive fields are in here
}

// When making outbound Paystack API calls — never log the full headers object
async function callPaystack(endpoint, body) {
  var response = await fetch('https://api.paystack.co' + endpoint, {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(body),
  });
  // Log the response, not the request headers
  var data = await response.json();
  console.log(JSON.stringify({ endpoint, status: response.status, ref: data.data?.reference }));
  return data;
}

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 security guide.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Never log your Paystack secret key. If it appears in a log file, rotate it immediately.
  • ✓Do not log the raw Authorization header from outbound Paystack API requests — it contains your secret key.
  • ✓The authorization_code from a charge is safe to store encrypted in your database, but do not log it in plaintext.
  • ✓Log: reference, amount, status, gateway_response, customer email — this is enough for debugging.
  • ✓Sanitize request bodies before logging: replace the Authorization header value with "[REDACTED]".
  • ✓Use structured logging (JSON) so you can filter out sensitive fields by key, not by regex over text.

Frequently Asked Questions

What should I do if I find my Paystack secret key in a log file?
Rotate the key immediately from the Paystack dashboard (Settings → API Keys). Then audit who had access to the log file and for how long. Check your Paystack transaction history for any unexpected API calls. Update your application with the new key before the old one is deactivated. Treat this as a security incident.
Is it safe to log the customer email address?
Email addresses are personal data — they should be masked in logs (show only the first character and domain). Full emails in logs create a data privacy risk if the logs are accessed by unauthorized parties, and in some jurisdictions may require you to include log stores in your data processing register.
Can I store the authorization_code in my database?
Yes — the authorization_code is a safe token for re-charging a card. Store it encrypted in your database (not in plaintext). It is useless without your Paystack secret key, but encryption adds defense in depth. Do not put it in application logs where it might be exported to third-party log aggregation services.
My log aggregator (Datadog, Papertrail) collects all console.log output. Is this safe?
Only if you sanitize before logging. Log aggregators index everything they receive — if your secret key ever appears in console.log output, it is stored in the aggregator's systems. Use the sanitize pattern above and never log raw request objects that include headers or environment variables.

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

Paystack Security, Keys and PCI Compliance: Complete Guide

A complete security reference for Paystack integrations. Covers API key types and rotation, secure key storage, PCI DSS compliance scope, price tampering prevention, webhook replay attacks, rate limiting, fraud signals, and logging without exposing secrets.

Read more

Never Commit Your Paystack Key: Detection and Remediation

Committing a Paystack secret key to version control is one of the most common and most dangerous mistakes in payment integrations. This guide shows you how to detect committed keys, set up automated prevention with pre-commit hooks, and remediate the damage when a key does slip through.

Read more

Price Tampering Attacks on Paystack Checkouts

Price tampering is the most common attack on Paystack integrations. The attacker modifies the amount in the frontend checkout initialization, paying a fraction of the actual price. This guide shows how the attack works and how server-side amount validation stops it completely.

Read more

Velocity Checks and Card Testing Attack Defence

Card testing attacks use stolen card numbers to probe your checkout — making small charges until they find valid cards. These attacks generate failed transaction fees, damage your Paystack account standing, and waste real money. This guide covers detecting card testing patterns and building velocity checks to stop them.

Read more

Paystack Mobile Money Charge Stuck at Pending

A mobile money charge on Paystack stays "pending" for minutes or hours. The customer may have approved it, ignored it, or never received the prompt. Here is how to handle every scenario.

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.