1. Go to this page and download the library: Download iamolayemi/laravel-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/ */
iamolayemi / laravel-paystack example snippets
use Iamolayemi\Paystack\Facades\Paystack;
// Initialize a payment
$paymentData = [
'amount' => 500000, // 5000 NGN in kobo
'email' => '[email protected]',
'reference' => 'PAY_' . uniqid(),
'callback_url' => 'https://yourdomain.com/payment/callback',
];
$response = Paystack::transaction()
->initialize($paymentData)
->response();
if ($response['status']) {
$authorizationUrl = $response['data']['authorization_url'];
// Redirect user to $authorizationUrl
}
// Using the helper function
$response = paystack()->transaction()
->initialize($paymentData)
->response();
// Get only the authorization URL
$authorizationUrl = Paystack::transaction()
->initialize($paymentData)
->response('data.authorization_url');
// Or use the dedicated method
$authorizationUrl = Paystack::transaction()
->initialize($paymentData)
->authorizationURL();
// Verify a transaction
$reference = 'PAY_xxxxxxxxx';
$verification = Paystack::transaction()
->verify($reference)
->response();
if ($verification['status'] && $verification['data']['status'] === 'success') {
// Payment was successful
$amount = $verification['data']['amount'];
$customerEmail = $verification['data']['customer']['email'];
}