Nagad is one of the Financial Services in Bangladesh. This package is built for Nagad Payment Gateway for Laravel 6.x, 7.x and 8.x+
You can install the package via composer:
composer require dgvai/laravel-nagadExtract the nagad config files:
php artisan vendor:publish --tag=nagad-config-
This will publish and config file in
config_path()of your application. Eg.config/nagad.php -
Configure the configurations for the nagad merchant acocunt. Use
sandbox = truefor development stage. -
Be sure to set the timezone of you application to
Asia/Dhakain order to work with Nagad PG. To do this: go toconfig/app.phpand set'timezone' => 'Asia/Dhaka'
NagadPG uses three stages of payment process, and two of theme are simultaneous. To get started, first you have to setup
a callback route (GET) for the Nagad Callback and name the route in the nagad config file.
// in routes/web.php
Route::get('/nagad/callback', 'NagadController@callback')->name('nagad.callback');
//in config/nagad.php
'callback' => 'nagad.callback' // or use env variable to storeTo Start payment, in your controller:
// in SomeController.php
use DGvai\Nagad\Facades\Nagad;
public function createPayement()
{
/**
* Method 1: Quickest
* This will automatically redirect you to the Nagad PG Page
* */
return Nagad::setOrderID('ORDERID123')
->setAmount('540')
->checkout()
->redirect();
/**
* Method 2: Manual Redirection
* This will return only the redirect URL and manually redirect to the url
* */
$url = Nagad::setOrderID('ORDERID123')
->setAmount('540')
->checkout()
->getRedirectUrl();
return ['url' => $url];
/**
* Method 3: Advanced
* You set additional params which will be return at the callback
* */
return Nagad::setOrderID('ORDERID123')
->setAmount('540')
->setAddionalInfo(['pid' => 9, 'myName' => 'DG'])
->checkout()
->redirect();
/**
* Method 4: Advanced Custom Callabck
* You can set/override callback url while creating payment
* */
return Nagad::setOrderID('ORDERID123')
->setAmount('540')
->setAddionalInfo(['pid' => 9, 'myName' => 'DG'])
->setCallbackUrl("https://manual-callback.url/callback")
->checkout()
->redirect();
}
To receive the callback response, in your callback controller method:
// in CallbackController.php
use DGvai\Nagad\Facades\Nagad;
use Illuminate\Http\Request;
/**
* This is the routed callback method
* which receives a GET request.
*
* */
public function callback(Request $request)
{
$verified = Nagad::callback($request)->verify();
if($verified->success()) {
// Get Additional Data
dd($verified->getAdditionalData());
// Get Full Response
dd($verified->getVerifiedResponse());
} else {
dd($verified->getErrors());
}
}setOrderID(string $orderID):$orderIDto be any unique AlphaNumeric StringsetAmount(string $amount):$amountto be any valid currency numeric StringsetAddionalInfo(array $array):$arrayto be any array to be returned at callbacksetCallbackUrl(string $url):$urlto be any url string to be overidden the defualt callback url set in configcheckout(): to initiate checkout process.redirect(): to direct redirect to the NagadPG Web Page.getRedirectUrl(): instead of redirecting, getting the redirect url manually.
callback($request):$requestto beIlluminate\Http\Requestinstanceverify(): to verify the response.success(): to check if transaction is succeed.getErrors(): to get the error and errorCode if fails transactions | returnsarray[]getVerifiedResponse(): to get the full verified response | returnsarray[]getAdditionalData(bool $object): to get the additional info passed during checkout.$objectis to set return object or array.
Please see CHANGELOG for more information what has changed recently.
The MIT License (MIT). Please see License File for more information.