1. Go to this page and download the library: Download sslcommerz/laravel 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/ */
sslcommerz / laravel example snippets
use Sslcommerz\Laravel\Facades\SSLCOMMERZ;
public function checkout(Request $request)
{
$response = SSLCOMMERZ::initiate([
'tran_id' => 'ORDER_' . uniqid(),
'total_amount' => 1500.00,
'cus_name' => $request->name,
'cus_email' => $request->email,
// ...
]);
if ($response->isSuccessful()) {
return $response->redirect(); // Fluent redirect to SSLCOMMERZ
}
return back()->with('error', $response->failedReason);
}
use Sslcommerz\Laravel\Facades\SSLCOMMERZ;
$schedule = json_encode([
'refer' => 'REF1234', // Plan ID from Merchant Panel
'acct_no' => 'CUS_001', // Customer account reference
'type' => 'monthly',
'dayofmonth' => '24',
]);
$encryptedSchedule = SSLCOMMERZ::getEncryptionService()->encrypt($schedule);
$response = SSLCOMMERZ::initiate([
// ...
'schedule' => $encryptedSchedule,
]);
// If successful, a subscription_id will be returned in the callback/response
if ($response->isSuccessful()) {
$subscriptionId = $response->subscriptionId;
}
// routes/web.php
Route::get('/payment/success', function () {
return view('payment.success');
});
use Sslcommerz\Laravel\Events\PaymentSucceeded;
use Sslcommerz\Laravel\Events\PaymentFailed;
use Sslcommerz\Laravel\Events\PaymentCancelled;
use Sslcommerz\Laravel\Events\IpnReceived;
use Sslcommerz\Laravel\Events\RefundInitiated;
protected $listen = [
PaymentSucceeded::class => [
UpdateOrderStatus::class,
SendPaymentConfirmation::class,
],
PaymentFailed::class => [
HandleFailedPayment::class,
],
IpnReceived::class => [
ProcessIpnNotification::class,
],
];
namespace App\Listeners;
use Sslcommerz\Laravel\Events\PaymentSucceeded;
use App\Models\Order;
class UpdateOrderStatus
{
public function handle(PaymentSucceeded $event): void
{
// Access callback data via $event->payment
// Access API validation data via $event->validation
$tranId = $event->payment->tranId;
$orderId = $event->payment->valueA; // Your custom reference
Order::where('id', $orderId)->update([
'status' => 'paid',
'paid_at' => now(),
'payment_id' => $tranId,
]);
}
}