mpesa_sdk_dart

Last updated:

0 purchases

mpesa_sdk_dart Image
mpesa_sdk_dart Images
Add to Cart

Description:

mpesa sdk dart

mpesa_sdk_dart #



Dart package for M-Pesa API (Mozambique)
Ready Methods/APIs

✅ C2B
✅ B2B
✅ B2C
✅ TRANSACTION STATUS
✅ REVERSAL

Requisites #
We highly recommend reading Mpesa API docs first!
You Will need a few things from there before development.

Api Key
Public Key


Login or Register as a M-Pesa developer here if you haven't.
You will be issued with an API Key and a Public Key. You will use these to generate your access token.

Usage #
Add dependency in pubspec.yaml
dependencies:
mpesa_sdk_dart: <latest_version>
copied to clipboard
Import in your Flutter app or plain dart app.
import 'package:mpesa_sdk_dart/mpesa_sdk_dart.dart';
copied to clipboard
Generate a token #
String token = MpesaConfig.getBearerToken(
'API_KEY_HERE',
'PUBLIC_KEY_HERE',
);
copied to clipboard
C2B Api Call #
Initialize your payload
PaymentRequest payload = PaymentRequest(
inputTransactionReference: 'inputTransactionReference',
inputCustomerMsisdn: '25884xxxxxxx',
inputAmount: inputAmount,
inputThirdPartyReference: 'inputThirdPartyReference',
inputServiceProviderCode: 'inputServiceProviderCode',
);
copied to clipboard
Perform the api call
MpesaTransaction.c2b(token, apiHost, payload);
copied to clipboard
B2C Api Call #
Initialize your payload
PaymentRequest payload = PaymentRequest(
inputTransactionReference: 'inputTransactionReference',
inputCustomerMsisdn: '25884xxxxxxx',
inputAmount: inputAmount,
inputThirdPartyReference: 'inputThirdPartyReference',
inputServiceProviderCode: 'inputServiceProviderCode',
);
copied to clipboard
Perform the api call
MpesaTransaction.b2c(token, apiHost, payload);
copied to clipboard
Reversal Api Call #
Initialize your payload
ReversalRequest payload = ReversalRequest(
inputTransactionID: 'input_TransactionID',
inputSecurityCredential: 'input_SecurityCredential',
inputInitiatorIdentifier: 'input_InitiatorIdentifier',
inputThirdPartyReference: 'input_ThirdPartyReference',
inputServiceProviderCode: 'input_ServiceProviderCode',
inputReversalAmount: montant, // Optional
);
copied to clipboard
Perform the api call
MpesaTransaction.reversal(token, apiHost, payload);
copied to clipboard
B2B Api Call #
Initialize your payload
TransferRequest payload = TransferRequest(
inputTransactionReference: 'input_TransactionReference',
inputAmount: inputAmount,
inputThirdPartyReference: 'input_ThirdPartyReference',
inputPrimaryPartyCode: 'input_PrimaryPartyCode',
inputReceiverPartyCode: 'input_ReceiverPartyCode',
);
copied to clipboard
Perform the api call
MpesaTransaction.b2b(token, apiHost, payload);
copied to clipboard
Query Transaction Status Api Call #
Perform the api call
MpesaTransaction.getTransactionStatus(
token,
apiHost,
'input_ThirdPartyReference',
'input_QueryReference',
'input_ServiceProviderCode',
);
copied to clipboard
Handle Response #
All transaction methods returned an http response. So what you have to do is assign your call to a property of type Response (From http package). Note that this is an async task.
Response response = await MpesaTransaction.c2b(token, apiHost, payload);
print(response.body);

if(response.statusCode == 201) { // if is resource created!
// Do something!
}
copied to clipboard
Copyright and license #
MIT License
Copyright (c) 2020-2021 Ergito Vilanculos
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.