gomonnify

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 14 Imported by: 0

README

GoMonnify - TeamAPT's Monnify API Wrapper

Build Status codecov GoDoc

Installation

$ go get github.com/jcobhams/gomonnify

Usage
package main

import (
	"github.com/jcobhams/gomonnify"
    "fmt"
)

func main() {
    monnifyCfg := Config{
                 		Environment:         gomonnify.EnvLive,
                 		APIKey:              "Your_KEY",
                 		SecretKey:           "Your_Secret",
                 		RequestTimeout:      5 * time.Second,
                 		DefaultContractCode: "Your_Contract_Code",
                 	}
    
    monnify, err := gomonnify.New(monnifyCfg)
    if err != nil {
        //Handle error
    }
    
    res, err := monnify.Disbursements.WalletBalance("your_wallet_id")
    if err != nil {
        //handle error
    }
    
    fmt.Println(res)
}
Modules
  1. Disbursements (All EndPoints) - https://docs.teamapt.com/display/MON/Monnify+Disbursements

  2. ReservedAccounts (Except UpdateIncomeSplitConfig() and UpdatePaymentSourceFilter() )

  3. Invoice - Coming soon or open a PR :)

  4. General - Only TransactionVerification, GetTransaction and GetBanks are implemented.

Test Helpers

GoMonnify ships with nifty test helpers to ease unit and integration testing your code that import or relies on gomonnify. Set the following environment variables:

GOMONNIFY_TESTMODE this tells the module to assume it's running in a test context.

GOMONNIFY_TESTURL a full integration server is bundled with the module, you can use it or write one if you need.

Example Test File my_controller_test.go

package gomonnify

import (
	"github.com/jcobhams/gomonnify/testhelpers"
	"os"
	"testing"
)

func TestMain(m *testing.M) {
	mockAPIServer := testhelpers.MockAPIServer()

	os.Setenv("GOMONNIFY_TESTMODE", "ON")
	os.Setenv("GOMONNIFY_TESTURL", mockAPIServer.URL)
	
	os.Exit(m.Run())
}

func TestMyContollerMethodThatUsesGoMonnify(t *testing.T) {
    ...
    // test body
    ...

}



Run Tests

$ go test -race -v -coverprofile cover.out

View Coverage

$ go tool cover -html=cover.out

Documentation

Index

Constants

View Source
const (
	EnvSandbox Environment = "sandbox" //Sandbox environment for development
	EnvLive    Environment = "live"    //Live environmrnt
	EnvTest    Environment = "test"    //Test environment used during unit/integration testing

	SandBoxAPIKey       string = "MK_TEST_SAF7HR5F3F"
	SandBoxSecretKey    string = "4SY6TNL8CK3VPRSBTHTRG2N8XXEGC6NL"
	DefaultContractCode string = "4934121686"

	APIBaseUrlSandbox string = "https://sandbox.monnify.com/api"
	APIBaseUrlLive    string = "https://api.monnify.com/api"

	RequestTimeout time.Duration = 5 * time.Second

	CurrencyNGN = params.CurrencyNGN

	ValidationFailedContinue = params.ValidationFailedContinue
	ValidationFailedBreak    = params.ValidationFailedBreak

	NotificationInterval10  = params.NotificationInterval10
	NotificationInterval20  = params.NotificationInterval20
	NotificationInterval50  = params.NotificationInterval50
	NotificationInterval100 = params.NotificationInterval100

	PaymentStatusPaid          string = "PAID"
	PaymentStatusPending       string = "PENDING"
	PaymentStatusOverpaid      string = "OVERPAID"
	PaymentStatusPartiallyPaid string = "PARTIALLY_PAID"
	PaymentStatusExpired       string = "EXPIRED"
	PaymentStatusFailed        string = "FAILED"
	PaymentStatusCancelled     string = "CANCELLED"
)

Variables

View Source
var (
	DefaultConfig = Config{
		Environment:         EnvSandbox,
		APIKey:              SandBoxAPIKey,
		SecretKey:           SandBoxSecretKey,
		RequestTimeout:      RequestTimeout,
		DefaultContractCode: DefaultContractCode,
	}

	AuthToken string
	ExpiresIn time.Time
)

Functions

This section is empty.

Types

type Bank added in v1.1.0

type Bank struct {
	Name                 string `json:"name"`
	Code                 string `json:"code"`
	USSDTemplate         string `json:"ussdTemplate"`
	BaseUSSDCode         string `json:"baseUssdCode"`
	TransferUSSDTemplate string `json:"transferUssdTemplate"`
}

type BanksResponse added in v1.1.0

type BanksResponse struct {
	ResponseBody []Bank `json:"responseBody"`
	// contains filtered or unexported fields
}

type BulkTransferDetailsResponse

type BulkTransferDetailsResponse struct {
	ResponseBody struct {
		Title             string  `json:"title"`
		TotalAmount       float64 `json:"totalAmount"`
		TotalFee          float64 `json:"totalFee"`
		BatchReference    string  `json:"batchReference"`
		TotalTransactions int     `json:"totalTransactions"`
		FailedCount       int     `json:"failedCount"`
		SuccessfulCount   int     `json:"successfulCount"`
		PendingCount      int     `json:"pendingCount"`
		BatchStatus       string  `json:"batchStatus"`
		DateCreated       string  `json:"dateCreated"`
	} `json:"responseBody"`
	// contains filtered or unexported fields
}

type BulkTransferResponse

type BulkTransferResponse struct {
	ResponseBody struct {
		TotalAmount       float64 `json:"totalAmount"`
		TotalFee          float64 `json:"totalFee"`
		BatchReference    string  `json:"batchReference"`
		BatchStatus       string  `json:"batchStatus"`
		TotalTransactions int     `json:"totalTransactions"`
		DateCreated       string  `json:"date_created"`
	}
	// contains filtered or unexported fields
}

type Config

type Config struct {
	Environment         Environment
	APIKey              string
	SecretKey           string
	RequestTimeout      time.Duration
	DefaultContractCode string
}

Config is used to initialize the Monnify client. Environment - sets the current environment. Sandbox or Live APIKey - well pretty obvious :) SecretKey - same as above RequestTimeout - used to set a deadline on the HTTP requests made. defaults to 5seconds. setting it to 0 to ignores timeout and could make request wait indefinitely (not recommended). DefaultContractCode - used by some endpoints. is not provided in the endpoint method params. Not required.

type Environment

type Environment string

type GeneralTransaction added in v1.1.0

type GeneralTransaction struct {
	TransactionReference string `json:"transactionReference"`
	PaymentReference     string `json:"paymentReference"`
	AmountPaid           string `json:"amountPaid"`
	TotalPayable         string `json:"totalPayable"`
	SettlementAmount     string `json:"settlementAmount"`
	PaidOn               string `json:"paidOn"`
	PaymentStatus        string `json:"paymentStatus"`
	PaymentDescription   string `json:"paymentDescription"`
	TransactionHash      string `json:"transactionHash"`
	Currency             string `json:"currency"`
	PaymentMethod        string `json:"paymentMethod"`
	Product              struct {
		Type      string `json:"type"`
		Reference string `json:"reference"`
	} `json:"product"`
	CardDetails struct {
		CardType          string `json:"cardType"`
		AuthorizationCode string `json:"authorizationCode"`
		Last4             string `json:"last4"`
		ExpMonth          string `json:"expMonth"`
		ExpYear           string `json:"expYear"`
		Bin               string `json:"bin"`
		Reusable          bool   `json:"reusable"`
	} `json:"cardDetails"`
	AccountDetails  accountDetails   `json:"accountDetails"`
	AccountPayments []accountDetails `json:"accountPayments"`
	Customer        struct {
		Email string `json:"email"`
		Name  string `json:"name"`
	} `json:"customer"`
	MetaData struct {
		Name string `json:"name"`
		Age  string `json:"age"`
	}
}

type GeneralTransactionResponse added in v1.1.0

type GeneralTransactionResponse struct {
	ResponseBody GeneralTransaction `json:"responseBody"`
	// contains filtered or unexported fields
}

type LoginResponse

type LoginResponse struct {
	ResponseBody struct {
		AccessToken string `json:"accessToken"`
		ExpiresIn   int    `json:"expiresIn"`
	}
	// contains filtered or unexported fields
}

type Monnify

type Monnify struct {
	General *general
	//Invoicing        *invoicing
	Disbursements    *disbursements
	ReservedAccounts *reservedAccounts
}

func New

func New(config Config) (*Monnify, error)

New create a new instance of the Monnify struct based on provided config. Returns a pointer to the struct and nil error if successful or a nil pointer and an error

type ResendOTPResponse

type ResendOTPResponse struct {
	ResponseBody struct {
		Message string `json:"message"`
	} `json:"responseBody"`
	// contains filtered or unexported fields
}

type ReserveAccountResponse

type ReserveAccountResponse struct {
	ResponseBody struct {
		ContractCode         string `json:"contractCode"`
		AccountReference     string `json:"accountReference"`
		AccountName          string `json:"accountName"`
		CurrencyCode         string `json:"currencyCode"`
		CustomerEmail        string `json:"customerEmail"`
		CustomerName         string `json:"customerName"`
		AccountNumber        string `json:"accountNumber"`
		BankName             string `json:"bankName"`
		BankCode             string `json:"bankCode"`
		CollectionChannel    string `json:"collectionChannel"`
		ReservationReference string `json:"reservationReference"`
		ReservedAccountType  string `json:"reservedAccountType"`
		Status               string `json:"status"`
		CreatedOn            string `json:"createdOn"`
		IncomeSplitConfig    []struct {
			SubAccountCode  string  `json:"subAccountCode"`
			FeePercentage   float64 `json:"feePercentage"`
			FeeBearer       bool    `json:"feeBearer"`
			SplitPercentage float64 `json:"splitPercentage"`
		} `json:"incomeSplitConfig"`
		RestrictPaymentSource bool `json:"restrictPaymentSource"`
		Contract              struct {
			Name                                       string `json:"name"`
			Code                                       string `json:"code"`
			Description                                string `json:"description"`
			SupportsAdvancedSettlementAccountSelection bool   `json:"supportsAdvancedSettlementAccountSelection"`
			SweepToExternalAccount                     bool   `json:"sweepToExternalAccount"`
		} `json:"contract"`
	} `json:"responseBody"`
	// contains filtered or unexported fields
}

type ReservedAccountTransaction added in v1.1.0

type ReservedAccountTransaction struct {
	CustomerDTO struct {
		Email        string `json:"email"`
		Name         string `json:"name"`
		MerchantCode string `json:"merchantCode"`
	} `json:"customerDTO"`
	ProviderAmount       float64 `json:"providerAmount"`
	PaymentMethod        string  `json:"paymentMethod"`
	CreatedOn            string  `json:"createdOn"`
	Amount               float64 `json:"amount"`
	Flagged              bool    `json:"flagged"`
	ProviderCode         string  `json:"providerCode"`
	Fee                  float64 `json:"fee"`
	CurrencyCode         string  `json:"currencyCode"`
	CompletedOn          string  `json:"completedOn"`
	PaymentDescription   string  `json:"paymentDescription"`
	PaymentStatus        string  `json:"paymentStatus"`
	TransactionReference string  `json:"transactionReference"`
	PaymentReference     string  `json:"paymentReference"`
	MerchantCode         string  `json:"merchantCode"`
	MerchantName         string  `json:"merchantName"`
	PayableAmount        float64 `json:"payableAmount"`
	AmountPaid           float64 `json:"amountPaid"`
	Completed            bool    `json:"completed"`
}

type ReservedAccountTransactionsResponse added in v1.1.0

type ReservedAccountTransactionsResponse struct {
	ResponseBody struct {
		Content  []ReservedAccountTransaction `json:"content"`
		Pageable struct {
			Sort struct {
				Sorted   bool `json:"sorted"`
				Unsorted bool `json:"unsorted"`
				Empty    bool `json:"empty"`
			} `json:"sort"`
			PageSize   int  `json:"pageSize"`
			PageNumber int  `json:"pageNumber"`
			Offset     int  `json:"offset"`
			Unpaged    bool `json:"unpaged"`
			Paged      bool `json:"paged"`
		} `json:"pageable"`
		TotalElements int  `json:"totalElements"`
		TotalPages    int  `json:"totalPages"`
		Last          bool `json:"last"`
		Sort          struct {
			Sorted   bool `json:"sorted"`
			Unsorted bool `json:"unsorted"`
			Empty    bool `json:"empty"`
		} `json:"sort"`
		First            bool `json:"first"`
		NumberOfElements int  `json:"numberOfElements"`
		Size             int  `json:"size"`
		Number           int  `json:"number"`
		Empty            bool `json:"empty"`
	} `json:"responseBody"`
	// contains filtered or unexported fields
}

type SingleTransferDetails

type SingleTransferDetails struct {
	Amount        float64 `json:"amount"`
	Reference     string  `json:"reference"`
	Narration     string  `json:"narration"`
	BankCode      string  `json:"bankCode"`
	AccountNumber string  `json:"accountNumber"`
	Currency      string  `json:"currency"`
	AccountName   string  `json:"accountName"`
	BankName      string  `json:"bankName"`
	DateCreated   string  `json:"dateCreated"`
	Fee           float64 `json:"fee"`
	Status        string  `json:"status"`
}

type SingleTransferDetailsResponse

type SingleTransferDetailsResponse struct {
	ResponseBody SingleTransferDetails `json:"responseBody"`
	// contains filtered or unexported fields
}

type SingleTransferResponse

type SingleTransferResponse struct {
	ResponseBody struct {
		Amount      float64 `json:"amount"`
		Reference   string  `json:"reference"`
		Status      string  `json:"status"`
		DateCreated string  `json:"dateCreated"`
	}
	// contains filtered or unexported fields
}

type TransferTransactionsResponse

type TransferTransactionsResponse struct {
	ResponseBody struct {
		Content  []SingleTransferDetails `json:"content"`
		Pageable struct {
			Sort struct {
				Sorted   bool `json:"sorted"`
				Unsorted bool `json:"unsorted"`
				Empty    bool `json:"empty"`
			} `json:"sort"`
			PageSize   int  `json:"pageSize"`
			PageNumber int  `json:"pageNumber"`
			Offset     int  `json:"offset"`
			Unpaged    bool `json:"unpaged"`
			Paged      bool `json:"paged"`
		} `json:"pageable"`
		TotalElements int  `json:"totalElements"`
		TotalPages    int  `json:"totalPages"`
		Last          bool `json:"last"`
		Sort          struct {
			Sorted   bool `json:"sorted"`
			Unsorted bool `json:"unsorted"`
			Empty    bool `json:"empty"`
		} `json:"sort"`
		First            bool `json:"first"`
		NumberOfElements int  `json:"numberOfElements"`
		Size             int  `json:"size"`
		Number           int  `json:"number"`
		Empty            bool `json:"empty"`
	} `json:"responseBody"`
	// contains filtered or unexported fields
}

type ValidAccountNumberResponse

type ValidAccountNumberResponse struct {
	ResponseBody struct {
		AccountNumber string `json:"accountNumber"`
		AccountName   string `json:"accountName"`
		BankCode      string `json:"bankCode"`
	} `json:"responseBody"`
	// contains filtered or unexported fields
}

type WalletBalanceResponse

type WalletBalanceResponse struct {
	ResponseBody struct {
		AvailableBalance float64 `json:"availableBalance"`
		LedgerBalance    float64 `json:"ledgerBalance"`
	} `json:"responseBody"`
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL