Paystack

Paystack PHP SDK Documentation

Welcome

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:

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:

<?php

use MusheAbdulHakim\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:

<?php

use MusheAbdulHakim\Paystack\Paystack;
use GuzzleHttp\Client as GuzzleHttpClient; // 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(new GuzzleHttpClient()) // 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:

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.