cerberus

package module
v0.0.0-...-f1c2a04 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: MIT Imports: 11 Imported by: 0

README

Cerberus

GoDoc Build and run all tests

A Go client library for Paystack.

Installation

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

go mod init

Then, reference cerberus in a Go program with import:

import (
    "github.com/adelowo/cerberus"
)

Run any of the normal go commands (build/install/test). The Go toolchain will resolve and fetch the cerberus module automatically.

Documentation

Index

Constants

View Source
const (
	BVNLen = 11
)

Variables

This section is empty.

Functions

func IsStringEmpty

func IsStringEmpty(s string) bool

IsStringEmpty checks if the given string (s) is empty or not. It strips out spaces while performing the check

Types

type Authorization

type Authorization struct {
	AuthorizationCode string `json:"authorization_code"`
	Bin               string `json:"bin"`
	Last4             string `json:"last4"`
	ExpMonth          string `json:"exp_month"`
	ExpYear           string `json:"exp_year"`
	Channel           string `json:"channel"`
	CardType          string `json:"card_type"`
	Bank              string `json:"bank"`
	CountryCode       string `json:"country_code"`
	Brand             string `json:"brand"`
	Reusable          bool   `json:"reusable"`
	Signature         string `json:"signature"`
	AccountName       string `json:"account_name"`
}

Authorization represents a payment method The Reusable field should be taken note of as it determines if this authorization code can be used again

type BVN

type BVN struct {
	FirstName    string `json:"first_name"`
	LastName     string `json:"last_name"`
	DOB          string `json:"dob"`
	FormattedDOB string `json:"formatted_dob"`
	Mobile       string `json:"mobile"`
	Value        string `json:"bvn"`
}

BVN represents a user's BVN

func (BVN) IsZero

func (b BVN) IsZero() bool

type BVNMatchOptions

type BVNMatchOptions struct {
	AccountNumber string `json:"account_number"`
	BankCode      string `json:"bank_code"`
	BVN           string `json:"bvn"`
	FirstName     string `json:"first_name"`
	LastName      string `json:"last_name"`
	MiddleName    string `json:"middle_name"`
}

BVNMatchOptions defines the data for matching a BVN

func (*BVNMatchOptions) Validate

func (b *BVNMatchOptions) Validate() error

Validate makes sure to check for the request is properly formatted. Makes sure the required fields are present

type BVNMatchResponse

type BVNMatchResponse struct {
	Meta struct {
		CallsThisMonth int `json:"calls_this_month,omitempty"`
		FreeCallsLeft  int `json:"free_calls_left,omitempty"`
	} `json:"meta,omitempty"`

	Data struct {
		AccountNumber bool   `json:"account_number"`
		FirstName     bool   `json:"first_name"`
		LastName      bool   `json:"last_name"`
		IsBlacklisted bool   `json:"is_blacklisted"`
		BVN           string `json:"bvn"`
	} `json:"data"`
}

BVNMatchResponse is a response type that gives an actual representation of the provided data by the user.

type BVNResponse

type BVNResponse struct {
	Meta struct {
		CallsThisMonth int `json:"calls_this_month,omitempty"`
		FreeCallsLeft  int `json:"free_calls_left,omitempty"`
	} `json:"meta,omitempty"`

	Data struct {
		BVN
	} `json:"data,omitempty"`
}

func (BVNResponse) IsZero

func (b BVNResponse) IsZero() bool

IsZero checks if the BVN in the response is empty or an unusable state

type Bank

type Bank struct {
	Name      string    `json:"name"`
	Slug      string    `json:"slug"`
	Code      string    `json:"code"`
	LangCode  string    `json:"lang_code"`
	Gateway   string    `json:"gateway"`
	Active    bool      `json:"active"`
	ID        int64     `json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Bank represents a known bank

type BankListOptions

type BankListOptions struct {
	PerPage  int    `url:"perPage"`
	Page     int    `url:"page"`
	Type     string `url:"type"`
	Currency string `url:"currency"`
	Country  string `url:"country"`
}

BankListOptions is used to filter results of the banks api

type BankService

type BankService service

BankService is a service for communicating with the bank related API of Paystack's API

func (BankService) ListBanks

func (b BankService) ListBanks(ctx context.Context, params *BankListOptions) ([]Bank, error)

ListBanks returns a list of known banks Docs: https://developers.paystack.co/reference#list-banks

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the root object of cerberus. Used to interact with Paystack's API

func New

func New(opts ...Option) (*Client, error)

New creates a new instance of Cerberus

func (*Client) Bank

func (c *Client) Bank() *BankService

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

Do makes the HTTP request and writes the body of the response into v

func (*Client) NewRequest

func (c *Client) NewRequest(method string, url string, v interface{}) (*http.Request, error)

NewRequest creates a new http.Request for the current operation

func (*Client) Transaction

func (c *Client) Transaction() *TransactionService

func (*Client) Transfer

func (c *Client) Transfer() *TransactionService

func (*Client) Verification

func (c *Client) Verification() *VerificationService

type CreateTransferRecipientOptions

type CreateTransferRecipientOptions struct {
	Type              string   `json:"type"`
	Name              string   `json:"name"`
	MetaData          MetaData `json:"meta_data"`
	AccountNumber     Nuban    `json:"account_number"`
	BankCode          string   `json:"bank_code"`
	Currency          string   `json:"currency"`
	Description       string   `json:"description"`
	AuthorizationCode string   `json:"authorization_code"`
}

CreateTransferRecipientOptions is the request body for creating a transfer recipient

func (*CreateTransferRecipientOptions) Validate

func (c *CreateTransferRecipientOptions) Validate() error

Validate makes sure required value are provided

type CreateTransferRecipientResponse

type CreateTransferRecipientResponse struct {
	Type        string `json:"type"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Metadata    struct {
		Job string `json:"job"`
	} `json:"metadata"`
	Domain  string `json:"domain"`
	Details struct {
		AccountNumber Nuban  `json:"account_number"`
		AccountName   string `json:"account_name"`
		BankCode      string `json:"bank_code"`
		BankName      string `json:"bank_name"`
	} `json:"details"`
	Currency      string    `json:"currency"`
	RecipientCode string    `json:"recipient_code"`
	Active        bool      `json:"active"`
	ID            int       `json:"id"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

CreateTransferRecipientResponse is a model that represents a successful recipient creation

type InitializeTransactionRequest

type InitializeTransactionRequest struct {
	CallbackURL       string   `json:"callback_url"`
	Reference         string   `json:"reference"`
	Amount            string   `json:"amount"`
	Email             string   `json:"email"`
	Plan              string   `json:"plan"`
	InvoiceLimit      int      `json:"invoice_limit"`
	MetaData          MetaData `json:"meta_data"`
	SubAccount        string   `json:"sub_account"`
	TransactionCharge int      `json:"transaction_charge"`
	Bearer            string   `json:"bearer"`
	Channels          []string `json:"channels"`
}

InitializeTransactionRequest represents a model for creating/initializing a Paystack payment

func (*InitializeTransactionRequest) Validate

func (i *InitializeTransactionRequest) Validate() error

Validate makes sure required data is provided for initializing the transaction

type InitializeTransactionResponse

type InitializeTransactionResponse struct {
	AccessCode       string `json:"access_code"`
	Reference        string `json:"reference"`
	AuthorizationURL string `json:"authorization_url"`
}

InitializeTransactionResponse is

type MetaData

type MetaData map[string]string

type Nuban

type Nuban string

Nuban is a custom type that represents a Nigerian account number

func (Nuban) String

func (a Nuban) String() string

String implements fmt.Stringer by making Nuban printable

func (Nuban) Validate

func (a Nuban) Validate() error

Validate makes sure the NUBAN is exactly 10 digits long

type NubanOptions

type NubanOptions struct {
	AccountNumber Nuban  `json:"account_number" url:"account_number"`
	BankCode      string `json:"bank_code" url:"bank_code"`
}

NubanOptions represents query parameters for fetching data of a Nuban

func (*NubanOptions) Validate

func (n *NubanOptions) Validate() error

Validate checks that required data is provided

type NubanResponse

type NubanResponse struct {
	AccountName   string `json:"account_name"`
	AccountNumber string `json:"account_number"`
}

NubanResponse represents an account number an it's corresponding name

type Option

type Option func(*Client)

Option is a configuration type

func HTTPClient

func HTTPClient(h *http.Client) Option

HTTPClient is an Option type that allows you provide your own HTTP client

func SecretKey

func SecretKey(s string) Option

SecretKey allows you set the key required to communicate with Paystack

func UserAgent

func UserAgent(s string) Option

UserAgent is a custom user agent for Cerberus when making requests to Paystack

type Transaction

type Transaction struct {
	ID              int       `json:"id"`
	Domain          string    `json:"domain"`
	Status          string    `json:"status"`
	Reference       string    `json:"reference"`
	Amount          int       `json:"amount"`
	Message         string    `json:"message"`
	GatewayResponse string    `json:"gateway_response"`
	PaidAt          time.Time `json:"paid_at"`
	CreatedAt       time.Time `json:"created_at"`
	Channel         string    `json:"channel"`
	Currency        string    `json:"currency"`
	IPAddress       string    `json:"ip_address"`
	// Metadata is actually a string :)
	Metadata string `json:"metadata"`
	Log      struct {
		StartTime int           `json:"start_time"`
		TimeSpent int           `json:"time_spent"`
		Attempts  int           `json:"attempts"`
		Errors    int           `json:"errors"`
		Success   bool          `json:"success"`
		Mobile    bool          `json:"mobile"`
		Input     []interface{} `json:"input"`
		History   []struct {
			Type    string `json:"type"`
			Message string `json:"message"`
			Time    int    `json:"time"`
		} `json:"history"`
	} `json:"log"`
	Fees          int           `json:"fees"`
	FeesSplit     string        `json:"fees_split"`
	Authorization Authorization `json:"authorization"`
	Customer      struct {
		ID           int      `json:"id"`
		FirstName    string   `json:"first_name"`
		LastName     string   `json:"last_name"`
		Email        string   `json:"email"`
		CustomerCode string   `json:"customer_code"`
		Phone        string   `json:"phone"`
		Metadata     MetaData `json:"metadata"`
		RiskAction   string   `json:"risk_action"`
	} `json:"customer"`
	Plan  interface{} `json:"plan"`
	Split struct {
	} `json:"split"`
	OrderID         interface{} `json:"order_id"`
	RequestedAmount int         `json:"requested_amount"`
	TransactionDate time.Time   `json:"transaction_date"`
}

Transaction represents the response from Paystack's API

type TransactionService

type TransactionService service

TransactionService interacts with the transaction section of Paystack's API

func (TransactionService) CreateRecipient

CreateRecipient creates a transfer recipient https://developers.paystack.co/reference#create-transfer-recipient

func (*TransactionService) Initialize

Initialize initializes a Paystack transaction. https://developers.paystack.co/reference#initialize-a-transaction

func (*TransactionService) Verify

func (t *TransactionService) Verify(ctx context.Context, reference string) (Transaction, error)

Verify fetches the status of a transaction by it's reference https://developers.paystack.co/reference#verify-transaction

type TransferService

type TransferService service

type VerificationService

type VerificationService service

VerificationService is used to communicate with the verification section of Paystack's API

func (*VerificationService) MatchBVN

MatchBVN compares the provided data to what is available in the BVN database Docs: https://developers.paystack.co/reference#match-bvn

func (*VerificationService) ResolveBVN

func (v *VerificationService) ResolveBVN(ctx context.Context, b string) (BVNResponse, error)

ResolveBVN fetches the data of the provided bvn Docs: https://developers.paystack.co/reference#resolve-bvn

func (*VerificationService) ResolveNuban

func (v *VerificationService) ResolveNuban(ctx context.Context, opts *NubanOptions) (NubanResponse, error)

ResolveNuban retrieves data of the provided Nuban Docs: https://developers.paystack.co/reference#resolve-account-number

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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