MPower Payments Python client library
Project description
MPower Python Client Library
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
For more information, please read the MPower Payments HTTP API
Tested on Python 2.6, 2.7, and 3+. Build Status
Project details
Release history Release notifications | RSS feed
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.1.tar.gz
(145.3 kB
view details)
File details
Details for the file mpower-0.1.1.tar.gz
.
File metadata
- Download URL: mpower-0.1.1.tar.gz
- Upload date:
- Size: 145.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6702ddbc33f5c4880353202987cb46461281bc80f008d5d746cf6a6e827f922 |
|
MD5 | 593d3c907d630a13336667a1fdd5e215 |
|
BLAKE2b-256 | b8782e80d6ccd77c4a10dd7121ec0c2462e92de77a0fbaae6402dd7515670da3 |