yogeshgupta/phonepe-laravel
Composer 安装命令:
composer require yogeshgupta/phonepe-laravel
包简介
Complete PhonePe Payment Gateway v2 integration for Laravel with OAuth, Webhook, Auto-Logging, Events & Facade
README 文档
README
A Laravel package for integrating the PhonePe API v2 payment gateway, developed by Yogesh Gupta. This is a standalone implementation designed to simplify PhonePe payment gateway integration in Laravel applications, supporting the PhonePe checkout v2 API for secure and efficient transactions.
Features
- Initiate payments using the PhonePe API v2.
- Verify payment status with the PhonePe checkout v2 endpoint.
- Support for UAT and production environments.
- Token caching for efficient PhonePe API v2 calls.
- Laravel configuration and facade for easy Laravel PhonePe integration.
Requirements
- PHP >= 8.1
- Laravel 9.x, 10.x, 11.x, or 12.x
Installation
- Install the package via Composer:
composer require yogeshgupta/phonepe-laravel
- Publish the configuration file:
php artisan vendor:publish --tag=phonepe-config
This will create a config/phonepe.php file in your Laravel project.
- Add your PhonePe credentials to your
.envfile:
PHONEPE_ENV=uat PHONEPE_UAT_CLIENT_ID=SU2504041946024365502022 PHONEPE_UAT_CLIENT_VERSION=1 PHONEPE_UAT_CLIENT_SECRET=ae83cba2-07c0-43a9-b0c4-1d84c261fd12 PHONEPE_PROD_CLIENT_ID=your_prod_client_id PHONEPE_PROD_CLIENT_VERSION=your_prod_client_version PHONEPE_PROD_CLIENT_SECRET=your_prod_client_secret PHONEPE_REDIRECT_URL=https://your-app.com/phonepe/process
Configuration
The configuration file (config/phonepe.php) allows you to customize:
- Environment (
uatorprod) - Client ID, version, and secret for both environments
- Token cache path
- Redirect URL after PhonePe API v2 payment
Example configuration:
return [ 'environment' => env('PHONEPE_ENV', 'uat'), 'uat' => [ 'client_id' => env('PHONEPE_UAT_CLIENT_ID', 'SU2504041946024365502022'), 'client_version' => env('PHONEPE_UAT_CLIENT_VERSION', 1), 'client_secret' => env('PHONEPE_UAT_CLIENT_SECRET', 'ae83cba2-07c0-43a9-b0c4-1d84c261fd12'), 'base_url' => 'https://api-preprod.phonepe.com/apis/pg-sandbox', 'auth_url' => 'https://api-preprod.phonepe.com/apis/pg-sandbox', 'token_cache_path' => storage_path('app/phonepe/phonepe_token_uat.json'), ], 'prod' => [ // ... ], ];
Usage
Initiating a Payment
use YogeshGupta\PhonePe\Facades\PhonePe; $result = PhonePe::initiatePayment(10000, 'SUB123'); // Amount in paisa, subscription ID if ($result['success']) { return redirect($result['redirectUrl']); } else { \Log::error('Payment initiation failed: ' . $result['error']); return back()->withErrors(['error' => $result['error']]); }
Verifying Payment Status
use YogeshGupta\PhonePe\Facades\PhonePe; $result = PhonePe::verifyPhonePePayment('merchantOrderId123'); if ($result['success']) { \Log::info('Payment status: ' . json_encode($result['data'])); return response()->json($result['data']); } else { \Log::error('Payment verification failed: ' . $result['error']); return response()->json(['error' => $result['error']], 400); }
Example Controller
namespace App\Http\Controllers; use YogeshGupta\PhonePe\Facades\PhonePe; use Illuminate\Http\Request; class PaymentController extends Controller { public function initiate(Request $request) { $amount = $request->input('amount'); // Amount in paisa $subscriptionId = $request->input('subscription_id'); $result = PhonePe::initiatePayment($amount, $subscriptionId); if ($result['success']) { return redirect($result['redirectUrl']); } return back()->withErrors(['error' => $result['error']]); } public function verify(Request $request) { $merchantOrderId = $request->input('merchantOrderId'); $result = PhonePe::verifyPhonePePayment($merchantOrderId); if ($result['success']) { \Log::info('Payment status: ' . json_encode($result['data'])); return response()->json($result['data']); } \Log::error('Verification failed: ' . $result['error']); return response()->json(['error' => $result['error']], 400); } }
Testing
To run tests (if included):
vendor/bin/phpunit vendor/yogeshgupta/phonepe-laravel/tests
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -m 'Add your feature'). - Push to the branch (
git push origin feature/your-feature). - Open a pull request.
Issues
Report bugs or suggest features by opening an issue on the GitHub repository.
License
This Laravel PhonePe integration package is licensed under the MIT License.
yogeshgupta/phonepe-laravel 适用场景与选型建议
yogeshgupta/phonepe-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.15k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yogeshgupta/phonepe-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yogeshgupta/phonepe-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-22