Khalti driver for the Omnipay PHP payment processing library
Omnipay is a framework agnostic, multi-gateway payment processing library for PHP.
This package implements Khalti support for Omnipay.
Omnipay is installed via Composer.
To install, simply require league/omnipay
and pralhadstha/omnipay-khalti
with Composer:
composer require league/omnipay pralhadstha/omnipay-khalti
use Omnipay\Omnipay;
use Exception;
$gateway = Omnipay::create('Khalti_Khalti');
$gateway->setSecret('secret_key_provided_by_khalti');
$gateway->setTestMode(true);
try {
$response = $gateway->purchase([
'amount' => 10000, // Rs. 100 in paisa
'purchaseOrderId' => 'SH-100',
'purchaseOrderName' => "Basmati Rice 500gm",
'websiteUrl' => 'https://merchant.com/',
'returnUrl' => 'https://merchant.com/payment/1/complete',
])->send();
if ($response->isRedirect()) {
$response->redirect();
}
} catch (Exception $e) {
return $e->getMessage();
}
After successful payment and redirect back to merchant site, you can verify the payment status and work accordingly.
$gateway = Omnipay::create('Khalti_Khalti');
$gateway->setSecret('secret_key_provided_by_khalti');
$gateway->setTestMode(true);
$payload = $_GET;
try {
$response = $gateway->fetchTransaction([
'paymentId' => $payload['pidx']
])->send();
if ($response->isSuccessful()) {
// Verified
} else {
// Unverified
}
} catch (Exception $e) {
return $e->getMessage();
}
Want to see working examples before integrating them into your project? View the examples here
Please follow the Official Doc to understand about the parameters and their descriptions.
Contributions are welcome and will be fully credited.
Contributions can be made via a Pull Request on Github.
If you are having general issues with Omnipay Khalti, drop an email to pralhad.shrestha05@gmail.com for quick support.
If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.
This package is open-sourced software licensed under the MIT license.