PHP code example of karim007 / laravel-nagad

1. Go to this page and download the library: Download karim007/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/ */

    

karim007 / laravel-nagad example snippets

bash
php artisan vendor:publish --provider="Karim007\LaravelNagad\NagadServiceProvider"

php artisan make:controller NagadController

public function callback(Request $request)
{
    if (!$request->status && !$request->order_id) {
        return response()->json([
            "error" => "Not found any status"
        ], 500);
    }

    if (config("nagad.response_type") == "json") {
        return response()->json($request->all());
    }

    $verify = NagadPayment::verify($request->payment_ref_id); // $paymentRefId which you will find callback URL request parameter

    if (isset($verify->status) && $verify->status == "Success") {
        return $this->success($verify->orderId);
    } else {
        return $this->fail($verify->orderId);
    }

}


public function refund($paymentRefId)
{
    $refundAmount=1000;
    $verify = NagadRefund::refund($paymentRefId,$refundAmount);
    //$verify = NagadRefund::refund($paymentRefId,$refundAmount,'','sss',1); last parameter for manage account

    if (isset($verify->status) && $verify->status == "Success") {
        return $this->success($verify->orderId);
    } else {
        return $this->fail($verify->orderId);
    }
}


public function success($transId)
{
    return view("nagad::success", compact('transId'));
}

public function fail($transId)
{
    return view("nagad::failed", compact('transId'));
}