Download the PHP package islam016/laravel-safe-checkout without Composer
On this page you can find all versions of the php package islam016/laravel-safe-checkout. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download islam016/laravel-safe-checkout
More information about islam016/laravel-safe-checkout
Files in islam016/laravel-safe-checkout
Package laravel-safe-checkout
Short Description Safe checkout for Laravel with Moyasar and Tap: idempotent payment creation, verified webhooks, amount reconciliation against the gateway, and a status state machine that never pays an order twice or marks a wrong amount as paid.
License MIT
Homepage https://github.com/Islam016/laravel-safe-checkout
Informations about the package laravel-safe-checkout
Laravel Safe Checkout
Payments for Laravel with Moyasar and Tap that are hard to get wrong.
Calling a payment API is the easy part. The bugs that cost money live around it:
| What goes wrong | What this package does |
|---|---|
| The customer double-clicks "Pay", or a request is retried, and two checkouts are opened | Checkout::start() takes an idempotency key. The same key returns the same payment and the same checkout page. A unique index protects against races. |
| Someone posts a fake "paid" webhook to your endpoint | Webhooks are verified (Moyasar secret token, Tap HMAC-SHA256 hashstring) and rejected with 403 otherwise. |
| The webhook body is trusted for the status or the amount | The payload is only used to find the payment. Status and amount are always fetched from the gateway API. |
| A payment for 1 SAR is accepted for a 1,500 SAR order | The amount and currency the gateway reports must match the order exactly, or the payment is failed with amount_mismatch. |
| The gateway delivers the same webhook 3 times and the order is fulfilled 3 times | Each delivery is recorded once. PaymentSucceeded fires exactly once. |
| A late or out-of-order webhook turns a paid order back into failed | A state machine makes paid and expired final. |
| Your server or the gateway API was down when the webhook came | On gateway errors the webhook returns 503 so it is retried, and safe-checkout:reconcile catches anything that was missed. |
0.1 + 0.2 and float rounding |
Money is stored as an integer in halalas (or fils for KWD/BHD/OMR, with 3 decimals). |
Installation
Point the gateway's webhook to:
To change the prefix, middleware or table names: php artisan vendor:publish --tag=safe-checkout-config.
Usage
1. Start a checkout
Tap needs a customer:
2. Fulfil the order when, and only when, it is really paid
3. On the page the customer returns to
The redirect itself proves nothing, so confirm with the gateway:
4. Safety net for missed webhooks
Queue mode
Set CHECKOUT_QUEUE=true to answer webhooks immediately and reconcile in a queued job (5 tries with backoff).
How a payment moves
Adding another gateway
Implement IslamGaber\SafeCheckout\Contracts\Gateway (createCheckout, fetch, parseWebhook) and add a gateways.hyperpay entry with 'driver' => 'hyperpay' to the config. Everything else (idempotency, verification flow, amount checks, state machine, events) comes for free.
Testing
Every flow above has a test with faked gateway responses: double clicks, forged and tampered webhooks, replayed deliveries, wrong amounts, stale responses, gateway outages and missed webhooks. CI runs on PHP 8.2–8.4 with SQLite, and on real MySQL 8.4 and PostgreSQL 17.
Notes
- Moyasar: hosted invoices (
POST /v1/invoices), Basic auth with the secret key, amounts in halalas. - Tap: hosted charges (
POST /v2/charges, sourcesrc_allby default), Bearer auth, amounts in major units. - Refunds and saved cards are not covered yet.
License
MIT © Islam Gaber
All versions of laravel-safe-checkout with dependencies
illuminate/console Version ^12.0
illuminate/database Version ^12.0
illuminate/http Version ^12.0
illuminate/queue Version ^12.0
illuminate/routing Version ^12.0
illuminate/support Version ^12.0
guzzlehttp/guzzle Version ^7.8