opsofts / laravel-paystack
Lightweight Paystack integration for Laravel, built directly on Laravel's own HTTP client.
Requires
- php: ^8.2
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
README
A minimal Paystack integration for Laravel, built directly on Laravel's own HTTP client (Illuminate\Support\Facades\Http). No external HTTP SDK dependency — just illuminate/support/illuminate/http, which ship with every Laravel app and are maintained on the same cadence as the framework itself.
What it does
Implements the four Paystack operations most apps actually need:
- Initialize a transaction — start a Paystack checkout and get back an authorization URL to redirect the payer to
- Verify a transaction — confirm a transaction's status by reference, typically after redirect or inside a webhook handler
- Refund — issue a full or partial refund against a transaction reference
- Verify a webhook signature — validate the
x-paystack-signatureheader (HMAC-SHA512) before trusting any webhook payload
Anything beyond these (bank list lookups, transfer recipients, subaccounts, etc.) isn't included — the package stays intentionally small. Feel free to extend src/Paystack.php if you need more of Paystack's API surface.
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
Install
composer require opsofts/laravel-paystack php artisan vendor:publish --tag=paystack-config
Set your keys in .env:
PAYSTACK_PUBLIC_KEY=pk_... PAYSTACK_SECRET_KEY=sk_... PAYSTACK_MERCHANT_EMAIL=you@example.com
Usage
use Opsofts\LaravelPaystack\Facades\Paystack; // Initialize a transaction $data = Paystack::initializeTransaction([ 'email' => $customer->email, 'amount' => $amountInKobo, // smallest currency unit, not decimal Naira 'reference' => $orderReference, 'callback_url' => route('payment.callback'), ]); // redirect the payer to $data['authorization_url'] // Verify after redirect and/or from a webhook handler $data = Paystack::verifyTransaction($reference); if ($data['status'] === 'success') { // mark the order/payment as paid } // Refund (full or partial) Paystack::refund($transactionReference, amount: $partialAmountInKobo); // Webhook signature verification -- do this before trusting ANY webhook payload $isValid = Paystack::verifyWebhookSignature( rawPayload: $request->getContent(), signatureHeader: $request->header('x-paystack-signature'), ); if (! $isValid) { abort(401); }
What this package deliberately does not do
No card storage, no saved payment methods. It only ever talks to Paystack's API and hands back what Paystack returns — persisting authorization_url/reference/gateway tokens on your own models is the calling application's responsibility, same as with any SDK.
Testing
Http::fake() works exactly as it does for any Laravel HTTP client usage — fake the api.paystack.co/* pattern in your tests rather than hitting the real API. No custom test helpers are provided; standard Laravel HTTP testing covers this package fully.
License
MIT.