This a go implementation library that interfaces with the mpower http api.
Built on the MPower Payments HTTP API (beta)
.
$ go get github.com/ngenerio/mpower
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)
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)
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)
// `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)
// `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)
Docs coming up soon
Docs coming up soon
For more docs, read up: Mpower docs