haystack
Haystack
Haystack is a low-level API client for Paystack. It features an intuitive interface that maps directly to the Paystack API.
Haystack comes with a webhook handler that intercepts events received from Paystack, and allows you to perform actions based on the event type.
Usage Examples
-
Create client:
paystack = Haystack.new(secret_key: "secret-key") -
Create charge:
paystack.charges.create( email: "customer@email.com", amount: "20000" ) do |response| return puts response.message unless response.success? response.data.try do |transaction| puts transaction.transaction_date.try &.second puts transaction.subaccount.try &.account_number puts transaction.status # ... end end -
Initialize transaction:
paystack.transactions.initiate( email: "customer@email.com", amount: "20000", currency: "GHS" ) do |response| return puts response.message unless response.success? response.data.try do |authorization| puts authorization.access_code puts authorization.authorization_url puts authorization.reference # ... end end -
Verify transaction:
paystack.transactions.verify(reference: "abcdef") do |response| return puts response.message unless response.success? response.data.try do |transaction| puts transaction.status puts transaction.authorization.try &.authorization_code puts transaction.channel # ... end end -
List invoices:
paystack.invoices.list(perPage: "20", page: "2") do |response| return puts response.message unless response.success? response.data.try &.each do |invoice| puts invoice.archived puts invoice.currency puts invoice.description # ... end end
Documentation
Find the complete documentation in the docs/ directory of this repository.
Development
-
Copy your test secret key from your Paystack dashboard.
-
Create a
.env.shfile:#!/bin/bash # export PAYSTACK_SECRET_KEY='your-paystack-test-secret-key-here' -
Update the file with your own details. Then run tests with
source .env.sh && crystal spec.
IMPORTANT: Remember to set permissions for your env file to 0600 or stricter: chmod 0600 .env*.
Contributing
- Fork it
- Switch to the
masterbranch:git checkout master - Create your feature branch:
git checkout -b my-new-feature - Make your changes, updating changelog and documentation as appropriate.
- Commit your changes:
git commit - Push to the branch:
git push origin my-new-feature - Submit a new Pull Request against the
GrottoPress:masterbranch.
haystack
- 6
- 0
- 0
- 0
- 2
- 4 months ago
- July 7, 2021
MIT License
Fri, 31 Oct 2025 17:40:54 GMT