Skip to content

A complete MPESA DARAJA API intergration of C2B, B2C, TransactionStatus & AccountBalance Requests

License

Notifications You must be signed in to change notification settings

L00P3R93/daraja-mpesa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

M-PESA DARAJA API Package

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

This is a PHP package for the Safaricom's M-Pesa Daraja API.

Installations

This project supports both composer dependency management tool and can also be used without composer

Using Composer

  1. Run the following command
composer require sntaks/daraja-mpesa

Without composer

  1. Download the source code as zipped

  2. Follow the following directions

<?php

use PP\Mpesa\Init as Mpesa;
  1. Check the following example for usage example/mpesa.php

Configuration

The library comes with a structured config file based on the API that you intend to use.

To add the necessary configurations:-

  1. Open the folder installation.

  2. Look for a file named config/conf.php

  3. Edit the necessary keys that reflects the product you are using.

Usage

<?php

use PP\Mpesa\Init as Mpesa;
$mpesa = new Mpesa();

try {

    // B2C Payment Request User Params
    $user_params = [
        'Amount' => 10,
        'PartyB' => 'xxx',
        'Remarks' => 'Test Business Payment'
    ];

    //Initiate B2C Payment Request
    $response = $mpesa->b2c($user_params);

    //Requests Account Balance
    $response = $mpesa->b2c_account_balance();
    $response = $mpesa->c2b_account_balance();

    // B2C Payment Transaction Status User Params
    $user_params = [
        'TransactionID' => 'xxxx'
    ];

    // B2C Payment Transaction Status Request
    $response = $mpesa->b2c_transaction_status($user_params);

    //C2B Register Endpoints
    $response_register = $mpesa->c2b();
}catch(\Exception $e){
    $response = json_decode($e->getMessage());
}

header('Content-Type: application/json');
echo json_encode($response);

Support

Need support using this package:- Send a quick message here

API's Supported

The library implements all the exposed endpoints by Safaricom as listed below:-

    What it is?

The Lipa na M-Pesa Online Payment endpoint(STK push) allows you to request payment from your users/clients. With this endpoint all the user is required to do is input their M-PESA pin to a prompt to send a payment to you.

    How to implement it?

Read docs here.

    What it is?

When you request payment from your users/clients via Lipa na M-Pesa Online endpoint above you might want to know the status of that request. This endpoint facilitates that. It allows you to query the status of any STK push on demand.

    How to implement it?

Read docs here.

3. C2B

    What it is?

This endpoint enables developers to receive real time notifications when a client makes a payments to a merchant's Till number or Paybill number. It assumes the payment are made via the SIM card toolkit and as a developer you need to know when that payment hits the merchants till/paybill number for reconciliation and accounting purposes.

    How to implement it?

Read docs here.

4. B2C

    What it is?

This endpoints enables merchants to pay their customers from they paybill account. Some of the use cases are but not limited to paying salaries, paying promotions to customers etc.

    How to implement it?

Read docs here.

    What it is?

This endpoint enables developers to initiate status check of a B2B, B2C and C2B transactions. It really comes in handy where one party in a transactions fails/claims not to have received an acknowledgment for a transaction.

    How to implement it?

Read docs here.

    What it is?

This endpoint enables merchants to query their Till/Paybill numbers account balance on demand.

    How to implement it?

Read docs here.

License

The M-Pesa Package is open-sourced software licensed under the GNU license.

About

A complete MPESA DARAJA API intergration of C2B, B2C, TransactionStatus & AccountBalance Requests

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages