承接 yogeshgupta/phonepe-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Install the package via Composer:
composer require yogeshgupta/phonepe-laravel
  1. Publish the configuration file:
php artisan vendor:publish --tag=phonepe-config

This will create a config/phonepe.php file in your Laravel project.

  1. Add your PhonePe credentials to your .env file:
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 (uat or prod)
  • 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:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -m 'Add your feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 yogeshgupta/phonepe-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-22