PHPackages                             codenson/daraja-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. codenson/daraja-api

ActiveLibrary[API Development](/categories/api)

codenson/daraja-api
===================

A Laravel package for integrating with the M-PESA Daraja API.

v1.1.1(2mo ago)016MITPHP ^8.0|^8.1|^8.2|^8.3

Since May 22Compare

[ Source](https://github.com/KIMGITO/DARAJA-API)[ Packagist](https://packagist.org/packages/codenson/daraja-api)[ RSS](/packages/codenson-daraja-api/feed)WikiDiscussions Synced 3w ago

READMEChangelog (1)Dependencies (4)Versions (12)Used By (0)

Laravel Daraja Package
======================

[](#laravel-daraja-package)

A comprehensive Laravel package for Safaricom Daraja APIs - Complete M-PESA integration made easy.

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [Features](#Features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage Examples](#usage-examples)
    - [Authentication](#authentication)
    - [M-Pesa Express (STK Push)](#m-pesa-express-stk-push)
    - [Customer to Business (C2B)](#customer-to-business-c2b)
    - [Business to Customer (B2C)](#business-to-customer-b2c)
    - [Transaction Status](#transaction-status)
    - [Account Balance](#account-balance)
    - [Transaction Reversal](#transaction-reversal)
    - [Tax Remittance](#tax-remittance)
    - [Business PayBill](#business-paybill)
    - [Business Buy Goods](#business-buy-goods)
    - [Bill Manager](#bill-manager)
    - [B2B Express Checkout](#b2b-express-checkout)
    - [Pull Transactions](#pull-transactions)
    - [Business to Pochi (B2Pochi)](#business-to-pochi-b2pochi)
    - [IMSI Verification](#imsi-verification-sim-swap-detection)
    - [Lipa na Bonga Points](#lipa-na-bonga-points)
    - [B2C Account Top Up](#b2c-account-top-up)
    - [M-Pesa Ratiba (Standing Orders)](#m-pesa-ratiba-standing-orders)
    - [Dynamic QR Code](#dynamic-qr-code)
- [Webhook Handling](#webhook-handling)
- [Error Handling](#error-handling)
- [Testing](#testing)
- [License](#license)

✨ Features
----------

[](#-features)

- ✅ OAuth Authentication with automatic token caching
- ✅ M-Pesa Express (STK Push) with query capability
- ✅ Customer to Business (C2B) with URL registration
- ✅ Business to Customer (B2C) payments
- ✅ Transaction Status Query
- ✅ Account Balance Enquiry
- ✅ Reversal API
- ✅ Tax Remittance to KRA
- ✅ Business PayBill
- ✅ Business Buy Goods
- ✅ Bill Manager (create/update bills)
- ✅ B2B Express Checkout (USSD Push to till)
- ✅ Pull Transactions (reconciliation)
- ✅ Business to Pochi (Micro SME wallet)
- ✅ IMSI Verification (SIM Swap Detection)
- ✅ Lipa na Bonga Points
- ✅ B2C Account Top Up
- ✅ M-Pesa Ratiba (Standing Orders)
- ✅ Dynamic QR Code Generation
- ✅ Sandbox &amp; Production support
- ✅ Database migration for transaction logging

📦 Requirements
--------------

[](#-requirements)

- PHP 8.0 or higher
- Laravel 9.x, or higher
- Guzzle HTTP Client

🔧 Installation
--------------

[](#-installation)

```
composer require codenson/laravel-daraja

php artisan codenson:install
```

⚙️ Configuration
----------------

[](#️-configuration)

```
# API Environment (sandbox or production)
MPESA_ENVIRONMENT=sandbox

# API Credentials
MPESA_CONSUMER_KEY=your_consumer_key
MPESA_CONSUMER_SECRET=your_consumer_secret

# Business Details
MPESA_SHORTCODE=174379
MPESA_PASSKEY=your_passkey
MPESA_TILL_NUMBER=your_till_number
MPESA_PAYBILL=your_paybill_number

# Initiator Credentials
MPESA_INITIATOR_NAME=your_initiator_name
MPESA_INITIATOR_PASSWORD=your_initiator_password
MPESA_SECURITY_CREDENTIAL=your_security_credential

# Callback URLs
MPESA_STK_CALLBACK_URL=https://your-domain.com/api/mpesa/stk-callback
MPESA_C2B_CONFIRMATION_URL=https://your-domain.com/api/mpesa/c2b-confirmation
MPESA_C2B_VALIDATION_URL=https://your-domain.com/api/mpesa/c2b-validation
MPESA_B2C_TIMEOUT_URL=https://your-domain.com/api/mpesa/b2c-timeout
MPESA_B2C_RESULT_URL=https://your-domain.com/api/mpesa/b2c-result

# Optional
MPESA_LOGGING=true
MPESA_TIMEOUT=30
```

🚀 Usage Examples
----------------

[](#-usage-examples)

```
