Search by

toneflix / paystack-php

3m1n3nc3

A modern, dependency-light PHP client for the Paystack API.

Package info

github.com/toneflix/paystack-php

pkg:composer/toneflix/paystack-php

Statistics

Installs: 190

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-24 06:40 UTC

This package is auto-updated.

Last update: 2026-10-24 08:13:05 UTC


README

Latest Version on Packagist Tests Total Downloads

Introduction

A small, dependency-light PHP client for the Paystack API. It covers transactions, transfers, transfer recipients and customer authorization management, and is built against PHP 8.3/8.4 with no required HTTP client dependency (cURL is used directly, and the transport is swappable for testing).

Installation

composer require toneflix/paystack-php

Usage

use Toneflix\Paystack\Paystack;

$paystack = new Paystack('sk_test_xxx');

// Initialize a transaction
$tranx = $paystack->transaction->initialize([
    'amount' => 500000, // in kobo
    'email' => 'customer@example.com',
    'reference' => 'TRX-123',
]);

// Verify a transaction
$verified = $paystack->transaction->verify(['reference' => 'TRX-123']);

// Deactivate a customer's saved authorization
$paystack->customer->deactivateAuthorization('AUTH_abc123');

// Create a transfer recipient and initiate a transfer
$recipient = $paystack->transferrecipient->create([
    'type' => 'nuban',
    'name' => 'Jane Doe',
    'account_number' => '0123456789',
    'bank_code' => '058',
    'currency' => 'NGN',
]);

$transfer = $paystack->transfer->initiate([
    'source' => 'balance',
    'amount' => 500000,
    'recipient' => $recipient->data->recipient_code,
    'reference' => 'TRX-124',
]);

Building checkout metadata

MetadataBuilder mirrors Paystack's metadata object: withCustomField() appends an entry to custom_fields, and any other withX() call sets the matching snake_case key (e.g. withCancelAction($url) sets cancel_action).

use Toneflix\Paystack\MetadataBuilder;

$metadata = (new MetadataBuilder())
    ->withCustomField('Name', 'Jane Doe')
    ->withCancelAction('https://example.com/cancel')
    ->build();

$paystack->transaction->initialize([
    'amount' => 500000,
    'email' => 'customer@example.com',
    'metadata' => $metadata,
]);

Error handling

A failed API call throws Toneflix\Paystack\Exception\ApiException, whose getResponseObject() returns the decoded Paystack response (when one was received) for inspection.

use Toneflix\Paystack\Exception\ApiException;

try {
    $paystack->transaction->initialize(['amount' => -1]);
} catch (ApiException $e) {
    report($e->getMessage());
    report($e->getResponseObject());
}

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.