https://github.com/rammyblog/go-paystack
A simple paystack wrapper built using GO
https://github.com/rammyblog/go-paystack
go golang paystack paystack-api
Last synced: 10 days ago
JSON representation
A simple paystack wrapper built using GO
- Host: GitHub
- URL: https://github.com/rammyblog/go-paystack
- Owner: rammyblog
- Created: 2023-11-08T00:13:10.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-16T03:02:57.000Z (11 months ago)
- Last Synced: 2025-04-30T07:05:00.487Z (9 months ago)
- Topics: go, golang, paystack, paystack-api
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-paystack
A Go client library for [Paystack](https://paystack.com), a payments platform that allows you to accept payments from customers in 154+ countries.
## Installation
```bash
go get github.com/rammyblog/go-paystack
```
## Usage
```go
package main
import (
"context"
"log"
"time"
"github.com/rammyblog/go-paystack"
"github.com/rammyblog/go-paystack/transaction"
)
func main() {
// Create client with default settings
client := paystack.New("sk_test_your_secret_key")
// Or with custom options
client := paystack.New("sk_test_your_secret_key",
paystack.WithTimeout(10*time.Second),
)
ctx := context.Background()
// Initialize a transaction
resp, err := client.Transaction.Initialize(ctx, &transaction.TransactionRequest{
Amount: 100000, // Amount in kobo (1000 NGN)
Email: "customer@example.com",
Currency: "NGN",
Reference: "unique_reference",
CallbackURL: "https://yoursite.com/callback",
})
if err != nil {
log.Fatal(err)
}
log.Printf("Authorization URL: %s\n", resp.AuthorizationURL)
// Verify a transaction
txn, err := client.Transaction.Verify(ctx, "reference")
if err != nil {
log.Fatal(err)
}
log.Printf("Transaction status: %s\n", txn.Status)
// List transactions with query parameters
list, err := client.Transaction.List(ctx, paystack.Query("page", "1"))
if err != nil {
log.Fatal(err)
}
log.Printf("Total transactions: %d\n", list.Meta.Total)
}
```
## Available Services
- **Transaction** - Initialize, verify, list, charge, export transactions
- **Plans** - Create, list, fetch, update subscription plans
- **Subscription** - Create, list, enable, disable subscriptions
- **Transaction Splits** - Create and manage split payments
## Client Options
```go
// Custom HTTP client
paystack.New(apiKey, paystack.WithHTTPClient(customClient))
// Custom timeout
paystack.New(apiKey, paystack.WithTimeout(30*time.Second))
// Custom logger
paystack.New(apiKey, paystack.WithLogger(customLogger))
```
## Examples
See the [example](./example) directory for more usage examples.
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
## License
[MIT](https://choosealicense.com/licenses/mit/)