1. Go to this page and download the library: Download rayhan-bapari/sslcommerz 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/ */
// app/Listeners/HandleSslcommerzIpn.php
namespace App\Listeners;
class HandleSslcommerzIpn
{
public function handle(array $payload): void
{
if (!$payload['verified']) {
return; // Hash check passed but server validation failed
}
$tranId = $payload['tran_id'];
$status = $payload['status']; // VALID | VALIDATED
$bankTranId = $payload['bank_tran_id']; // Save for refunds
$amount = $payload['amount'];
$userId = $payload['value_a']; // Your pass-through field
// Update your order in the database here
}
}
// By your tran_id
$result = Sslcommerz::transactionQueryById('INV-12345');
// By SSLCommerz sessionkey
$result = Sslcommerz::transactionQueryBySessionId('session_abc123');
// You need the bank_tran_id from the original transaction
$result = Sslcommerz::initiateRefund(
bankTranId: '1709162345070ANJdZV8LyI4cMw',
refundAmount: 50.00,
refundRemarks: 'Customer request',
refe_id: 'REF-TRACK-001' // optional tracking reference
);
// $result['status'] → 'success' | 'failed' | 'processing'
// $result['refund_ref_id'] → save this for status checking
// Check refund status
$status = Sslcommerz::refundStatus($result['refund_ref_id']);
// $status['status'] → 'refunded' | 'processing' | 'cancelled'
use RayhanBapari\SslcommerzPayment\Exceptions\SslcommerzException;
use RayhanBapari\SslcommerzPayment\Exceptions\SslcommerzIpnException;
try {
$response = Sslcommerz::initiatePayment($dto);
} catch (SslcommerzException $e) {
// Configuration or API communication error
Log::error('SSLCommerz error: ' . $e->getMessage());
}