Categorygithub.com/borderlesshq/paystack-go
modulepackage
0.0.3
Repository: https://github.com/borderlesshq/paystack-go.git
Documentation: pkg.go.dev

# 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/borderlesshq/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:     "[email protected]",
    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.

# Functions

NewClient creates a new Paystack API client with the given API key and HTTP client, allowing overriding of the HTTP client to use.

# Structs

APIError includes the response from the Paystack API and some HTTP request info.
No description provided by the author
Authorization represents Paystack authorization object.
AuthorizationRequest represents a request to enable/revoke an authorization.
Bank represents a Paystack bank.
BankAccount is used as bank in a charge request.
BankList is a list object for banks.
BulkChargeBatch represents a bulk charge batch object For more details see https://developers.paystack.co/v1.0/reference#initiate-bulk-charge.
BulkChargeBatchList is a list object for bulkcharges.
BulkChargeRequest is an array of objects with authorization codes and amount.
BulkItem represents a single bulk charge request item.
BulkTransfer represents a Paystack bulk transfer You need to disable the Transfers OTP requirement to use this endpoint.
BVNResponse represents response from resolve_bvn endpoint.
Card represents a Card object.
ChargeRequest represents a Paystack charge request.
Client manages communication with the Paystack API.
Customer is the resource representing your Paystack customer.
CustomerList is a list object for customers.
ErrorResponse represents an error response from the Paystack API server.
ListMeta is pagination metadata for paginated responses from the Paystack API.
Page represents a Paystack page For more details see https://developers.paystack.co/v1.0/reference#create-page.
PageList is a list object for pages.
Plan represents a For more details see https://developers.paystack.co/v1.0/reference#create-plan.
PlanList is a list object for Plans.
SettlementList is a list object for settlements.
SubAccount is the resource representing your Paystack subaccount.
SubAccountList is a list object for subaccounts.
Subscription represents a Paystack subscription For more details see https://developers.paystack.co/v1.0/reference#create-subscription.
SubscriptionList is a list object for subscriptions.
SubscriptionRequest represents a Paystack subscription request.
Transaction is the resource representing your Paystack transaction.
TransactionList is a list object for transactions.
TransactionRequest represents a request to start a transaction.
TransactionTimeline represents a timeline of events in a transaction session.
Transfer is the resource representing your Paystack transfer.
TransferList is a list object for transfers.
TransferRecipient represents a Paystack transfer recipient For more details see https://developers.paystack.co/v1.0/reference#create-transfer-recipient.
TransferRecipientList is a list object for transfer recipient.
TransferRequest represents a request to create a transfer.
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

Logger interface for custom loggers.

# Type aliases

BankService handles operations related to the bank For more details see https://developers.paystack.co/v1.0/reference#bank.
BulkChargeService handles operations related to the bulkcharge For more details see https://developers.paystack.co/v1.0/reference#initiate-bulk-charge.
ChargeService handles operations related to bulk charges For more details see https://developers.paystack.co/v1.0/reference#charge-tokenize.
CustomerService handles operations related to the customer For more details see https://developers.paystack.co/v1.0/reference#create-customer.
Metadata is an key-value pairs added to Paystack API requests.
PageService handles operations related to the page For more details see https://developers.paystack.co/v1.0/reference#create-page.
PlanService handles operations related to the plan For more details see https://developers.paystack.co/v1.0/reference#create-plan.
RequestValues aliased to url.Values as a workaround.
Response represents arbitrary response data.
SettlementService handles operations related to the settlement For more details see https://developers.paystack.co/v1.0/reference#create-settlement.
SubAccountService handles operations related to sub accounts For more details see https://developers.paystack.co/v1.0/reference#create-subaccount.
SubscriptionService handles operations related to the subscription For more details see https://developers.paystack.co/v1.0/reference#create-subscription.
TransactionService handles operations related to transactions For more details see https://developers.paystack.co/v1.0/reference#create-transaction.
TransferService handles operations related to the transfer For more details see https://developers.paystack.co/v1.0/reference#create-transfer.
No description provided by the author