1. Go to this page and download the library: Download xentixar/khalti-sdk 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/ */
xentixar / khalti-sdk example snippets
use Xentixar\KhaltiSdk\Khalti;
Khalti secret key
$khalti->setSecretKey('test_secret_key_1392a63451d740c59806685acd57730a');
// Configure the payment details
$khalti->config(
'http://localhost:8000/decode.php', // Return URL
'http://localhost:8000', // Website URL
10, // Amount in rupees
'124', // Purchase Order ID
'test', // Purchase Order Name
[ // Customer Information
"name" => "Khalti Bahadur",
"email" => "[email protected]",
"phone" => "9800000000"
]
);
// Initiate the payment
$khalti->init();
$khalti->init(true); // Set to true for production
$response = $khalti->validate('transaction_code_here');
if ($response) {
// Handle the response
echo $response;
} else {
echo "Error: Invalid response from Khalti API.";
}
$response = $khalti->validate('transaction_code_here', true); // Set to true for production
$data = $khalti->decode();
if ($data) {
// Process the data
print_r($data);
} else {
echo "Error: No data to decode.";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.