Git Product home page Git Product logo

wit-mtn-momo-api-python-sdk's Introduction

Welcome to Wit MTN MOMO API Python SDK, here is the full tutorial on how to use it:

Dependancies

  • pip install basicauth

Requirements for production users

Requirements For Sandbox/Testing users

  • Collections and disbursment subscription keys

What to do before you start using this:

Open pay.py and update these values:

  1. Update collections_subkey with your collections subscription key
#Collections Subscription Key:
collections_subkey = "{{Collections_subscription_key}}"
  1. Update disbursment_subkey with your disbursement subscription key
#Collections Subscription Key:
disbursment_subkey = ""
  1. Only for users in production Update collections api user
    collections_apiuser = "" Update api key with your collections key api_key_collections = ""
  2. Set application environment By default the environment is sandbox
    #Application mode
    environment_mode = "sandbox"
    

Calling request to pay

from pay import PayClass

callPay = PayClass.momopay(amount, currency, txt_ref, phone_number, payermessage)
print(callPay["response"])

To return the reference(UUID), print out this:

print(callPay["ref"]) 

And to return the status code print out this:

print(callPay["response"])

Note: If it returns 202 or 200 then it means the request was successful

Verify and check the transaction status

Checking the transaction status is used to verify if the customer has confirmed the payment or not. Here is the calling for transaction status and verification check.

from pay import PayClass

#Verify the transaction
verify = PayClass.verifymomo("Reference returned by momopay function")

Status 200 or 202 means okay When the transaction is successful it returns:

{
 "amount": 100,
 "currency": "UGX",
 "financialTransactionId": 23503452,
 "externalId": 947354,
 "payer": {
   "partyIdType": "MSISDN",
   "partyId": 4656473839.0
 },
 "status": "SUCCESSFUL"
}

For the complete reference of payment verification read on the bottom page from this link" https://momodeveloper.mtn.com/docs/services/collection/operations/requesttopay-referenceId-GET?

Checking the account balance from the collections account

This function is used to check the account balance for the money inside the collections wallet account. Here is how the API call is done:

from pay import PayClass
#Checking the collections balance
checkcollectionsbalance = PayClass.momobalance()

If the status is 200 or 202 it means the call was successful. After the call above it returns the account balance

Checking the account balance from the disbursement account

This function is used to check the account balance for the money inside the Disbursement wallet account. Here is how the API call is done:

#Checking the disbursment balance
disbursementBalanceCheck = PayClass.momobalancedisbursement()

If the status is 200 or 202 it means the call was successful. After the call above it returns the account balance

Transfer money from MTN Disbursement wallet to an MTN mobile money account

This function is used to transfer money from MTN disbursement account to an MTN mobile money account. Here is how it is done:

from pay import PayClass
#Transfer money from disbursement account
withdrawmoney = PayClass.withdrawmtnmomo(amount, currency, txt_ref, phone_number, payermessage)

After a successful transfer it either returns 202 or 200 Note: To check the status print this

print(withdrawmoney["response"])

To Check the transaction UUID(Reference) Print this:

print(withdrawmoney["ref"])
Note: The call withdrawmoney["ref"] returns a unique UUID(reference) which we will use in the next part

Checking withdraw status

This function is used to check the withdraw status after calling a withdraw function. Here is the code:

from pay import PayClass
CheckWithdrawStatus = PayClass.checkwithdrawstatus("UUID reference returned from the transfer")

REFERENCES

MTN DEVELOPER, (2019). /Token - Post. MOMO DEVELOPER PORTAL, Available: https://momodeveloper.mtn.com/docs/services/collection/operations/token-POST?, [ACCESSED: 7 july, 2022]

MTN DEVELOPER, (2019). Request to pay. MOMO DEVELOPER PORTAL, Available: https://momodeveloper.mtn.com/docs/services/collection/operations/requesttopay-POST?, [ACCESSED: 7 july, 2022]

MTN DEVELOPER, (2019). /requesttopay/{referenceId} - GET. MOMO DEVELOPER PORTAL, Available: https://momodeveloper.mtn.com/docs/services/collection/operations/requesttopay-referenceId-GET?, [ACCESSED: 7 july, 2022]

MTN DEVELOPER, (2019). /v1_0/account/balance - GET. MOMO DEVELOPER PORTAL, Available: https://momodeveloper.mtn.com/docs/services/collection/operations/get-v1_0-account-balance?, [ACCESSED: 7 july, 2022]

MTN DEVELOPER, (2019). Disbursement token. MOMO DEVELOPER PORTAL, Available: https://momodeveloper.mtn.com/docs/services/disbursement/operations/token-POST?, [ACCESSED: 7 july, 2022]

MTN DEVELOPER, (2019). /transfer - POST. MOMO DEVELOPER PORTAL, Available: https://momodeveloper.mtn.com/docs/services/disbursement/operations/transfer-POST?, [ACCESSED: 7 july, 2022]

MTN DEVELOPER, (2019). /transfer/{referenceId} - GET. MOMO DEVELOPER PORTAL, Available: https://momodeveloper.mtn.com/docs/services/disbursement/operations/transfer-referenceId-GET?, [ACCESSED: 7 july, 2022]

MTN DEVELOPER, (2019). /v1_0/account/balance - GET. MOMO DEVELOPER PORTAL, Available: https://momodeveloper.mtn.com/docs/services/disbursement/operations/get-v1_0-account-balance?, [ACCESSED: 7 july, 2022]

wit-mtn-momo-api-python-sdk's People

Contributors

comfortchambeshi avatar justinekatebe69 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.