sarojsardar/esewa-epay
Composer 安装命令:
composer require sarojsardar/esewa-epay
包简介
eSewa Payment Integration Package for Laravel
README 文档
README
This package provides a simple and effective way to integrate eSewa payment processing into your Laravel application. It supports initiating payments and verifying transactions through the eSewa API.
Table of Contents
- Features
- Requirements
- Installation
- Configuration
- Usage
- Example Controller
- Testing the Package
- Contributing
- License
Features
- Easy integration with eSewa payment gateway.
- Supports payment initiation and transaction verification.
- Customizable payment form view.
Requirements
- PHP 8.1 or higher
- Laravel 11.x
Installation
-
Install the package via Composer:
Run the following command in your Laravel project directory:
composer require sarojsardar/esewa-epay:dev-main
Publish the configuration file:
After installation, publish the package configuration file using the following command:
bash Copy code
- php artisan vendor:publish --provider="Sarojsardar\EsewaEpay\EsewaEpayServiceProvider"
This command will create a configuration file at config/esewa.php.
Configuration Add your eSewa merchant credentials to your .env file:
env Copy code ESEWA_MERCHANT_CODE=your_merchant_code ESEWA_SECRET=your_secret_key ESEWA_API_ENDPOINT=https://rc-epay.esewa.com.np/api/epay/main/v2 Replace your_merchant_code and your_secret_key with the appropriate values provided by eSewa. For production, change the API endpoint to: env Copy code ESEWA_API_ENDPOINT=https://epay.esewa.com.np/api/epay/main/v2 Usage Set Up Environment Variables Ensure that you have set up the environment variables as shown in the configuration section.
Using the Service You can use the EpayService class in your controllers to handle payments.
Payment Form View The package provides a view for the payment form. You can customize it as needed. The view is located at resources/views/vendor/esewa/payment-form.blade.php.
Defining Routes Define routes in your web.php file for initiating and verifying payments:
php Copy code use App\Http\Controllers\PaymentController;
Route::get('/payment/initiate', [PaymentController::class, 'initiatePayment']); Route::get('/payment/verify/{transactionId}', [PaymentController::class, 'verifyPayment']); Example Controller Create a controller named PaymentController:
php Copy code namespace App\Http\Controllers;
use Sarojsardar\EsewaEpay\EpayService; use Illuminate\Http\Request;
class PaymentController extends Controller { protected $epayService;
public function __construct(EpayService $epayService)
{
$this->epayService = $epayService;
}
// Method to initiate payment
public function initiatePayment(Request $request)
{
$amount = $request->input('amount', 100); // Default amount
$transactionUuid = 'your-transaction-uuid'; // Generate a unique transaction UUID
$productCode = 'EPAYTEST';
$successUrl = 'https://your-success-url.com';
$failureUrl = 'https://your-failure-url.com';
return $this->epayService->initiatePayment($amount, $transactionUuid, $productCode, $successUrl, $failureUrl);
}
// Method to verify payment
public function verifyPayment($transactionId)
{
$result = $this->epayService->verifyTransaction($transactionId);
// Handle the result as needed
return response()->json($result);
}
} Testing the Package To test the package, you can use the following steps:
Run your Laravel application: Start your local server with:
bash Copy code php artisan serve Initiate a payment: Open your browser and navigate to http://localhost:8000/payment/initiate. This should redirect you to the eSewa payment page.
Verify the payment: After completing the payment, you will be redirected to the success URL you specified. You can verify the transaction by calling the verifyPayment method with the transaction ID.
sarojsardar/esewa-epay 适用场景与选型建议
sarojsardar/esewa-epay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sarojsardar/esewa-epay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sarojsardar/esewa-epay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-03