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. Verify Paystack Payments in Go
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 20, 2026

Verify Paystack Payments in Go

To verify a Paystack payment in Go, make a GET request to the verify endpoint, decode the JSON response into a typed struct, check status, amount, and currency, and use an atomic database update to prevent double-granting.

In this article

  1. 1. Verification Function
  2. 2. Retry Logic
  3. 3. Verify Handler
  4. 4. Ship Payments Faster

Verification Function

func verifyTransaction(reference string) (*VerifyResponse, error) {
    req, err := http.NewRequest("GET",
        "https://api.paystack.co/transaction/verify/"+reference, nil)
    if err != nil {
        return nil, err
    }
    req.Header.Set("Authorization", "Bearer "+paystackSecret)

    client := &http.Client{Timeout: 10 * time.Second}
    resp, err := client.Do(req)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()

    var result VerifyResponse
    if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
        return nil, err
    }

    return &result, nil
}

func verifyAndFulfill(reference string, db *sql.DB) error {
    result, err := verifyTransaction(reference)
    if err != nil {
        return fmt.Errorf("verification failed: %w", err)
    }

    if !result.Status || result.Data.Status != "success" {
        return fmt.Errorf("payment not successful: %s", result.Data.Status)
    }

    // TODO: Check amount and currency against database

    // Atomic update
    res, err := db.Exec(
        "UPDATE orders SET paid = true, paid_at = NOW() WHERE reference = $1 AND paid = false",
        reference,
    )
    if err != nil {
        return err
    }

    rows, _ := res.RowsAffected()
    if rows == 0 {
        // Already fulfilled
        return nil
    }

    // Deliver value
    return nil
}

Retry Logic

func verifyWithRetry(reference string, maxRetries int) (*VerifyResponse, error) {
    for attempt := 0; attempt < maxRetries; attempt++ {
        result, err := verifyTransaction(reference)
        if err == nil {
            return result, nil
        }

        if attempt < maxRetries-1 {
            time.Sleep(time.Duration(1<

Get weekly developer tips

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

No spam. Unsubscribe anytime.

Verify Handler

func verifyHandler(w http.ResponseWriter, r *http.Request) {
    reference := r.URL.Query().Get("reference")
    if reference == "" {
        http.Error(w, "Missing reference", http.StatusBadRequest)
        return
    }

    err := verifyAndFulfill(reference, db)
    if err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }

    w.Header().Set("Content-Type", "application/json")
    json.NewEncoder(w).Encode(map[string]bool{"success": true})
}

Ship Payments Faster

This guide is part of the Paystack integration guides by language and framework series.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Go structs with json tags provide type-safe Paystack response parsing.
  • ✓Always check status, amount, and currency against your database records.
  • ✓Use SQL UPDATE with a WHERE clause on paid=false for atomic idempotent fulfillment.
  • ✓Go error handling makes verification failures explicit and easy to trace.
  • ✓Create a reusable VerifyAndFulfill function for use in callbacks and webhooks.
  • ✓Retry with exponential backoff using time.Sleep for network failures.

Frequently Asked Questions

Can I verify a transaction multiple times?
Yes. The Paystack verify endpoint is idempotent and returns the same result every time.
Should I use context.Context for verification?
Yes. In production, use http.NewRequestWithContext to respect request cancellation and timeouts.
How do I handle verification in goroutines?
The atomic SQL UPDATE with WHERE paid=false ensures only one goroutine fulfills the order, even if multiple run concurrently.

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 Integration Guides by Language and Framework

A complete directory of Paystack integration guides organized by programming language and framework. Each guide covers accepting payments, verifying transactions, handling webhooks, and building subscriptions in your specific stack.

Read more

Accept Payments with Paystack in Svelte and SvelteKit

Accept Paystack payments in SvelteKit using server endpoints for backend logic and Svelte components for the frontend. This guide covers initializing transactions, inline popup checkout, redirect checkout, and verification in a single full-stack SvelteKit project.

Read more

Verify Paystack Payments in Flask

Verify Paystack payments server-side in your Flask application. This guide covers calling the Paystack verify endpoint, validating amounts and currencies, building reusable verification helpers, and preventing double-granting.

Read more

Build Paystack Subscriptions in ASP.NET Core

Implement Paystack recurring billing in ASP.NET Core. This guide covers creating plans, subscribing customers through transaction initialization, handling renewal webhooks with C#, and cancelling subscriptions.

Read more

Paystack OTP and PIN Flows in Custom Checkout

When you use the Paystack Charge API to build a custom checkout, most card charges require the customer to enter a PIN, an OTP, or both. This guide explains exactly when each step appears, how to collect and submit the values, and how to handle the edge cases that break real-world checkouts.

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.