PHPackages                             phpcorelab/payment-gateways - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. phpcorelab/payment-gateways

ActiveLibrary[Payment Processing](/categories/payments)

phpcorelab/payment-gateways
===========================

Provider-agnostic PHP payment gateway library. Unified API for Razorpay, PhonePe, PayU, Paytm and Juspay.

1.0.1(5d ago)02MITPHPPHP ^8.1CI passing

Since Mar 16Pushed 5d agoCompare

[ Source](https://github.com/PHPCoreLab/payment-gateways)[ Packagist](https://packagist.org/packages/phpcorelab/payment-gateways)[ RSS](/packages/phpcorelab-payment-gateways/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

phpcorelab/payment-gateways
===========================

[](#phpcorelabpayment-gateways)

[![Latest Version](https://camo.githubusercontent.com/54acb745f291450b3091602fed8b08a94be9dc95ab50d4895b504414859a3a9e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706870636f72656c61622f7061796d656e742d6761746577617973)](https://packagist.org/packages/phpcorelab/payment-gateways)[![PHP Version](https://camo.githubusercontent.com/c5803c36e7a66c75761c1dcbb87909e66b1006c580dda8612f793bba0956c52e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706870636f72656c61622f7061796d656e742d6761746577617973)](https://packagist.org/packages/phpcorelab/payment-gateways)[![License](https://camo.githubusercontent.com/784083687440abbcc6b155856d69ac730feefeca1d9c3654679c6936dbeeb0c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706870636f72656c61622f7061796d656e742d6761746577617973)](LICENSE)

> Provider-agnostic PHP payment gateway library. Unified API for Razorpay, PhonePe, PayU, Paytm and Juspay. Switch providers with a single config change — no code changes required.

Installation
------------

[](#installation)

```
composer require phpcorelab/payment-gateways
```

Requires PHP 8.1+.

Supported Providers
-------------------

[](#supported-providers)

ProviderCreate OrderVerify PaymentRefundWebhookRazorpay✅✅✅✅PhonePe✅✅✅✅PayU✅✅✅✅Paytm🚧🚧🚧🚧Juspay✅✅✅✅How It Works
------------

[](#how-it-works)

```
Frontend                    Backend                     Provider
   |                           |                            |
   |--- POST /payment/order --> |                            |
   |                           |--- createOrder() --------> |
   |                           | |
   |                           | 'razorpay',  // change this to switch provider
        'environment'     => 'sandbox',   // 'sandbox' | 'live'
        'providers'       => [
            'razorpay' => [
                'sandbox_key_id'     => $_ENV['RAZORPAY_SANDBOX_KEY_ID'],
                'sandbox_key_secret' => $_ENV['RAZORPAY_SANDBOX_KEY_SECRET'],
                'live_key_id'        => $_ENV['RAZORPAY_LIVE_KEY_ID'],
                'live_key_secret'    => $_ENV['RAZORPAY_LIVE_KEY_SECRET'],
            ],
            // ... other providers
        ],
    ])
);

// Step 1 — Create order, get payload for frontend
$order = $gateway->createOrder(new OrderPayload(
    orderId:       'ORD-001',
    amountPaisa:   49900,       // INR 499.00 — always in paise
    customerName:  'Rahul Sharma',
    customerEmail: 'rahul@example.com',
    customerPhone: '9876543210',
    returnUrl:     'https://yourapp.com/payment/return',
    description:   'Order #ORD-001',
));

// Send to frontend:
// $order->sdkPayload  → for JS SDK providers (Razorpay)
// $order->paymentUrl  → for redirect-based providers (PhonePe, PayU)

// Step 2 — After frontend payment, verify it
$result = $gateway->verifyPayment('ORD-001', $request->all());

if ($result->status === PaymentStatus::Success) {
    // fulfil the order
}

// Refund
$refund = $gateway->refund($result->providerPaymentId, 49900);

// Handle webhook
$event = $gateway->handleWebhook(
    file_get_contents('php://input'),
    getallheaders()
);
```

Frontend Integration by Provider
--------------------------------

[](#frontend-integration-by-provider)

### Razorpay (JS SDK modal)

[](#razorpay-js-sdk-modal)

```
const options = JSON.parse(sdkPayload);
options.handler = function(response) {
    // POST response to /payment/confirm/:orderId
    fetch(`/payment/confirm/${orderId}`, {
        method: 'POST',
        body: JSON.stringify(response)
    });
};
const rzp = new Razorpay(options);
rzp.open();
```

### PhonePe / PayU (redirect)

[](#phonepe--payu-redirect)

```
// Simply redirect the user to payment_url
window.location.href = paymentUrl;
// Provider redirects back to your return_url after payment
```

### Juspay (SDK or redirect)

[](#juspay-sdk-or-redirect)

```
// Use client_auth_token from sdk_payload with Juspay Hypercheckout SDK
// or redirect to payment_url
```

Laravel Integration
-------------------

[](#laravel-integration)

### AppServiceProvider

[](#appserviceprovider)

```
use PHPCoreLab\PaymentGateways\PaymentGateway;
use PHPCoreLab\PaymentGateways\Core\GatewayConfig;

$this->app->singleton(PaymentGateway::class, fn() =>
    new PaymentGateway(GatewayConfig::fromArray(config('payment-gateways')))
);
```

### Routes

[](#routes)

```
Route::middleware('auth:sanctum')->group(function () {
    Route::post('/payment/order',               [PaymentController::class, 'createOrder']);
    Route::post('/payment/confirm/{orderId}',   [PaymentController::class, 'confirmPayment']);
    Route::post('/payment/refund/{paymentId}',  [PaymentController::class, 'refund']);
});
Route::post('/payment/webhook',                 [PaymentController::class, 'webhook']);
```

DTOs Reference
--------------

[](#dtos-reference)

ClassKey Properties`OrderPayload``orderId`, `amountPaisa`, `customerName`, `customerEmail`, `returnUrl``OrderResult``orderId`, `providerOrderId`, `paymentUrl`, `sdkPayload``PaymentResult``orderId`, `providerPaymentId`, `status`, `amountPaisa`, `providerRef``RefundResult``refundId`, `success`, `message``PaymentEvent``orderId`, `providerPaymentId`, `status`, `amountPaisa`, `providerRef``PaymentStatus` enum: `Pending · Success · Failed · Expired · Refunded · Cancelled`

Exceptions
----------

[](#exceptions)

ExceptionWhen thrown`ProviderException`HTTP / API call to provider fails`WebhookVerificationException`Signature or checksum mismatch`ProviderNotFoundException`Provider name not registeredAll extend `PaymentGatewayException extends RuntimeException`.

Running Tests
-------------

[](#running-tests)

```
composer install
composer test
```

License
-------

[](#license)

MIT — [PHPCoreLab](https://github.com/PHPCoreLab)

###  Health Score

39

—

LowBetter than 87% of packages

Maintenance99

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

5d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59a56eba5b07cd0fb82f0c2c24f98b03804d94afe88f11249bde7f3e8187fa3c?d=identicon)[PHPCoreLab](/maintainers/PHPCoreLab)

---

Top Contributors

[![office-amanraj](https://avatars.githubusercontent.com/u/187439178?v=4)](https://github.com/office-amanraj "office-amanraj (5 commits)")

---

Tags

laravelpaymentgatewaypayuindiarazorpaypaytmjuspayPhonePe

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpcorelab-payment-gateways/health.svg)

```
[![Health](https://phpackages.com/badges/phpcorelab-payment-gateways/health.svg)](https://phpackages.com/packages/phpcorelab-payment-gateways)
```

###  Alternatives

[evryn/laravel-toman

A simple stable Laravel package to handle popular payment gateways in Iran including ZarinPal and IDPay.

1079.8k](/packages/evryn-laravel-toman)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
