1. Go to this page and download the library: Download kodemeric/payment-gateways 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 SoftPayment\PaymentGateways\Facades\PaymentGateway;
// Using default gateway
$gateway = PaymentGateway::default();
// Or specify a gateway
$gateway = PaymentGateway::gateway('paystack');
use SoftPayment\PaymentGateways\Facades\PaymentGateway;
use SoftPayment\PaymentGateways\Dtos\InitiateTransactionRequest;
// Create request using DTO
$request = InitiateTransactionRequest::fromArray([
'amount' => 1000, // Amount in base currency
'email' => '[email protected]',
'reference' => 'unique_ref_123', // Optional, auto-generated if not provided
'callback_url' => 'https://yoursite.com/callback', // Optional
'user_id' => auth()->id(), // Optional, track which user initiated the transaction
'metadata' => ['order_id' => 123], // Optional
]);
// Or create directly
$request = new InitiateTransactionRequest(
amount: 1000,
email: '[email protected]',
reference: 'unique_ref_123',
callbackUrl: 'https://yoursite.com/callback',
userId: auth()->id(), // Track the authenticated user
metadata: ['order_id' => 123]
);
$result = PaymentGateway::gateway('paystack')->initiateTransaction($request);
if ($result->success) {
return redirect($result->paymentUrl);
}
use SoftPayment\PaymentGateways\PaymentGatewayManager;
use SoftPayment\PaymentGateways\Dtos\InitiateTransactionRequest;
class PaymentController extends Controller
{
public function __construct(
protected PaymentGatewayManager $paymentManager
) {}
public function pay(Request $request)
{
$gateway = $this->paymentManager->gateway('paystack');
$transactionRequest = InitiateTransactionRequest::fromArray([
'amount' => $request->amount,
'email' => $request->email,
'user_id' => auth()->id(), // Track the authenticated user
'metadata' => ['order_id' => $request->order_id],
]);
$result = $gateway->initiateTransaction($transactionRequest);
if ($result->success) {
return redirect($result->paymentUrl);
}
}
}
use SoftPayment\PaymentGateways\Models\Transaction;
$transaction = Transaction::where('reference', 'ref_123')->first();
$logs = $transaction->logs; // Get related transaction logs
// Get user's transactions
$userTransactions = Transaction::where('user_id', auth()->id())->get();
// Get the user who made the transaction
$user = $transaction->user;
use SoftPayment\PaymentGateways\Models\TransactionLog;
$logs = TransactionLog::where('gateway', 'paystack')->get();
$response = $gateway->initiateTransaction($request);
if ($response->success) {
// Redirect customer to payment page
return redirect($response->paymentUrl);
// Or get transaction details
$reference = $response->reference; // 'ref_abc123'
$accessCode = $response->accessCode; // 'ACC_xyz789' (if applicable)
}
if (!$response->success) {
$errorMessage = $response->message; // 'Failed to initialize transaction'
$gatewayError = $response->gatewayResponse; // Raw gateway error details
}
use SoftPayment\PaymentGateways\Dtos\VerifyTransactionResponse;
$response = $gateway->verifyTransaction('ref_abc123');
if ($response->success) {
if ($response->status === 'success') {
// Transaction was successful
$amount = $response->amount; // 5000.00
$currency = $response->currency; // 'NGN'
// Process successful payment
// ...
} elseif ($response->status === 'pending') {
// Payment is still pending
} else {
// Payment failed
}
} else {
// Verification failed (network error, invalid reference, etc.)
$errorMessage = $response->message;
}
use SoftPayment\PaymentGateways\Dtos\WebhookPayload;
// In your webhook handler
public function handleWebhook(Request $request)
{
// WebhookPayload automatically parses different gateway formats
$payload = WebhookPayload::fromArray($request->all());
// Get the transaction reference (works across all gateways)
$reference = $payload->getReference();
// Get event type
$event = $payload->event ?? $payload->eventType;
// Get full payload data
$data = $payload->data;
}
use SoftPayment\PaymentGateways\Dtos\WebhookPayload;
use SoftPayment\PaymentGateways\Dtos\WebhookResponse;
// In WebhookController (handled automatically by the package)
$payload = WebhookPayload::fromArray($request->all());
$response = $gateway->handleWebhook($payload);
// Response is automatically returned as JSON
// Success: 200 status with response data
// Failure: 400 status with error message
bash
php artisan payment-gateways:install
bash
php artisan payment-gateways:publish
bash
php artisan payment-gateways:migrate
bash
php artisan migrate
bash
php artisan payment-gateways:install
bash
php artisan payment-gateways:publish
bash
php artisan payment-gateways:publish --force
bash
php artisan payment-gateways:migrate
bash
php artisan payment-gateways:migrate --force
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.