PHP code example of starfolksoftware / paystack-php
1. Go to this page and download the library: Download starfolksoftware/paystack-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use StarfolkSoftware\Paystack\Client as PaystackClient;
try {
$paystack = new PaystackClient([
'secretKey' => 'sk_test_your_secret_key_here',
]);
$transaction = $paystack->transactions->initialize([
'email' => 'invalid-email', // This will cause an error
'amount' => 20000
]);
} catch (\Psr\Http\Client\ClientExceptionInterface $e) {
// Network or HTTP-related errors
echo "HTTP Error: " . $e->getMessage() . "\n";
} catch (\Exception $e) {
// General errors
echo "Error: " . $e->getMessage() . "\n";
}
// Handle API response errors
$response = $paystack->transactions->verify('invalid_reference');
if (!$response['status']) {
echo "API Error: " . $response['message'] . "\n";
// Handle the error appropriately
}
$paystack = new PaystackClient([
'secretKey' => 'sk_test_your_secret_key_here',
'apiVersion' => 'v1', // API version (default: v1)
'baseUri' => 'https://api.paystack.co', // Custom base URI
]);
// Access the underlying HTTP client if needed
$httpClient = $paystack->getHttpClient();
// Use test secret key
$paystack = new PaystackClient([
'secretKey' => 'sk_test_your_test_secret_key_here',
]);
// Test card numbers for different scenarios
$testCards = [
'success' => '4084084084084081',
'insufficient_funds' => '4084084084084107',
'invalid_pin' => '4084084084084099'
];
bash
composer
bash
# Clone the repository
git clone https://github.com/starfolksoftware/paystack-php.git
cd paystack-php
# Install dependencies
composer install
# Run tests
composer test
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.