Class Api
Contains the main api calls and extra utils
Inheritance
Inherited Members
Namespace: System.Dynamic.ExpandoObject
Assembly: cs.temp.dll.dll
Syntax
public class Api
Constructors
Api(Api.Env, String, String, Api.ExtraConfig)
Initializes a new instance of the Api class.
Declaration
public Api(Api.Env env, string consumerKey, string consumerSecret, Api.ExtraConfig config = null)
Parameters
Api.Env
env
Env. |
System.String
consumerKey
Consumer key. |
System.String
consumerSecret
Consumer secret. |
Api.ExtraConfig
config
Configuration for LNM, Security credentials etc. |
Examples
Api mpesa = new Api(Env.Sandbox, "Key", "Secret", null);
Methods
AccountBalance(IdentityParty, String, String, String)
Accounts the balance.
Declaration
public Task<IRestResponse<AccountBalanceResponse>> AccountBalance(IdentityParty partyA, string queueUrl, string resultUrl, string remarks = "Checking account balance")
Parameters
IdentityParty
partyA
The account you are checking balance for |
System.String
queueUrl
Queue URL. |
System.String
resultUrl
Result URL. |
System.String
remarks
Remarks. |
Returns
System.Threading.Tasks.Task<IRestResponse<AccountBalanceResponse>>
The balance awaitable. |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var accountyParty = new IdentityParty(configs.ShortCode, IdentityParty.IdentifierType.SHORTCODE);
var res = await mpesa.AccountBalance(partyA
, queueUrl
, resultUrl
);
var transactionId = res.Data.ConversationID;
Auth()
OAuth.
Declaration
public IRestResponse<AuthResponse> Auth()
Returns
IRestResponse<AuthResponse>
The Creds. |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var token = mpesa.Auth().Data.AccessToken
AuthAsync()
Async OAuth.
Declaration
public Task<IRestResponse<AuthResponse>> AuthAsync()
Returns
System.Threading.Tasks.Task<IRestResponse<AuthResponse>>
The credentials awaitable. |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var res = await mpesa.AuthAsync();
var token = res.Data.AccessToken
B2B(IdentityParty, Int32, String, String, CommandID, String, String)
Business to Business Mpesa transaction
Declaration
public Task<IRestResponse<B2BResponse>> B2B(IdentityParty receiverParty, int amount, string queueUrl, string resultUrl, CommandID commandId = null, string remarks = "B2B Payment", string accountRef = null)
Parameters
IdentityParty
receiverParty
Receiver party. |
System.Int32
amount
Amount. |
System.String
queueUrl
Queue URL. |
System.String
resultUrl
Result URL. |
CommandID
commandId
Command identifier. |
System.String
remarks
Remarks. |
System.String
accountRef
Account reference. |
Returns
System.Threading.Tasks.Task<IRestResponse<B2BResponse>>
The Status |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var receiverParty = new IdentityParty(600111, IdentityParty.IdentifierType.SHORTCODE);
var res = await mpesa.B2B(receiverParty
, amount
, queueUrl
, resultUrl
);
var transactionId = res.Data.ConversationID;
B2C(Int64, Int32, String, String, CommandID, String, String)
Business to Customer Mpesa Transaction
Declaration
public Task<IRestResponse<B2CResponse>> B2C(long msisdn, int amount, string queueUrl, string resultUrl, CommandID commandId = null, string remarks = "B2C Payment", string occasion = "None")
Parameters
System.Int64
msisdn
Msisdn. |
System.Int32
amount
Amount. |
System.String
queueUrl
Queue URL. |
System.String
resultUrl
Result URL. |
CommandID
commandId
Command identifier. |
System.String
remarks
Remarks. |
System.String
occasion
Occasion. |
Returns
System.Threading.Tasks.Task<IRestResponse<B2CResponse>>
The transaction status |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var res = await mpesa.B2C(msisdn, 100, queueURL, resultURL);
var transactionId = res.Data.ConversationID;
C2BRegister(String, String)
C2B Register URL.
Declaration
public Task<IRestResponse<C2BRegisterResponse>> C2BRegister(string confirmationURL, string validationURL)
Parameters
System.String
confirmationURL
The Confirmation URL. |
System.String
validationURL
The Validation URL |
Returns
System.Threading.Tasks.Task<IRestResponse<C2BRegisterResponse>>
The acknowledgement. |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var res = await mpesa.C2BRegister(confirmationURL
, validationURL
)
var transactionId = res.Data.ConversationID;
C2BSimulate(Int64, Int32, String, CommandID)
Customer to Business Transaction Simulation
Declaration
public Task<IRestResponse<C2BSimulateResponse>> C2BSimulate(long msisdn, int amount, string billRefNumber, CommandID commandId = null)
Parameters
System.Int64
msisdn
Msisdn. |
System.Int32
amount
Amount. |
System.String
billRefNumber
Bill reference number. |
CommandID
commandId
Command identifier. |
Returns
System.Threading.Tasks.Task<IRestResponse<C2BSimulateResponse>>
The status. |
Remarks
Since Mpesa transactions may be triggered from the users STK menu, this is used in Sandbox to simulate that transaction
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var res = await mpesa.C2BSimulate(msisdn, 100, "Sample Ref");
var transactionId = res.Data.ConversationID;
GetSecurityCredential()
Gets the security credential.
Declaration
protected string GetSecurityCredential()
Returns
System.String
The security credential. |
LipaNaMpesaOnline(Int64, Int32, String, String, String)
Lipa na mpesa online.
Declaration
public Task<IRestResponse<LNMPaymentResponse>> LipaNaMpesaOnline(long senderMsisdn, int amount, string callbackUrl, string accountRef, string transactionDesc = "Lipa na mpesa online")
Parameters
System.Int64
senderMsisdn
Sender msisdn. |
System.Int32
amount
Amount. |
System.String
callbackUrl
Callback URL. |
System.String
accountRef
Account reference. |
System.String
transactionDesc
Transaction desc. |
Returns
System.Threading.Tasks.Task<IRestResponse<LNMPaymentResponse>>
The Transaction Status. |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var res = await mpesa.LipaNaMpesaOnline(msisdn, 100, callbackURL, "Some Ref");
var transactionId = res.Data.CheckoutRequestID;
LipaNaMpesaQuery(String)
Lipa na mpesa query.
Declaration
public Task<IRestResponse<LNMQueryResponse>> LipaNaMpesaQuery(string checkoutRequestId)
Parameters
System.String
checkoutRequestId
Checkout request identifier. |
Returns
System.Threading.Tasks.Task<IRestResponse<LNMQueryResponse>>
The transaction rtesult |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var res = await mpesa.LipaNaMpesaQuery(checkoutId);
var transactionId = res.Data.ConversationID;
ReversalRequest(String, Int32, String, String, String, String)
Reverses a request.
Declaration
public Task<IRestResponse<ReversalResponse>> ReversalRequest(string transactionId, int amount, string queueUrl, string resultUrl, string remarks = "Reversal", string occasion = "Reversal")
Parameters
System.String
transactionId
Transaction identifier. |
System.Int32
amount
Amount. |
System.String
queueUrl
Queue URL. |
System.String
resultUrl
Result URL. |
System.String
remarks
Remarks. |
System.String
occasion
Occasion. |
Returns
System.Threading.Tasks.Task<IRestResponse<ReversalResponse>>
The request status. |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var res = await mpesa.ReversalRequest("LKXXXX1234", 100, queueUrl, resultUrl );
var transactionId = res.Data.ConversationID;
TransactionStatus(String, String, String, String, String)
Gets a transaction status.
Declaration
public Task<IRestResponse<TransactionStatusResponse>> TransactionStatus(string transactionId, string queueUrl, string resultUrl, string remarks = "TransactionReversal", string occasion = "TransactionReversal")
Parameters
System.String
transactionId
Transaction identifier. |
System.String
queueUrl
Queue URL. |
System.String
resultUrl
Result URL. |
System.String
remarks
Remarks. |
System.String
occasion
Occasion. |
Returns
System.Threading.Tasks.Task<IRestResponse<TransactionStatusResponse>>
The status |
Examples
Api mpesa = new Api(Env.Sandbox, "consumerKey", "consumerSecret", configs);
var res = await mpesa.TransactionStatus("LKXXXX1234", queueUrl, resultUrl );
var transactionId = res.Data.ConversationID;