Go library for the Paystack API https://developers.paystack.co/v1.0/reference
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
Dockerfile.test
LICENSE
Makefile
README.md
bank.go
bank_test.go
bulkcharge.go
charge.go
charge_test.go
customer.go
customer_test.go
doc.go
error.go
glide.lock
glide.yaml
page.go
page_test.go
paystack.go
paystack_test.go
plan.go
plan_test.go
runtests.sh
settlement.go
settlement_test.go
subaccount.go
subaccount_test.go
subscription.go
subscription_test.go
transaction.go
transaction_test.go
transfer.go
transfer_test.go

README.md

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:

$ make docker && docker run -i -t paystack:latest

To use a different API key, update the API key in runtests.sh file.

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.