paystack

package module
v0.0.0-...-196191f Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 12 Imported by: 0

README

GoDoc Build Status

Go library for the Paystack API.

paystack-go is a Go client library for accessing the Paystack API.

Where possible, the services available on the client groups the API into logical chunks and correspond to the structure of the Paystack API documentation at https://developers.paystack.co/v1.0/reference.

Usage

import "github.com/rpip/paystack-go"

apiKey := "sk_test_b748a89ad84f35c2f1a8b81681f956274de048bb"

// second param is an optional http client, allowing overriding of the HTTP client to use.
// This is useful if you're running in a Google AppEngine environment
// where the http.DefaultClient is not available.
client := paystack.NewClient(apiKey)

recipient := &TransferRecipient{
    Type:          "Nuban",
    Name:          "Customer 1",
    Description:   "Demo customer",
    AccountNumber: "0100000010",
    BankCode:      "044",
    Currency:      "NGN",
    Metadata:      map[string]interface{}{"job": "Plumber"},
}

recipient1, err := client.Transfer.CreateRecipient(recipient)

req := &TransferRequest{
    Source:    "balance",
    Reason:    "Delivery pickup",
    Amount:    30,
    Recipient: recipient1.RecipientCode,
}

transfer, err := client.Transfer.Initiate(req)
if err != nil {
    // do something with error
}

// retrieve list of plans
plans, err := client.Plan.List()

for i, plan := range plans.Values {
  fmt.Printf("%+v", plan)
}

cust := &Customer{
    FirstName: "User123",
    LastName:  "AdminUser",
    Email:     "user123@gmail.com",
    Phone:     "+23400000000000000",
}
// create the customer
customer, err := client.Customer.Create(cust)
if err != nil {
    // do something with error
}

// Get customer by ID
customer, err := client.Customers.Get(customer.ID)

See the test files for more examples.

Docker

Test this library in a docker container:

# PAYSTACK_KEY is an environment variable that should be added to your rc file. i.e .bashrc
$ make docker && docker run -e PAYSTACK_KEY -i -t paystack:latest

TODO

  • Maybe support request context?
  • Test on App Engine

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

Overview

Package paystack provides the binding for Paystack REST APIs. Where possible, the services available on the client groups the API into logical chunks and correspond to the structure of the Paystack API documentation at https://developers.paystack.co/v1.0/reference.

Usage:

import "github.com/rpip/paystack-go"

apiKey := "sk_test_b748a89ad84f35c2f1a8b81681f956274de048bb"

// second param is an optional http client, allowing overriding of the HTTP client to use.
// This is useful if you're running in a Google AppEngine environment
// where the http.DefaultClient is not available.
client := paystack.NewClient(apiKey)

recipient := &TransferRecipient{
	Type:          "Nuban",
	Name:          "Customer 1",
	Description:   "Demo customer",
	AccountNumber: "0100000010",
	BankCode:      "044",
	Currency:      "NGN",
	Metadata:      map[string]interface{}{"job": "Plumber"},
}

recipient1, err := client.Transfer.CreateRecipient(recipient)

req := &TransferRequest{
	Source:    "balance",
	Reason:    "Delivery pickup",
	Amount:    30,
	Recipient: recipient1.RecipientCode,
}

transfer, err := client.Transfer.Initiate(req)

// retrieve list of plans
plans, err := client.Plan.List()

for i, plan := range plans.Values {
  fmt.Printf("%+v", plan)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Message        string        `json:"message,omitempty"`
	HTTPStatusCode int           `json:"code,omitempty"`
	Details        ErrorResponse `json:"details,omitempty"`
	URL            *url.URL      `json:"url,omitempty"`
	Header         http.Header   `json:"header,omitempty"`
}

APIError includes the response from the Paystack API and some HTTP request info

func (*APIError) Error

func (aerr *APIError) Error() string

APIError supports the error interface

type Authorization

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

Authorization represents Paystack authorization object

type AuthorizationRequest

type AuthorizationRequest struct {
	Reference         string   `json:"reference,omitempty"`
	AuthorizationCode string   `json:"authorization_code,omitempty"`
	Amount            int      `json:"amount,omitempty"`
	Currency          string   `json:"currency,omitempty"`
	Email             string   `json:"email,omitempty"`
	Metadata          Metadata `json:"metadata,omitempty"`
}

AuthorizationRequest represents a request to enable/revoke an authorization

type BVNResponse

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

BVNResponse represents response from resolve_bvn endpoint

type Bank

type Bank struct {
	ID        int    `json:"id,omitempty"`
	CreatedAt string `json:"createdAt,omitempty"`
	UpdatedAt string `json:"updatedAt,omitempty"`
	Name      string `json:"name,omitempty"`
	Slug      string `json:"slug,omitempty"`
	Code      string `json:"code,omitempty"`
	LongCode  string `json:"long_code,omitempty"`
	Gateway   string `json:"gateway,omitempty"`
	Active    bool   `json:"active,omitempty"`
	IsDeleted bool   `json:"is_deleted,omitempty"`
}

Bank represents a Paystack bank

type BankAccount

type BankAccount struct {
	Code          string `json:"code,omitempty"`
	AccountNumber string `json:"account_number,omitempty"`
}

BankAccount is used as bank in a charge request

type BankList

type BankList struct {
	Meta   ListMeta
	Values []Bank `json:"data,omitempty"`
}

BankList is a list object for banks.

type BankService

type BankService service

BankService handles operations related to the bank For more details see https://developers.paystack.co/v1.0/reference#bank

func (*BankService) List

func (s *BankService) List() (*BankList, error)

List returns a list of all the banks. For more details see https://developers.paystack.co/v1.0/reference#list-banks

func (*BankService) ResolveAccountNumber

func (s *BankService) ResolveAccountNumber(accountNumber, bankCode string) (Response, error)

ResolveAccountNumber docs https://developers.paystack.co/v1.0/reference#resolve-account-number

func (*BankService) ResolveBVN

func (s *BankService) ResolveBVN(bvn int) (*BVNResponse, error)

ResolveBVN docs https://developers.paystack.co/v1.0/reference#resolve-bvn

type BulkChargeBatch

type BulkChargeBatch struct {
	ID            int    `json:"id,omitempty"`
	CreatedAt     string `json:"createdAt,omitempty"`
	UpdatedAt     string `json:"updatedAt,omitempty"`
	BatchCode     string `json:"batch_code,omitempty"`
	Status        string `json:"status,omitempty"`
	Integration   int    `json:"integration,omitempty"`
	Domain        string `json:"domain,omitempty"`
	TotalCharges  string `json:"total_charges,omitempty"`
	PendingCharge string `json:"pending_charge,omitempty"`
}

BulkChargeBatch represents a bulk charge batch object For more details see https://developers.paystack.co/v1.0/reference#initiate-bulk-charge

type BulkChargeBatchList

type BulkChargeBatchList struct {
	Meta   ListMeta
	Values []BulkChargeBatch `json:"data,omitempty"`
}

BulkChargeBatchList is a list object for bulkcharges.

type BulkChargeRequest

type BulkChargeRequest struct {
	Items []BulkItem
}

BulkChargeRequest is an array of objects with authorization codes and amount

type BulkChargeService

type BulkChargeService service

BulkChargeService handles operations related to the bulkcharge For more details see https://developers.paystack.co/v1.0/reference#initiate-bulk-charge

func (*BulkChargeService) Get

func (s *BulkChargeService) Get(idCode string) (*BulkChargeBatch, error)

Get returns a bulk charge batch This endpoint retrieves a specific batch code. It also returns useful information on its progress by way of the total_charges and pending_charges attributes. For more details see https://developers.paystack.co/v1.0/reference#fetch-bulk-charge-batch

func (*BulkChargeService) GetBatchCharges

func (s *BulkChargeService) GetBatchCharges(idCode string) (Response, error)

GetBatchCharges returns charges in a batch This endpoint retrieves the charges associated with a specified batch code. Pagination parameters are available. You can also filter by status. Charge statuses can be pending, success or failed. For more details see https://developers.paystack.co/v1.0/reference#fetch-charges-in-a-batch

func (*BulkChargeService) Initiate

Initiate initiates a new bulkcharge For more details see https://developers.paystack.co/v1.0/reference#initiate-bulk-charge

func (*BulkChargeService) List

List returns a list of bulkcharges. For more details see https://developers.paystack.co/v1.0/reference#list-bulkcharges

func (*BulkChargeService) ListN

func (s *BulkChargeService) ListN(count, offset int) (*BulkChargeBatchList, error)

ListN returns a list of bulkcharges For more details see https://developers.paystack.co/v1.0/reference#list-bulkcharges

func (*BulkChargeService) PauseBulkCharge

func (s *BulkChargeService) PauseBulkCharge(batchCode string) (Response, error)

PauseBulkCharge stops processing a batch For more details see https://developers.paystack.co/v1.0/reference#pause-bulk-charge-batch

func (*BulkChargeService) ResumeBulkCharge

func (s *BulkChargeService) ResumeBulkCharge(batchCode string) (Response, error)

ResumeBulkCharge stops processing a batch For more details see https://developers.paystack.co/v1.0/reference#resume-bulk-charge-batch

type BulkItem

type BulkItem struct {
	Authorization string  `json:"authorization,omitempty"`
	Amount        float32 `json:"amount,omitempty"`
}

BulkItem represents a single bulk charge request item

type BulkTransfer

type BulkTransfer struct {
	Currency  string                   `json:"currency,omitempty"`
	Source    string                   `json:"source,omitempty"`
	Transfers []map[string]interface{} `json:"transfers,omitempty"`
}

BulkTransfer represents a Paystack bulk transfer You need to disable the Transfers OTP requirement to use this endpoint

type Card

type Card struct {
	Number            string `json:"card_number,omitempty"`
	CVV               string `json:"card_cvc,omitempty"`
	ExpirtyMonth      string `json:"expiry_month,omitempty"`
	ExpiryYear        string `json:"expiry_year,omitempty"`
	AddressLine1      string `json:"address_line1,omitempty"`
	AddressLine2      string `json:"address_line2,omitempty"`
	AddressLine3      string `json:"address_line3,omitempty"`
	AddressCountry    string `json:"address_country,omitempty"`
	AddressPostalCode string `json:"address_postal_code,omitempty"`
	Country           string `json:"country,omitempty"`
}

Card represents a Card object

type ChargeRequest

type ChargeRequest struct {
	Email             string       `json:"email,omitempty"`
	Amount            float32      `json:"amount,omitempty"`
	Birthday          string       `json:"birthday,omitempty"`
	Card              *Card        `json:"card,omitempty"`
	Bank              *BankAccount `json:"bank,omitempty"`
	AuthorizationCode string       `json:"authorization_code,omitempty"`
	Pin               string       `json:"pin,omitempty"`
	Metadata          *Metadata    `json:"metadata,omitempty"`
}

ChargeRequest represents a Paystack charge request

type ChargeService

type ChargeService service

ChargeService handles operations related to bulk charges For more details see https://developers.paystack.co/v1.0/reference#charge-tokenize

func (*ChargeService) CheckPending

func (s *ChargeService) CheckPending(reference string) (Response, error)

CheckPending returns pending charges When you get "pending" as a charge status, wait 30 seconds or more, then make a check to see if its status has changed. Don't call too early as you may get a lot more pending than you should. For more details see https://developers.paystack.co/v1.0/reference#check-pending-charge

func (*ChargeService) Create

func (s *ChargeService) Create(req *ChargeRequest) (Response, error)

Create submits a charge request using card details or bank details or authorization code For more details see https://developers.paystack.co/v1.0/reference#charge

func (*ChargeService) SubmitBirthday

func (s *ChargeService) SubmitBirthday(birthday, reference string) (Response, error)

SubmitBirthday submits Birthday when requested For more details see https://developers.paystack.co/v1.0/reference#submit-pin

func (*ChargeService) SubmitOTP

func (s *ChargeService) SubmitOTP(otp, reference string) (Response, error)

SubmitOTP submits OTP to continue a charge For more details see https://developers.paystack.co/v1.0/reference#submit-pin

func (*ChargeService) SubmitPIN

func (s *ChargeService) SubmitPIN(pin, reference string) (Response, error)

SubmitPIN submits PIN to continue a charge For more details see https://developers.paystack.co/v1.0/reference#submit-pin

func (*ChargeService) SubmitPhone

func (s *ChargeService) SubmitPhone(phone, reference string) (Response, error)

SubmitPhone submits Phone when requested For more details see https://developers.paystack.co/v1.0/reference#submit-pin

func (*ChargeService) Tokenize

func (s *ChargeService) Tokenize(req *ChargeRequest) (Response, error)

Tokenize tokenizes payment instrument before a charge For more details see https://developers.paystack.co/v1.0/reference#charge-tokenize

type Client

type Client struct {

	// Services supported by the Paystack API.
	// Miscellaneous actions are directly implemented on the Client object
	Customer     *CustomerService
	Transaction  *TransactionService
	SubAccount   *SubAccountService
	Plan         *PlanService
	Subscription *SubscriptionService
	Page         *PageService
	Settlement   *SettlementService
	Transfer     *TransferService
	Charge       *ChargeService
	Bank         *BankService
	BulkCharge   *BulkChargeService

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

Client manages communication with the Paystack API

func NewClient

func NewClient(key string, httpClient *http.Client) *Client

NewClient creates a new Paystack API client with the given API key and HTTP client, allowing overriding of the HTTP client to use. This is useful if you're running in a Google AppEngine environment where the http.DefaultClient is not available.

func (*Client) Call

func (c *Client) Call(method, path string, body, v interface{}) error

Call actually does the HTTP request to Paystack API

func (*Client) CheckBalance

func (c *Client) CheckBalance() (Response, error)

CheckBalance docs https://developers.paystack.co/v1.0/reference#resolve-card-bin

func (*Client) GetSessionTimeout

func (c *Client) GetSessionTimeout() (Response, error)

GetSessionTimeout fetches payment session timeout

func (*Client) ResolveCardBIN

func (c *Client) ResolveCardBIN(bin int) (Response, error)

ResolveCardBIN docs https://developers.paystack.co/v1.0/reference#resolve-card-bin

func (*Client) UpdateSessionTimeout

func (c *Client) UpdateSessionTimeout(timeout int) (Response, error)

UpdateSessionTimeout updates payment session timeout

type Customer

type Customer struct {
	ID             int            `json:"id,omitempty"`
	CreatedAt      string         `json:"createdAt,omitempty"`
	UpdatedAt      string         `json:"updatedAt,omitempty"`
	Domain         string         `json:"domain,omitempty"`
	Integration    int            `json:"integration,omitempty"`
	FirstName      string         `json:"first_name,omitempty"`
	LastName       string         `json:"last_name,omitempty"`
	Email          string         `json:"email,omitempty"`
	Phone          string         `json:"phone,omitempty"`
	Metadata       Metadata       `json:"metadata,omitempty"`
	CustomerCode   string         `json:"customer_code,omitempty"`
	Subscriptions  []Subscription `json:"subscriptions,omitempty"`
	Authorizations []interface{}  `json:"authorizations,omitempty"`
	RiskAction     string         `json:"risk_action"`
}

Customer is the resource representing your Paystack customer. For more details see https://developers.paystack.co/v1.0/reference#create-customer

type CustomerList

type CustomerList struct {
	Meta   ListMeta
	Values []Customer `json:"data"`
}

CustomerList is a list object for customers.

type CustomerService

type CustomerService service

CustomerService handles operations related to the customer For more details see https://developers.paystack.co/v1.0/reference#create-customer

func (*CustomerService) Create

func (s *CustomerService) Create(customer *Customer) (*Customer, error)

Create creates a new customer For more details see https://developers.paystack.co/v1.0/reference#create-customer

func (*CustomerService) DeactivateAuthorization

func (s *CustomerService) DeactivateAuthorization(authorizationCode string) (*Response, error)

DeactivateAuthorization deactivates an authorization For more details see https://developers.paystack.co/v1.0/reference#deactivate-authorization

func (*CustomerService) Get

func (s *CustomerService) Get(customerCode string) (*Customer, error)

Get returns the details of a customer. For more details see https://paystack.com/docs/api/#customer-fetch

func (*CustomerService) List

func (s *CustomerService) List() (*CustomerList, error)

List returns a list of customers. For more details see https://developers.paystack.co/v1.0/reference#list-customers

func (*CustomerService) ListN

func (s *CustomerService) ListN(count, offset int) (*CustomerList, error)

ListN returns a list of customers For more details see https://developers.paystack.co/v1.0/reference#list-customers

func (*CustomerService) SetRiskAction

func (s *CustomerService) SetRiskAction(customerCode, riskAction string) (*Customer, error)

SetRiskAction can be used to either whitelist or blacklist a customer For more details see https://developers.paystack.co/v1.0/reference#whiteblacklist-customer

func (*CustomerService) Update

func (s *CustomerService) Update(customer *Customer) (*Customer, error)

Update updates a customer's properties. For more details see https://developers.paystack.co/v1.0/reference#update-customer

type ErrorResponse

type ErrorResponse struct {
	Status  bool                   `json:"status,omitempty"`
	Message string                 `json:"message,omitempty"`
	Errors  map[string]interface{} `json:"errors,omitempty"`
}

ErrorResponse represents an error response from the Paystack API server

type ListMeta

type ListMeta struct {
	Total     int `json:"total"`
	Skipped   int `json:"skipped"`
	PerPage   int `json:"perPage"`
	Page      int `json:"page"`
	PageCount int `json:"pageCount"`
}

ListMeta is pagination metadata for paginated responses from the Paystack API

type Logger

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

Logger interface for custom loggers

type Metadata

type Metadata map[string]interface{}

Metadata is an key-value pairs added to Paystack API requests

type Page

type Page struct {
	ID           int                 `json:"id,omitempty"`
	CreatedAt    string              `json:"createdAt,omitempty"`
	UpdatedAt    string              `json:"updatedAt,omitempty"`
	Domain       string              `json:"domain,omitempty"`
	Integration  int                 `json:"integration,omitempty"`
	Name         string              `json:"name,omitempty"`
	Slug         string              `json:"slug,omitempty"`
	Description  string              `json:"description,omitempty"`
	Amount       float32             `json:"amount,omitempty"`
	Currency     string              `json:"currency,omitempty"`
	Active       bool                `json:"active,omitempty"`
	RedirectURL  string              `json:"redirect_url,omitempty"`
	CustomFields []map[string]string `json:"custom_fields,omitempty"`
}

Page represents a Paystack page For more details see https://developers.paystack.co/v1.0/reference#create-page

type PageList

type PageList struct {
	Meta   ListMeta
	Values []Page `json:"data,omitempty"`
}

PageList is a list object for pages.

type PageService

type PageService service

PageService handles operations related to the page For more details see https://developers.paystack.co/v1.0/reference#create-page

func (*PageService) Create

func (s *PageService) Create(page *Page) (*Page, error)

Create creates a new page For more details see https://developers.paystack.co/v1.0/reference#create-page

func (*PageService) Get

func (s *PageService) Get(id int) (*Page, error)

Get returns the details of a page. For more details see https://developers.paystack.co/v1.0/reference#fetch-page

func (*PageService) List

func (s *PageService) List() (*PageList, error)

List returns a list of pages. For more details see https://developers.paystack.co/v1.0/reference#list-pages

func (*PageService) ListN

func (s *PageService) ListN(count, offset int) (*PageList, error)

ListN returns a list of pages For more details see https://developers.paystack.co/v1.0/reference#list-pages

func (*PageService) Update

func (s *PageService) Update(page *Page) (*Page, error)

Update updates a page's properties. For more details see https://developers.paystack.co/v1.0/reference#update-page

type Plan

type Plan struct {
	ID                int     `json:"id,omitempty"`
	CreatedAt         string  `json:"createdAt,omitempty"`
	UpdatedAt         string  `json:"updatedAt,omitempty"`
	Domain            string  `json:"domain,omitempty"`
	Integration       int     `json:"integration,omitempty"`
	Name              string  `json:"name,omitempty"`
	Description       string  `json:"description,omitempty"`
	PlanCode          string  `json:"plan_code,omitempty"`
	Amount            float32 `json:"amount,omitempty"`
	Interval          string  `json:"interval,omitempty"`
	SendInvoices      bool    `json:"send_invoices,omitempty"`
	SendSMS           bool    `json:"send_sms,omitempty"`
	Currency          string  `json:"currency,omitempty"`
	InvoiceLimit      float32 `json:"invoice_limit,omitempty"`
	HostedPage        string  `json:"hosted_page,omitempty"`
	HostedPageURL     string  `json:"hosted_page_url,omitempty"`
	HostedPageSummary string  `json:"hosted_page_summary,omitempty"`
}

Plan represents a For more details see https://developers.paystack.co/v1.0/reference#create-plan

type PlanList

type PlanList struct {
	Meta   ListMeta
	Values []Plan `json:"data"`
}

PlanList is a list object for Plans.

type PlanService

type PlanService service

PlanService handles operations related to the plan For more details see https://developers.paystack.co/v1.0/reference#create-plan

func (*PlanService) Create

func (s *PlanService) Create(plan *Plan) (*Plan, error)

Create creates a new plan For more details see https://developers.paystack.co/v1.0/reference#create-plan

func (*PlanService) Get

func (s *PlanService) Get(id int) (*Plan, error)

Get returns the details of a plan. For more details see https://developers.paystack.co/v1.0/reference#fetch-plan

func (*PlanService) List

func (s *PlanService) List() (*PlanList, error)

List returns a list of plans. For more details see https://developers.paystack.co/v1.0/reference#list-plans

func (*PlanService) ListN

func (s *PlanService) ListN(count, offset int) (*PlanList, error)

ListN returns a list of plans For more details see https://developers.paystack.co/v1.0/reference#list-plans

func (*PlanService) Update

func (s *PlanService) Update(plan *Plan) (Response, error)

Update updates a plan's properties. For more details see https://developers.paystack.co/v1.0/reference#update-plan

type RequestValues

type RequestValues url.Values

RequestValues aliased to url.Values as a workaround

func (RequestValues) MarshalJSON

func (v RequestValues) MarshalJSON() ([]byte, error)

MarshalJSON to handle custom JSON decoding for RequestValues

type Response

type Response map[string]interface{}

Response represents arbitrary response data

type SettlementList

type SettlementList struct {
	Meta   ListMeta
	Values []Response `json:"data,omitempty"`
}

SettlementList is a list object for settlements.

type SettlementService

type SettlementService service

SettlementService handles operations related to the settlement For more details see https://developers.paystack.co/v1.0/reference#create-settlement

func (*SettlementService) List

func (s *SettlementService) List() (*SettlementList, error)

List returns a list of settlements. For more details see https://developers.paystack.co/v1.0/reference#settlements

func (*SettlementService) ListN

func (s *SettlementService) ListN(count, offset int) (*SettlementList, error)

ListN returns a list of settlements For more details see https://developers.paystack.co/v1.0/reference#settlements

type SubAccount

type SubAccount struct {
	ID                  int      `json:"id,omitempty"`
	CreatedAt           string   `json:"createdAt,omitempty"`
	UpdatedAt           string   `json:"updatedAt,omitempty"`
	Domain              string   `json:"domain,omitempty"`
	Integration         int      `json:"integration,omitempty"`
	BusinessName        string   `json:"business_name,omitempty"`
	SubAccountCode      string   `json:"subaccount_code,omitempty"`
	Description         string   `json:"description,omitempty"`
	PrimaryContactName  string   `json:"primary_contact_name,omitempty"`
	PrimaryContactEmail string   `json:"primary_contact_email,omitempty"`
	PrimaryContactPhone string   `json:"primary_contact_phone,omitempty"`
	Metadata            Metadata `json:"metadata,omitempty"`
	PercentageCharge    float32  `json:"percentage_charge,omitempty"`
	IsVerified          bool     `json:"is_verified,omitempty"`
	SettlementBank      string   `json:"settlement_bank,omitempty"`
	AccountNumber       string   `json:"account_number,omitempty"`
	SettlementSchedule  string   `json:"settlement_schedule,omitempty"`
	Active              bool     `json:"active,omitempty"`
	Migrate             bool     `json:"migrate,omitempty"`
}

SubAccount is the resource representing your Paystack subaccount. For more details see https://developers.paystack.co/v1.0/reference#create-subaccount

type SubAccountList

type SubAccountList struct {
	Meta   ListMeta
	Values []SubAccount `json:"data"`
}

SubAccountList is a list object for subaccounts.

type SubAccountService

type SubAccountService service

SubAccountService handles operations related to sub accounts For more details see https://developers.paystack.co/v1.0/reference#create-subaccount

func (*SubAccountService) Create

func (s *SubAccountService) Create(subaccount *SubAccount) (*SubAccount, error)

Create creates a new subaccount For more details see https://paystack.com/docs/api/#subaccount-create

func (*SubAccountService) Get

func (s *SubAccountService) Get(id int) (*SubAccount, error)

Get returns the details of a subaccount. For more details see https://developers.paystack.co/v1.0/reference#fetch-subaccount TODO: use ID or slug

func (*SubAccountService) List

func (s *SubAccountService) List() (*SubAccountList, error)

List returns a list of subaccounts. For more details see https://developers.paystack.co/v1.0/reference#list-subaccounts

func (*SubAccountService) ListN

func (s *SubAccountService) ListN(count, offset int) (*SubAccountList, error)

ListN returns a list of subaccounts For more details see https://paystack.com/docs/api/#subaccount-list

func (*SubAccountService) Update

func (s *SubAccountService) Update(subaccount *SubAccount) (*SubAccount, error)

Update updates a subaccount's properties. For more details see https://developers.paystack.co/v1.0/reference#update-subaccount TODO: use ID or slug

type Subscription

type Subscription struct {
	ID          int    `json:"id,omitempty"`
	CreatedAt   string `json:"createdAt,omitempty"`
	UpdatedAt   string `json:"updatedAt,omitempty"`
	Domain      string `json:"domain,omitempty"`
	Integration int    `json:"integration,omitempty"`
	// inconsistent API response. Create returns Customer code, Fetch returns an object
	Customer  interface{} `json:"customer,omitempty"`
	Plan      string      `json:"plan,omitempty"`
	StartDate string      `json:"start,omitempty"`
	// inconsistent API response. Fetch returns string, List returns an object
	Authorization    interface{}   `json:"authorization,omitempty"`
	Invoices         []interface{} `json:"invoices,omitempty"`
	Status           string        `json:"status,omitempty"`
	Quantity         int           `json:"quantity,omitempty"`
	Amount           int           `json:"amount,omitempty"`
	SubscriptionCode string        `json:"subscription_code,omitempty"`
	EmailToken       string        `json:"email_token,omitempty"`
	EasyCronID       string        `json:"easy_cron_id,omitempty"`
	CronExpression   string        `json:"cron_expression,omitempty"`
	NextPaymentDate  string        `json:"next_payment_date,omitempty"`
	OpenInvoice      string        `json:"open_invoice,omitempty"`
}

Subscription represents a Paystack subscription For more details see https://developers.paystack.co/v1.0/reference#create-subscription

type SubscriptionList

type SubscriptionList struct {
	Meta   ListMeta
	Values []Subscription `json:"data"`
}

SubscriptionList is a list object for subscriptions.

type SubscriptionRequest

type SubscriptionRequest struct {
	// customer code or email address
	Customer string `json:"customer,omitempty"`
	// plan code
	Plan          string `json:"plan,omitempty"`
	Authorization string `json:"authorization,omitempty"`
	StartDate     string `json:"start,omitempty"`
}

SubscriptionRequest represents a Paystack subscription request

type SubscriptionService

type SubscriptionService service

SubscriptionService handles operations related to the subscription For more details see https://developers.paystack.co/v1.0/reference#create-subscription

func (*SubscriptionService) Create

func (s *SubscriptionService) Create(subscription *SubscriptionRequest) (*Subscription, error)

Create creates a new subscription For more details see https://developers.paystack.co/v1.0/reference#create-subscription

func (*SubscriptionService) Disable

func (s *SubscriptionService) Disable(subscriptionCode, emailToken string) (Response, error)

Disable disables a subscription For more details see https://developers.paystack.co/v1.0/reference#disable-subscription

func (*SubscriptionService) Enable

func (s *SubscriptionService) Enable(subscriptionCode, emailToken string) (Response, error)

Enable enables a subscription For more details see https://developers.paystack.co/v1.0/reference#enable-subscription

func (*SubscriptionService) Get

func (s *SubscriptionService) Get(id int) (*Subscription, error)

Get returns the details of a subscription. For more details see https://developers.paystack.co/v1.0/reference#fetch-subscription

func (*SubscriptionService) List

List returns a list of subscriptions. For more details see https://developers.paystack.co/v1.0/reference#list-subscriptions

func (*SubscriptionService) ListN

func (s *SubscriptionService) ListN(count, offset int) (*SubscriptionList, error)

ListN returns a list of subscriptions For more details see https://developers.paystack.co/v1.0/reference#list-subscriptions

func (*SubscriptionService) Update

func (s *SubscriptionService) Update(subscription *Subscription) (*Subscription, error)

Update updates a subscription's properties. For more details see https://developers.paystack.co/v1.0/reference#update-subscription

type Transaction

type Transaction struct {
	ID              int                    `json:"id,omitempty"`
	CreatedAt       string                 `json:"createdAt,omitempty"`
	Domain          string                 `json:"domain,omitempty"`
	Metadata        string                 `json:"metadata,omitempty"` //TODO: why is transaction metadata a string?
	Status          string                 `json:"status,omitempty"`
	Reference       string                 `json:"reference,omitempty"`
	Amount          float32                `json:"amount,omitempty"`
	Message         string                 `json:"message,omitempty"`
	GatewayResponse string                 `json:"gateway_response,omitempty"`
	PaidAt          string                 `json:"piad_at,omitempty"`
	Channel         string                 `json:"channel,omitempty"`
	Currency        string                 `json:"currency,omitempty"`
	IPAddress       string                 `json:"ip_address,omitempty"`
	Log             map[string]interface{} `json:"log,omitempty"` // TODO: same as timeline?
	Fees            int                    `json:"int,omitempty"`
	FeesSplit       string                 `json:"fees_split,omitempty"` // TODO: confirm data type
	Customer        Customer               `json:"customer,omitempty"`
	Authorization   Authorization          `json:"authorization,omitempty"`
	Plan            Plan                   `json:"plan,omitempty"`
	SubAccount      SubAccount             `json:"sub_account,omitempty"`
}

Transaction is the resource representing your Paystack transaction. For more details see https://developers.paystack.co/v1.0/reference#initialize-a-transaction

type TransactionList

type TransactionList struct {
	Meta   ListMeta
	Values []Transaction `json:"data"`
}

TransactionList is a list object for transactions.

type TransactionRequest

type TransactionRequest struct {
	CallbackURL       string   `json:"callback_url,omitempty"`
	Reference         string   `json:"reference,omitempty"`
	AuthorizationCode string   `json:"authorization_code,omitempty"`
	Currency          string   `json:"currency,omitempty"`
	Amount            float32  `json:"amount,omitempty"`
	Email             string   `json:"email,omitempty"`
	Plan              string   `json:"plan,omitempty"`
	InvoiceLimit      int      `json:"invoice_limit,omitempty"`
	Metadata          Metadata `json:"metadata,omitempty"`
	SubAccount        string   `json:"subaccount,omitempty"`
	TransactionCharge int      `json:"transaction_charge,omitempty"`
	Bearer            string   `json:"bearer,omitempty"`
	Channels          []string `json:"channels,omitempty"`
}

TransactionRequest represents a request to start a transaction.

type TransactionService

type TransactionService service

TransactionService handles operations related to transactions For more details see https://developers.paystack.co/v1.0/reference#create-transaction

func (*TransactionService) ChargeAuthorization

func (s *TransactionService) ChargeAuthorization(req *TransactionRequest) (*Transaction, error)

ChargeAuthorization is for charging all authorizations marked as reusable whenever you need to recieve payments. For more details see https://developers.paystack.co/v1.0/reference#charge-authorization

func (*TransactionService) CheckAuthorization

func (s *TransactionService) CheckAuthorization(req AuthorizationRequest) (Response, error)

CheckAuthorization checks authorization For more details see https://developers.paystack.co/v1.0/reference#check-authorization

func (*TransactionService) Export

func (s *TransactionService) Export(params RequestValues) (Response, error)

Export exports transactions to a downloadable file and returns a link to the file For more details see https://developers.paystack.co/v1.0/reference#export-transactions

func (*TransactionService) Get

func (s *TransactionService) Get(id int) (*Transaction, error)

Get returns the details of a transaction. For more details see https://developers.paystack.co/v1.0/reference#fetch-transaction

func (*TransactionService) Initialize

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

Initialize initiates a transaction process For more details see https://developers.paystack.co/v1.0/reference#initialize-a-transaction

func (*TransactionService) List

List returns a list of transactions. For more details see https://paystack.com/docs/api/#transaction-list

func (*TransactionService) ListN

func (s *TransactionService) ListN(count, offset int) (*TransactionList, error)

ListN returns a list of transactions For more details see https://developers.paystack.co/v1.0/reference#list-transactions

func (*TransactionService) ReAuthorize

func (s *TransactionService) ReAuthorize(req AuthorizationRequest) (Response, error)

ReAuthorize requests reauthorization For more details see https://developers.paystack.co/v1.0/reference#request-reauthorization

func (*TransactionService) Timeline

func (s *TransactionService) Timeline(reference string) (*TransactionTimeline, error)

Timeline fetches the transaction timeline. Reference can be ID or transaction reference For more details see https://developers.paystack.co/v1.0/reference#view-transaction-timeline

func (*TransactionService) Totals

func (s *TransactionService) Totals() (Response, error)

Totals returns total amount received on your account For more details see https://developers.paystack.co/v1.0/reference#transaction-totals

func (*TransactionService) Verify

func (s *TransactionService) Verify(reference string) (*Transaction, error)

Verify checks that transaction with the given reference exists For more details see https://api.paystack.co/transaction/verify/reference

type TransactionTimeline

type TransactionTimeline struct {
	TimeSpent      int                      `json:"time_spent,omitempty"`
	Attempts       int                      `json:"attempts,omitempty"`
	Authentication string                   `json:"authentication,omitempty"` // TODO: confirm type
	Errors         int                      `json:"errors,omitempty"`
	Success        bool                     `json:"success,omitempty"`
	Mobile         bool                     `json:"mobile,omitempty"`
	Input          []string                 `json:"input,omitempty"` // TODO: confirm type
	Channel        string                   `json:"channel,omitempty"`
	History        []map[string]interface{} `json:"history,omitempty"`
}

TransactionTimeline represents a timeline of events in a transaction session

type Transfer

type Transfer struct {
	ID           int     `json:"id,omitempty"`
	CreatedAt    string  `json:"createdAt,omitempty"`
	UpdatedAt    string  `json:"updatedAt,omitempty"`
	Domain       string  `json:"domain,omitempty"`
	Integration  int     `json:"integration,omitempty"`
	Source       string  `json:"source,omitempty"`
	Amount       float32 `json:"amount,omitempty"`
	Currency     string  `json:"currency,omitempty"`
	Reason       string  `json:"reason,omitempty"`
	TransferCode string  `json:"transfer_code,omitempty"`
	// Initiate returns recipient ID as recipient value, Fetch returns recipient object
	Recipient interface{} `json:"recipient,omitempty"`
	Status    string      `json:"status,omitempty"`
	// confirm types for source_details and failures
	SourceDetails interface{} `json:"source_details,omitempty"`
	Failures      interface{} `json:"failures,omitempty"`
	TransferredAt string      `json:"transferred_at,omitempty"`
	TitanCode     string      `json:"titan_code,omitempty"`
}

Transfer is the resource representing your Paystack transfer. For more details see https://developers.paystack.co/v1.0/reference#initiate-transfer

type TransferList

type TransferList struct {
	Meta   ListMeta
	Values []Transfer `json:"data,omitempty"`
}

TransferList is a list object for transfers.

type TransferRecipient

type TransferRecipient struct {
	ID            int                    `json:"id,omitempty"`
	CreatedAt     string                 `json:"createdAt,omitempty"`
	UpdatedAt     string                 `json:"updatedAt,omitempty"`
	Type          string                 `json:",omitempty"`
	Name          string                 `json:"name,omitempty"`
	Metadata      Metadata               `json:"metadata,omitempty"`
	AccountNumber string                 `json:"account_number,omitempty"`
	BankCode      string                 `json:"bank_code,omitempty"`
	Currency      string                 `json:"currency,omitempty"`
	Description   string                 `json:"description,omitempty"`
	Active        bool                   `json:"active,omitempty"`
	Details       map[string]interface{} `json:"details,omitempty"`
	Domain        string                 `json:"domain,omitempty"`
	RecipientCode string                 `json:"recipient_code,omitempty"`
}

TransferRecipient represents a Paystack transfer recipient For more details see https://developers.paystack.co/v1.0/reference#create-transfer-recipient

type TransferRecipientList

type TransferRecipientList struct {
	Meta   ListMeta
	Values []TransferRecipient `json:"data,omitempty"`
}

TransferRecipientList is a list object for transfer recipient.

type TransferRequest

type TransferRequest struct {
	Source    string  `json:"source,omitempty"`
	Amount    float32 `json:"amount,omitempty"`
	Currency  string  `json:"currency,omitempty"`
	Reason    string  `json:"reason,omitempty"`
	Recipient string  `json:"recipient,omitempty"`
}

TransferRequest represents a request to create a transfer.

type TransferService

type TransferService service

TransferService handles operations related to the transfer For more details see https://developers.paystack.co/v1.0/reference#create-transfer

func (*TransferService) CreateRecipient

func (s *TransferService) CreateRecipient(recipient *TransferRecipient) (*TransferRecipient, error)

CreateRecipient creates a new transfer recipient For more details see https://developers.paystack.co/v1.0/reference#create-transferrecipient

func (*TransferService) DisableOTP

func (s *TransferService) DisableOTP() (Response, error)

DisableOTP disables OTP requirement for Transfers In the event that you want to be able to complete transfers programmatically without use of OTPs, this endpoint helps disable that…. with an OTP. No arguments required. You will get an OTP.

func (*TransferService) EnableOTP

func (s *TransferService) EnableOTP() (Response, error)

EnableOTP enables OTP requirement for Transfers In the event that a customer wants to stop being able to complete transfers programmatically, this endpoint helps turn OTP requirement back on. No arguments required.

func (*TransferService) Finalize

func (s *TransferService) Finalize(code, otp string) (Response, error)

Finalize completes a transfer request For more details see https://developers.paystack.co/v1.0/reference#finalize-transfer

func (*TransferService) FinalizeOTPDisable

func (s *TransferService) FinalizeOTPDisable(otp string) (Response, error)

FinalizeOTPDisable finalizes disabling of OTP requirement for Transfers For more details see https://developers.paystack.co/v1.0/reference#finalize-disabling-of-otp-requirement-for-transfers

func (*TransferService) Get

func (s *TransferService) Get(idCode string) (*Transfer, error)

Get returns the details of a transfer. For more details see https://developers.paystack.co/v1.0/reference#fetch-transfer

func (*TransferService) Initiate

func (s *TransferService) Initiate(req *TransferRequest) (*Transfer, error)

Initiate initiates a new transfer For more details see https://developers.paystack.co/v1.0/reference#initiate-transfer

func (*TransferService) List

func (s *TransferService) List() (*TransferList, error)

List returns a list of transfers. For more details see https://developers.paystack.co/v1.0/reference#list-transfers

func (*TransferService) ListN

func (s *TransferService) ListN(count, offset int) (*TransferList, error)

ListN returns a list of transfers For more details see https://developers.paystack.co/v1.0/reference#list-transfers

func (*TransferService) ListRecipients

func (s *TransferService) ListRecipients() (*TransferRecipientList, error)

ListRecipients returns a list of transfer recipients. For more details see https://developers.paystack.co/v1.0/reference#list-transferrecipients

func (*TransferService) ListRecipientsN

func (s *TransferService) ListRecipientsN(count, offset int) (*TransferRecipientList, error)

ListRecipientsN returns a list of transfer recipients For more details see https://developers.paystack.co/v1.0/reference#list-transferrecipients

func (*TransferService) MakeBulkTransfer

func (s *TransferService) MakeBulkTransfer(req *BulkTransfer) (Response, error)

MakeBulkTransfer initiates a new bulk transfer request You need to disable the Transfers OTP requirement to use this endpoint For more details see https://developers.paystack.co/v1.0/reference#initiate-bulk-transfer

func (*TransferService) ResendOTP

func (s *TransferService) ResendOTP(transferCode, reason string) (Response, error)

ResendOTP generates a new OTP and sends to customer in the event they are having trouble receiving one. For more details see https://developers.paystack.co/v1.0/reference#resend-otp-for-transfer

Jump to

Keyboard shortcuts

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