{"id":24529617,"url":"https://github.com/felixojiambo/mpesabridge","last_synced_at":"2026-04-11T17:43:03.740Z","repository":{"id":270689509,"uuid":"862768045","full_name":"felixojiambo/MpesaBridge","owner":"felixojiambo","description":"The project provides implementations for interacting with the Mpesa Daraja API, which is used for mobile money transactions in Kenya.","archived":false,"fork":false,"pushed_at":"2025-01-02T11:43:21.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T14:39:42.311Z","etag":null,"topics":["configuration","daraja-api","java","json","mongodb","mpesa","okttp3","payments","rest-api","spring","springboot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/felixojiambo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-25T06:51:34.000Z","updated_at":"2025-09-05T00:01:11.000Z","dependencies_parsed_at":"2025-01-02T12:45:36.730Z","dependency_job_id":null,"html_url":"https://github.com/felixojiambo/MpesaBridge","commit_stats":null,"previous_names":["felixojiambo/mpesabridge"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/felixojiambo/MpesaBridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixojiambo%2FMpesaBridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixojiambo%2FMpesaBridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixojiambo%2FMpesaBridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixojiambo%2FMpesaBridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felixojiambo","download_url":"https://codeload.github.com/felixojiambo/MpesaBridge/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixojiambo%2FMpesaBridge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31689762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T13:07:20.380Z","status":"ssl_error","status_checked_at":"2026-04-11T13:06:47.903Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","daraja-api","java","json","mongodb","mpesa","okttp3","payments","rest-api","spring","springboot"],"created_at":"2025-01-22T07:39:08.728Z","updated_at":"2026-04-11T17:43:03.721Z","avatar_url":"https://github.com/felixojiambo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Daraja API Integration\n\nThis project is a **Spring Boot** application designed to integrate with Safaricom's **Daraja API** for M-Pesa services. The application implements various M-Pesa services such as C2B (Customer to Business) transactions, B2C (Business to Customer) payments, STK Push, checking account balance, and transaction status queries.\n\n## Features\n\n- **Access Token Management**: Fetches and manages OAuth 2.0 tokens for authenticating M-Pesa API requests.\n- **Register URLs**: Registers confirmation and validation URLs for M-Pesa C2B transactions.\n- **Simulate C2B Transactions**: Simulates M-Pesa transactions for testing purposes.\n- **Perform B2C Transactions**: Processes business-to-customer payments.\n- **Transaction Status Query**: Fetches the status of M-Pesa transactions.\n- **STK Push**: Initiates an STK push for payments via M-Pesa.\n- **Check Account Balance**: Queries the account balance for the business shortcode.\n\n## Technologies Used\n\n- **Spring Boot**: The core framework for building the REST API.\n- **OkHttp**: A client for making HTTP requests to the M-Pesa Daraja API.\n- **Jackson**: For parsing JSON responses.\n- **Lombok**: To reduce boilerplate code (e.g., for logging).\n- **M-Pesa Daraja API**: Safaricom’s M-Pesa API for mobile money services.\n- **Maven**: For managing dependencies and building the project.\n\n## Prerequisites\n\n1. **Java 21** or higher installed.\n2. **Maven** installed.\n3. **M-Pesa Daraja API account** with valid credentials, including:\n   - Consumer Key\n   - Consumer Secret\n   - Shortcode\n   - B2C Initiator Name and Password\n   - Passkey for STK Push\n\n## Project Setup\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/felixojiambo/MpesaBridge.git\n   cd MpesaBridge\n   ```\n\n2. Configure the application by updating the `MpesaConfig` with your M-Pesa Daraja API credentials:\n\n   ```yaml\n   mpesa:\n     consumerKey: YOUR_CONSUMER_KEY\n     consumerSecret: YOUR_CONSUMER_SECRET\n     shortCode: YOUR_SHORT_CODE\n     b2cInitiatorName: YOUR_INITIATOR_NAME\n     b2cInitiatorPassword: YOUR_INITIATOR_PASSWORD\n     stkPushShortCode: YOUR_STK_SHORT_CODE\n     stkPassKey: YOUR_STK_PUSH_PASSKEY\n     oauthEndpoint: https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials\n     registerUrlEndpoint: https://sandbox.safaricom.co.ke/mpesa/c2b/v1/registerurl\n     simulateTransactionEndpoint: https://sandbox.safaricom.co.ke/mpesa/c2b/v1/simulate\n     b2cTransactionEndpoint: https://sandbox.safaricom.co.ke/mpesa/b2c/v1/paymentrequest\n     transactionResultUrl: https://sandbox.safaricom.co.ke/mpesa/transactionstatus/v1/query\n     checkAccountBalanceUrl: https://sandbox.safaricom.co.ke/mpesa/accountbalance/v1/query\n     stkPushRequestUrl: https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest\n     lnmQueryRequestUrl: https://sandbox.safaricom.co.ke/mpesa/stkpushquery/v1/query\n   ```\n\n3. Build the project using Maven:\n\n   ```bash\n   mvn clean install\n   ```\n\n4. Run the application:\n\n   ```bash\n   mvn spring-boot:run\n   ```\n\n## API Endpoints\n\n### Authentication\n\n- **Get Access Token**: Automatically managed by the service.\n\n### C2B (Customer to Business) Simulation\n\n- **URL**: `/mobile-money/c2b/simulate`\n- **Method**: POST\n- **Description**: Simulates a C2B transaction.\n- **Request Body**:\n  ```json\n  {\n    \"shortCode\": \"YOUR_SHORT_CODE\",\n    \"commandID\": \"CustomerPayBillOnline\",\n    \"amount\": 1000,\n    \"msisdn\": \"254708374149\",\n    \"billRefNumber\": \"12345678\"\n  }\n  ```\n\n### B2C (Business to Customer) Payments\n\n- **URL**: `/mobile-money/b2c/payment`\n- **Method**: POST\n- **Description**: Sends payments from the business to a customer.\n- **Request Body**:\n  ```json\n  {\n    \"amount\": 1000,\n    \"commandID\": \"BusinessPayment\",\n    \"partyB\": \"254708374149\",\n    \"remarks\": \"Payment\",\n    \"occassion\": \"Occasion\"\n  }\n  ```\n\n### STK Push\n\n- **URL**: `/mobile-money/stkpush`\n- **Method**: POST\n- **Description**: Initiates an STK push request for mobile payment.\n- **Request Body**:\n  ```json\n  {\n    \"amount\": 1000,\n    \"phoneNumber\": \"254708374149\"\n  }\n  ```\n\n### Transaction Status Query\n\n- **URL**: `/mobile-money/transactionstatus`\n- **Method**: POST\n- **Description**: Queries the status of a transaction.\n- **Request Body**:\n  ```json\n  {\n    \"transactionID\": \"ABC123DEF456\"\n  }\n  ```\n\n### Check Account Balance\n\n- **URL**: `/mobile-money/accountbalance`\n- **Method**: POST\n- **Description**: Fetches the business account balance.\n\n## Helper Utilities\n\n- **HelperUtility**: Utility class for encoding data and generating timestamps.\n- **Constants**: Contains static values for HTTP headers, M-Pesa command IDs, and identifiers.\n\n## Running Tests\n\nTo run unit tests:\n\n```bash\nmvn test\n```\n\n## Logging\n\nThe application uses Lombok’s `@Slf4j` annotation for logging various events such as transaction failures, access token issues, and request/response details.\n\n## Contributing\n\nFeel free to fork the repository and submit pull requests for any bug fixes or feature enhancements.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixojiambo%2Fmpesabridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelixojiambo%2Fmpesabridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixojiambo%2Fmpesabridge/lists"}