afrikpay

package module
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2022 License: MIT Imports: 13 Imported by: 0

README

afrikpay-go

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

This package provides a Go client for the AfrikPay HTTP API https://developer.afrikpay.com

Installation

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"

Implemented

  • Airtime
    • POST /api/airtime/v2/: Transfer airtime
    • POST /api/airtime/status/v2/: Airtime status
  • Account
    • POST /api/account/agent/balance/v2/: Account Balance
  • Bill
    • POST /api/bill/v2/: Pay bills or subscriptions
    • POST /api/bill/status/v2/: Bill transaction status
    • POST /api/bill/getamount/: Get bill amount

Usage

Initializing the Client

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 */),
  )
}
Error handling

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
}
Airtime
POST /api/airtime/v2/: Transfer airtime

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
POST /api/airtime/status/v2/: Airtime Status

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
Account
POST /api/account/agent/balance/v2/: Account Balance

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
Bill
POST /api/bill/v2/: Pay bills or subscriptions

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
POST /api/bill/status/v2/: Bill transaction status

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
POST /api/bill/getamount/: Get bill amount

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

Testing

You can run the unit tests for this client 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

Documentation

Index

Constants

View Source
const (
	// ModeCash payment from agent partner account
	ModeCash = Mode("cash")
	// ModeMoney send payment request
	ModeMoney = Mode("money")
	// ModeAccount make payment operation from afrikpay client
	ModeAccount = Mode("account")
)
View Source
const (
	// BillerEneoPostpay is used for postpaid bills of ENEO
	BillerEneoPostpay = Biller("eneopostpay")
	// BillerEneoPrepay is used for postpaid bills of ENEO
	BillerEneoPrepay = Biller("eneoprepay")
	// BillerCamwater is used for postpaid bills of Cameroon Water Corporation
	BillerCamwater = Biller("camwater")
	// BillerCanal is used for canal+ subscriptions
	BillerCanal = Biller("canal")
	// BillerUDS is used for bills of the University of Dschang
	BillerUDS = Biller("uds")
)
View Source
const (
	// BillSMSEnabled means you will receive a notification via SMS
	BillSMSEnabled = BillSMS("yes")
	// BillSMSDisabled means you will not receive a notification via SMS
	BillSMSDisabled = BillSMS("no")
)

Variables

This section is empty.

Functions

func PointerToString added in v0.0.3

func PointerToString(input *string) string

PointerToString converts a string to *string

func StringToPointer added in v0.0.3

func StringToPointer(input string) *string

StringToPointer converts a string to *string

Types

type AccountBalance added in v0.0.2

type AccountBalance struct {
	Name        string `json:"name"`
	MainBalance string `json:"mainbalance"`
	MainDeposit string `json:"maindeposit"`
}

AccountBalance contains details about the account

type AccountBalanceResponse added in v0.0.2

type AccountBalanceResponse struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Result  *AccountBalance `json:"result,omitempty"`
}

AccountBalanceResponse is the response when querying the account balance

func (AccountBalanceResponse) IsSuccessfull added in v0.0.2

func (response AccountBalanceResponse) IsSuccessfull() bool

IsSuccessfull determines if the transaction was successful

type AirtimeResponse

type AirtimeResponse struct {
	Code    int                 `json:"code"`
	Message string              `json:"message"`
	Result  *AirtimeTransaction `json:"result,omitempty"`
}

AirtimeResponse is returned from airtime api requests

func (AirtimeResponse) IsSuccessful added in v0.0.3

func (response AirtimeResponse) IsSuccessful() bool

IsSuccessful determines if the transaction was successful

type AirtimeTransaction

type AirtimeTransaction struct {
	OperatorID       string      `json:"operatorid"`
	TransactionID    string      `json:"txnid"`
	Status           string      `json:"status"`
	Date             string      `json:"date"`
	Ticket           interface{} `json:"ticket,omitempty"`
	ReferenceID      string      `json:"referenceid"`
	ProcessingNumber string      `json:"processingnumber"`
}

AirtimeTransaction is the details for an aitime transaction

type AirtimeTransferParams

type AirtimeTransferParams struct {
	Operator          string
	PhoneNumber       string
	PurchaseReference string
	Amount            string
	Mode              Mode
}

AirtimeTransferParams parameters for airtime transfer request

type BillAmountResponse added in v0.0.4

type BillAmountResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Result  *int   `json:"result,omitempty"`
}

BillAmountResponse is returned from bill amount api requests

func (BillAmountResponse) IsSuccessful added in v0.0.4

func (response BillAmountResponse) IsSuccessful() bool

IsSuccessful determines if the transaction was successful

type BillPayParams added in v0.0.3

type BillPayParams struct {
	Biller           Biller
	BillID           string
	Mode             Mode
	Amount           *string
	Provider         *string
	Account          *string
	Mobile           *string
	Code             *string
	SMS              *BillSMS
	ProcessingNumber *string
}

BillPayParams parameters for bill payment request

type BillPayResponse added in v0.0.4

type BillPayResponse struct {
	Code    int              `json:"code"`
	Message string           `json:"message"`
	Result  *BillTransaction `json:"result,omitempty"`
}

BillPayResponse is returned from bill pay/status api requests

func (BillPayResponse) IsPending added in v0.0.6

func (response BillPayResponse) IsPending() bool

IsPending determines if the transaction is pending

func (BillPayResponse) IsSuccessful added in v0.0.4

func (response BillPayResponse) IsSuccessful() bool

IsSuccessful determines if the transaction was successful

type BillSMS added in v0.0.3

type BillSMS string

BillSMS determines if we want to receive a notification via SMS

func (BillSMS) Pointer added in v0.0.3

func (sms BillSMS) Pointer() *BillSMS

Pointer converts BillSMS to *BillSMS

type BillTransaction added in v0.0.3

type BillTransaction struct {
	OperatorID       *string     `json:"operatorid"`
	TransactionID    string      `json:"txnid"`
	Status           string      `json:"status"`
	Date             string      `json:"date"`
	ReferenceID      interface{} `json:"referenceid"`
	ProcessingNumber string      `json:"processingnumber"`
}

BillTransaction is the details for a bill payment transaction

func (*BillTransaction) GetDate added in v0.0.6

func (transaction *BillTransaction) GetDate() (time.Time, error)

GetDate returns the date as time.Time

type Biller added in v0.0.3

type Biller string

Biller is the type of bill we want to pay

type Client

type Client struct {
	Airtime *airtimeService
	Account *accountService
	Bill    *billService
	// contains filtered or unexported fields
}

Client is the afrikpay API client. Do not instantiate this client with Client{}. Use the New method instead.

func New

func New(options ...Option) *Client

New creates and returns a new *Client from a slice of Option.

type Mode added in v0.0.3

type Mode string

Mode is used to determine the payment mode

func (Mode) String added in v0.0.3

func (mode Mode) String() string

String converts the Mode to a string

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is options for constructing a client

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API Key

func WithAgentID

func WithAgentID(agentID string) Option

WithAgentID sets the Agent ID for api calls

func WithAgentPassword

func WithAgentPassword(agentPassword string) Option

WithAgentPassword sets the agent password

func WithAgentPlatform

func WithAgentPlatform(agentPlatform string) Option

WithAgentPlatform sets the agent platform

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL set's the base url for the afrikpay API

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the underlying HTTP client used for API requests. By default, http.DefaultClient is used.

type Response

type Response struct {
	HTTPResponse *http.Response
	Body         *[]byte
}

Response captures the http response

func (*Response) Error

func (r *Response) Error() error

Error ensures that the response can be decoded into a string inc ase it's an error response

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL