farsh4d/laravel-bank is a Laravel package for a package to connect to any ipg to make a payment.
It currently has 5 GitHub stars and 4 downloads on Packagist (latest version 1.0.0).
Install it with composer require farsh4d/laravel-bank.
Discover more Laravel packages by farsh4d
or browse all Laravel packages to compare alternatives.
Last updated
This is a package to connect to any Internet Payment Gateways.
This package now only supports Mellat IPG for now but we are developing other IPGs ASAP.
Require this package with composer.
composer require farsh4d/laravel-bank
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
Farsh4d\Bank\Providers\BankServiceProvider::class,
php artisan vendor:publish --provider="Farsh4d\Bank\Providers\BankServiceProvider"
php artisan migrate
You need 2 routes, one to start a payment and one for callback:
routes.php
Route::get('/payment-start', 'PaymentController@start')->name('payment_start');
Route::any('/payment-callback', 'PaymentController@callback')->name('payment_callback');
Remember to exclude your callback route from CSRF verification.
In start method initialize your desired driver and set required data (price, orderId and callback):
PaymentController.php @start
$amount = 50000;
$orderId = '123456';
$bankDriver = Bank::driver('Mellat');
$bankDriver->price($amount)
->orderId($orderId)
->callback(route('payment_callback'));
try {
$bankDriver->ready();
return $bankDriver->redirect();
} catch (\Exception $e) {
// Handle failed transaction initiation; ie:
return view('payment-error');
}
If everything goes right user redirects to IPG and makes a payment and then redirects to your callback.
PaymentController.php @verify
try {
Bank::verify();
// Show transaction success view or do sth else; ie:
return view('payment-success');
} catch (\Exception $e) {
// Handle failed payment; ie:
return view('payment-failed');
}