PHPackages                             samrat415/khalti-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. samrat415/khalti-laravel

ActiveLibrary[Payment Processing](/categories/payments)

samrat415/khalti-laravel
========================

Easy Khalti ePayment Integration Package for Laravel

V1(2y ago)638[2 PRs](https://github.com/samrat415/khalti-laravel-package/pulls)MITPHPPHP ^8.1

Since Mar 3Pushed 1y ago2 watchersCompare

[ Source](https://github.com/samrat415/khalti-laravel-package)[ Packagist](https://packagist.org/packages/samrat415/khalti-laravel)[ Docs](https://github.com/samrat415/khalti-laravel)[ GitHub Sponsors](https://github.com/Khalti)[ RSS](/packages/samrat415-khalti-laravel/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (1)Dependencies (12)Versions (4)Used By (0)

---

Easy Khalti ePayment Integration Package for Laravel
====================================================

[](#easy-khalti-epayment-integration-package-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e6727619c4a30085851aac885676d6b629c8922ab5f595fa02f0fe47e56bdba3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d7261743431352f6b68616c74692d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samrat415/khalti-laravel)[![GitHub Tests Action Status](https://camo.githubusercontent.com/df4fbaaadd67c553e433ce465a2e36054638389959bdf6313c919e23aecfa347/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616d7261743431352f6b68616c74692d6c61726176656c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/samrat415/khalti-laravel/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/72e8c9c27ab94deebab9f7ad0f6a4c8c5b4fa248f27210dbe52596434bc6c816/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616d7261743431352f6b68616c74692d6c61726176656c2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/samrat415/khalti-laravel/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/4ce58970044bc64b9257993f6975596959743cd1eb7cec67f906b5f023a70657/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616d7261743431352f6b68616c74692d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samrat415/khalti-laravel)

This Laravel package provides easy integration for Khalti ePayment services.

Installation
------------

[](#installation)

To install the package, use Composer:

```
composer require samrat415/khalti-laravel
```

Once installed, run the package's installation command to publish the configuration file:

```
php artisan khalti-laravel:install
```

This will publish the configuration file `khalti-laravel.php` to the `config` folder. Modify the configuration file as needed, and then run:

```
php artisan config:cache
```

Usage
-----

[](#usage)

You can initiate a payment request using the `ePaymentInitiateRequest` method provided by the package. Here's an example of how you can use it in your controller:

```
use Illuminate\Http\Request;
use Khalti\KhaltiLaravel\Khalti;

public function initiatePaymentRequest(Request $request) {
    $requestArray = [
        'purchase_order_id' => 1, // Your Purchase ID
        'purchase_order_name' => "test", // Your Order Name
        'amount' => $request->input('amount',100)
    ];

    $request = new Request($requestArray);
    $response = Khalti::ePaymentInitiateRequest($request); // Must be of Illuminate\Http\Request
    return $response;
}
```

Frontend Implementation
-----------------------

[](#frontend-implementation)

To initiate a payment request from the frontend, you can create a form with a single field for the amount and a submit button. Here's an example:

```

    Amount:
    {{ csrf_field() }}

    function submitForm(event) {
        event.preventDefault(); // Prevent the default form submission

        var form = document.getElementById("paymentForm");
        var formData = new FormData(form);

        // Convert formData to JSON
        var formDataJson = {};
        formData.forEach(function(value, key){
            formDataJson[key] = value;
        });

        // Make a POST request to the external service
        fetch("{{ route('khalti.ePayment-initiate') }}", {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(formDataJson)
        })
            .then(response => response.json())
            .then(data => {
                if (data.error_key === "validation_error") {
                    // Handle validation error
                    alert(data.detail);
                } else if (data.payment_url) {
                    // Redirect to the payment_url if available
                    window.location.href = data.payment_url;
                } else {
                    console.log("Unexpected response from server:", data);
                }
            })
            .catch(error => {
                console.error("Error:", error);
            });
    }

```

Replace the JavaScript code with the provided code to handle form submission and response.

Validation Example
------------------

[](#validation-example)

To complete the payment and validate it, you can use the following method:

```
public function completePayment(Request $request){
    $response =  Khalti::ePaymentValidationRequest($request);
    return $response;
}
```

Here's an example of the expected request payload:

```
/?pidx=pUmazJyRT2F8a5Fz7xXSiK&transaction_id=XdcQ5qwWUfscAKbrGbKD9F&tidx=XdcQ5qwWUfscAKbrGbKD9F&amount=31500&total_amount=31500&mobile=98XXXXX005&status=Completed&purchase_order_id=1&purchase_order_name=test

```

Please note that `Khalti::ePaymentValidationRequest($request)` expects the `$request` object to have a `pidx` field and `$request` to be of type `Illuminate\Http\Request`.

---

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability within this package, please send an email to the maintainer at .

Credits
-------

[](#credits)

- [Samrat Thapa](https://github.com/samrat415)

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

853d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f6e64696eaba7af48ffc0345baa32ac261b46fbda83f3ca92901cec27fa59360?d=identicon)[samrat415](/maintainers/samrat415)

---

Top Contributors

[![samrat415](https://avatars.githubusercontent.com/u/43883707?v=4)](https://github.com/samrat415 "samrat415 (5 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelkhaltikhalti-laravel

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/samrat415-khalti-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/samrat415-khalti-laravel/health.svg)](https://phpackages.com/packages/samrat415-khalti-laravel)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M167](/packages/spatie-laravel-health)[nativephp/mobile

NativePHP for Mobile

1.1k75.1k96](/packages/nativephp-mobile)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[codebar-ag/laravel-docuware

DocuWare integration with Laravel

1123.7k](/packages/codebar-ag-laravel-docuware)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
