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. Building a Payments Support Chatbot on Paystack Data
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Building a Payments Support Chatbot on Paystack Data

Architecture: 1) Authenticate the user first — verify their email or phone number before the chatbot can access their payment data. 2) Define customer-scoped tools: get_customer_transactions(email), get_subscription_status(subscription_code), get_transaction_by_reference(ref). 3) Pass the verified customer email + tools to the LLM. 4) LLM can only see that customer's data — not other customers. 5) Chatbot is read-only. Any refund or cancellation request goes to a human support agent queue.

Support Chatbot Architecture

// Customer-scoped tools — all queries filter by verified customer email
function buildCustomerTools(verifiedEmail) {
  return [
    {
      name: 'get_my_transactions',
      description: 'Get recent transactions for this customer.',
      input_schema: {
        type: 'object',
        properties: {
          status: { type: 'string', enum: ['success', 'failed', 'pending'] },
          limit: { type: 'number' },
        },
      },
    },
    {
      name: 'get_transaction_by_reference',
      description: 'Look up a specific transaction by reference code.',
      input_schema: {
        type: 'object',
        properties: { reference: { type: 'string' } },
        required: ['reference'],
      },
    },
    {
      name: 'get_subscription_status',
      description: 'Check the status of a subscription.',
      input_schema: {
        type: 'object',
        properties: { subscription_code: { type: 'string' } },
        required: ['subscription_code'],
      },
    },
    {
      name: 'request_human_agent',
      description: 'Escalate to a human support agent for refunds, cancellations, or complex issues.',
      input_schema: {
        type: 'object',
        properties: { reason: { type: 'string' } },
        required: ['reason'],
      },
    },
  ];
}

// Tool execution — always enforces the verified email scope
async function executeSupportTool(toolName, input, verifiedEmail) {
  var headers = { Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY };

  if (toolName === 'get_my_transactions') {
    var params = 'customer=' + encodeURIComponent(verifiedEmail) + '&perPage=' + (input.limit || 10);
    if (input.status) params += '&status=' + input.status;
    var res = await fetch('https://api.paystack.co/transaction?' + params, { headers });
    return (await res.json()).data;
  }

  if (toolName === 'get_transaction_by_reference') {
    var res = await fetch('https://api.paystack.co/transaction/verify/' + input.reference, { headers });
    var data = (await res.json()).data;
    // Security: only return if this transaction belongs to the verified customer
    if (data?.customer?.email !== verifiedEmail) {
      return { error: 'Transaction not found for your account' };
    }
    return data;
  }

  if (toolName === 'request_human_agent') {
    await db.supportQueue.insert({ customerEmail: verifiedEmail, reason: input.reason, ts: new Date() });
    return { status: 'queued', message: 'A human agent will contact you within 2 business hours' };
  }
}

Learn More

See using an LLM to explain failed payments for the failure code explanation pattern to include in your chatbot system prompt.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Authenticate the customer before the chatbot can access any Paystack data — no anonymous payment lookups.
  • ✓Scope all tool calls to the verified customer's email — never allow cross-customer data access.
  • ✓Keep the chatbot read-only — refunds and cancellations go to a human queue.
  • ✓Give the LLM plain-English failure code explanations as a reference in the system prompt.
  • ✓Log every chatbot session with the customer identifier, questions asked, and tools called.

Frequently Asked Questions

How do I authenticate the customer before giving the chatbot access to their data?
Use your existing session authentication. If the customer is logged in to your application, their verified email is in the session — pass it as the scope for the chatbot. If the chatbot is on a public widget, require the customer to enter their email and send an OTP to verify it before opening the chat session. Never trust a customer-supplied email without verification.
What should the chatbot do when it cannot find the transaction?
Return an honest response: "I could not find a transaction with that reference on your account." Then offer the request_human_agent option. Never let the LLM speculate about why a transaction is missing — it can produce plausible but wrong explanations. Missing transactions warrant a human check.
Should I include refund capabilities in the chatbot?
No — not as an automated action. A confused or manipulated LLM can refund the wrong transaction. Build a refund request tool that queues the request for human review. The chatbot can confirm the refund request was received and provide a timeline, but a human approves and executes the actual refund via Paystack dashboard or API.

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 AI Agents and the MCP Server: The Complete Guide

A comprehensive guide to building AI agents that interact with Paystack through the Model Context Protocol (MCP) server. Covers connecting the MCP server to Claude Code, querying transactions with natural language, building payment support chatbots, AI-assisted reconciliation, agentic payouts with safety rails, secret key security, human-in-the-loop design, prompt injection risks, and audit trails for AI-initiated financial actions.

Read more

Using an LLM to Explain Failed Payments to Customers

"Insufficient Funds" is clear. "Do Not Honor", "Restricted Card", or "Transaction Not Permitted to Cardholder" are not. An LLM translates these into actionable, customer-friendly messages without revealing implementation details.

Read more

Why You Should Never Give an LLM Your Paystack Secret Key

Your Paystack secret key can initialize transactions, trigger transfers, and access all your transaction data. Giving it to an LLM — even once — creates risks that do not go away when you close the chat window.

Read more

Building a Voice Agent That Collects Payment

A customer calls your number. They say what they want to pay for. The voice agent creates a Paystack payment link and texts it to their phone. No human operator needed. Here is how to build it.

Read more

Build Paystack Subscriptions in Android with Kotlin

Add Paystack subscription billing to a native Android app. This guide covers initializing subscription transactions from your backend, the WebView checkout flow in Kotlin, checking subscription status, and building a plan management screen.

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.