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 Supabase Edge Functions
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Verify Paystack Payments in Supabase Edge Functions

Create a Supabase Edge Function at supabase/functions/verify/index.ts. Read the transaction reference from the URL query string, call GET https://api.paystack.co/transaction/verify/:reference with your PAYSTACK_SECRET_KEY from Deno.env, check data.status === "success", update your Supabase database with the Supabase client, and return the result.

In this article

  1. 1. Verify Edge Function
  2. 2. Deploy and Call
  3. 3. Learn More

Verify Edge Function

// supabase/functions/verify/index.ts
import { serve } from "https://deno.land/std@0.208.0/http/server.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2";

const corsHeaders = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
};

serve(async (req) => {
  if (req.method === "OPTIONS") {
    return new Response("ok", { headers: corsHeaders });
  }

  const url = new URL(req.url);
  const reference = url.searchParams.get("reference");

  if (!reference) {
    return new Response(
      JSON.stringify({ error: "Reference is required" }),
      { status: 400, headers: { ...corsHeaders, "Content-Type": "application/json" } }
    );
  }

  const secretKey = Deno.env.get("PAYSTACK_SECRET_KEY");

  // Call Paystack verify
  const paystackResponse = await fetch(
    "https://api.paystack.co/transaction/verify/" + encodeURIComponent(reference),
    { headers: { Authorization: "Bearer " + secretKey } }
  );

  const paystackData = await paystackResponse.json();

  if (!paystackData.status || paystackData.data.status !== "success") {
    return new Response(
      JSON.stringify({
        verified: false,
        status: paystackData.data?.status,
        message: paystackData.data?.gateway_response || "Payment not verified",
      }),
      { status: 400, headers: { ...corsHeaders, "Content-Type": "application/json" } }
    );
  }

  const txData = paystackData.data;

  // Update database using service role key (bypasses RLS)
  const supabase = createClient(
    Deno.env.get("SUPABASE_URL")!,
    Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!
  );

  const { error: dbError } = await supabase
    .from("orders")
    .update({
      status: "paid",
      paid_at: new Date().toISOString(),
      amount_paid: txData.amount / 100,
      currency: txData.currency,
    })
    .eq("reference", reference);

  if (dbError) {
    console.error("DB update failed:", dbError.message);
  }

  return new Response(
    JSON.stringify({
      verified: true,
      amount: txData.amount / 100,
      currency: txData.currency,
      reference: txData.reference,
      customer_email: txData.customer.email,
    }),
    { headers: { ...corsHeaders, "Content-Type": "application/json" } }
  );
});

Deploy and Call

supabase functions deploy verify
// Frontend call
const { data, error } = await supabase.functions.invoke('verify', {
  method: 'GET',
  // or pass as query param:
})

// Or direct fetch:
var response = await fetch(
  process.env.SUPABASE_URL + '/functions/v1/verify?reference=' + reference,
  {
    headers: { 'Authorization': 'Bearer ' + process.env.SUPABASE_ANON_KEY }
  }
)
var result = await response.json()

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 integration guides by language and framework series.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Verification happens in the Edge Function, not on the frontend. The secret key stays in Deno.env.
  • ✓Use native fetch in Deno to call the Paystack verify endpoint.
  • ✓After verification, use the Supabase service role key to update the database (bypasses RLS).
  • ✓Return a clean response to the frontend — verified, amount, currency, reference.
  • ✓Always check both status ("success") and amount against your database record before granting access.
  • ✓Log failed verifications for debugging. Paystack test mode returns real responses that test your logic.

Frequently Asked Questions

Why use the service role key for database updates in Edge Functions?
The service role key bypasses Row Level Security (RLS) policies. When a payment is verified server-side, your application logic has determined the action is legitimate. The anon key would be subject to RLS policies that might block updates from the Edge Function context.
Can I verify and update the database in the same Edge Function?
Yes, and you should. The verify Edge Function in this guide does both: calls Paystack to verify, then updates the Supabase orders table. This is the right approach — keep the entire verification flow in one serverless function.
What is the difference between SUPABASE_URL and SUPABASE_ANON_KEY in Edge Functions?
SUPABASE_URL, SUPABASE_ANON_KEY, and SUPABASE_SERVICE_ROLE_KEY are automatically available in Edge Functions via Deno.env. You do not need to set them manually. They are injected by the Supabase runtime. Only external secrets like PAYSTACK_SECRET_KEY need to be set with supabase secrets set.
How do I test Edge Function verification locally?
Run supabase functions serve verify. Test with curl: curl "http://localhost:54321/functions/v1/verify?reference=test_ref". Use test API keys and Paystack test mode for local development. The function runs identically locally and in production.

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 Supabase Edge Functions

Supabase Edge Functions run Deno TypeScript at the edge. Use them as your Paystack backend to initialize transactions, verify payments, and handle webhooks without deploying a separate server.

Read more

Handle Paystack Webhooks in Supabase Edge Functions

Receive Paystack webhook events in a Supabase Edge Function written in Deno TypeScript. This guide covers HMAC SHA512 signature verification using the Web Crypto API, returning 200 before processing, and updating your Supabase database after confirming the event.

Read more

Transaction Not Found on Paystack Verify

Paystack returns "Transaction not found" when the reference you pass to the verify endpoint does not match any transaction in the current environment. The causes range from wrong reference strings to test/live key confusion to URL encoding problems. This guide covers every cause with specific fixes.

Read more

Idempotency in Paystack Payment Flows

Duplicate charges are the nightmare scenario for any payment integration. A customer clicks pay twice, a network timeout triggers a retry, or a webhook fires before the redirect callback. Idempotency is the engineering discipline that makes sure the same payment operation produces the same result no matter how many times it runs.

Read more

Paystack Transfer Failed: Reasons and Recovery

Paystack transfers fail for specific, diagnosable reasons. This guide covers every failure reason, the exact webhook payload for each, and a production-ready recovery strategy with code.

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.