Skip to main content

Khalti Integration

blade for api


@extends('layouts.frontMaster')
@section('content')    <!--suppress ALL -->    <br>    <br>    <br>    <html>    <head>        <script            src="https://code.jquery.com/jquery-3.3.1.min.js"            integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="            crossorigin="anonymous"></script>        <script src="https://khalti.com/static/khalti-checkout.js"></script>    </head>    <body>    ...
    <!-- Place this where you need payment button -->    <button id="payment-button">Pay with Khalti</button>    {{--<button id="payment-button" onclick="clickedbtn()">Clickme</button>--}}    <!-- Place this where you need payment button -->    <!-- Paste this code anywhere in you body tag -->    <script>        var config = {
            // replace the publicKey with yours            "publicKey": "test_public_key_15903a44695e4e409a98aa3fcb281c4c",            "productIdentity": "1234567890",            "productName": "Dragon",            "productUrl": "http://gameofthrones.wikia.com/wiki/Dragons",            "eventHandler": {
                onSuccess (payload) {
                    $.ajax({
                        type: "get",                        url: "/khaltiapi",                        data: { payload: payload},                        dataType: "json",                        success: function(response) {
                            console.log(response);                            },
                        error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); }
                    });                                      // hit merchant api for initiating verfication                    console.log(payload);                },                onError (error) {
                    console.log(error);                },                onClose () {
                    console.log('widget is closing');                }
            }
        };
        var checkout = new KhaltiCheckout(config);        var btn = document.getElementById("payment-button");        btn.onclick = function () {
            checkout.show({amount: 10000});        }
    </script>       <!-- Paste this code anywhere in you body tag -->    ...
    </body>    </html>    {{--<h1>this is Final page for submission</h1>--}}
@endsection


Route: for blade

Route for Ajax Call;
Route::get('/khaltiapi', 'BikeBookingController@khaltiapi')->name('bike.khalti');


Controller: for blade view

Controller for : hadndeling ajax call

    public function khaltiapi(Request $request)    {        $payloads=$request->input('payload');//        $payload=[2.1,234,345,4535];//        print_r($payloads);
//        $x=$request->input('ListID');        $token= $payloads['token'];        $amount= $payloads['amount'];        $amount=(int)$amount;//        return $amount;
        $args = http_build_query(array(            'token' => $token,            'amount'  => $amount        ));//        return $token;        $url = "https://khalti.com/api/v2/payment/verify/";
# Make the call using API.        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_POST, 1);        curl_setopt($ch, CURLOPT_POSTFIELDS,$args);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $headers = ['Authorization:Key test_secret_key_179d2e03983e4cea9cec75c2349f0823'];        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Response        $response = curl_exec($ch);        echo $response;        $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);        curl_close($ch);        return $response;    }









Comments

Popular posts from this blog

Installing Admin LTE in Laravel

step 1:  Reference---  https://hdtuto.com/article/laravel-56-adminlte-bootstrap-theme-installation-example Step 2 : after completion first reference view this link:    https://github.com/JeroenNoten/Laravel-AdminLTE step 3:  For more additional information view this link:   https://github.com/jeroennoten/Laravel-AdminLTE#2-updating Now you are done statically : https://adminlte.io/blog/integrate-adminlte-with-laravel Steps: 1:  composer require jeroennoten/laravel-adminlte 2: 'providers' => [ .... JeroenNoten\LaravelAdminLte\ServiceProvider::class, ], 3: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=assets 5: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=config 6: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=views 7: for admin pannel php artisan ...

Integration of adminlte admin pannel in laravel 6 adn above

Create new laravel project : laravel new projectname --auth Steps to integrate admin pannel i.e. adminlte 1.  composer require jeroennoten/laravel-adminlte 2.  php artisan adminlte:install 3.  php artisan adminlte:install --only=auth_views 4. php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\AdminLteServiceProvider" --tag=views Filemanager: https://unisharp.github.io/laravel-filemanager/installation 1.  composer require unisharp/laravel-filemanager:~1.8 php artisan vendor:publish --tag = lfm_config php artisan vendor:publish --tag = lfm_public 3.  php artisan route:clear php artisan config:clear you will get a problem regarding file relode after upload and to solve do this fix it on vendor\unisharp\laravel-filemanager\src\Controllers\UploadController.php replace line 60 return count($this->errors) > 0 ? $this->errors : parent::$success_response; by return count($this->errors) > 0 ? ...

Setting and Getting Cookie and Session in laravel

First of all lets discuss many ways to set cookies inside controller : $response = new Response ( redirect ( 'news' )); //$minute=5; // $response->withCookie(cookie('name', 'virat', $minutes)); $response -> withCookie ( cookie ()-> forever ( 'news_id' , $newsid )); return $response ; // or // Cookie::queue('news_id', $news_id, 15); // return redirect('news'); // or // return redirect('news')->withCookie(cookie('name', 'virat', $minutes)); use Illuminate\Support\Facades\ Request ; use Illuminate\Http\ Response ; use Illuminate\Support\Facades\ Cookie ; To get cookies: inside controller $val = Request :: cookie ( 'news_id' ); // dd($val); $v = Cookie :: get ( 'news_id' ); // dd($v); or $value = $request -> cookie ( 'name' ); in blade: {{ Cookie :: get ( 'news_id' ) }} Now lets see for session: Ref...