1. Go to this page and download the library: Download prabin/laravelesewa library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
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
}
}
bash
php artisan vendor:publish
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.