Skip to content

Safaricom mobile banking 'MPESA' SDK implementation for .NET.

License

Notifications You must be signed in to change notification settings

mutiadavid/MpesaSDK.NET

Repository files navigation

MpesaSDK.NET

Mpesa Daraja SDK implementation for .net.

Build Status Nuget Nuget

For More Info check Safaricom Mpesa Documentation

Download and Install

nugget install

Usage

Sending Requests


Mpesa Client
using MpesaSDK.NET.Dtos.InitiateRequests;
using MpesaSDK.NET.Dtos.Responses;
using MpesaSDK.NET.Enums;
...
//http client
 using HttpClient client = new() { Timeout = TimeSpan.FromSeconds(10) };
//mpesa client
 MpesaClient mpesaClient = new MpesaClient(client, new MpesaClientOptions
 {
     ConsumerKey = "your-consumerkey",
     ConsumerSecret = "your-consumer-secret",
     IsSandBox = true /* change this flag to false if Production */ 
 });
STK Push request
var result = await mpesaclient.STKPushAsync(...);
Stk Push Query request
var result = await mpesaclient.StkPushQueryAsync(...);
B2C request
var result = await mpesaclient.B2CAsync(...);
B2B request
var result = await mpesaclient.B2BAsync(...);

To get MPesa Security credetials for both B2B and B2C use method below.

string credential = "pass".ToMpesaSecurityCredential(); 
C2B Register Url request
var result = await mpesaclient.C2BRegisterUrlAsync(...);
C2B Simulate Transaction request
var result = await mpesaclient.C2BSimulateTransactionAsync(...);
Account Balance request
var result = await mpesaclient.AccountBalanceAsync(...);
Transaction Status request
var result = await mpesaclient.TransactionStatusAsync(...);
Reversal request
var result = await mpesaclient.ReversalAsync(...);

Callback server


Check sample callback api MpesaSDK.NET.CallbackAPI

Docs to be updated soon.

LICENSE

Apache LICENSE-2.0 read more