This package provides a Go client for the AfrikPay HTTP API https://developer.afrikpay.com
afrikpay-go
is compatible with modern Go releases in module mode, with Go installed:
go get github.com/NdoleStudio/afrikpay-go
Alternatively the same can be achieved if you use import
in a package:
import "github.com/NdoleStudio/afrikpay-go"
- Airtime
POST /api/airtime/v2/
: Transfer airtimePOST /api/airtime/status/v2/
: Airtime status
- Account
POST /api/account/agent/balance/v2/
: Account Balance
- Bill
POST /api/bill/v2/
: Pay bills or subscriptionsPOST /api/bill/status/v2/
: Bill transaction statusPOST /api/bill/getamount/
: Get bill amount
An instance of the client can be created using New()
.
package main
import (
"github.com/NdoleStudio/afrikpay-go"
)
func main() {
client := afrikpay.New(
afrikpay.WithAgentID(""/* agent id */),
afrikpay.WithAPIKey(""/* api key */),
afrikpay.WithAgentPassword(""/* agent password */),
afrikpay.WithAgentPlatform(""/* agent platform */),
)
}
All API calls return an error
as the last return object. All successful calls will return a nil
error.
status, response, err := afrikpay.Airtime.Transfer(context.Background())
if err != nil {
//handle error
}
Transfer is intended for communication / Internet credit transfer operations to telephone numbers.
transaction, _, err := afrikpay.Airtime.Transfer(context.Background(), &AirtimeTransferParams{
Operator: "mtn",
PurchaseReference: "test-ref",
Amount: "987",
PhoneNumber: "00000000",
Mode: "cash",
})
if err != nil {
log.Fatal(err)
}
log.Println(status.Code) // 200
The Airtime Status API is intended for getting the status of a airtime transaction
transaction, _, err := afrikpay.Airtime.Status(context.Background(), ""/* Transaction ID */)
if err != nil {
log.Fatal(err)
}
log.Println(status.Code) // 200
The Balance API is used for the partner to get the Balance of their account
balance, _, err := afrikpay.Account.Balance(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println(status.Code) // 200
The Bill API is intended for bill payment operations.
transaction, _, err := client.Bill.Pay(context.Background(), BillPayParams{
Biller: BillerEneoPostpay,
BillID: billerID,
Mode: ModeCash
})
if err != nil {
log.Fatal(err)
}
log.Println(transaction.Code) // 200
The Bill Status API is intended for getting the status of a bill transaction
transaction, _ , err := client.Bill.Status(context.Background(), "transaction-id")
if err != nil {
log.Fatal(err)
}
log.Println(transaction.Code) //200
The Bill Amount API is used to get the amount of a specific bill
amount, _ , err := client.Bill.Amount(context.Background(), afrikpay.BillerEneoPostpay, "bill-number")
if err != nil {
log.Fatal(err)
}
log.Println(transaction.Code) //200
You can run the unit tests for this client from the root directory using the command below:
go test -v
This project is licensed under the MIT License - see the LICENSE file for details