Context
Fineract provides accounts and can be thought of as a Digital Financial Service Provider (DFSP) backend software stack. Mojaloop is an embodiment of the LevelOneProject.org principles in code, and provides the interoperability switch for transfers for all kinds of payment use cases. Integrating Fineract with Mojaloop is about bringing these two platforms together in a way that creates full end to end flows of funds, and thereby lowers the cost to providers and to end customers.
Use Cases
The initial use cases that we wish to implement are as follows. In each case the transfers will occur between different DFSPs. We will use multiple Fineract instances, and will also work to look at other DFSPs such as Musoni or even a provider like mPesa.
- Peer-to-Peer (P2P) transfer
- Merchant Payment
- Bulk transfer (ie. payroll disbursement)
Installation of Mojaloop platform
The Mojaloop platform can be installed using the interop-devops repo: https://github.com/mojaloop/interop-devops
To create your own installation, use the instructions here: https://github.com/mojaloop/interop-devops/blob/master/README_VAGRANT.md
I created a Mojaloop installation on Ubuntu 16.04 that is publicly available. The important endpoints for this installation are:
mifosmojaloop.com:3000 - Central Directory service
mifosmojaloop.com:3001 - End User Registry
mifosmojaloop.com:3002 - Central Ledger
mifosmojaloop.com:3004 - Central Ledger Admin
Note, the interop-devops installation includes 2 sample DFSP instances. We are not using these instances at all, as Fineract is the DFSP for these cases.
Documentation for API calls for the central directory and central ledger can be found here:
https://github.com/mojaloop/central-directory/blob/9b3a0cb3c79512a9b8eb1c7712ea9d2b4e8c145f/API.md
https://github.com/mojaloop/central-ledger/blob/master/API.md
Configuration of DFSPs
Before we can perform any transactions all Fineract instances involved in transactions need to be properly configured to use the Mifos Payment Gateway as well as Mojaloop.
Fineract and Payment Gateway
The current version of Fineract with the Payment Gateway code (which is still in development) can be found at: https://github.com/conradsp/fineract/tree/payment-gateway-integration
Create payment channels in Fineract for Mojaloop. I have updated the community app to allow users to create new payment channels (Organization->Payment Channels). The updated community-app can be found here: https://github.com/conradsp/community-app
Create a mojaloop payment channel, point to the ActiveMQ instance on the Fineract machine, and set the queue names to mojaloop.request and mojaloop.response
Ensure that the system user has super user role assigned to it
Mojaloop configuration
Each DFSP has to be registered with Mojaloop – both the central-directory and the central-ledger. For each DFSP, make the following POST requests:
Headers – the authorization uses admin/admin
Authorization: “Basic YWRtaW46YWRtaW4=”
Content-Type: “application/json”
Body – I used Mifos1 and Mifos2 as dfspNames. The providerUrl is https://localhost:8443/fineract-provider/api/v1 or whatever is appropriate for your Fineract instance
name: <dfspName>
shortName: <dfspName>
providerUrl: <API endpoint for Fineract instance>
NOTE: this call will return an object which contains the key and secret which will be used for future requests. Save these values.
Headers: same as above
Body:
name: <dfspName>
password: <dfspPassword>
Set up charges and fees for transfers. Make the following POST request for each charge
Headers: same as above
Body
name: <name of the charge>
charge_type: “fee”
rate_type: “percent” or “flat”
rate: amount of charge
minimum: minimum transfer amount to apply this charge
maximum: maximum transfer amount to apply the charge
code: <3 character code to identify the charge>
is_active: true or false
payer: sender, receiver or ledger
payee: sender, receiver or ledger
Configure Interledger
On each Fineract instance, we must install the ilp-connector and ilp-service in order to communicate with the Central Ledger using the Interledger protocol.
- Install ilp-connector from https://github.com/interledgerjs/ilp-connector
- To correctly configure the ILP connector, several environment variables must be set, including: CONNECTOR_LEDGERS, CONNECTOR_ROUTES, CONNECTOR_PEERS, CONNECTOR_BACKEND, as well as other settings. See the documentation for this repo for more information.
- Install ilp-service from https://github.com/mojaloop/ilp-service
- This service requires several configuration environment variables as well, including: ILP_SERVICE_LEDGER_ADMIN_ACCOUNT, ILP_SERVICE_LEDGER_ADMIN_USERNAME, ILP_SERVICE_CENTRAL_CONNECTOR_PASSWORD, ILP_SERVICE_LEDGER_ROOT, ILP_SERVICE_CENTRAL_CONNECTOR_ACCOUNT, ILP_SERVICE_CENTRAL_CONNECTOR_USERNAME, ILP_SERVICE_CONNECTOR_ACCOUNT, ILP_SERVICE_BACKEND, ILP_SERVICE_CENTRAL_CONNECTOR_PREFIX as well as others. Again, see repo documentation for details.
P2P payment flow:
The first transaction flow that has been implemented is a simple P2P (peer-to-peer) payment. The payment flow is based on the Mojaloop API documentation, page 173.
Before a user can participate in a transaction, the user must be registered in Mojaloop. For each user, make the following post request:
Headers – use the key and secret that were returned when registering the Dfsp above
Authorization: “Basic “+new Buffer(key+”:”+secret).toString(“base64”)
Directory-Api-Key: dfspName
Content-Type: “application/json”
Body (NOTE: I was not able to get E.164 telephone lookup working correctly, so am using eur (end-user-registry) lookup)
identifier: “eur:<unique id>” or “tel:<phone number>”
primary: true
Once users are registered, the full flow for a P2P payment is:
Look up the sender and recipient DFSPs in Mojaloop (based on tel or eur). This will provide the URLs where we can access each Fineract instance (through ActiveMQ)
GET - http://mifosmojaloop.com:3000/resources?identifier=eur:<number>
Returns object that contains the dfspName and providerUrl. The providerUrl is used to call Fineract
Call the ilp-service /quoteSourceAmount API to determine fees for the transaction
- This call will provide the ledger URL for the recipient
- Endpoints needed in Fineract: ledger URL for recipient
Prompt the sender with the fees for the request and wait for confirmation.
Create ActiveMQ client to transfer messages between the gateway and Fineract. The hostname comes from step 1 above and the queue names will be ‘mojaloop.request’ and ‘mojaloop.response’
Get the account numbers for the sender and recipient in Fineract – we use the provider URLs that we obtained in step 1 above and make a call to retrieve information about the sender and recipient from the DFSP (Fineract).
Make a GET request to: providerUrl+”/receivers/”+<tel or eur identifier>
Return the user data, including the account number (TODO: write out the complete response payload)
Send ActiveMQ request to sender’s Fineract instance to verify that they have sufficient funds in the account for the transaction (transaction prepare)
Create the transaction in the Mojaloop central ledger using the ilp service and connector. Generate a UUID to identify this transaction.
Call the ilp-service /payIPR method to execute the actual payment transaction.
In this call, we will pass in the ledger URLs for both the payer and receipient
Endpoints needed in URL: ledger URL for payment and credit for sender and receiver
Notify the user of successful transaction
End of day activities/reconciliation
Here, we will outline the process to Reconcile ledgers
Call central ledger API to settle transfers and fees (http://mifosmojaloop.com:3004/webhooks/settle-transfers)
Findings
What worked out of the box
What needed to be addressed
Current gaps