A PHP API wrapper for Paystack.
- Curl 7.34.0 or more recent (Unless using Guzzle)
- PHP 5.4.0 or more recent
- OpenSSL v1.0.1 or more recent
$ composer require yabacon/paystack-phpDownload a release version from the releases page. Extract, then:
require 'path/to/src/Paystack.php';
\Yabacon\Paystack::registerAutoloader();Version 2 is not compatible with version 1 code! It throws an error if there's problem error in cURL or if the Paystack API gives a false status in the response body.
Check ibrahimlawal/paystack-php-sample for a sample donation page that uses this library
$paystack = new \Yabacon\Paystack('secret_key');
// Make a call to the resource/method
// $paystack->{resource}->{method}();
// Shortcuts
// for gets, use $paystack->{resource}(id)
// for list, use $paystack->{resource}s()
// $headers is an array of header values.
// $response is an stdClass object created from json_decoding response
$response = $paystack->customer(12);
$response = $paystack->customer->fetch(12);
$response = $paystack->customers();
$response = $paystack->customer->list();
$response = $paystack->customer->list(['perPage'=>5,'page'=>2]); // list the second page at 5 customers per page
$response = $paystack->customer->create([
'first_name'=>'Dafe',
'last_name'=>'Aba',
'email'=>"[email protected]",
'phone'=>'08012345678'
]);
$response = $paystack->transaction->initialize([
'reference'=>'unique_refencecode',
'amount'=>'120000',
'email'=>'[email protected]'
]);
$response = $paystack->transaction->verify([
'reference'=>'refencecode'
]);###Use Guzzle for requests Only available if project is managed using composer.
Install Guzzle
$ composer require guzzlehttp/guzzleMake calls
// create a paystack object
$paystack = new \Yabacon\Paystack('secret_key');
/* IMPORTANT tell it to use guzzle if found (else installing Guzzle will not have had any effect) */
$paystack->useGuzzle();
// Make a call to the resource/method
// $paystack->{resource}->{method}();
// Shortcuts
// for gets, use $paystack->{resource}(id)
// for list, use $paystack->{resource}s()
// $response is a GuzzleHttp\Psr7\Response Object
$response = $paystack->customer(12);
$response = $paystack->customer->list();
$response = $paystack->customer->list(['perPage'=>5,'page'=>2]); // list the second page at 5 customers per page
$response = $paystack->customer->create([
'first_name'=>'Dafe',
'last_name'=>'Aba',
'email'=>"[email protected]",
'phone'=>'08012345678'
]);
$response = $paystack->transaction->initialize([
'reference'=>'unique_refencecode',
'amount'=>'120000',
'email'=>'[email protected]'
]);
$response = $paystack->transaction->verify([
'reference'=>'refencecode'
]);Check SAMPLES for more sample calls
Please see CHANGELOG for more information what has changed recently.
$ composer testPlease see CONTRIBUTING and CONDUCT for details. Check our todo list for features already intended.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
- Yabacon
- Issa Jubril
- Ibrahim Lawal
- Opeyemi Obembe - followed the style he employed in creating the NodeJS Wrapper
- All Contributors
The MIT License (MIT). Please see License File for more information.
