PHPackages                             laraditz/razorpay - 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. laraditz/razorpay

ActiveLibrary

laraditz/razorpay
=================

Laravel package for interacting with Razorpay API.

00PHPCI passing

Since Jul 31Pushed todayCompare

[ Source](https://github.com/laraditz/razorpay)[ Packagist](https://packagist.org/packages/laraditz/razorpay)[ RSS](/packages/laraditz-razorpay/feed)WikiDiscussions main Synced today

READMEChangelog (2)DependenciesVersions (2)Used By (0)

Laravel Curlec by Razorpay
==========================

[](#laravel-curlec-by-razorpay)

[![Latest Version on Packagist](https://camo.githubusercontent.com/81c60a1ff69507772dd27093d030d2d3102881db98b57bfe71f0eda9c24f756d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6172616469747a2f72617a6f727061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laraditz/razorpay)[![Total Downloads](https://camo.githubusercontent.com/cf1ba0d1b464c0108c903c2cdf1f54ce967a9dfd2eaf0a94d615824bb0a08f7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6172616469747a2f72617a6f727061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laraditz/razorpay)[![License](https://camo.githubusercontent.com/750611788d354a3e4961dcffc4d5ccbea7883afcf070d3cf14979e789fa7e700/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6172616469747a2f72617a6f727061793f7374796c653d666c61742d737175617265)](./LICENSE.md)[![GitHub Actions](https://github.com/laraditz/razorpay/actions/workflows/main.yml/badge.svg)](https://github.com/laraditz/razorpay/actions/workflows/main.yml/badge.svg)

A Laravel wrapper package for the [Razorpay](https://razorpay.com) API. Built directly on Laravel's HTTP client, it provides a fluent facade for Payment Links, Orders, Payments, Refunds, and Settlements with database persistence and webhook-driven, event-based sync out of the box.

Features
--------

[](#features)

- 🔗 **Payment Links** — create, fetch, update, cancel, list, resend notification
- 🧾 **Orders** — create, fetch, list, update, fetch payments for an order, plus Checkout payment-signature verification
- 💳 **Payments** — fetch, capture, update, list — synced locally from both the API response and the `payment.authorized`/`captured`/`failed` webhooks
- 💸 **Refunds** — create, fetch, list (account-wide and per-payment), update
- 🏦 **Settlements** — fetch, list — synced locally from both the API response and the `settlement.processed` webhook
- 🗄️ Local database persistence for every resource (`RazorpayPaymentLink`, `RazorpayOrder`, `RazorpayPayment`, `RazorpayRefund`, `RazorpaySettlement`), each a `payment_id`/`razorpay_id` join away from the others
- 📜 **API request/response logging** — every outbound call recorded, with customer PII redacted and configurable retention
- 🕵️ **Webhook audit log** — every signature-valid inbound webhook recorded for later audit, separately from signature-failure diagnostics in your app's log channel
- 🔔 Automatic webhook handling with HMAC-SHA256 signature verification
- 🔁 Idempotent webhook sync — local records stay correct even if Razorpay retries a delivery
- 🎯 Generic + typed events for every webhook-driven state change
- 📦 Uses Laravel's HTTP client only — no Guzzle, no vendor SDK
- 🛡️ Type-safe with PHP 8.2+ backed enums
- 🚫 Package-owned exception hierarchy — never leaks raw HTTP or vendor exceptions

Requirements
------------

[](#requirements)

- PHP 8.2+ (Laravel 13.x itself requires PHP 8.3+)
- Laravel 10.x, 11.x, 12.x, or 13.x

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

[](#installation)

Install the package via composer:

```
composer require laraditz/razorpay
```

Publish the configuration and migrations:

```
php artisan vendor:publish --tag=razorpay-config
php artisan vendor:publish --tag=razorpay-migrations
```

Run the migrations:

```
php artisan migrate
```

Add your Razorpay credentials to `.env`:

```
RAZORPAY_KEY_ID=rzp_test_your_key_id
RAZORPAY_KEY_SECRET=your_key_secret
RAZORPAY_WEBHOOK_SECRET=your_webhook_secret
RAZORPAY_CURRENCY=MYR
```

Configuration
-------------

[](#configuration)

`config/razorpay.php`:

```
return [
    'key_id' => env('RAZORPAY_KEY_ID'),
    'key_secret' => env('RAZORPAY_KEY_SECRET'),
    'base_url' => env('RAZORPAY_BASE_URL', 'https://api.razorpay.com/v1'),
    'default_currency' => env('RAZORPAY_CURRENCY', 'MYR'),
    'timeout' => env('RAZORPAY_TIMEOUT', 30),
    'webhook_secret' => env('RAZORPAY_WEBHOOK_SECRET'),
    'webhook_path' => env('RAZORPAY_WEBHOOK_PATH', '/razorpay/webhook'),
    'log_api_calls' => env('RAZORPAY_LOG_API_CALLS', true),
    'api_log_retention_days' => env('RAZORPAY_API_LOG_RETENTION_DAYS', 30),
    'log_webhook_calls' => env('RAZORPAY_LOG_WEBHOOK_CALLS', true),
    'webhook_log_retention_days' => env('RAZORPAY_WEBHOOK_LOG_RETENTION_DAYS', 30),
];
```

Usage
-----

[](#usage)

Every service is accessed through the `Razorpay` facade. Full method reference, parameters, and more examples for each are in [`/docs`](docs) — linked below and in the [Documentation](#documentation) section.

### Payment Links

[](#payment-links)

```
use Laraditz\Razorpay\Facades\Razorpay;

$link = Razorpay::paymentLink()->create([
    'amount' => 50000, // smallest currency subunit
    'currency' => 'MYR',
    'customer' => ['name' => 'John Doe', 'email' => 'john@example.com'],
    'reference_id' => 'ORDER-123',
]);

return redirect($link['short_url']);
```

→ [Full documentation](docs/payment-links.md)

### Orders

[](#orders)

```
use Laraditz\Razorpay\Facades\Razorpay;

$order = Razorpay::order()->create(['amount' => 50000, 'currency' => 'MYR']);

// Pass $order['id'] to Checkout.js, then verify the signature it returns:
$isValid = Razorpay::order()->verifyPaymentSignature(
    $request->input('razorpay_order_id'),
    $request->input('razorpay_payment_id'),
    $request->input('razorpay_signature'),
);
```

→ [Full documentation](docs/orders.md)

### Payments

[](#payments)

```
use Laraditz\Razorpay\Facades\Razorpay;

$payment = Razorpay::payment()->fetch('pay_29QQoUBi66xm2f');
$payment = Razorpay::payment()->capture('pay_29QQoUBi66xm2f', ['amount' => 50000, 'currency' => 'MYR']);
```

→ [Full documentation](docs/payments.md)

### Refunds

[](#refunds)

```
use Laraditz\Razorpay\Facades\Razorpay;

$refund = Razorpay::refund()->create('pay_29QQoUBi66xm2f', ['amount' => 10000]);
```

→ [Full documentation](docs/refunds.md)

### Settlements

[](#settlements)

```
use Laraditz\Razorpay\Facades\Razorpay;

$settlements = Razorpay::settlement()->all(['count' => 20]);
```

→ [Full documentation](docs/settlements.md)

### Querying local records

[](#querying-local-records)

Every `create()` call (and, for Payments/Settlements, every `fetch()`/`capture()`/`update()`/`all()` call too) persists a local Eloquent record, kept in sync automatically as webhooks arrive — no manual polling required:

```
use Laraditz\Razorpay\Models\RazorpayOrder;

$order = RazorpayOrder::where('razorpay_id', 'order_EKwxwAgItmmXdp')->first();

if ($order->status->isPaid()) {
    // ...
}

$order->payment; // the RazorpayPayment that settled it, via the payment_id column
```

### Error Handling

[](#error-handling)

Every non-2xx API response is caught and rethrown as a package-owned exception — you never need to catch raw HTTP client exceptions:

```
use Laraditz\Razorpay\Exceptions\AuthenticationException; // 401
use Laraditz\Razorpay\Exceptions\ValidationException;     // 400, carries field errors via getErrors()
use Laraditz\Razorpay\Exceptions\ApiException;             // any other 4xx/5xx, carries the full body via getResponse()

try {
    Razorpay::paymentLink()->create(['amount' => 50000]);
} catch (ValidationException $e) {
    logger()->warning('Razorpay validation failed', $e->getErrors());
} catch (ApiException $e) {
    logger()->error('Razorpay API error', $e->getResponse());
}
```

Webhooks
--------

[](#webhooks)

A webhook route is registered automatically at `POST /razorpay/webhook` (configurable via `RAZORPAY_WEBHOOK_PATH`) — never part of Laravel's `web` middleware group, so the `X-Razorpay-Signature` header is the sole authentication boundary. Point your Razorpay Dashboard's webhook URL at it and set `RAZORPAY_WEBHOOK_SECRET`.

Typed events fire for the events this package understands (`PaymentLinkPaid`, `PaymentAuthorized`, `PaymentCaptured`, `PaymentFailed`, `OrderPaid`, `RefundCreated`/`Processed`/`Failed`, `SettlementProcessed`), each keeping the matching local record in sync — plus a generic `RazorpayWebhookReceived` event for every verified delivery, regardless of type.

```
class FulfillOrder
{
    public function handle(\Laraditz\Razorpay\Events\PaymentLinkPaid $event): void
    {
        if ($event->paymentLink === null) {
            return;
        }

        // $event->paymentLink->status is already PaymentLinkStatus::Paid here
    }
}
```

→ [Full documentation](docs/webhooks.md) — event reference, listener setup, idempotency notes

Logging
-------

[](#logging)

Outbound API calls and inbound webhook deliveries can each be optionally recorded for troubleshooting/audit, independently toggled and retained:

```
RAZORPAY_LOG_API_CALLS=false
RAZORPAY_LOG_WEBHOOK_CALLS=false
```

→ [Full documentation](docs/logging.md)

Documentation
-------------

[](#documentation)

For detailed documentation on each service, please refer to:

- **[Payment Links](docs/payment-links.md)** — create, fetch, update, cancel, list, resend notification
- **[Orders](docs/orders.md)** — create, fetch, list, update, fetch payments for an order, Checkout signature verification
- **[Payments](docs/payments.md)** — fetch, capture, update, list
- **[Refunds](docs/refunds.md)** — full/partial refunds, account-wide and per-payment listing
- **[Settlements](docs/settlements.md)** — fetch, list, reconciliation
- **[Webhooks](docs/webhooks.md)** — event reference, listener setup, idempotency
- **[Logging](docs/logging.md)** — API request/response logging and webhook audit log

Testing
-------

[](#testing)

```
composer test
```

The test suite uses `Http::fake()`/`Event::fake()` throughout — no real network access or live Razorpay credentials are required.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

21

↑

LowBetter than 17% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1203676?v=4)[Raditz Farhan](/maintainers/raditzfarhan)[@raditzfarhan](https://github.com/raditzfarhan)

---

Top Contributors

[![raditzfarhan](https://avatars.githubusercontent.com/u/1203676?v=4)](https://github.com/raditzfarhan "raditzfarhan (154 commits)")

### Embed Badge

![Health badge](/badges/laraditz-razorpay/health.svg)

```
[![Health](https://phpackages.com/badges/laraditz-razorpay/health.svg)](https://phpackages.com/packages/laraditz-razorpay)
```

PHPackages © 2026

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