Skip to content

A Golang client library interfacing with the MPower HTTP API

License

Notifications You must be signed in to change notification settings

nanaeasiedu/mpower

Repository files navigation

MPOWER - GOLANG LIBRARY FOR MPOWER API

Build Status

GoDoc

This a go implementation library that interfaces with the mpower http api.

Built on the MPower Payments HTTP API (beta).

Installation

$ go get github.com/ngenerio/mpower

Documentation

Create a new store instance to use in the checkout or onsite invoice

mpowerStore := NewStore("Awesome Store")

Create a new setup instance to use in the checkout or onsite invoice

// Get your keys from MPower Integration Setup
mpowerSetup := NewSetup(MASTER_KEY, PRIVATE_KEY , PUBLIC_KEY, TOKEN)

Checkout and Onsite Invoice

To use the checkout invoice, you need create an mpower instance

mpower := mpower.NewMPower(seup, store, "test")
checkout := mpower.NewCheckoutInvoice(mpower)
onsite := mpower.NewOnsiteInvoice(mpower)

Add an item to the invoice

checkout.AddItem("Yam Phone", 1, 50.00, 50.00, "Hello World")

Add tax information to the invoice to be displayed on the cutomer's receipt

checkout.AddTax("VAT", 30.00)

Set custom data on the invoice

checkout.SetCustomData("bonus", yeah)

Set some description on the invoice

checkout.SetDescription("Hello World")

Set the total amount on the invoice

checkout.SetTotalAmount(80.00)

Creating an invoice

This sample code shows how to create an mpower invoice after adding some items to your checkout or onsite invoice

//`response` is of type [`napping.Response`](http://godoc.org/github.com/jmcvetta/napping#Response)
responseBody, response, err := checkout.Create()

if err != nil {
    // handle the error
}
// where `responseBody.Token` is the token of the created invoice
fmt.Println(responseBody.Token)

Confirming the status of an invoice

// `TOKEN` is the token of the invoice created
responseBody, response, err := checkout.Confirm(TOKEN)

if err != nil {
    // handle the error
}

// `response.Status` could either be `pending`, `cancelled` or `completed`
fmt.Println(responseBody.Status)

Charging the mpower customer with onsite payment request

// `TOKEN` is the onsite token of the invoice created and the `CUSTOMER_TOKEN` is from the customer
responseBody, response, err := onsite.Charge(TOKEN, CUSTOMER_TOKEN)

Direct Mobile

Docs coming up soon

Direct Pay

Docs coming up soon

For more docs, read up: Mpower docs

About

A Golang client library interfacing with the MPower HTTP API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages