Search by

mohamed-haroun / laravel-paymob-hmac

king980

Verify Paymob Accept transaction callbacks (HMAC SHA-512) in Laravel. Middleware, verifier class and tests.

Package info

github.com/mohamed-haroun/laravel-paymob-hmac

pkg:composer/mohamed-haroun/laravel-paymob-hmac

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-12-02 09:03 UTC

This package is auto-updated.

Last update: 2026-12-02 09:45:58 UTC


README

Verify Paymob Accept Transaction Processed callbacks in Laravel. Reject forged payment notifications before they touch your orders.

العربية | English

  • HMAC-SHA512, constant-time comparison, no extra dependencies
  • Route middleware or a plain class you can call anywhere
  • Tested against the sample transaction in the Paymob docs
  • Laravel 11 and 12, PHP 8.2+

Install

composer require mohamed-haroun/laravel-paymob-hmac

Add your secret (Paymob dashboard > Settings > API Keys > HMAC Secret):

PAYMOB_HMAC_SECRET=your-secret

Use as middleware

use MohamedHaroun\PaymobHmac\Http\Middleware\VerifyPaymobHmac;

Route::post('/paymob/callback', PaymobCallbackController::class)
    ->middleware(VerifyPaymobHmac::class);

Invalid or missing signatures get a 401. Paymob sends the signature as the hmac query parameter and the transaction under obj in the JSON body.

Use the class directly

use MohamedHaroun\PaymobHmac\PaymobHmac;

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

What it signs

The 20 fields of obj, in Paymob's documented order, cast to strings (booleans become true / false) and joined with no separator: 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.

A null value is treated as an empty string. Paymob's docs do not say what a null field should become, so if you see a callback that fails with a null field, open an issue with the (redacted) payload.

Not covered

Card-token callbacks and the GET "response" callback use different field lists. Only the POST Transaction Processed callback is supported for now.

Also do this

Verify the signature, then make the update idempotent: store obj.id with a unique constraint so a retried callback does not fulfil an order twice.

Tests

composer install && vendor/bin/phpunit

بالعربي

حزمة Laravel للتحقق من توقيع (HMAC) إشعارات الدفع من Paymob، عشان محدش يبعتلك إشعار دفع مزيف.

composer require mohamed-haroun/laravel-paymob-hmac

حط الـ HMAC Secret من لوحة Paymob (Settings > API Keys) في .env:

PAYMOB_HMAC_SECRET=your-secret

وبعدين استخدم الـ middleware على راوت الـ callback:

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

أي توقيع غلط أو ناقص بيرجع 401. الحزمة بتدعم حاليًا إشعار Transaction Processed (POST) بس.

License

MIT