PHPackages                             sarojsardar/hamropay - 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. sarojsardar/hamropay

ActiveLibrary[Payment Processing](/categories/payments)

sarojsardar/hamropay
====================

Unofficial HamroPay payment gateway integration for Laravel

00PHP

Since Jul 10Pushed 1mo agoCompare

[ Source](https://github.com/sarojsardar/HamroPay)[ Packagist](https://packagist.org/packages/sarojsardar/hamropay)[ RSS](/packages/sarojsardar-hamropay/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

sarojsardar/hamropay
====================

[](#sarojsardarhamropay)

A production-ready Laravel package for the [HamroPay](https://hamropatro.com) payment gateway.

 [![Latest Version](https://camo.githubusercontent.com/ce563ef8a863814d0647648ce7e9449a30dc213278e9f4a1343c626f5ce384c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7361726f6a7361726461722f68616d726f7061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sarojsardar/hamropay) [![PHP Version](https://camo.githubusercontent.com/b872851e382b4fa4030c459118d32b55914699192ed0f30fd37d5aa368479244/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7361726f6a7361726461722f68616d726f7061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sarojsardar/hamropay) [![License](https://camo.githubusercontent.com/6c0d205f5a71a0ef6977da786e7cfc58bf7677f5428fce1fe519ac7f4b2cec37/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7361726f6a7361726461722f68616d726f7061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sarojsardar/hamropay) [![Tests](https://camo.githubusercontent.com/602548e845add0018d80bbc39cbc1dfb092fefefbc96fbb74076b82afa80fc6c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7361726f6a7361726461722f48616d726f5061792f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/sarojsardar/HamroPay/actions)

> **Disclaimer:** This is an unofficial community package and is not affiliated with or endorsed by HamroPatro Pvt. Ltd.

---

Features
--------

[](#features)

- **HMAC-SHA512 signed** requests — all API calls are cryptographically signed
- **Laravel events** — `PaymentInitiated` and `WebhookReceived` for clean application hooks
- **Auto-registered routes** — configurable prefix, middleware, and toggle
- **Config validation** — throws on missing credentials at boot time, not at runtime
- **Retry &amp; timeout** — configurable HTTP client options for production resilience
- **Rate limiting** — built-in throttle on initiate and transaction endpoints
- **Fully tested** — 16 tests, 45 assertions with Pest
- **PHPStan level 8** — strict static analysis via Larastan
- **Laravel Pint** — enforced code style

---

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

[](#requirements)

DependencyVersionPHP`^8.2`Laravel`10.x` `11.x` `12.x`---

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

[](#installation)

Install via Composer:

```
composer require sarojsardar/hamropay
```

Laravel auto-discovers the service provider — no manual registration needed.

Publish the config file:

```
php artisan vendor:publish --tag=hamropay-config
```

---

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

[](#configuration)

Add the following to your `.env` file:

```
# API Endpoints
HAMROPAY_API_BASE_URL=https://uat-payclient.hamropatro.com
HAMROPAY_GATEWAY_URL=https://uat-checkout-pay.hamropatro.com

# Merchant Credentials (from HamroPay merchant portal)
HAMROPAY_MERCHANT_ID=your-merchant-id
HAMROPAY_CLIENT_ID=your-client-id
HAMROPAY_CLIENT_API_KEY=your-client-api-key
HAMROPAY_SECRET=your-secret
HAMROPAY_WEBHOOK_SECRET=your-webhook-secret

# Redirect URLs
HAMROPAY_SUCCESS_URL=https://yourapp.com/payment/success
HAMROPAY_FAILURE_URL=https://yourapp.com/payment/failed

# HTTP Options (optional)
HAMROPAY_VERIFY_SSL=true
HAMROPAY_TIMEOUT=30
HAMROPAY_RETRY=1
HAMROPAY_RETRY_DELAY=500

# Routes (optional)
HAMROPAY_ROUTES_ENABLED=true
HAMROPAY_ROUTES_PREFIX=api/hamropay
```

---

Quick Start
-----------

[](#quick-start)

### 1. Initiate a Payment

[](#1-initiate-a-payment)

```
use SarojSardar\HamroPay\Facades\HamroPay;

$result = HamroPay::initiate(
    amount: 1000,           // Amount in paisa (1000 = Rs. 10)
    remarks: 'Order #42',
);

// $result['gateway_url']     — POST form action URL
// $result['merchant_txn_id'] — your transaction reference
// $result['params']          — hidden fields to submit
```

### 2. Submit to Gateway (Blade)

[](#2-submit-to-gateway-blade)

```

    @foreach ($result['params'] as $key => $value)

    @endforeach
    Pay with HamroPay

```

### 3. Handle the Webhook

[](#3-handle-the-webhook)

Listen to the `WebhookReceived` event in your `AppServiceProvider`:

```
use SarojSardar\HamroPay\Events\WebhookReceived;

Event::listen(WebhookReceived::class, function (WebhookReceived $event) {
    $payload = $event->payload;

    if ($payload['status'] === 'SUCCESS') {
        // Mark order as paid
    }
});
```

---

Usage
-----

[](#usage)

### Via Dependency Injection (recommended)

[](#via-dependency-injection-recommended)

```
use SarojSardar\HamroPay\Contracts\HamroPayClient;
use SarojSardar\HamroPay\Exceptions\HamroPayException;

class PaymentController extends Controller
{
    public function __construct(private readonly HamroPayClient $hamroPay) {}

    public function initiate(Request $request): JsonResponse
    {
        try {
            $result = $this->hamroPay->initiate(
                amount: $request->integer('amount'),
                remarks: "Order #{$request->input('order_id')}",
                products: $request->array('products'),
                metadata: $request->array('metadata'),
            );
        } catch (HamroPayException $e) {
            return response()->json(['error' => $e->getMessage()], 422);
        }

        return response()->json($result);
    }
}
```

### Fetch Transaction Status

[](#fetch-transaction-status)

```
$txn = HamroPay::getTransaction($merchantTxnId);

// $txn['status']  — SUCCESS | FAILED | NOT_INITIATED
// $txn['amount']  — amount in paisa
```

### Webhook Verification (manual)

[](#webhook-verification-manual)

```
$valid = HamroPay::verifyWebhookSignature(
    headerSig: $request->header('Signature'),
    merchantTxnId: $payload['merchantTxnId'],
    status: $payload['status'],
    amount: (float) $payload['amount'],
);
```

Or use `handleWebhook()` which verifies and fires the `WebhookReceived` event in one call:

```
if (! HamroPay::handleWebhook($request->header('Signature'), $request->all())) {
    abort(401, 'Invalid signature');
}
```

---

API Routes
----------

[](#api-routes)

The package auto-registers these routes under the `api` middleware group:

MethodURIDescription`POST``api/hamropay/initiate`Create a payment session`POST``api/hamropay/transaction`Fetch transaction status`POST``api/hamropay/webhook`Receive webhook callback### Customise Routes

[](#customise-routes)

```
// config/hamropay.php
'routes' => [
    'enabled'    => true,
    'prefix'     => 'payments/hamropay',
    'middleware' => ['api', 'auth:sanctum'],
],
```

### Disable and Define Your Own

[](#disable-and-define-your-own)

```
HAMROPAY_ROUTES_ENABLED=false
```

```
use SarojSardar\HamroPay\Http\Controllers\HamroPayController;

Route::middleware('api')->group(function () {
    Route::post('/pay/initiate',   [HamroPayController::class, 'initiate']);
    Route::post('/pay/status',     [HamroPayController::class, 'transaction']);
    Route::post('/pay/webhook',    [HamroPayController::class, 'webhook']);
});
```

---

Events
------

[](#events)

EventFired whenPayload`PaymentInitiated`Session created successfully`merchantTxnId`, `amount`, `remarks``WebhookReceived`Valid webhook signature verifiedFull webhook `payload` array---

Error Handling
--------------

[](#error-handling)

All API failures throw `HamroPayException`:

```
use SarojSardar\HamroPay\Exceptions\HamroPayException;

try {
    $result = HamroPay::initiate(1000);
} catch (HamroPayException $e) {
    $e->getMessage();   // Human-readable error
    $e->getCode();      // HTTP status code (for requestFailed)
    $e->context();      // ['status' => 400, 'body' => '...']
}
```

---

Testing
-------

[](#testing)

```
# Run tests
composer test

# Run with coverage (requires Xdebug or PCOV)
composer test:coverage

# Static analysis
composer analyse

# Code style
composer format
```

### Faking in Application Tests

[](#faking-in-application-tests)

```
use Illuminate\Support\Facades\Http;

Http::fake([
    'uat-payclient.hamropatro.com/*' => Http::response([
        'sessionId' => 'fake-session-id',
    ]),
]);

$this->postJson('/api/hamropay/initiate', ['amount' => 1000])
     ->assertOk()
     ->assertJsonStructure(['gateway_url', 'merchant_txn_id', 'params']);
```

---

Security
--------

[](#security)

- All outbound requests are signed with `HMAC-SHA512`
- Webhook signatures are verified with `hash_equals()` to prevent timing attacks
- SSL verification is enabled by default (`HAMROPAY_VERIFY_SSL=true`)
- Credentials are validated at service resolution time — misconfiguration fails fast

To report a security vulnerability, please email  instead of opening a public issue.

---

Contributing
------------

[](#contributing)

Contributions are welcome. Please open an issue first to discuss what you would like to change.

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/my-feature`)
3. Run tests (`composer test`) and static analysis (`composer analyse`)
4. Submit a pull request

---

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for release history.

---

License
-------

[](#license)

The MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance60

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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/108754250?v=4)[Saroj Sardar](/maintainers/sarojsardar)[@sarojsardar](https://github.com/sarojsardar)

---

Top Contributors

[![sarojsardar](https://avatars.githubusercontent.com/u/108754250?v=4)](https://github.com/sarojsardar "sarojsardar (2 commits)")

### Embed Badge

![Health badge](/badges/sarojsardar-hamropay/health.svg)

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

###  Alternatives

[pagseguro/php

Biblioteca de integração com o PagSeguro

23260.3k6](/packages/pagseguro-php)[wp-pay-extensions/gravityforms

Gravity Forms driver for the WordPress payment processing library.

1134.5k5](/packages/wp-pay-extensions-gravityforms)[omalizadeh/laravel-multi-payment

A driver-based laravel package for online payments via multiple gateways

491.2k](/packages/omalizadeh-laravel-multi-payment)[airwallex/payments-plugin-magento

134.5k](/packages/airwallex-payments-plugin-magento)

PHPackages © 2026

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