matscode / paystack-php-sdk
Paystack PHP SDK is for communicating with PAYSTACK API
Requires
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- mockery/mockery: 1.4.x-dev
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: 3.*
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-19 14:27:25 UTC
README
Full Documentation
For version 1 of this SDK, visit matscode/paystack.
Available resources
- Transaction (
Initialize,List,Verify,isSuccessful, Fluent Setters) - Plan (
Create,List,Fetch,Update) - Subscription (
Create,List,Fetch,Disable,Enable) - Miscellaneous (
Bank,Country,Card)
Resource roadmap
More resources would be added in time
Transfersothers...
This SDK communicates with Paystack API. You need to have a paystack merchant account and paystack secret key to use this SDK.
Development is actively ongoing while releases are Stable.
If you find a BUG/Security Issue, do be kind to open an issue or contact me.
Requirements
- GuzzleHttp
- PHP 7.4+ / 8.x
Installation
composer require matscode/paystack-php-sdk
Manual
- Download the archive
- Extract into your project
- And lastly
require_once __DIR__ . "/vendor/autoload.php";
Initialize Paystack SDK
use Matscode\Paystack\Paystack; $paystackSecret = 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $Paystack = new Paystack($paystackSecret);
Transaction Resource
Initialize Charge
$response = $Paystack->transaction->initialize([ 'email' => 'customer.email@gmail.com', 'amount' => 500000, // amount is in kobo 'callback_url' => 'https://www.app.local/paystack/transaction/verify' ]);
OR
// Set data to post using fluent methods $response = $Paystack->transaction ->setCallbackUrl('https://www.app.local/paystack/transaction/verify') ->setEmail('customer.email@gmail.com') ->setAmount(75000) // amount is treated in kobo/pesewas ->initialize();
Now do a redirect to payment page (using authorization_url)
Recommended to check if authorization_url is set, and save your transaction reference code useful to verify Transaction status.
header('Location: ' . $response->data->authorization_url);
Verifying Transaction
$reference_code = $_GET['reference']; $response = $Paystack->transaction->verify($reference_code);
OR
// This method does the check for you and returns `(bool) true|false` $isSuccessful = $Paystack->transaction->isSuccessful($reference_code);
List Transactions
$response = $Paystack->transaction->list(50, 1);
Miscellaneous Resources
Get list of banks
// Supports optional filters such as country, perPage, use_cursor, etc. $response = $Paystack->miscellaneous->bank->list(['country' => 'nigeria']);
Resolve account info
$bank_code = '063'; $account_number = '0022728151'; $response = $Paystack->miscellaneous->bank->resolve($bank_code, $account_number);
Validate account info
$response = $Paystack->miscellaneous->bank->validate([ 'bank_code' => '632005', 'country_code' => 'ZA', 'account_number' => '0123456789', 'account_name' => 'Ann Bron', 'account_type' => 'personal', 'document_type' => 'identityNumber', 'document_number' => '1234567890123' ]);
Get supported countries
$response = $Paystack->miscellaneous->country->list();
Resolve Card Information (BIN lookup)
// Shields underlying fintech complexity behind a clean method name $response = $Paystack->miscellaneous->card->resolveInfo('539983');
Plan Resource
Create a plan
$response = $Paystack->plan->create([ 'name' => 'Monthly Retainer', 'amount' => 500000, 'interval' => 'monthly' ]);
List, Fetch, and Update Plans
$plans = $Paystack->plan->list(); $plan = $Paystack->plan->fetch('PLN_xxxxxx'); $updated = $Paystack->plan->update('PLN_xxxxxx', ['name' => 'Updated Plan Name']);
Subscription Resource
Create a subscription
$response = $Paystack->subscription->create([ 'customer' => 'CUS_xxxxxx', 'plan' => 'PLN_xxxxxx' ]);
Manage Subscriptions
$subscriptions = $Paystack->subscription->list(); $subscription = $Paystack->subscription->fetch('SUB_xxxxxx'); // Enable or disable $Paystack->subscription->disable(['code' => 'SUB_xxxxxx', 'token' => 'SUB_tokenxxx']); $Paystack->subscription->enable(['code' => 'SUB_xxxxxx', 'token' => 'SUB_tokenxxx']);
Author
Michael Akanji - matsco.de