sarepay

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 7 Imported by: 0

README

Go library for the SarePay API.

sarepay-go is a Go client library for accessing the SarePay API.

Usage

    var (
        res map[string]interface{}
        c http.Client
    )

	papiKey := "PUBLIC-test"
	merchantKey := "test"


	client := sarepay.NewClient(papiKey, &c)

	transRequest := sarepay.TransactionInput{
		Key:    papiKey,
		Token:  merchantKey,
		Amount: 10000,
		Customer: sarepay.Customer{
			Name:  "philip",
			Email: "test@test.com",
		},
		Reference: "jekkditestsffarepddddassy",
	}
    
	res, err := client.Transaction.Initialize(&transRequest)
	if err != nil {
		//do something with error
	}

	datas, ok := res["data"].(map[string]interface{})
	if !ok {
		errors, ok := res["errors"].(map[string]interface{})
		if !ok {
			fmt.Println("Error: 'errors' is not a string")
			return
		}

		fmt.Println(errors)
		return
	}

	link, ok := datas["link"].(string)
	if !ok {
		fmt.Println("Error: 'link' is not a string")
		return
	}

	// Print the link
	fmt.Println("Link:", link)

CONTRIBUTING

Contributions are of course always welcome. The calling pattern is pretty well established, so adding new methods is relatively straightforward. Please make sure the build succeeds and the test suite passes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountDetails added in v0.1.1

type AccountDetails struct {
	AccountNumber string `json:"account_number"`
	BankCode      string `json:"bank_code"`
}

type AccountResponse added in v0.1.1

type AccountResponse struct {
	Success bool `json:"success"`
	Data    struct {
		AccountNumber string `json:"account_number"`
		AccountName   string `json:"account_name"`
	} `json:"data"`
	Message string `json:"message"`
}

type Client

type Client struct {

	// Services supported by the Sarepay API.
	// Miscellaneous actions are directly implemented on the Client object
	Transaction    *TransactionService
	VirtualAccount *VirtualAccountService
	Transfer       *TransferService

	LoggingEnabled bool
	Log            Logger
	// contains filtered or unexported fields
}

Client manages communication with the Sarepay API

func NewClient

func NewClient(publickey, secretkey string, httpClient *http.Client) *Client

NewClient creates a new Sarepay API client with the given API key

type Customer

type Customer struct {
	Name  string `json:"name,omitempty"`
	Email string `json:"email,omitempty"`
}

type InitializeTransactionInput

type InitializeTransactionInput struct {
	Key                  string   `json:"key,omitempty"`
	Token                string   `json:"token,omitempty"`
	Amount               int      `json:"amount,omitempty"`
	Currency             string   `json:"currency,omitempty"`
	FeeBearer            string   `json:"feeBearer,omitempty"`
	DefaultPaymentMethod string   `json:"defaultPaymentMethod"`
	PaymentMethods       []string `json:"paymentMethods,omitempty"`
	Customer             Customer `json:"customer,omitempty"`
	ContainerID          string   `json:"containerId,omitempty"`
	Metadata             Metadata `json:"metadata"`
	Reference            string   `json:"reference,omitempty"`
}

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger interface for custom loggers

type Metadata

type Metadata struct {
	TaxID      string `json:"taxIs,omitempty"`
	CustomerID string `json:"customerId,omitempty"`
}

type Response

type Response map[string]interface{}

Response represents arbitrary response data

type TransactionInput

type TransactionInput struct {
	Key       string   `json:"key,omitempty"`
	Token     string   `json:"token,omitempty"`
	Amount    int      `json:"amount,omitempty"`
	Customer  Customer `json:"customer,omitempty"`
	Reference string   `json:"reference,omitempty"`
}

type TransactionService

type TransactionService service

TransactionService handles operations related to transactions For more details see

func (*TransactionService) Initialize

func (s *TransactionService) Initialize(txn *TransactionInput) (Response, error)

Initialize initiates a transaction process For more details see https://documenter.getpostman.com/view/28866628/2s9Y5bRh7W#678924c7-250b-460b-b870-8dbd68c4de16

type TransferRequest added in v0.1.1

type TransferRequest struct {
	CustomerReference string `json:"customer_reference"`
	AccountNumber     string `json:"account_number"`
	BankCode          string `json:"bank_code"`
	Amount            string `json:"amount"`
	Narration         string `json:"narration"`
	RecipientName     string `json:"recipient_name"`
}

type TransferResponse added in v0.1.1

type TransferResponse struct {
	Success bool `json:"success"`
	Data    struct {
		Reference              string  `json:"reference"`
		Amount                 string  `json:"amount"`
		Charge                 string  `json:"charge"`
		Status                 string  `json:"status"`
		RecipientName          string  `json:"recipient_name"`
		RecipientBankCode      string  `json:"recipient_bank_code"`
		RecipientAccountNumber string  `json:"recipient_account_number"`
		ProcessorReference     *string `json:"processor_reference"` // Use *string to handle null values
		MerchantReference      string  `json:"merchant_reference"`
	} `json:"data"`
	Message string `json:"message"`
}

type TransferService added in v0.1.1

type TransferService service

func (*TransferService) AccountLookup added in v0.1.1

func (s *TransferService) AccountLookup(txn *AccountDetails) (AccountResponse, error)

Account Lookup

func (*TransferService) ProcessTransfer added in v0.1.1

func (s *TransferService) ProcessTransfer(txn *TransferRequest) (TransferResponse, error)

Process Transfer For more details see https://documenter.getpostman.com/view/28866628/2s9Y5bRh7W#678924c7-250b-460b-b870-8dbd68c4de16

func (*TransferService) VerifyTransfer added in v0.1.1

func (s *TransferService) VerifyTransfer(reference string) (TransferResponse, error)

Verify Transfer

type VirtualAccountRequest added in v0.1.1

type VirtualAccountRequest struct {
	FirstName    string `json:"first_name"`
	LastName     string `json:"last_name"`
	OtherName    string `json:"other_name"`
	Bvn          string `json:"bvn"`
	Dob          string `json:"dob"`
	PhoneNumber  string `json:"phone_number"`
	BusinessType string `json:"business_type"`
	Type         string `json:"type"`
	Currency     string `json:"currency"`
}

type VirtualAccountResponse added in v0.1.1

type VirtualAccountResponse struct {
	Data struct {
		AccountNumber    string `json:"account_number"`
		AccountName      string `json:"account_name"`
		AccountReference string `json:"account_reference"`
		Bank             string `json:"bank"`
		Status           string `json:"status"`
		Type             string `json:"type"`
		ExpiresAt        string `json:"expires_at"`
		ValidityType     string `json:"validity_type"`
	} `json:"data"`
}

type VirtualAccountService added in v0.1.1

type VirtualAccountService service

func (*VirtualAccountService) GeneratePermanentAccount added in v0.1.1

func (s *VirtualAccountService) GeneratePermanentAccount(txn *VirtualAccountRequest) (VirtualAccountResponse, error)

Generates virtual account number For more details see https://documenter.getpostman.com/view/28866628/2s9Y5bRh7W#678924c7-250b-460b-b870-8dbd68c4de16

Jump to

Keyboard shortcuts

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