This documentation provides a comprehensive guide to the MusheAbdulHakim\Paystack PHP SDK, a robust and intuitive library designed for seamless integration with the Paystack API. Built with a focus on developer experience, this SDK offers a fluent, object-oriented interface to manage your payments, customers, subscriptions, and more.
Key Features:
Fluent API: Chain method calls for clean, readable, and highly maintainable code.
Object-Oriented Design: Encapsulates Paystack API endpoints into dedicated classes for logical organization.
PSR-18 HTTP Client Support: Flexible integration with any PSR-18 compatible HTTP client.
Strong Typing: Leverages PHP’s type hints for improved code quality and IDE support.
Extensible Architecture: Easily extendable to accommodate custom transporters or new API modules.
Getting Started
Installation
The recommended way to install the Paystack PHP SDK is via Composer:
composer require musheabdulhakim/paystack
Quick Start
Initialize the Paystack client using your secret key to begin interacting with the API.
Simple Initialization:
<?phpuseMusheAbdulHakim\Paystack\Paystack;$secretKey='sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxx';// Replace with your actual Paystack secret key$client=Paystack::client($secretKey);// Example: List all transactions$transactions=$client->transaction()->list();print_r($transactions);?>
Advanced Initialization with Factory:
For more control over the HTTP client, base URI, or default headers, use the Paystack::factory() method:
<?phpuseMusheAbdulHakim\Paystack\Paystack;useGuzzleHttp\ClientasGuzzleHttpClient;// Example: Using Guzzle as a custom client$secretKey='sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxx';// Replace with your actual Paystack secret key$client=Paystack::factory()->withSecretKey($secretKey)->withBaseUri('[https://api.paystack.com/](https://api.paystack.com/)')// Optional: Specify a custom base URI->withHeaders([// Optional: Add custom headers'X-App-Version'=>'1.0','User-Agent'=>'MyCustomPaystackApp/1.0',])->withHttpClient(newGuzzleHttpClient())// Optional: Provide a custom PSR-18 HTTP client->make();// Example: Create a new customer$customer=$client->customer()->create(['email'=>'new.customer@example.com','first_name'=>'New','last_name'=>'Customer',]);print_r($customer);?>
API Reference
Explore the dedicated classes for each Paystack API resource:
Create, assign, list, fetch, requery, deactivate virtual accounts, manage split transactions, and retrieve bank providers.
Extending the SDK
The MusheAbdulHakim\Paystack SDK is designed for extensibility. You can customize its behavior by providing your own PSR-18 HTTP client, or by implementing custom transporters to handle request/response logic. This allows for advanced use cases such as custom logging, error handling, or integrating with specific HTTP client libraries.
License
This Paystack PHP SDK is open-sourced software licensed under the MIT license.