prabin / laravelesewa
v1.0.0
2024-02-17 17:20 UTC
This package is auto-updated.
Last update: 2024-09-17 18:40:17 UTC
README
此仓库包含将eSewa支付网关集成到Laravel应用程序的源代码和资源。
从表单开始 # 当您从esewa复制表单时,请确保包含以下内容
<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>
环境变量
ESEWA_DEV="https://uat.esewa.com.np" ESEWA_LIVE="https://esewa.com.np" ESEWA_DEV_MERCHANT="EPAYTEST" ESEWA_LIVE_MERCHANT="" PAYMENT_VERIFICATION="https://uat.esewa.com.np/epay/transrec"
安装和设置
-
通过Composer安装eSewa包
composer require prabin/esewa
-
发布供应商文件
php artisan vendor:publish
-
将以下代码添加到您的
config/app.php
文件中的提供者部分Prabin\Esewa\EsewaServiceProvider::class,
用法
-
定义路由:
Route::get('/payment-success', [EsewaController::class, 'success'])->name('payment.success'); Route::get('/payment-failure', [EsewaController::class, 'failure'])->name('payment.failure');
-
创建控制器方法:
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 } }
许可
本项目采用MIT许可。