Skip to main content

MPower Payments Python client library

Project description

This is a Python library for accessing the MPower Payments HTTP API.

Installation

$ sudo pip install mpower
$ OR git clone https://github.com/mawuli/mpower-python
$ cd mpower-python; python setup.py install`
$ nosetests tests/  # run unit tests

Usage

import mpower

# runtime configs
MP_ACCESS_TOKENS = {
    'MP-Master-Key': "Your MPower master key",
    'MP-Private-Key': "Your MPower private key",
    'MP-Token': "Your MPower token"
}
# defaults to False
mpower.debug = True
# set the access/api keys
mpower.api_keys = MP_ACCESS_TOKENS

# Invoice
store = mpower.Store({'name':'FooBar Shop'})
items = [{"name": "VIP Ticket", "quantity": 2,
     "unit_price": "35.0", "total_price": "70.0",
     "description": "VIP Tickets for the MPower Event"}]
invoice = mpower.Invoice(store)
invoice.add_items(items * 10)
# taxes are (key,value) pairs
invoice.add_taxes([("NHIS TAX", 23.8), ("VAT", 5)])
invoice.add_custom_data([("phone_brand", "Motorola V3"),
            ("model", "65456AH23")])

# you can also pass the items, taxes, custom to the `create` method
successful, response = invoice.create()
if successful:
    do_something_with_resp(response)

# confirm invoice
invoice.confirm(response['token'])


# OPR
opr_data = {'account_alias': '02XXXXXXXX',
            'description': 'Hello World',
             'total_amount': 345}
store = mpower.Store({"name":"FooBar Shop"})
opr = mpower.OPR(opr_data, store)
# You can also pass the data to the `create` function
successful, response = opr.create()
if successful:
   do_something_with_response(response)
status, _ = opr.charge({'token': token,
                'confirm_token': user_submitted_token})


# Direct card
card_info = {"card_name" : "Alfred Robert Rowe",
    "card_number" : "4242424242424242", "card_cvc" : "123",
    "exp_month" : "06", "exp_year" : "2010", "amount" : "300"
}
direct_card = mpower.DirectCard(card_info)
# this request should fail since the card_info data is invalid
successful, response = direct_card.process()


# Direct Pay
account_alias =  "02XXXXXXXX"
amount =  30.50
# toggle debug switch to True
direct_pay = mpower.DirectPay(account_alias, amount)
status, response = direct_pay.process()

License

see LICENSE.txt

Contributing

Issues, forks, and pull requests are welcome!

Note

  • Some of the API calls require formal approval from MPower Payments

  • This library has not being used in any production environment, yet.

  • For more information, please read the MPower Payments HTTP API

  • Tested on Python 2.6, 2.7, and 3+. Build Status

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpower-0.1.0.tar.gz (146.6 kB view details)

Uploaded Source

File details

Details for the file mpower-0.1.0.tar.gz.

File metadata

  • Download URL: mpower-0.1.0.tar.gz
  • Upload date:
  • Size: 146.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mpower-0.1.0.tar.gz
Algorithm Hash digest
SHA256 29c226a7ae7a1a66e53fe43703436891330eb3bbfc9d113b90089b4fb779f45d
MD5 121050045bf53b9703bef1bb3d7c60fe
BLAKE2b-256 c8b150dbeaa7fa4afd1b3833d4bcf59e267de80c606cc1977145a1d145862980

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page