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 Laravel
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 20, 2026

Verify Paystack Payments in Laravel

To verify a Paystack payment in Laravel, use Http::withToken() to GET the verify endpoint. Check data.data.status is "success", the amount matches your Order model, and the currency is correct. Use Order::where("reference", $ref)->where("paid", false)->update() for idempotent fulfillment.

In this article

  1. 1. PaystackService Class
  2. 2. Using the Service in Controllers
  3. 3. Retry Logic
  4. 4. Common Mistakes
  5. 5. Ship Payments Faster

PaystackService Class

// app/Services/PaystackService.php
namespace App\Services;

use App\Models\Order;
use Illuminate\Support\Facades\Http;

class PaystackService
{
    private string $secretKey;

    public function __construct()
    {
        $this->secretKey = config('services.paystack.secret_key');
    }

    public function verify(string $reference): array
    {
        $response = Http::withToken($this->secretKey)
            ->get('https://api.paystack.co/transaction/verify/' . $reference);

        return $response->json();
    }

    public function verifyAndFulfill(string $reference): array
    {
        $order = Order::where('reference', $reference)->first();

        if (!$order) {
            return ['success' => false, 'error' => 'Order not found'];
        }

        if ($order->paid) {
            return ['success' => true, 'already_fulfilled' => true];
        }

        $result = $this->verify($reference);

        if (!($result['status'] ?? false) || $result['data']['status'] !== 'success') {
            return ['success' => false, 'error' => 'Payment not successful'];
        }

        if ($result['data']['amount'] !== $order->amount) {
            return ['success' => false, 'error' => 'Amount mismatch'];
        }

        if ($result['data']['currency'] !== $order->currency) {
            return ['success' => false, 'error' => 'Currency mismatch'];
        }

        $updated = Order::where('reference', $reference)
            ->where('paid', false)
            ->update(['paid' => true, 'paid_at' => now()]);

        return [
            'success' => true,
            'already_fulfilled' => $updated === 0,
            'amount' => $order->amount / 100,
            'currency' => $order->currency,
        ];
    }
}

Using the Service in Controllers

// In PaymentController
public function callback(Request $request, PaystackService $paystack)
{
    $reference = $request->query('reference') ?? $request->query('trxref');

    if (!$reference) {
        return redirect('/')->with('error', 'Missing reference');
    }

    $result = $paystack->verifyAndFulfill($reference);

    if ($result['success']) {
        return view('payment.success', ['reference' => $reference]);
    }

    return view('payment.failed', ['error' => $result['error']]);
}

public function verify(Request $request, PaystackService $paystack)
{
    $reference = $request->query('reference');

    if (!$reference) {
        return response()->json(['error' => 'Missing reference'], 400);
    }

    $result = $paystack->verifyAndFulfill($reference);

    return response()->json($result, $result['success'] ? 200 : 400);
}

Laravel automatically injects the PaystackService through constructor or method injection.

Get weekly developer tips

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

No spam. Unsubscribe anytime.

Retry Logic

public function verifyWithRetry(string $reference, int $maxRetries = 3): ?array
{
    for ($attempt = 0; $attempt < $maxRetries; $attempt++) {
        try {
            $response = Http::withToken($this->secretKey)
                ->timeout(10)
                ->get('https://api.paystack.co/transaction/verify/' . $reference);

            if ($response->successful()) {
                return $response->json();
            }
        } catch (\Exception $e) {
            // Log and retry
        }

        if ($attempt < $maxRetries - 1) {
            sleep(pow(2, $attempt));
        }
    }

    return null;
}

Common Mistakes

  • Using $order->save() instead of ::where()->update(). The save() method is not atomic. Two concurrent requests could both read paid=false and both save paid=true.
  • Trusting request input for amounts. Always compare against the Eloquent model.
  • Mixing test and live keys. Both must be in the same mode.
  • Not checking currency. Always verify the currency matches.

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

  • ✓Laravel HTTP client makes verification calls clean: Http::withToken($key)->get($url).
  • ✓Always check status, amount, and currency against your Eloquent model.
  • ✓Use where("paid", false)->update() for atomic idempotent fulfillment.
  • ✓Create a PaystackService class for reusable verification logic across controllers.
  • ✓Both callback and webhook handlers should call the same verification method.
  • ✓If the verify call fails, retry. The Paystack transaction state does not change.

Frequently Asked Questions

Can I verify a transaction multiple times?
Yes. The Paystack verify endpoint is idempotent. It returns the same result every time for the same reference.
Should I register PaystackService as a singleton?
It depends on your needs. As a singleton, the same instance is reused. As a regular binding, a new instance is created per request. Both work fine for Paystack API calls.
How do I handle verification in queued jobs?
Your webhook handler can dispatch a job that calls verifyAndFulfill. The idempotent logic ensures safety even if the job runs multiple times.

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

Accepting QR Payments Through Paystack

QR payments let customers scan a code with their banking app and pay without entering card details, typing USSD codes, or making a manual bank transfer. This guide covers how QR payments work on Paystack, how to generate QR codes for your customers, and how to build the payment flow end-to-end.

Read more

Paystack Dedicated Account Not Assigned: Every Cause and Fix

Your Paystack dedicated virtual account request failed because a prerequisite was not met. This guide walks through every eligibility requirement and shows you exactly how to diagnose and fix the problem.

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.