DEV Community

Cover image for Monnify payment gateway with Golang
Mathias Jiya
Mathias Jiya

Posted on • Updated on

Monnify payment gateway with Golang

Note: This article was written based on the v1.0.0 of the monnify-go library and the library is now in its v2.0.0. You can click here to view the recent article on the v2.0.0

In today's article, I would be showing you how to integrate the monnify payment gateway into your Go project.
Monnify is a payment gateway for businesses to accept payments from customers, either on a recurring or one-time basis. Monnify offers an easier, faster and cheaper way for businesses to get paid on their web and mobile applications using convenient payment methods for customers with the highest success rates obtainable in Nigeria.
We would be using a monnify library I created for the implementation. Here's the github link to the library https://github.com/iqquee/monnify-go

Installation

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
Enter fullscreen mode Exit fullscreen mode
  • Import it in your code:
import "github.com/iqquee/monnify-go"
Enter fullscreen mode Exit fullscreen mode

Accept Payment

Use this to accept payments from customers

package main

import (
    "fmt"
    monnify "github.com/iqquee/monnify-go"
    "github.com/iqquee/monnify-go/transaction"
)

func main() {
    apiKey := ""
    secretKey := ""
    baseUrl := "https://sandbox.monnify.com" // for test
    monnify.Options(apiKey, secretKey, baseUrl)

    amount := 100 
    paymentReference := "ref123"
    paymentDesc := "test payment"
    currencyCode := "NGN"
    contractCode := ""
    customerName := ""
    customerEmail := ""
    customerNumber := "" 
    redirectUrl := "https://google.com" // test redirect url
    res, status, err := transaction.AcceptPayment(amount,paymentReference , paymentDesc, currencyCode, contractCode, customerName, customerEmail, customerNumber, redirectUrl)
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println(status)
    fmt.Println(res)
}
Enter fullscreen mode Exit fullscreen mode

Get Accepted Payment Status

Use this to get accepted payment status

package main

import (
    "fmt"
    monnify "github.com/iqquee/monnify-go"
    "github.com/iqquee/monnify-go/transaction"
)

func main() {
    apiKey := ""
    secretKey := ""
    baseUrl := "https://sandbox.monnify.com" // for test
    monnify.Options(apiKey, secretKey, baseUrl)

    paymentReference := "ref123"
    res, status, err := transaction.GetTransactionStatus(paymentReference)
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println(status)
    fmt.Println(res)
}
Enter fullscreen mode Exit fullscreen mode

Initiate Single Transfer

Use this to initiate single transfers

package main

import (
    "fmt"
    monnify "github.com/iqquee/monnify-go"
    "github.com/iqquee/monnify-go/transaction"
)

func main() {
    apiKey := ""
    secretKey := ""
    baseUrl := "https://sandbox.monnify.com" // for test
    monnify.Options(apiKey, secretKey, baseUrl)

    amount := 100
    paymentReference := "ref123"
    narration := "example transaction"
    bankCode := "058" // for GT Bank
    currency := "NGN"
    accountNumber := ""
    walletId := ""
    res, status, err := transaction.InitiateSingleTransfer(amount, paymentReference, narration, currency, bankCode, accountNumber, walletId)
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println(status)
    fmt.Println(res)
}
Enter fullscreen mode Exit fullscreen mode

Initiate Single Transfer Status

Use this to get the initiated single transfer status

package main

import (
    "fmt"
    monnify "github.com/iqquee/monnify-go"
    "github.com/iqquee/monnify-go/transaction"
)

func main() {
    apiKey := ""
    secretKey := ""
    baseUrl := "https://sandbox.monnify.com" // for test
    monnify.Options(apiKey, secretKey, baseUrl)

    paymentReference := "ref123"
    res, status, err := transaction.GetInitiateSingleTransferStatus(paymentReference)
    if err != nil {
        fmt.Println(err)
    }

    fmt.Println(status)
    fmt.Println(res)
}
Enter fullscreen mode Exit fullscreen mode

This package monnify-go is in it stable v1.0.0 and the methods above is what this library offers now. But as time goes on, all the features monnify offers would be added to this package.

Top comments (0)