DEV Community

Cover image for Monnify Payment Gateway with Golang v1.4.0
Mathias Jiya
Mathias Jiya

Posted on • Updated on

Monnify Payment Gateway with Golang v1.4.0

There have been a lot of updates to the monnify-go library since the last time I published an article on this subject.
Today' article is on the updates in the library as the previous methods in the library were updated alongside their request payload and some other new methods were added to the library as well.
The monnify-go library is now in its v1.4.0 and it contains all the API endpoints made available by monnify. This library (monnify-go) is properly documented as there is an example code for each of the methods available in the package to make it easy for anyone to use. You can visit the monnify-go github repo for the complete documentation of all the methods in the library.
Here are some code sample below:

Get Disburstment Wallet Balance

Use this to get disburstment wallet balance

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"
    monnify.Options(apiKey, secretKey, baseUrl)

    walletId := "123"
    res, status, err := transaction.GetDisburstmentWalletBal(walletId)
    if err != nil {
        fmt.Println(err)
    }

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

Accept Payment

Use this to accept payments from customers

Use this object payload to implement the AcceptPayment() method

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"`
}
Enter fullscreen mode Exit fullscreen mode
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)

    payload := transaction.AcceptPaymentReq{}

    res, status, err := transaction.AcceptPayment(payload)
    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

Use this object payload to implement the InitiateSingleTransfer() method

type InitiateSingleTransferReq struct {
    Amount        int    `json:"amount"`
    Reference     string `json:"reference"`
    Narration     string `json:"narration"`
    BankCode      int    `json:"bankCode"`
    Currency      string `json:"currency"`
    AccountNumber int    `json:"accountNumber"`
    WalletId      string `json:"walletId"`
}
Enter fullscreen mode Exit fullscreen mode
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)

    payload := transaction.InitiateSingleTransferReq{}
    res, status, err := transaction.InitiateSingleTransfer(payload)
    if err != nil {
        fmt.Println(err)
    }

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

Single Transfer Details

Use this to get the initiated single transfer details

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.GetSingleTransferDetails(paymentReference)
    if err != nil {
        fmt.Println(err)
    }

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

Initiate Bulk Transfer

Use this to initiate bulk transfer

Use this object payload to implement the InitiateBulkTransfer() method

Note: Use BREAK to tell Monnify to reject the entire batch and use CONTINUE to tell Monnify to process the valid transactions for the OnValidationFailure field

type InitiateBulkTransferReq struct {
    Title                string                                   `json:"title"`
    BatchReference       string                                   `json:"batchReference"`
    Narration            string                                   `json:"narration"`
    WalletId             string                                   `json:"walletId"`
    OnValidationFailure  string                                   `json:"onValidationFailure"`
    NotificationInterval int                                   `json:"notificationInterval"`
    TransactionList      []InitiateBulkTransferReqTransactionList `json:"transactionList"`
}

type InitiateBulkTransferReqTransactionList struct {
    Amount        string `json:"amount"`
    Reference     string `json:"reference"`
    Narration     string `json:"narration"`
    BankCode      string `json:"bankCode"`
    AccountNumber string `json:"accountNumber"`
    Currency      string `json:"currency"`
}
Enter fullscreen mode Exit fullscreen mode
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)

    payload := transaction.InitiateBulkTransferReq{}
    res, status, err := transaction.InitiateBulkTransfer(payload)
    if err != nil {
        fmt.Println(err)
    }

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

Top comments (0)