Tutorials

Integrating Paystack Payment Links with WhatsApp Business API

Learn how to integrate Paystack payment links with WhatsApp Business API. Automate payment requests, send invoices via WhatsApp, and confirm with webhooks.

StartMessaging Team Updated

Automating customer transactions is a critical capability for any business operating in the Nigerian digital commerce space. By using a whatsapp paystack integration, you can programmatically send dynamic payment links directly to customers within their chat screens. This minimises payment friction and replaces slower email or SMS invoicing methods that suffer from low conversion rates. In this tutorial, we will show you how to generate these payment links on your backend and deliver them using WhatsApp templates.

The StartMessaging WhatsApp API is built on Meta’s official Cloud API. Every send goes to one endpoint, POST https://waba-api.startmessaging.com/api/v1/messages, authenticated with an API key in the Authorization: Bearer sm_live_... header. Create the key in the dashboard under Developers → API keys with the messages:send scope (it is shown once, so store it safely). See Authentication for scopes and key management.


For Nigerian businesses, collecting payments directly via messaging solves a major user experience hurdle. Instead of asking a user to exit WhatsApp, open a web browser, navigate to a store page, and checkout, you deliver a single, clickable checkout link. When the customer clicks the link, they are redirected to a secure Paystack checkout page where they can pay via direct bank transfer, USSD, or debit card. Once the transaction completes, a webhook notifies your backend, allowing you to trigger a real-time receipt message back to the customer on WhatsApp.

The architecture relies on three distinct operations:

  1. Link Generation: Your backend communicates with the Paystack API to initialize a transaction and retrieve a unique payment URL.
  2. Message Delivery: Your backend sends an approved WhatsApp template containing the payment link to the customer via the StartMessaging API.
  3. Status Syncing: Paystack sends a POST request (webhook) to your server when the customer pays, which triggers a confirmation message.

This model is highly scalable and fits various business sizes, from informal retail shops managing orders to automated fintech platforms.


Before You Start: Create the Templates

A payment request is a business-initiated message, so it must be an approved template. Templates are created in the StartMessaging dashboard and reviewed by Meta; the API sends approved templates but does not create them (see Message Templates). For this tutorial, create two Utility templates in English (en_US):

  • invoice_payment_request: body Hello {{1}}, your invoice {{2}} is ready. Tap the button below to pay securely with Paystack. and a Visit website button named “Pay Now” with a dynamic URL https://checkout.paystack.com/{{1}}.
  • payment_confirmation: body Thank you {{1}}. We have received your payment of {{2}} (reference {{3}}).

The template’s Send via API panel in the dashboard shows exactly which values each template needs.


To start the process, we build a backend service that requests a payment link from Paystack’s Initialize Transaction endpoint. The examples use Node.js 18+ with the built-in fetch.

Keep your Paystack Secret Key in an environment variable. Paystack charges its own transaction fees; check Paystack’s pricing page for the current local rates when calculating order values.

Here is the code to initialize a payment link:

/**
 * Initializes a Paystack transaction and returns its checkout link
 * @param {string} email - Customer's billing email
 * @param {number} amountInKobo - Amount in kobo (e.g. ₦1,000 = 100000 kobo)
 * @param {string} reference - Unique transaction reference
 * @param {object} metadata - Data you want back on the webhook (phone, name)
 */
export async function generatePaystackPaymentLink(email, amountInKobo, reference, metadata) {
  const res = await fetch('https://api.paystack.co/transaction/initialize', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.PAYSTACK_SECRET_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      email,
      amount: amountInKobo,
      reference,
      callback_url: 'https://yourdomain.com/payment/callback',
      metadata,
    }),
  });
  const body = await res.json();
  if (!res.ok || !body.status) {
    throw new Error(`Paystack initialization failed: ${body.message}`);
  }
  // authorization_url is https://checkout.paystack.com/<access_code>
  return {
    authorizationUrl: body.data.authorization_url,
    accessCode: body.data.access_code,
  };
}

This helper receives the customer’s email, the amount, a unique reference and a metadata object. Paystack accepts amounts in kobo (the sub-unit of the Naira), so a payment of ₦5,000 must be sent as 500000. Paystack returns the metadata you pass here on the charge.success webhook, which is how we get the customer’s WhatsApp number back later.


Sending the Payment Request via the WhatsApp Business API

Now we send the link with the invoice_payment_request template. Templates are required to start a conversation or to reach a customer outside the 24-hour customer service window. Body variables go in template.parameters in order, and the dynamic part of the URL button goes in template.buttonParameters with subType: "url". Because the template’s button URL is https://checkout.paystack.com/{{1}}, we send only the Paystack access_code.

const SM_API = 'https://waba-api.startmessaging.com/api/v1/messages';

/**
 * Sends a Paystack payment link to a customer via WhatsApp
 * @param {string} phoneNumber - Customer's WhatsApp number in E.164 (e.g. +2348030000000)
 * @param {string} customerName - First name of the customer
 * @param {string} invoiceId - Your invoice or order ID
 * @param {string} accessCode - The access_code returned by Paystack
 */
export async function sendWhatsAppPaymentRequest(phoneNumber, customerName, invoiceId, accessCode) {
  const res = await fetch(SM_API, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.SM_API_KEY}`,
      'Content-Type': 'application/json',
      'Idempotency-Key': `invoice-${invoiceId}-payment-request`,
    },
    body: JSON.stringify({
      to: phoneNumber,
      type: 'template',
      template: {
        name: 'invoice_payment_request',
        language: 'en_US',
        parameters: [{ text: customerName }, { text: invoiceId }],
        buttonParameters: [{ index: 0, subType: 'url', text: accessCode }],
      },
      clientReference: `invoice-${invoiceId}`,
    }),
  });
  const body = await res.json();
  if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
  console.log(`Payment link sent to ${body.data.to}. Message ID: ${body.data.id}`);
  return body.data;
}

A 201 Created response means WhatsApp accepted the message; body.data holds the message id, status: "sent", the conversationId and your clientReference. The Idempotency-Key header makes a retry safe: the same key never sends twice. The clientReference comes back on every delivery webhook for this message, so you can match receipts to the invoice without storing our message id.

Errors you should handle:

HTTPCodeWhat it means
400VALIDATION_ERRORThe body is wrong; error.message names the field
402META_PAYMENT_REQUIREDAdd or fix the payment method in WhatsApp Manager
404TEMPLATE_NOT_FOUNDCheck template.name and template.language
422TEMPLATE_NOT_APPROVEDMeta has not approved the template yet
422TEMPLATE_BUTTON_PARAM_REQUIREDThe URL button value is missing from buttonParameters
422CONTACT_OPTED_OUTThe customer replied STOP; they must opt back in first
429RATE_LIMIT_EXCEEDEDWait for the Retry-After seconds and retry

The full list is in Errors & Limits.


Confirming Successful Payments in Real Time via Webhooks

After the customer pays, Paystack sends a webhook to your server. Paystack signs each event with the x-paystack-signature header: an HMAC-SHA512 of the request body, keyed with your Paystack secret key. Verify it against the raw body before trusting the event, answer with 200 quickly, then process charge.success.

Below is an Express route that verifies the Paystack signature and sends the payment_confirmation template on WhatsApp:

import express from 'express';
import { createHmac, timingSafeEqual } from 'node:crypto';

const router = express.Router();
const SM_API = 'https://waba-api.startmessaging.com/api/v1/messages';

// Read the raw body so the signature is computed over the exact bytes Paystack sent
router.post('/paystack-webhook', express.raw({ type: 'application/json' }), async (req, res) => {
  const signature = Buffer.from(String(req.headers['x-paystack-signature'] ?? ''));
  const expected = Buffer.from(
    createHmac('sha512', process.env.PAYSTACK_SECRET_KEY).update(req.body).digest('hex'),
  );

  if (signature.length !== expected.length || !timingSafeEqual(signature, expected)) {
    return res.sendStatus(401);
  }

  // Acknowledge receipt immediately, then do the work
  res.sendStatus(200);

  const event = JSON.parse(req.body.toString('utf8'));
  if (event.event !== 'charge.success') return;

  const { amount, reference, metadata } = event.data;
  const amountPaid = amount / 100; // kobo to Naira

  try {
    await sendWhatsAppPaymentConfirmation(metadata.phone, metadata.name, reference, amountPaid);
  } catch (error) {
    console.error('Error sending confirmation message:', error.message);
  }
});

/**
 * Sends a payment confirmation template via WhatsApp
 */
async function sendWhatsAppPaymentConfirmation(phoneNumber, customerName, reference, amountPaid) {
  const res = await fetch(SM_API, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.SM_API_KEY}`,
      'Content-Type': 'application/json',
      // Paystack may deliver the same event more than once; this key keeps it to one message
      'Idempotency-Key': `paystack-${reference}-confirmation`,
    },
    body: JSON.stringify({
      to: phoneNumber,
      type: 'template',
      template: {
        name: 'payment_confirmation',
        language: 'en_US',
        parameters: [
          { text: customerName },
          { text: `₦${amountPaid.toFixed(2)}` },
          { text: reference },
        ],
      },
      clientReference: `paystack-${reference}`,
    }),
  });
  const body = await res.json();
  if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
  console.log(`Confirmation sent to ${body.data.to}`);
}

export default router;

This controller verifies that the request originates from Paystack, reads the phone number and name you stored in metadata at initialization, and sends a transaction confirmation message. Because the key is derived from the Paystack reference, a repeated Paystack delivery does not send the customer a second receipt.


Tracking Delivery with StartMessaging Webhooks

To know whether the payment request actually reached the customer, add a StartMessaging webhook endpoint in Developers → Webhooks → Add endpoint and subscribe to message.delivered, message.read and message.failed. Each delivery is signed with your endpoint’s secret: an HMAC-SHA256 of X-SM-Timestamp, a dot and the raw body, keyed with the whole whsec_... secret. Here is the verification function from the Webhooks docs:

import { createHmac, timingSafeEqual } from "node:crypto";

// rawBody: the request body exactly as received (a Buffer or string),
// before any JSON parsing. secret: the whole "whsec_..." string.
export function verifySignature(rawBody, headers, secret) {
  const timestamp = String(headers["x-sm-timestamp"] ?? "");
  // Refuse a missing timestamp, and anything older than 5 minutes.
  if (!/^\d+$/.test(timestamp)) return false;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;

  const expected = Buffer.from(
    createHmac("sha256", secret)
      .update(`${timestamp}.`)
      .update(rawBody)
      .digest("hex"),
  );

  // While a secret is being rotated, several signatures arrive; accept any.
  return String(headers["x-sm-signature"] ?? "")
    .split(",")
    .some((part) => {
      const signature = Buffer.from(part.trim().replace(/^v1=/, ""));
      // Compare byte lengths first: timingSafeEqual throws on a mismatch.
      return (
        signature.length === expected.length &&
        timingSafeEqual(signature, expected)
      );
    });
}

And a route that uses it:

router.post('/webhooks/startmessaging', express.raw({ type: 'application/json' }), (req, res) => {
  if (!verifySignature(req.body, req.headers, process.env.SM_WEBHOOK_SECRET)) {
    return res.sendStatus(401);
  }
  const event = JSON.parse(req.body.toString('utf8'));
  res.sendStatus(200); // answer within 5 seconds, then do the work

  // Deduplicate on event.id in your database: delivery is at least once
  if (event.type === 'message.failed') {
    const { clientReference, failureCode, failureReason } = event.data.message;
    // e.g. clientReference "invoice-INV-1042": email the payment link instead
    console.warn(`WhatsApp send failed for ${clientReference}: ${failureCode} ${failureReason}`);
  }
});

If a customer is not on WhatsApp, the message cannot be delivered. StartMessaging has no automatic SMS fallback, so send the link by email or through your own SMS provider when you receive message.failed.


Frequently Asked Questions

Q: Do customers need to have a registered card to pay via WhatsApp payment links?

A: No, Paystack supports multiple payment options including direct bank transfers, USSD codes (such as *737#), and card payments. This is highly beneficial in Nigeria, where bank transfers are the preferred transaction method for most digital shoppers.

Q: Are there additional fees when integrating Paystack with StartMessaging?

A: There are three separate costs. Paystack charges its own transaction fee (see Paystack’s pricing). StartMessaging charges only your plan and never charges per message: the Developer plan is free for 100 API messages a month, with paid sizes from ₹100/month; see pricing. Meta bills WhatsApp messages directly to your own WhatsApp Business Account at its published rates, using the payment method you add in WhatsApp Manager. Since 1 October 2026 Meta charges every delivered template message, including utility templates like these payment requests and receipts, even inside the 24-hour customer service window. Rates vary by country and category; see Meta’s rate card.

Q: Can I send dynamic payment links without a website or web server?

A: You will need a simple backend server or cloud function to handle the API calls to Paystack and StartMessaging. If you do not run a traditional server, you can deploy these functions serverless using platforms like AWS Lambda or Vercel Serverless Functions.

Q: How do I handle transactions that are not completed on Paystack?

A: Paystack handles the checkout interface and shows failure states directly to the customer. To follow up on links that were never paid, check the transaction with Paystack’s Verify Transaction endpoint (GET https://api.paystack.co/transaction/verify/:reference) after a set time, and if it is still unpaid, send a reminder template on WhatsApp.


Automating your payment flows using a whatsapp paystack integration minimises friction and optimises your invoicing process. By generating links on the fly, delivering them within chat, and verifying via webhooks, you create a seamless transaction experience for your customers. Start building by asking our sales team to open your workspace (with a 14-day Business trial), then connecting your WhatsApp Business Account and creating your templates. For every request field, see the Send Messages documentation.

S

StartMessaging Team

StartMessaging Team

Related posts