PHPackages                             mohamedhekal/oncegate - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. mohamedhekal/oncegate

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mohamedhekal/oncegate
=====================

Stripe-style Idempotency-Key middleware for Laravel APIs with response replay and concurrent locks

v0.1.0(1mo ago)00MITPHPPHP ^8.2CI passing

Since Jul 16Pushed 1mo agoCompare

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

READMEChangelogDependencies (11)Versions (2)Used By (0)

OnceGate
========

[](#oncegate)

Stripe-style `Idempotency-Key` middleware for Laravel APIs. Store the first response, replay safe retries, reject payload mismatches, and return `409` while a request with the same key is still in flight.

[![Tests](https://github.com/mohamedhekal/oncegate/actions/workflows/tests.yml/badge.svg)](https://github.com/mohamedhekal/oncegate/actions/workflows/tests.yml)[![License: MIT](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

> Update badge URLs after publishing the GitHub repository.

Problem
-------

[](#problem)

Mobile apps, payment clients, and flaky networks retry `POST`/`PUT` requests. Without idempotency keys, those retries create duplicate orders, charges, or shipments.

Features
--------

[](#features)

- `Idempotency-Key` header handling (name configurable)
- Request fingerprinting (method + path + body hash, optional user scope)
- Response replay with `Idempotent-Replayed: true`
- Fingerprint mismatch → `422`
- In-flight conflict → `409`
- Cache driver (default) and database driver
- Optional required-key mode
- `oncegate:purge` for expired database records

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

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

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

[](#installation)

```
composer require mohamedhekal/oncegate
php artisan vendor:publish --tag=oncegate-config
php artisan migrate
```

Quick start
-----------

[](#quick-start)

```
use Illuminate\Support\Facades\Route;

Route::middleware(['api', 'oncegate'])->group(function () {
    Route::post('/orders', [OrderController::class, 'store']);
});
```

Client:

```
POST /orders HTTP/1.1
Idempotency-Key: 8e2f1a6c-9b0d-4c3e-a1f2-7d6c5b4a3210
Content-Type: application/json

{"sku":"SKU-1","qty":1}
```

First response is executed normally. Retries with the same key and body receive the stored response and header `Idempotent-Replayed: true`.

Alias middleware name: `idempotency` (same class).

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

[](#configuration)

KeyDefaultMeaning`header``Idempotency-Key`Incoming header name`methods`POST, PUT, PATCH, DELETEMethods that participate`required``false`Abort 400 when header missing`driver``cache``cache` or `database``ttl``86400`Stored response lifetime (seconds)`lock_ttl``60`Processing marker TTL (cache)`fingerprint.include_user``true`Scope keys per authenticated userArchitecture
------------

[](#architecture)

See [docs/architecture.md](docs/architecture.md).

Testing
-------

[](#testing)

```
composer install
composer test
```

Security notes
--------------

[](#security-notes)

- Keys are scoped by user when `fingerprint.include_user` is enabled.
- Do not log raw idempotency payloads if they contain secrets—pair with a redaction package if needed.
- Prefer Redis cache in production for atomic `add` semantics under load.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

Credits
-------

[](#credits)

Mohamed Hekal.

###  Health Score

34

—

LowBetter than 74% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

45d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9d7c092a109fe780c7efd87ce4142eae2c0cec0f92fd1e87e769bec5661953b?d=identicon)[mohamedhekal](/maintainers/mohamedhekal)

---

Top Contributors

[![mohamedhekal](https://avatars.githubusercontent.com/u/21014387?v=4)](https://github.com/mohamedhekal "mohamedhekal (5 commits)")

---

Tags

apiidempotencylaravellaravel-packagemiddlewarephphttpphpmiddlewareapilaravelstripelaravel-packageidempotencyretriesexactly-onceidempotency-key

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mohamedhekal-oncegate/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3365.5M359](/packages/psalm-plugin-laravel)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k17.6M165](/packages/laravel-pulse)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

80732.6M270](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

58190.1k22](/packages/api-platform-laravel)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k2](/packages/mike-bronner-laravel-model-caching)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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