1. Go to this page and download the library: Download chainbook/paystack 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/ */
chainbook / paystack example snippets
use Chainbook\Paystack\Facades\Paystack;
// Initialize a transaction
$response = Paystack::initializeTransaction([
'email' => '[email protected]',
'amount' => 500000, // Amount in kobo/pesewas (= 5000 NGN/GHS)
'reference' => uniqid('ref_'),
'callback_url' => 'https://yourapp.com/payment/callback',
]);
// $response['data']['authorization_url'] — redirect the user here
// Verify a transaction
$verification = Paystack::verifyTransaction('ref_abc123');
if ($verification['data']['status'] === 'success') {
// Payment confirmed
}
// List transactions
$transactions = Paystack::listTransactions(['perPage' => 20, 'page' => 1]);
// Fetch a specific transaction
$transaction = Paystack::fetchTransaction(123456789);
// Charge a returning customer using saved authorization
$charge = Paystack::chargeAuthorization([
'authorization_code' => 'AUTH_xxxxxxxx',
'email' => '[email protected]',
'amount' => 500000,
]);
// Create a customer
$customer = Paystack::createCustomer([
'email' => '[email protected]',
'first_name' => 'Jane',
'last_name' => 'Doe',
'phone' => '+2348012345678',
]);
// Fetch a customer (by ID or customer code)
$customer = Paystack::fetchCustomer('CUS_xxxxxxxx');
// Update a customer
Paystack::updateCustomer('CUS_xxxxxxxx', ['first_name' => 'Janet']);
// List customers
$customers = Paystack::listCustomers(['perPage' => 50]);