A short guide from zero to a first payment. Full details live in the README. Arabic version: docs/ar/quickstart.md.
This is an EXPERIMENTAL pre-release. What was run against a real provider is Kashier (hosted checkout and a refund) and Paymob (session creation and the signed redirect HMAC) only. Geidea and Fawry are tested against recorded payloads, and the manual driver is exercised by the test suite. Do not take real money until you have tried it yourself.
composer require elbanbydev/paykit
php artisan vendor:publish --tag=paykit-configThe package ships no default keys and no test accounts.
In .env, fill in the gateway you have an account with. Paymob example:
PAYKIT_GATEWAY=paymob
PAYMOB_SECRET_KEY=sk_test_...
PAYMOB_PUBLIC_KEY=pk_test_...
PAYMOB_HMAC_SECRET=...
PAYMOB_INTEGRATION_IDS=5123456
PAYMOB_NOTIFICATION_URL=https://your-app.test/paykit/webhooks/paymob
PAYMOB_REDIRECTION_URL=https://your-app.test/checkout/doneEach gateway has its own section in config/paykit.php with exactly what it needs. Before the first payment, run:
php artisan paykit:checkIt prints one line per driver: ok, or missing with the key and its environment variable. It also warns about unsafe setups (plain-HTTP URLs, a volatile idempotency cache store, receipts on a public disk).
use Paykit\Data\Customer;
use Paykit\Data\Money;
use Paykit\Data\PaymentRequest;
use Paykit\Facades\Paykit;
$session = Paykit::createPayment(new PaymentRequest(
reference: 'ORDER-1042',
amount: Money::of('250.00', 'EGP'), // stored as 25000 piastres
customer: new Customer(
firstName: 'Ahmed',
lastName: 'Ali',
phone: '+201000000000',
),
idempotencyKey: 'order-1042-attempt-1',
));
return redirect()->away($session->checkoutUrl);Moneystores integer minor units: EGP 250.00 is 25000 piastres.PaymentSessioncarriesorderIdandcheckoutUrl. Store the reference and the order id with your order; they come back in the callback.- Retrying with the same
idempotencyKeyreturns the same session; the gateway is not called twice.
Want proof your keys really work? php artisan paykit:smoke starts one real payment on the gateway (it only reserves a payment page; no money moves at this step).
The package registers POST /paykit/webhooks/{gateway} itself (the path is configurable via paykit.webhooks.path). Point the gateway's notification_url at it.
No callback is read before its signature checks out. A wrong signature is refused, not guessed. Duplicates are filtered: one transaction reaches your code once. And a callback older than one already processed will not move the order backwards.
Listen for the result through events:
use Illuminate\Support\Facades\Event;
use Paykit\Events\PaymentSucceeded;
Event::listen(function (PaymentSucceeded $event) {
$event->event->reference; // 'ORDER-1042'
$event->event->amount->minor; // 25000
$event->event->transactionId; // the gateway's transaction id
});Paykit\Events\PaymentSucceeded- the payment succeeded.Paykit\Events\PaymentFailed- the payment failed or was rejected.
The redirection_url the customer lands on is not signed and anyone can open it: never update an order from it; state changes come only from the verified webhook.
No Egyptian wallet publishes a merchant API, so this driver does the manual part properly:
Paykit::createPayment($request->withMethod('vodafone_cash'), 'manual')returns a reference nobody can guess, the receiving account (wallet number or InstaPay handle) and the amount; show them to the customer.- The customer transfers the exact amount and uploads a receipt photo to the proof route.
- Someone on your team reviews in the panel (
/paykit/manual/panel) and approves or rejects. Approval raises the samePaymentSucceededthe gateways raise.
This driver needs a migration:
php artisan vendor:publish --tag=paykit-migrations
php artisan migrateThe panel is closed by default: routes register only when panel.ability is set, and every request must pass that Gate ability:
Gate::define('manage-payments', fn ($user) => $user->is_admin);Nobody can change an amount from a form, and receipts sit on a private disk, never on a public URL.
- Every driver and every setting: README.
- Exact sandbox results per gateway: sandboxes.md.
- Problems this package has actually met: troubleshooting.md.
- Security review and tried attacks: threat-model.md and security-audit.md.