chainbook/paystack

A Laravel package for seamless Paystack payment integration — initialize transactions, verify payments, manage customers, plans and subscriptions.

Maintainers

Package info

github.com/Chainbook-Software/laravel-paystack

Homepage

pkg:composer/chainbook/paystack

Statistics

Installs: 91

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-03-09 08:09 UTC

This package is not auto-updated.

Last update: 2026-04-07 06:38:58 UTC


README

Latest Version on Packagist Total Downloads License

A clean, simple Laravel package for Paystack payment integration. Supports transactions, customers, plans, subscriptions and webhook verification — with zero configuration beyond your API keys.

Requirements

  • PHP ^8.1
  • Laravel ^10 | ^11 | ^12

Installation

composer require chainbook/paystack

Laravel's auto-discovery will register the service provider and Paystack facade automatically.

Publish the config file (optional)

php artisan vendor:publish --provider="Chainbook\Paystack\PaystackServiceProvider" --tag="paystack-config"

Add your keys to .env

PAYSTACK_PUBLIC_KEY=pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PAYSTACK_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Usage

Transactions

use Chainbook\Paystack\Facades\Paystack;

// Initialize a transaction
$response = Paystack::initializeTransaction([
    'email'        => 'customer@example.com',
    'amount'       => 500000, // Amount in kobo/pesewas (= 5000 NGN/GHS)
    'reference'    => uniqid('ref_'),
    'callback_url' => 'https://yourapp.com/payment/callback',
]);

// $response['data']['authorization_url'] — redirect the user here

// Verify a transaction
$verification = Paystack::verifyTransaction('ref_abc123');

if ($verification['data']['status'] === 'success') {
    // Payment confirmed
}

// List transactions
$transactions = Paystack::listTransactions(['perPage' => 20, 'page' => 1]);

// Fetch a specific transaction
$transaction = Paystack::fetchTransaction(123456789);

// Charge a returning customer using saved authorization
$charge = Paystack::chargeAuthorization([
    'authorization_code' => 'AUTH_xxxxxxxx',
    'email'              => 'customer@example.com',
    'amount'             => 500000,
]);

Customers

// Create a customer
$customer = Paystack::createCustomer([
    'email'      => 'customer@example.com',
    'first_name' => 'Jane',
    'last_name'  => 'Doe',
    'phone'      => '+2348012345678',
]);

// Fetch a customer (by ID or customer code)
$customer = Paystack::fetchCustomer('CUS_xxxxxxxx');

// Update a customer
Paystack::updateCustomer('CUS_xxxxxxxx', ['first_name' => 'Janet']);

// List customers
$customers = Paystack::listCustomers(['perPage' => 50]);

Plans & Subscriptions

// Create a plan
$plan = Paystack::createPlan([
    'name'     => 'Monthly Premium',
    'interval' => 'monthly',
    'amount'   => 500000,
]);

// List plans / fetch / subscribe
$plans         = Paystack::listPlans();
$plan          = Paystack::fetchPlan('PLN_xxxxxxxx');
$subscription  = Paystack::createSubscription([
    'customer'   => 'CUS_xxxxxxxx',
    'plan'       => 'PLN_xxxxxxxx',
    'start_date' => now()->addDay()->toIso8601String(),
]);
$subscriptions = Paystack::listSubscriptions();

Webhook Verification

// routes/web.php
Route::post('/webhooks/paystack', function (Illuminate\Http\Request $request) {
    $signature = $request->header('X-Paystack-Signature');
    $computed  = hash_hmac('sha512', $request->getContent(), config('paystack.secret_key'));

    if ($signature !== $computed) {
        abort(400, 'Invalid signature');
    }

    $event = $request->json()->all();

    match ($event['event'] ?? null) {
        'charge.success'   => /* handle payment */ null,
        'transfer.success' => /* handle transfer */ null,
        default            => null,
    };

    return response('OK', 200);
})->withoutMiddleware([\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class]);

Get the Public Key (for frontend/JavaScript use)

$publicKey = Paystack::getPublicKey();

Configuration

After publishing, edit config/paystack.php:

return [
    'public_key'     => env('PAYSTACK_PUBLIC_KEY'),
    'secret_key'     => env('PAYSTACK_SECRET_KEY'),
    'base_url'       => env('PAYSTACK_BASE_URL', 'https://api.paystack.co'),
    'webhook_secret' => env('PAYSTACK_WEBHOOK_SECRET'),
];

Testing

composer test

License

The MIT License (MIT). See LICENSE for more information.