abdur-rahaman / laravel-bd-payment
Universal Laravel Payment Gateway Package for Bangladesh - bKash, Nagad, SSLCommerz, ShurjoPay, AamarPay, PayStation, EPS, PortPos
Package info
github.com/abdurrahamanbabu/laravel-bd-payment
pkg:composer/abdur-rahaman/laravel-bd-payment
Requires
- php: ^8.2
- illuminate/contracts: ^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0|^9.0|^10.0
- pestphp/pest: ^2.0|^3.0
- pestphp/pest-plugin-laravel: ^2.0|^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Universal Laravel package for integrating major Bangladeshi payment gateways through one consistent API.
Package: abdur-rahaman/laravel-bd-payment
Namespace: Abdurrahaman\PaymentGateway
License: MIT
PHP: 8.2+
Laravel: 10 / 11 / 12 / 13
Supported Gateways
| Gateway | Pay | Verify | Refund | Status |
|---|---|---|---|---|
| bKash | ✅ | ✅ | ✅ | Production |
| Nagad | ✅ | ✅ | ⚠️ | Production* |
| SSLCommerz | ✅ | ✅ | ⚠️ | Production |
| ShurjoPay | ✅ | ✅ | ⚠️ | Production |
| AamarPay | ✅ | ✅ | ⚠️ | Production |
| PayStation | ✅ | ✅ | ⚠️ | Production* |
| EPS | ✅ | ✅ | ⚠️ | Production* |
| PortPos | ✅ | ✅ | ⚠️ | Production* |
* Implement against official docs; endpoint paths may need adjustment after merchant onboarding. Always verify with sandbox credentials.
Features
- Unified
pay()/verify()/refund()API across gateways - Object-oriented classes and Laravel Facades
- Dynamic gateway selection via
Payment::gateway('bkash') - Normalized
PaymentResponsewith original provider payload preserved - Secure server-side verification (never trust redirects alone)
- Callback / IPN routes with idempotency protection
- Laravel events:
PaymentInitiated,PaymentSuccessful,PaymentFailed,PaymentCancelled,PaymentVerified,PaymentRefunded - Publishable config +
.envexample - Strict typing, PSR-12, SOLID-friendly design
Installation
composer require abdur-rahaman/laravel-bd-payment
Publish config:
php artisan vendor:publish --tag=payment-gateway-config
Copy variables from .env.example into your .env and fill credentials from each provider.
Quick Start
Facade (static) API
use Abdurrahaman\PaymentGateway\Facades\Bkash; use Abdurrahaman\PaymentGateway\Facades\Nagad; use Abdurrahaman\PaymentGateway\Facades\SSLCommerz; use Abdurrahaman\PaymentGateway\Facades\ShurjoPay; use Abdurrahaman\PaymentGateway\Facades\AamarPay; use Abdurrahaman\PaymentGateway\Facades\PayStation; use Abdurrahaman\PaymentGateway\Facades\EPS; use Abdurrahaman\PaymentGateway\Facades\PortPos; $response = Bkash::pay([ 'amount' => 1500, 'currency' => 'BDT', 'order_id' => 'ORDER-1001', 'customer_name' => 'John Doe', 'customer_phone' => '017XXXXXXXX', 'return_url' => route('payment.callback', ['gateway' => 'bkash']), ]); if ($response->isSuccessful() && $response->getPaymentUrl()) { return redirect()->away($response->getPaymentUrl()); }
Object-oriented API
use Abdurrahaman\PaymentGateway\Gateways\ShurjoPay\ShurjoPayGateway; $gateway = new ShurjoPayGateway(config('payment-gateway.gateways.shurjopay')); $response = $gateway->pay([...]);
Dynamic gateway selection
use Abdurrahaman\PaymentGateway\Facades\Payment; $response = Payment::gateway('sslcommerz')->pay([ 'amount' => 500, 'order_id' => 'ORDER-1003', 'customer_name' => 'Jane Doe', 'customer_email' => 'jane@example.com', 'customer_phone' => '018XXXXXXXX', 'return_url' => route('payment.callback', ['gateway' => 'sslcommerz']), ]);
Verification (always required)
$verified = Bkash::verify([ 'payment_id' => $paymentId, ]); if ($verified->getStatus() === 'successful') { // Update order — payment is confirmed by provider }
Never mark an order paid based only on a browser redirect.
Normalized Response
[
'success' => true,
'status' => 'pending', // pending|processing|successful|failed|cancelled|refunded|expired
'gateway' => 'bkash',
'transaction_id' => 'TR0011...',
'order_id' => 'ORDER-1001',
'amount' => 1500.0,
'currency' => 'BDT',
'payment_url' => 'https://...',
'message' => 'Payment initiated successfully',
'data' => [ /* original provider response */ ],
]
Callbacks & Events
Routes registered automatically:
GET|POST /payment/callback/{gateway}GET|POST /payment/ipn/{gateway}
Listen for events:
use Abdurrahaman\PaymentGateway\Events\PaymentSuccessful; Event::listen(PaymentSuccessful::class, function ($event) { // $event->response, $event->gateway });
Configuration
See config/payment-gateway.php. Each gateway has its own credential keys matching the official provider requirements. Do not invent shared credential shapes.
Security
- Credentials only via environment / config
- HTTPS enforced in production contexts
- Sensitive values redacted from logs
- Server-side amount/status verification
- Callback idempotency (24h cache key)
- Token caching with safe expiry for bKash / ShurjoPay / EPS
Testing
composer test
Use HTTP fakes; never commit real credentials.
Documentation
Per-gateway notes:
- docs/bkash.md
- docs/nagad.md
- docs/sslcommerz.md
- docs/shurjopay.md
- docs/aamarpay.md
- docs/paystation.md
- docs/eps.md
- docs/portpos.md
Contributing
See CONTRIBUTING.md.
Changelog
See CHANGELOG.md.
Security Vulnerabilities
See SECURITY.md.
License
MIT — see LICENSE.