If you take payments through Paymob in Egypt and your callback endpoint does not verify the signature, anyone who finds the URL can mark an order as paid. The endpoint is public by design, Paymob posts to it from outside, and the only thing that separates a real notification from a forged one is an HMAC you compute yourself.

This is the part I have seen go wrong in more than one codebase, and it is now a small package: laravel-paymob-hmac.

What Paymob actually signs

Paymob sends the signature as a query parameter named hmac, and the transaction as obj inside the JSON body. That split is the first trap: code that reads the signature from the body, or that verifies the body as a whole, fails or, worse, passes everything.

The signature is HMAC-SHA512 over 20 specific fields of obj, joined with no separator, in this exact order:

amount_cents, created_at, currency, error_occured, has_parent_transaction, id, integration_id, is_3d_secure, is_auth, is_capture, is_refunded, is_standalone_payment, is_voided, order.id, owner, pending, source_data.pan, source_data.sub_type, source_data.type, success 

Order matters. So does the cast: every value is stringified, booleans become true / false (not 1 / 0), and order.id is a nested path rather than a flat key. Get one of those wrong and every callback fails verification, which usually gets "fixed" by disabling the check.

The middleware

use MohamedHaroun\PaymobHmac\Http\Middleware\VerifyPaymobHmac; Route::post('/paymob/callback', PaymobCallbackController::class) ->middleware(VerifyPaymobHmac::class); 

Set the secret from the Paymob dashboard (Settings, then API Keys, then HMAC Secret):

PAYMOB_HMAC_SECRET=your-secret 

Missing or invalid signatures get a 401 and the controller never runs. If you would rather do it by hand, the verifier is a plain class:

$ok = app(PaymobHmac::class)->verify($request->json('obj'), $request->query('hmac')); 

The comparison is constant time, so a wrong signature does not leak how wrong it was through timing.

The second mistake, which is not about signatures

A valid signature only proves Paymob sent the callback. It does not stop the same callback from arriving twice. Paymob retries, networks duplicate, and a retried "transaction processed" that fulfils an order twice is a real loss.

Store obj.id with a unique constraint and make the handler idempotent:

DB::transaction(function () use ($payload) { $event = PaymobEvent::firstOrCreate(['paymob_id' => $payload['id']]); if (! $event->wasRecentlyCreated) { return; // already handled } // mark the order paid, once }); 

One field nobody documents

Paymob's docs do not say what a null field should become in the signature string. The package treats null as an empty string, which is the only choice that verifies against the callbacks I have seen. If you hit a callback that fails with a null field, the README asks for the redacted payload so the case can be pinned down rather than guessed at.

What the package does not cover

Card-token callbacks and the GET "response" callback use different field lists, so they are out of scope for now. Saying that in the README is deliberate: a package that quietly half-verifies a second callback type is worse than one that does not claim to handle it.

Install

composer require mohamed-haroun/laravel-paymob-hmac 

Laravel 11 and 12, PHP 8.2+, MIT, tested against the sample transaction in Paymob's own documentation.

If you build for Egypt, the other piece I keep re-writing per project is the governorate list for checkout and shipping zones: laravel-egypt-governorates has the 27 governorates with stable slugs and a validation rule.

The signature is the security boundary. Everything after it is bookkeeping, and both have to be right.