Skip to content

NdoleStudio/mobilenig-go

Repository files navigation

MobileNig Go

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides a go client for interacting with the MobileNig API

Installation

mobilenig-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/NdoleStudio/mobilenig-go

Alternatively the same can be achieved if you use import in a package:

import "github.com/NdoleStudio/mobilenig-go"

Implemented

  • Bills
    • DStv
      • GET /bills/user_check - Validate a DStv user
      • GET /bills/dstv - Pay a DStv subscription
      • GET /bills/query - Fetch a DStv transaction
      • GET /bills/get_package - Fetch current DStv package

Usage

Initializing the Client

An instance of the mobilenig client can be created using New(). The http.Client supplied will be used to make requests to the API.

package main

import (
	"github.com/NdoleStudio/mobilenig-go"
)

func main()  {
	client := mobilenig.New(
		mobilenig.WithUsername("" /* MobileNig Username */),
		mobilenig.WithAPIKey("" /* MobileNig API Key */),
		mobilenig.WithEnvironment(mobilenig.TestEnvironment),
	)
}

Error handling

All API calls return an error as the last return object. All successful calls will return a nil error.

payload, response, err := mobilenigClient.Token(context.Background())
if err != nil {
  //handle error
}

Bills

This handles all API requests whose URL begins with /bills/

DStv

Validate DStv User

GET /bills/user_check: Validate a DStv user

user, _, err := mobilenigClient.Bills.CheckDStvUser(context.Background(), "4131953321")

if err != nil {
    log.Fatal(err)
}

log.Println(user.Details.LastName) // e.g INI OBONG BASSEY
Pay a DStv subscription

GET /bills/dstv - Pay a DStv subscription

transaction, _, _ = client.Bills.PayDStv(context.Background(), &PayDstvOptions{
    TransactionID:   "122790223",
    Price:           "790",
    ProductCode:     "PRWE36",
    CustomerName:    "ESU INI OBONG BASSEY",
    CustomerNumber:  "275953782",
    SmartcardNumber: "4131953321",
})

log.Println(transaction.TransactionID) // e.g 122790223
Fetch a DStv transaction

GET /bills/query - Fetch a DStv transaction

transaction, _, err := client.Bills.QueryDStv(context.Background(), "122790223")
if err != nil {
    log.Fatal(err)
}

log.Println(transaction.TransactionID) // e.g 122790223
Get current DStv package

GET /bills/get_package - Returns the client's current DStv package

dstvPackage, _, err := client.Bills.GetDStvPackage(context.Background(), "122790223")
if err != nil {
    log.Fatal(err)
}

log.Println(dstvPackage) // e.g DStv French Touch

Testing

You can run the unit tests for this SDK from the root directory using the command below:

go test -v

License

This project is licensed under the MIT License - see the LICENSE file for details