MOMO.rs is a Rust library for the MOMO payment gateway.
Installation
[]
= "0.1.4"
or you can use cargo add
cargo add mtnmomo
MTN Mobile Money API
This package provides for an easy way to connect to MTN MoMo API, it provides for the following products:
- Collection
- Disbursements
- Remittance
- Provisioning in case of sandbox environment
how to use:
use Momo;
use Uuid;
use dotenv;
use env;
async
After initializing the Momo struct, you can then use the collection, disbursement or remittance methods to initialize the respective products. The products have methods that you can use to interact with the API. For example, to request a payment from a customer, you can use the request_to_pay method of the Collection product.
important notes:
mtnmomo::Momo::new_with_provisioning is used to initialize the Momo struct with the sandbox environment.
mtnmomo::Momo::new is used to initialize the Momo struct with the production environment.
example making a request to pay:
use ;
use Uuid;
use dotenv;
use env;
async
The above code will request a payment of 100 EUR from the customer with the phone number "46733123450" (MTN sandbox test number). In the sandbox environment, this test number will simulate a successful payment. The customer will receive a prompt on their phone to confirm the payment. If the customer confirms the payment, the payment will be processed and the customer will receive a confirmation message. If the customer declines the payment, the payment will not be processed and the customer will receive a message informing them that the payment was declined.
Testing with MTN Sandbox
When using the sandbox environment, you should use MTN's predefined test phone numbers:
46733123450- Successful payment46733123451- Payment rejection46733123452- Payment expiry46733123453- Ongoing payment46733123454- Delayed payment (succeeds after 30 seconds)
Callback Server
This library also includes a callback server for handling MTN MoMo webhooks. See the momo-callback-server directory for more details.