Monnify Payment Gateway with Golang v1.4.0
Tags: monnify, go, paymentgateway
Published: 2022-08-22 00:37:00

There have been a lot of updates to the [monnify-go](https://github.com/iqquee/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](https://github.com/iqquee/monnify-go) library is now in its v1.4.0 and it contains all the API endpoints made available by [monnify](https://monnify.com/). This library ([monnify-go](https://github.com/iqquee/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](https://github.com/iqquee/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
```go
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)
}
```

## 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
```go
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"`
}
```
```go
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)
}
```


## Get Accepted Payment Status
Use this to get accepted payment status
```go
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)
}
```

## Initiate Single Transfer
Use this to initiate single transfers

### Use this object payload to implement the InitiateSingleTransfer() method
```go
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"`
}
```
```go
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)
}
```

## Single Transfer Details
Use this to get the initiated single transfer details
```go
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)
}
```

## 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
```go
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"`
}
```

```go
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)
}
```