定制 codersandip/laravel-multi-payment-gateway 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

codersandip/laravel-multi-payment-gateway

Composer 安装命令:

composer require codersandip/laravel-multi-payment-gateway

包简介

A unified payment gateway wrapper for Indian-focused gateways (Razorpay, PayU, Stripe, Cashfree).

README 文档

README

A unified, production-ready payment gateway package for Indian-focused gateways (Razorpay, PayU, Stripe, Cashfree). Built specifically for Laravel 10+, implementing clean architecture, SOLID principles, and an automatic driver failover mechanism.

Features

  • Driver-based Architecture: Clean abstractions over multiple gateways.
  • Database Tracking: Eloquent models log all transactions, allowing instant audit trails.
  • Failover & Retries: Automatic retries for failed requests, and fallback to secondary gateways.
  • Robust Event System: Automatically dispatches PaymentSuccess and PaymentFailed events.
  • Async Queue Jobs: Run payment actions in the background.
  • Auto-Reconciliation Artisan Command: Scheduled DB cleanup for pending webhooks.
  • Extensible: Easily register custom drivers.
  • Centralized Logging: Dedicated channel logging for all gateway interactions.
  • Unified Standard Response: Predictable array returns [success, gateway, transaction_id, status, message, raw].
  • No Third-Party SDKs: Powered completely by Laravel's built-in HTTP client (Illuminate\Support\Facades\Http).

Installation

You can install the package via Composer:

composer require codersandip/laravel-multi-payment-gateway

Publish the configuration file and migrate the database:

php artisan vendor:publish --provider="Codersandip\MultiPayment\MultiPaymentServiceProvider" --tag="config"
php artisan migrate

Configuration

In config/multi-payment.php, you can set the default driver, failover drivers, error logging channel, and the allowed retries before moving to a fallback.

'default' => 'razorpay',
'failovers' => ['stripe', 'cashfree'],
'retries' => [
    'attempts' => 2,
    'sleep' => 1000, // milliseconds
],

Usage

1. Basic Charge

use Codersandip\MultiPayment\Facades\MultiPayment;

$response = MultiPayment::charge([
    'amount' => 500,
    'currency' => 'INR',
    'email' => 'customer@test.com',
    'phone' => '9999999999',
]);

2. Async Background Process

If you wish to handle the request later in the background through the Laravel Queue, simply use:

MultiPayment::chargeAsync([
    'amount' => 500,
    'currency' => 'INR',
]);

3. Failover Execution

The manager automatically attempts the charge via the default gateway using Laravel's native retry() mechanism. If all retries exhaust, the manager catches the Exception and automatically shifts to the failover stack (e.g. from Razorpay directly to Stripe).

4. Events System

The package fires standard events whenever a gateway successfully completes an API execution or exhausts all retries resulting in an error.

To listen to these events, register listeners in EventServiceProvider:

use Codersandip\MultiPayment\Events\PaymentSuccess;
use Codersandip\MultiPayment\Events\PaymentFailed;

protected $listen = [
    PaymentSuccess::class => [
        SendPaymentReceipt::class,
    ],
    PaymentFailed::class => [
        AlertSupportTeam::class,
    ],
];

5. Custom Driver Extensibility

Thanks to Laravel's Manager pattern, extending this package with any custom gateway is trivial. Inside your AppServiceProvider boot method:

use Codersandip\MultiPayment\Facades\MultiPayment;
use App\Payment\CustomGatewayDriver;

MultiPayment::extend('custom_gateway', function ($app) {
    return new CustomGatewayDriver(config('services.custom'));
});

Then use it instantly: MultiPayment::driver('custom_gateway')->charge(...)

Webhooks

We provide a built-in macro to handle webhooks asynchronously across any enabled gateway. Register this in your routes/api.php:

Route::paymentWebhooks('webhooks/payments');

This automatically handles verified posts to /api/webhooks/payments/razorpay, .../stripe, etc.

Database & Auto Reconciliation

Every charge request securely logs an pending Eloquent PaymentTransaction before communicating with the Gateway. Once a gateway returns successfully (or fails across all failovers), the DB is synced seamlessly.

If a Sandbox Sandbox or webhooks drop instantly, you can run and schedule our artisan command to manually query the Gateways and fix all drifted pending payments:

php artisan payment:reconcile-pending --days=3

You can cleanly schedule this in Laravel's Console/Kernel.php:

$schedule->command('payment:reconcile-pending')->hourly();

Frontend / Blade Components

The package natively ships with beautiful, pre-configured Blade Components targeting the official JavaScript SDK/Widgets of every supported gateway!

You can easily publish these views to customize them locally:

php artisan vendor:publish --tag="multi-payment-views"

Once a charge executes, pass the payload $response to any component in your blade file. They automatically mount the UI and redirect to your specified $verifyUrl upon success!

{{-- Stripe Elements --}}
@include('multi-payment::components.stripe', [
    'response' => $chargeResponse,
    'verifyUrl' => route('payment.verify') 
])

{{-- Razorpay Checkout js Modal --}}
@include('multi-payment::components.razorpay', [
    'response' => $chargeResponse,
    'verifyUrl' => route('payment.verify'),
    'themeColor' => '#ff0000', // Optional
])

{{-- Cashfree SDK Modal --}}
@include('multi-payment::components.cashfree', [
    'response' => $chargeResponse
])

{{-- PayU Auto-Submit Form --}}
@include('multi-payment::components.payu', [
    'response' => $chargeResponse,
    'autoOpen' => true 
])

Testing

The package relies on orchestra/testbench for Laravel container bindings. Run tests natively via PHPUnit:

composer require --dev orchestra/testbench phpunit/phpunit
vendor/bin/phpunit

codersandip/laravel-multi-payment-gateway 适用场景与选型建议

codersandip/laravel-multi-payment-gateway 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 codersandip/laravel-multi-payment-gateway 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codersandip/laravel-multi-payment-gateway 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-26