prabin / esewa
This package is auto-updated.
Last update: 2024-09-19 11:03:57 UTC
README
This repository contains the source code and resources for integrating the eSewa payment gateway into a Laravel application.
#Lets start from form When you copy form from esewa please make sure to include please make sure this action fild should be live url in case of production site
<form action="https://uat.esewa.com.np/epay/main" method="POST"> <input value="100" name="tAmt" type="hidden"> <input value="90" name="amt" type="hidden"> <input value="5" name="txAmt" type="hidden"> <input value="2" name="psc" type="hidden"> <input value="3" name="pdc" type="hidden"> <input value="EPAYTEST" name="scd" type="hidden"> <input value="1234strsst" name="pid" type="hidden"> <input value="{{route('payment.success')}}" type="hidden" name="su"> <input value="{{route('payment.failure')}}" type="hidden" name="fu"> <input value="Submit" type="submit"> </form>
Environment Variables
I am using test merchant id in case of live use valid merchant id
ESEWA_URL="https://uat.esewa.com.np" ESEWA_MERCHANT="EPAYTEST" PAYMENT_VERIFICATION="https://uat.esewa.com.np/epay/transrec"
Installation and Setup
-
Install the eSewa package via Composer:
composer require prabin/esewa
-
Publish the vendor files:
php artisan vendor:publish
-
Add the following code to your
config/app.php
file in the providers section:Prabin\Esewa\EsewaServiceProvider::class,
Usage
-
Define Routes:
Route::get('/payment-success', [EsewaController::class, 'success'])->name('payment.success'); Route::get('/payment-failure', [EsewaController::class, 'failure'])->name('payment.failure');
-
Create Controller Methods:
namespace App\Http\Controllers; use Prabin\Esewa\EsewaPayment; use Illuminate\Http\Request; class EsewaController extends Controller { public function success(Request $request) { $payment=new EsewaPayment(); // please make sure this totalAmount is come through your database // eg:$product=Product::find('id',$request->pid)->first(); // totalAmount=$product->totalamout; // in my case i am passing 100; $actualAmount=100; $response=$payment->paymentVerify($request->oid,$request->amt,$request->refId,$actualAmount); if(strpos($response,'Success')!==false){ // if you have orders and payment database then update your database return 'Payment Completed Successfully';//return where you want eg:return redirect('/') } else{ return 'failed'; //return redirect('/')->with('failure','something went Wrong'); } } public function failure() { // Add logic to handle failed payments here } }
License
This project is licensed under the MIT License.