Skip to content

NdoleStudio/flutterwave-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flutterwave-go

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

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

Installation

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

go get github.com/NdoleStudio/flutterwave-go

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

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

Implemented

  • Bills
    • POST /bills/: Create a bill payment
    • GET /bill-items/:item_code/validate: Validate services like DStv smartcard number, Meter number etc.
    • GET /bills/:reference: Get the verbose status of a bill payment
  • Payments
    • GET /v3/transactions/:id/verify: Verify a transaction
    • POST /v3/transactions/:id/refund: Create a Refund

Usage

Initializing the Client

An instance of the flutterwave client can be created using New().

package main

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

func main()  {
	client := flutterwave.New(
		flutterwave.WithSecretKey("" /* flutterwave Secret Key */),
	)
}

Error handling

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

data, httpResponse, err := flutterwaveClient.Bills.Create(context.Background(), request)
if err != nil {
    //handle error
}

BILLS

Create a bill payment

POST /bills/: Create a bill payment

response, _, err := flutterwaveClient.Bills.CreatePayment(context.Background(), &BillsCreatePaymentRequest{
    Country:    "NG",
    Customer:   "7034504232",
    Amount:     100,
    Recurrence: "ONCE",
    Type:       "DSTV",
    Reference:  uuid.New().String(),
    BillerName: "DSTV",
})

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

log.Println(response.Status) // success

Create a bill payment

GET /bill-items/{item_code}/validate: validate services like DSTV smartcard number, Meter number etc.

response, _, err := flutterwaveClient.Bills.Validate(context.Background(), "CB177", "BIL099", "08038291822")

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

log.Println(response.Status) // success

Get verbose status of a bill payment

GET /bills/{reference}: get the verbose status of a bill purchase

response, _, err := flutterwaveClient.Bills.GetStatusVerbose(context.Background(), "9300049404444")

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

log.Println(response.Status) // success

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