mpesa-system
This is a RESTful Actix Web API that connects to MySQL database. It integrates with Safaricom M-Pesa Mobile Money Payment Gateway (i.e exposed API endpoints for accessing M-Pesa services by Kenyan Telco called "Safaricom") and enables customers to transfer money and pay for utilities like water, PayTv, electricity from their phone wallets. The Kenyan Telco "Safaricom" has provided M-Pesa API endpoints for B2C, C2B and B2B (https://developer.safaricom.co.ke/Documentation).
Currently this RESTful API supports:
- Customer to Business
- Generate an OAuth Access Token
- Register C2B Confirmation and Validation URLs
The RESTful Actix Web API has below listed dependencies:
- Actix Web web framework for Rust
- Serde for serializing and deserializing Rust data structures
- Reqwest Rust HTTP Client
- MySQL MySQL database server
- mysql MySql database driver
Instructions
NOTE:
You may need to ensure that you are running the commands with the correct MySQL user/password.
-
Access MySQL Server
Log in to the MySQL Server using a user account that has the CREATE DATABASE privilege.
-
Create database
CREATE DATABASE my_mpesa;
-
Create tables in the database
Directory "mysql\sql" contains below listed ".sql" files:
- *.sql
Copy the contents of each of the ".sql" and execute them separately on MySQL Server. This will create tables/stored procedures in the database.
-
Create
.env
file:SERVER_ADDR=127.0.0.1:8080 MYSQL_USER=XXX MYSQL_PASSWORD=XXX MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_DBNAME=my_mpesa
Update "MYSQL_USER" and "MYSQL_PASSWORD" values with the correct MySQL user/password. If your password contains dollar sign "$", then remember to escape it eg "123$abc" will need to be changed to "123\$abc"
-
Run the server:
cargo run
-
Using a different terminal send an HTTP GET/POST requests to the running server:
Directory "mysql\apis" contains below listed api's files:
- generateauth.txt
- registerclienturls.txt
- validationc2b.txt
- confirmationc2b.txt
Copy the curl request on each of the ".txt" and execute them on separate terminals. Each ".txt" contains curl request and expected json reponse data.