Built on the MPower Payments HTTP API (beta).
0.1.xdocumentation is available here.
0.2.xintroduced breaking changes incompatible with
0.2.xis incompatible with Node.js
$ npm install --save mpower
Setup MPower API keys.
var setup =masterKey: 'dd6f2c90-f075-012f-5b69-00155d864600'privateKey: 'test_private_oDLVlm1eNyh0IsetdhdJvcl0ygA'publicKey: 'test_public_zzF3ywvX9DE-OSDNhUqKoaTI4wc'token: 'ca03737cf942cf644f36'mode: 'test' // optional. use in sandbox mode.;
It might usually be suitable to put your API configuration in environment variables. In that case you can initialize
mpower.Setup without passing configuration parameters.
The library will automatically detect the environment variables and use them.
Auto-detected environment variables:
var store =name: 'Awesome Store' // only name is requiredtagline: 'Easy shopping'phoneNumber: '0261234567'postalAddress: 'P.0. Box MP555, Accra'logoURL: '';
var invoice = setup store;
var invoice = setup store;
invoice; // name, quantity, unit price, total priceinvoicedescription = 'Apple product'
invoicetotalAmount = 500;
After setting total amount and adding items to your invoice you can create a checkout and redirect the customer. It takes a callback which gets passed the updated invoice object containing the url.
After setting total amount and adding items to your invoice get the MPower customer's username or phone number and start an OPR request.
To successfully complete an OPR charge, you need both your OPR Token & the Confirmation code sent to the customer. After a successfull charge you can programatically access the receipt url, customer information and more.
You may include tax information on on the checkout page. This information will be available on the invoice & receipt printouts and PDF downloads.
There are times when you may need to add an extra load of data with the checkout information for later use. MPower allows saving of custom data on their servers which are persisted even after successful payment. Note: Custom data is not displayed anywhere on the checkout page, invoice/receipt download & printouts.
You can optionally set the URL where your customers will be redirected to after canceling a checkout. Note: There are two options as to how the cancel URL is set, one is to set it globally using the checkout setup information and the other is set it as per checkout invoice. Setting the cancel URL directly on the invoice instance will overwrite the global settings if already set.
// Globallyvar store =name: 'Awesome Store'cancelURL: '';// Per CheckoutinvoicecancelURL;
MPower does a good job of managing receipt downloads and printouts after your customer successfuly makes payment. However there may be cases where you may descide to redirect your customers to another URL after successfully making payment. Return URL guarantees this action.
Note: MPower will append
?token=INVOICE_TOKEN to your URL.
// Globallyvar store =name: 'Awesome Store'returnURL: '';// Per CheckoutinvoicereturnURL;
The API allows you to check on the status of any checkout using the checkout token key. You have access to all the data including the receipt download link & customer information in cases where the checkout has been confirmed as completed.
var token = 'aodaff0023';var invoice = setup store;invoice;
You can pay any MPower account directly via your third party apps. This is particularly excellent for implementing your own Adaptive payment solutions on top of MPower.
var directPay = setup;directPay;
Add DirectCard functionality.
To run tests just setup the API configuration environment variables. An internet connection is required for some of the tests to pass.
npm install -g mocha
npm test or