Laravel Esewa

Laravel Esewa

Latest Stable Version Total Downloads License
View Package

laravel esewa

Overview: Laravel Esewa facilitates the integration of Esewa payment gateway into Laravel projects. With straightforward installation and configuration, developers can effortlessly incorporate Esewa payment functionality into their applications, enhancing user experience.

Installation: Begin by installing the package via Composer:

composer require dipesh79/laravel-esewa

Configuration: After installation, set your Esewa merchant ID and environment (sandbox or live) in the .env file:

ESEWA_MERCHANT_ID="Your Esewa Merchant ID"
ESEWA_ENV="Sandbox" # or "Live"

Next, publish the vendor file to customize settings:

php artisan vendor:publish --provider="Dipesh79\LaravelEsewa\EsewaServiceProvider"

Usage: Initiate payment redirection to Esewa's checkout page from your controller:

<?php

use Dipesh79\LaravelEsewa\LaravelEsewa;

public function esewaPayment()
{
    // Store payment details in DB with pending status
    $payment = new LaravelEsewa();
    $amount = 123; 
    $order_id = 251264889; // Your Unique Order Id
    $tax_amount = 0; // Tax Amount. If there is no tax amount then keep it 0
    $service_charge = 0; // Service Charge. If there is no service charge then keep it 0
    $delivery_charge = 0; // Delivery Charge. If there is no delivery charge then keep it 0
    $success_url = route('success.url');
    $fail_url = route('fail.url');
    return redirect($payment->esewaCheckout($amount, $tax_amount, $service_charge, $delivery_charge, $order_id, $success_url, $fail_url));
}

Upon successful or failed payment, Esewa will redirect the user to the respective URLs configured:

<?php

public function esewaSuccess(Request $request)
{
    $order_id = $request->oid;
    $payment = Payment::where('order_id', $order_id)->first();
    $payment->status = "Success";
    $payment->save();

    // Other Tasks   
}

public function esewaFail(Request $request)
{
    $payment = Payment::where('order_id', $request->oid)->first();
    $payment->status = "Fail";
    $payment->save();
    // Other Tasks   
}
?>

License: MIT

Support: For support, email [email protected].

This post is licensed under CC BY 4.0 by the author.