raziul/sslcommerz-laravel
Integrate SSLCommerz payments in Laravel 10+ with a clean API: initiate payments, configure success/fail/cancel/IPN callbacks, validate transactions, verify response hashes, and process refunds. Supports sandbox and live environments.
composer require raziul/sslcommerz-laravel
php artisan sslcommerz:install
.env:
SSLC_SANDBOX=true
SSLC_STORE_ID=your_store_id
SSLC_STORE_PASSWORD=your_store_password
SSLC_STORE_CURRENCY=BDT
routes/web.php:
Route::post('/sslcommerz/success', [SslcommerzController::class, 'success'])->name('sslc.success');
Route::post('/sslcommerz/failure', [SslcommerzController::class, 'failure'])->name('sslc.failure');
use Raziul\Sslcommerz\Facades\Sslcommerz;
$response = Sslcommerz::setOrder(100, 'INV-123', 'Premium Subscription')
->setCustomer('John Doe', 'john@example.com', '1234567890')
->makePayment();
if ($response->success()) {
return redirect($response->gatewayPageURL());
}
Initiate Payment Chain methods for order/customer details:
Sslcommerz::setOrder($amount, $invoiceId, $productName)
->setCustomer($name, $email, $phone)
->setShippingInfo(1, 'Dhaka, Bangladesh')
->makePayment();
Handle Callbacks Implement controller methods for:
public function success(Request $request) {
if (Sslcommerz::verifyHash($request->all())) {
// Process valid payment
}
}
Post-Payment Actions
Sslcommerz::validatePayment($requestData, $transactionId, $amount)Sslcommerz::refundPayment($bankTransactionId, $amount, 'Reason')Sslcommerz::checkRefundStatus($refundRefId)Sslcommerz:: for simplicity in controllers/views.SslcommerzService via constructor.verifyHash() before processing.SSLC_SANDBOX=true) for development.// 1. Payment Initiation with Custom Data
Sslcommerz::setOrder($amount, $invoiceId, 'Product')
->setCustomerData(['custom_field' => 'value'])
->makePayment();
// 2. Refund with Additional Metadata
Sslcommerz::refundPayment($txId, 50, 'Partial Refund')
->setRefundReason('Customer Request')
->execute();
Hash Mismatch Errors
SSLC_STORE_PASSWORD matches SSLCommerz dashboard.verifyHash() includes all required fields (e.g., val_id, status).Sandbox vs Live Mode
SSLC_SANDBOX=false in production causes failed transactions.Transaction IDs
transactionId (from makePayment()) ≠ bankTransactionId (used for refunds).Callback URL Validation
https://yourdomain.com/sslcommerz/success).Sslcommerz::setDebugMode(true); // Logs requests/responses to storage/logs/sslcommerz.log
$response = Sslcommerz::makePayment();
dd($response->getRawResponse()); // Raw SSLCommerz API response
Invalid Store ID/Password: Double-check .env values.Invalid Signature: Ensure verifyHash() includes all fields in the correct order.Customize Payment Data
Override default fields via setCustomData():
Sslcommerz::setCustomData(['product_id' => 123, 'user_id' => 456]);
Extend Validation
Add custom rules to validatePayment() by subclassing PaymentValidator:
class CustomValidator extends PaymentValidator {
protected function rules() {
return parent::rules() + ['custom_field' => 'required'];
}
}
Webhook Retries Implement exponential backoff for failed IPN callbacks:
if (!Sslcommerz::verifyHash($request->all())) {
// Retry logic or queue job
}
SSLC_STORE_CURRENCY matches SSLCommerz dashboard..env (SSLC_ROUTE_*) if conflicts exist.PaymentInitiated, PaymentSucceeded, etc., for decoupled logic.RefundPaymentJob::dispatch($txId, $amount, $reason);
$this->partialMock(Sslcommerz::class, 'makePayment')
->shouldReturn(new PaymentResponse(['success' => true]));
How can I help you explore Laravel packages today?