For version 1 of this SDK, visit matscode/paystack.
- Transaction (
Initialize,List,Verify,isSuccessful, Fluent Setters) - Plan (
Create,List,Fetch,Update) - Subscription (
Create,List,Fetch,Disable,Enable) - Miscellaneous (
Bank,Country,Card)
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.
- GuzzleHttp
- PHP 7.4+ / 8.x
composer require matscode/paystack-php-sdk- Download the archive
- Extract into your project
- And lastly
require_once __DIR__ . "/vendor/autoload.php";
use Matscode\Paystack\Paystack;
$paystackSecret = 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$Paystack = new Paystack($paystackSecret);$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);$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);$response = $Paystack->transaction->list(50, 1);// Supports optional filters such as country, perPage, use_cursor, etc.
$response = $Paystack->miscellaneous->bank->list(['country' => 'nigeria']);$bank_code = '063';
$account_number = '0022728151';
$response = $Paystack->miscellaneous->bank->resolve($bank_code, $account_number); $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'
]);$response = $Paystack->miscellaneous->country->list();// Shields underlying fintech complexity behind a clean method name
$response = $Paystack->miscellaneous->card->resolveInfo('539983');$response = $Paystack->plan->create([
'name' => 'Monthly Retainer',
'amount' => 500000,
'interval' => 'monthly'
]);$plans = $Paystack->plan->list();
$plan = $Paystack->plan->fetch('PLN_xxxxxx');
$updated = $Paystack->plan->update('PLN_xxxxxx', ['name' => 'Updated Plan Name']);$response = $Paystack->subscription->create([
'customer' => 'CUS_xxxxxx',
'plan' => 'PLN_xxxxxx'
]);$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']);Michael Akanji - matsco.de