Getting Started
Prerequisites
Before you begin setting up your development environment, ensure that you have the following prerequisites installed:
-
Android Studio Arctic Fox or later: This is the official Integrated Development Environment (IDE) for Android development, providing all the necessary tools to build, test, and debug Android applications. Make sure to keep it updated to leverage the latest features and improvements.
-
OpenJDK 17: Ensure that you have OpenJDK 17 installed and configured in Android Studio. This version is required for compiling and running the project. You can download OpenJDK from the Adoptium or OpenJDK websites.
Kotlin Style
To maintain consistent code formatting and style across the project, follow these steps to configure Android Studio:
-
Install and Configure the ktfmt Plugin:
- Go to Android Studio's
Settings
(orPreferences
on macOS). - Select the
Plugins
category, click theMarketplace
tab, search for thektfmt
plugin, and click theInstall
button. - After installation, navigate to
Editor
→ktfmt Settings
, tickEnable ktfmt
, change theCode style
toGoogle (Internal)
, and clickOK
.
- Go to Android Studio's
-
Set Indentation to 2 Spaces:
- In Android Studio's
Settings
(orPreferences
), go toEditor
→Code Style
→Kotlin
→Tabs and Indents
. - Set
Tab size
,Indent
, andContinuation indent
to2
, and clickOK
.
- In Android Studio's
-
Use Single Name Imports Sorted Lexicographically:
- In Android Studio's
Settings
(orPreferences
), go toEditor
→Code Style
→Kotlin
→Imports
. - In the
Top-level Symbols
andJava statics and Enum Members
sections, select theUse single name import
option. - Remove all rules in the
Packages to Use Imports with '*'
andImport Layout
sections, then clickOK
.
- In Android Studio's
After completing these steps, you can format your code by going to Code
→ Reformat Code
, or by pressing Ctrl+Alt+L
(or ⌘+⌥+L
for Mac).
Note: While these settings help maintain code quality, you can also rely on the Spotless plugin to format any code you want to push. For more details on Spotless, refer to the relevant documentation.
Build Setup
Follow these steps to set up the project for development:
-
Clone the Repository:
- Begin by cloning this repository to your local machine. Ensure you have OpenJDK 17 installed and configured in Android Studio to use the OpenJDK 17 JDK for this project. You can clone the repository using the following command:
git clone https://github.com/re-kast/android-mtn-momo-api-sdk.git
- Begin by cloning this repository to your local machine. Ensure you have OpenJDK 17 installed and configured in Android Studio to use the OpenJDK 17 JDK for this project. You can clone the repository using the following command:
-
Update the
local.properties
File:- Provide the required properties for the SDK and Sample App to run by updating the
local.properties
file. Here’s an example configuration:
infoImportant Note: Ensure that all entries in the
local.properties
file are filled out correctly. The application will fail to compile if any required entries are missing. Double-check your configuration to avoid compilation errors. For more information on how to find the different keys, read more here.# Local properties for the MTN MOMO API SDK
MOMO_BASE_URL="" ## Use https://sandbox.momodeveloper.mtn.com for sandbox and https://momodeveloper.mtn.com for production
MOMO_COLLECTION_PRIMARY_KEY="" ## The collection endpoint/product subscription primary key
MOMO_COLLECTION_SECONDARY_KEY="" ## The collection endpoint/product subscription secondary key
MOMO_REMITTANCE_PRIMARY_KEY="" ## The remittance endpoint/product subscription primary key
MOMO_REMITTANCE_SECONDARY_KEY="" ## The remittance endpoint/product subscription secondary key
MOMO_DISBURSEMENTS_PRIMARY_KEY="" ## The disbursements endpoint/product subscription primary key
MOMO_DISBURSEMENTS_SECONDARY_KEY="" ## The disbursements endpoint/product subscription secondary key
MOMO_API_USER_ID="" ## The sandbox API user ID. You can use a [UUID generator](https://www.uuidgenerator.net/version4) to create one
MOMO_ENVIRONMENT="" ## API environment, use 'sandbox' for testing and 'production' for live operations
MOMO_API_VERSION_V1="" ## The API version for v1 endpoints, use 'v1_0' for sandbox and 'v1' for production
MOMO_API_VERSION_V2="" ## The API version for v2 endpoints, use 'v2_0' for sandbox and 'v2' for productionFinding the Subscription DetailsYou can find all the subscription keys from the MTN MOMO Developer account. Please sign up by visiting MTN MOMO Developer. Once there, navigate to your profile and check the subscriptions section. Below is an image of how the section would look:
- Provide the required properties for the SDK and Sample App to run by updating the
-
Sync the Project:
- Sync the project via the Android Studio IDE to download all necessary dependencies. For more information on syncing, read more here.
-
Run the Sample App:
- Once all dependencies are downloaded, you can run the sample app from the Android Studio run menu to test the integration and functionality of the MTN MOMO API SDK.
By following these steps, you will have a fully set up development environment ready for building and testing applications that utilize the MTN MOMO API SDK.
Application Architecture
The MTN MOMO SDK is based on the MVVM (Model-View-ViewModel) Android application architecture. This architecture promotes a clear separation of concerns, making the codebase more manageable and testable. It also follows the recommended Repository Pattern on its data layer, which helps in abstracting data sources and providing a clean API for data access.
At the core is the Android FHIR SDK, which provides various APIs, including Data Access API, Search API, Sync API, Smart Guidelines API, and Data Capture API.
Project Structure
The project currently consists of an application module (sample
) and two Android library modules (momo-api-sdk
). This modular structure allows for better organization of code and easier maintenance.