Monnify-go is a Go library that allows you to integrate the MONNIFY payment gateway into your Go project.
- You encounter any error while using this package and that issue would be attended to immediately.
- In other to use this package, you need to first create an account with monnify via https://app.monnify.com/create-account
- After your account have been successfully created, locate the developer option at the bottom left of your dashboard to get your:
- Api key
- Secret Key
- Contract code
To install this monnify package, you need to install Go and set your Go workspace first.
- You can use the below Go command to install monnify-go
$ go get -u github.com/iqquee/monnify-go
- Import it in your code:
import "github.com/iqquee/monnify-go"
- An object of the response
- An error (if any)
# assume the following codes in example.go file
$ touch example.go
# open the just created example.go file in the text editor of your choice
Use this to accept payments from customers
Note: CurrencyCode should be "NGN" for naira
type AcceptPaymentReq struct {
PaymentReference string `json:"paymentReference"`
Amount int `json:"amount"`
CurrencyCode string `json:"currencyCode"`
ContractCode string `json:"contractCode"`
CustomerEmail string `json:"customerEmail"`
CustomerName string `json:"customerName"`
CustomerPhoneNumber string `json:"customerPhoneNumber"`
RedirectUrl string `json:"redirectUrl"`
PaymentDescription string `json:"paymentDescription"`
}
package main
import (
"fmt"
"net/http"
monnify "github.com/iqquee/monnify-go"
)
func main() {
apiKey := ""
secretKey := ""
baseUrl := "https://sandbox.monnify.com" // for test
client := monnify.New(*http.DefaultClient, baseUrl,apiKey, secretKey)
payload := monnify.AcceptPaymentReq{}
res, err := client.AcceptPayment(payload)
if err != nil {
fmt.Println(err)
}
fmt.Println(res)
}
Use this to get accepted payment status
package main
import (
"fmt"
"net/http"
monnify "github.com/iqquee/monnify-go"
)
func main() {
apiKey := ""
secretKey := ""
baseUrl := "https://sandbox.monnify.com" // for test
client := monnify.New(*http.DefaultClient, baseUrl,apiKey, secretKey)
paymentReference := "ref123"
res, err := client.GetTransactionStatus(paymentReference)
if err != nil {
fmt.Println(err)
}
fmt.Println(res)
}