pralhadstha/omnipay-khalti

Khalti Omnipay Package for PHP applications

v1.0.0 2025-04-14 06:38 UTC

This package is auto-updated.

Last update: 2025-05-14 07:31:53 UTC


README

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.

Installation

Omnipay is installed via Composer.

To install, simply require league/omnipay and pralhadstha/omnipay-khalti with Composer:

composer require league/omnipay pralhadstha/omnipay-khalti

Basic Usage

Purchase

    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.

Verify Payment

    $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();
    }

Working Example

Want to see working examples before integrating them into your project? View the examples here

Official Doc

Please follow the Official Doc to understand about the parameters and their descriptions.

Contributing

Contributions are welcome and will be fully credited.

Contributions can be made via a Pull Request on Github.

Support

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.

License

This package is open-sourced software licensed under the MIT license.