zarenta/phonepe
Composer 安装命令:
composer require zarenta/phonepe
包简介
Laravel PhonePay payment gateway
README 文档
README
This package provides an easy way to integrate the PhonePe payment gateway into your Laravel application.
Features
- Initiate payments via PhonePe.
- Check transaction statuses.
- Secure callback handling for payment notifications.
Installation
To get your api key go to PhonePe Official Website
Step 1: Install the Package
Run the following command to install the package via Composer:
composer require zarenta/phonepe
Step 2: Publish Configuration
Add Service provider to bootstrap/provider.php file
PhonePe\LaravelPhonePeServiceProvider::class,
Publish the configuration file using the artisan command:
php artisan vendor:publish --tag=phonepe-config
This will publish a config/phonepe.php file where you can set your PhonePe credentials.
Step 3: Add CSRF Exception for Callback URL
Update bootstrap/app.php to exclude the callback URL from CSRF verification. Add the following middleware configuration:
->withMiddleware(function (Middleware $middleware) { $middleware->web(append: [ \App\Http\Middleware\HandleInertiaRequests::class, \Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class, ]); $middleware->validateCsrfTokens(except: [ 'phonepe/callback', // Exclude PhonePe callback route from CSRF ]); })
Step 4: Set Up Environment Variables
In your .env file, add the following variables with your PhonePe account details:
PHONEPE_MERCHANT_ID=your_merchant_id PHONEPE_MERCHANT_USER_ID=your_merchant_user_id PHONEPE_SALT_KEY=your_salt_key PHONEPE_SALT_INDEX=your_salt_index PHONEPE_CALLBACK_URL=https://yourdomain.com/phonepe/callback PHONEPE_ENV=production # or sandbox for testing
Configuration
The published configuration file config/phonepe.php will have the following structure:
return [ 'merchantId' => env('PHONEPE_MERCHANT_ID'), 'merchantUserId' => env('PHONEPE_MERCHANT_USER_ID'), 'saltKey' => env('PHONEPE_SALT_KEY'), 'saltIndex' => env('PHONEPE_SALT_INDEX'), 'callBackUrl' => env('PHONEPE_CALLBACK_URL'), 'env' => env('PHONEPE_ENV', 'sandbox'), ];
Usage
Initiating Payment
Here's an example of how to initiate a payment using the PhonePeGateway:
use PhonePe\PhonePeGateway; public function initiatePayment(Request $request) { $phonePe = new PhonePeGateway(); try { $paymentUrl = $phonePe->makePayment( $amount = 1000, // Amount in rupees $redirectUrl = 'https://yourdomain.com/payment/success', $merchantTransactionId = 'your_unique_transaction_id', $phone = '9999999999', $email = 'user@example.com', $shortName = 'Your Company', $message = 'Payment for Order #1234' ); return redirect($paymentUrl); } catch (PhonePe\Exception\PhonePeException $e) { return response()->json(['error' => $e->getMessage()], 400); } }
Checking Transaction Status
To check the transaction status, use the getTransactionStatus method:
use PhonePe\PhonePeGateway; public function checkTransactionStatus($transactionId) { $phonePe = new PhonePeGateway(); $status = $phonePe->getTransactionStatus(\request()->all()); if ($status) { return response()->json(['status' => 'Transaction successful']); } else { return response()->json(['status' => 'Transaction failed or pending']); } }
Handling PhonePe Callback
Create a route to handle the PhonePe callback in your routes/web.php:
Route::post('/phonepe/callback', [YourPaymentController::class, 'handlePhonePeCallback']);
In your controller, you can write logic to handle the callback and update the transaction status accordingly.
License
This package is open-source and licensed under the MIT License.
zarenta/phonepe 适用场景与选型建议
zarenta/phonepe 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 zarenta/phonepe 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zarenta/phonepe 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-18