1. Go to this page and download the library: Download dgvai/laravel-nagad 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/ */
dgvai / laravel-nagad example snippets
// 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();
}
// 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());
}
}
php
// 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 store
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.