API Print

  • 27

Overview

This document is intended for customers of Kenpesa application only. You integrate MPESA with you custom made website using this HTTP API.

 1. HTTP API

This HTTP API supports the below things.

  • Validating MPESA transaction sent to a Pay bill A/C or Lipa Na MPESA

 

URL:

You will call the below URL using POST or GET method.

 Compulsory Parameter Description

          1) action = the action to be executed

          2) mpesa_code = the unique MPESA transaction ID

Request Parameters specifications

Parameter

Description

action

the action to be executed.

-      validate used to query the transaction details

-      close  used to update the transactions status to close

mpesa_code

the unique MPESA transaction ID

 

Response Parameters specifications

Key

Example value

Notes

id

12345678

A unique identifier for the notification (not the transaction).

orig

MPESA

 

dest

254706xxxx

Merchant’s business terminal phone number.

tstamp

2014-11-10 13:34:26

When the notification was sent by Safaricom.

customer_id

1234

An internal ID associated with the Merchant’s account.

mpesa_code

A123B456C

A unique identifier for the transaction.

mpesa_acc

ACCOUNT

Account entered by sender.

mpesa_msisdn

0726872512

Sender’s phone number.

mpesa_trx_date

10/11/14

Date of the transaction.

mpesa_trx_time

1:33 PM

Time of the transaction.

mpesa_amt

1000.00

Amount in KSh.

mpesa_sender

JOHN SMITH

The registered name of the sender.

business_number

123456

Merchant’s PayBill number.

  Example to call HTTP API:

 


$mpesa_code = 'GQ33AB533';
$action = 'validate';

$url = 'https://www.enetonlinesolutions.co.ke/portal/clients/modules/addons/kenpesapb/api.php';
$qry_str = "?action={$action}&mpesa_code={$mpesa_code}";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url.$qry_str);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);

$response = curl_exec ($ch);

curl_close ($ch);



$data = json_decode($response);



if ($data->success = 1){	
	$id = $data->message->id;

	$orig = $data->message->orig;
	$dest = $data->message->dest;
	$tstamp = $data->message->tstamp;
	$mpesa_code = $data->message->mpesa_code;
	$mpesa_acc = $data->message->mpesa_acc;
	$mpesa_msisdn = $data->message->mpesa_msisdn;
	$mpesa_trx_date = $data->message->mpesa_trx_date;
	$mpesa_trx_time = $data->message->mpesa_trx_time;
	$mpesa_amt = $data->message->mpesa_amt;
	$mpesa_sender = $data->message->mpesa_sender;
	$status = $data->message->status;
	$invoiceid = $data->message->invoiceid;
	$archivedate = $data->message->archivedate;
	
	if($status == 'Open'){
		//transaction is valid
	}else{
		//transaction not valid
	}
	
}else{
	$error_desc = $data->message;
}



 You will receive below json encoded response if transaction was found.

 

{"success":1,"message":{"id":"90616622","orig":"MPESA","dest":"254700371562","tstamp":"2015-03-14 11:30:13","mpesa_code":"GQ33AB533","mpesa_acc":"0","mpesa_msisdn":"254722917455","mpesa_trx_date":"14\/3\/15","mpesa_trx_time":"11:30","mpesa_amt":"10","mpesa_sender":"EMMANUEL MBITHI","status":"Open","invoiceid":"0","archivedate":"0000-00-00 00:00:00"}}

 You will receive below json encoded response if transaction was not found.

 

{"success":0,"message":"Invalid transaction code"}

 Other responses

Missing MPESA Transactions

{"success":0,"message":"Missing mpesa code parameter"}
Missing MPESA Transactions
{"success":0,"message":"Missing action parameter"}

Was this answer helpful?

« Back