blade for api
Route: for blade
Route for Ajax Call;
Controller: for blade view
Controller for : hadndeling ajax call
@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
Post a Comment