How to Set Up IntaSend Payment Integration and Confirm Payments

intasend payment integration step by step guide

Mobile payments are the backbone of most businesses in Kenya today, and Intasend payment integration with M-Pesa is one of the easiest ways to collect and confirm payments from customers.

If you’re building an e-commerce website, a billing platform, or even a donation page, IntaSend provides a simple and secure way to handle M-Pesa payments in PHP.

In this article, we’ll walk you through the main steps of integrating IntaSend M-Pesa STK Push in PHP. We’ll also explain how webhooks confirm payments, what you need to do to avoid failures, and share a live demo that you can test today.

1. Set Up Your Development Environment

Before starting, ensure you have:

  • XAMPP installed (for PHP, Apache, and MySQL)

  • Composer (to install the IntaSend SDK)

  • MySQL Database (to store payment transactions)

  • An IntaSend account (sandbox for testing, live for production)

2. Generate IntaSend API Credentials

From your IntaSend dashboard:

  • Get your Publishable Key

  • Get your Secret Token

  • Set whether you’re using sandbox (testing) or live (production)

 Always double-check credentials. Using the wrong ones is a common cause of payment failures.

For best practice, store them securely in a .env file instead of hardcoding.

3. Initiating the STK Push

When a customer enters their phone number and amount, your system:

  1. Sends a request to IntaSend using the publishable key and secret token.

  2. IntaSend generates an Invoice ID for that transaction.

  3. The customer receives the M-Pesa pop-up (STK Push) on their phone.

  4. They enter their PIN and complete the payment.

  5. Your system records the transaction in the database with the Invoice ID and sets the status as pending.

4. Setting Up the Webhook

The webhook is critical for confirming payments. Without it, your system won’t know if a customer actually paid.

  • Go to your IntaSend dashboard → Webhooks

  • Add your webhook URL (e.g., https://yourdomain.com/webhook.php)

  • Also, set a challenge token.

Why the Challenge Token?

This acts like a password between your system and IntaSend. Your webhook must check that the token from IntaSend matches the one you set; otherwise, it should reject the request. This prevents fake or malicious webhook calls.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

5. How the Webhook Updates the Database

Here’s the flow once payment is made:

  1. Customer initiates STK push → transaction saved with Invoice ID = pending.

  2. IntaSend webhook sends a notification to your server.

  3. Your webhook script checks the challenge token for security.

  4. If valid, it updates the database record linked to that Invoice ID.

    • If successful → status changes to completed.

    • If failed → status changes to failed.

This ensures your database always reflects the true state of the payment.

6. Confirming Payment on Your Page

Your web page (e.g., checkout or donation page) simply queries the database for the Invoice ID:

  • If still pending → “Waiting for payment…”

  • If completed → “Payment successful!”

  • If failed → “Payment failed, please try again.”

This avoids unnecessary API calls and keeps your system efficient.

Common Mistakes to Avoid

  • Wrong Credentials: Always use the correct publishable key & secret token (sandbox for testing, live for production).

  • Webhook Not Configured: Payments won’t confirm without a working webhook.

  • Challenge Token Not Matching: Make sure the challenge token in your IntaSend dashboard is the same one in your webhook code.

  • Database Not Updating: Always confirm your webhook is actually writing updates into the database.

Live Demo

We’ve built a working demo using IntaSend that you can test right now:

👉 BulkLookup Payment Demo

Here you can try making a test payment and see how the system handles the flow from STK Push to confirmation.

Our IntaSend Payment Integration Services

At ProKenyan Developers, we provide full IntaSend M-Pesa payment integration for just Ksh 10,000.

This includes:

  • Setting up your credentials securely

  • Database design for payments

  • STK Push request flow

  • Webhook integration with challenge token security

  • Full live testing

  • Deployment to your production server

If you’d like this done professionally, contact us today, and we’ll set up your payment system.

Leave a Comment

Your email address will not be published. Required fields are marked *