Download the PHP package digitaltunnel/moyasar without Composer
On this page you can find all versions of the php package digitaltunnel/moyasar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digitaltunnel/moyasar
More information about digitaltunnel/moyasar
Files in digitaltunnel/moyasar
Package moyasar
Short Description Moyasar payment gateway SDK for Laravel β credit card, Apple Pay, Samsung Pay, STC Pay, tokenization, webhooks.
License MIT
Informations about the package moyasar
Moyasar for Laravel
A typed, testable, batteries-included SDK for the Moyasar payment gateway with first-class Laravel integration. Credit cards, Apple Pay, Samsung Pay, STC Pay, tokenization, invoices, and webhooks β all covered out of the box.
Why this package
- π― Typed end to end β readonly DTOs and enums, not loose arrays.
- π§± Fluent builders for every payment source and the create-payment / create-invoice requests.
- π Webhooks that just work β auto-registered route outside the
webgroup (no CSRF dance), signature verification, idempotent de-duplication, optional queued processing. - π§Ύ Invoices API β hosted payment pages / payment links in two lines.
- π‘οΈ Secure-by-default checkout β a
verifyCallback()helper that re-fetches and validates the payment before you fulfil an order. - π§ͺ Genuinely testable β a
MoyasarFakedouble, plus 160+ tests, PHPStan level 6, and ~100% type coverage in this very package.
Requirements
| PHP | 8.2, 8.3, 8.4 |
| Laravel | 11, 12, 13 |
Installation
Then run the installer β it publishes the config and prints next steps:
Add your keys to .env:
The webhook route registers automatically outside the web middleware group, so CSRF
never applies β you don't need to touch VerifyCsrfToken::$except. Confirm it's live:
Configuration
Every option is environment-driven. Defaults shown.
| Env var | Config key | Default | Purpose |
|---|---|---|---|
MOYASAR_SECRET_KEY |
moyasar.secret_key |
β | Backend Basic-auth key. Never expose. |
MOYASAR_PUBLISHABLE_KEY |
moyasar.publishable_key |
β | Safe for the browser (tokenization, Apple Pay). |
MOYASAR_BASE_URL |
moyasar.base_url |
https://api.moyasar.com/v1 |
Override only for a mock/proxy. |
MOYASAR_TIMEOUT |
moyasar.http.timeout |
30 |
HTTP timeout (seconds). |
MOYASAR_RETRY_TIMES |
moyasar.http.retry.times |
0 |
Transient-failure retries (0 = off). |
MOYASAR_RETRY_SLEEP_MS |
moyasar.http.retry.sleep_ms |
200 |
Delay between retries. |
MOYASAR_WEBHOOK_ENABLED |
moyasar.webhook.enabled |
true |
Auto-register the inbound route. |
MOYASAR_WEBHOOK_PATH |
moyasar.webhook.path |
webhooks/moyasar |
Inbound webhook path. |
MOYASAR_WEBHOOK_NAME |
moyasar.webhook.name |
moyasar.webhook |
Route name. |
MOYASAR_WEBHOOK_SECRET |
moyasar.webhook.secret |
β | Shared secret token to verify deliveries. |
MOYASAR_WEBHOOK_QUEUE |
moyasar.webhook.queue |
false |
false=sync, true=default queue, or a connection name. |
MOYASAR_PERSIST_PAYMENTS |
moyasar.persistence.payments.enabled |
true |
Mirror payments to moyasar_payments. |
MOYASAR_PERSIST_TOKENS |
moyasar.persistence.tokens.enabled |
true |
Mirror tokens to moyasar_tokens. |
MOYASAR_LOG_WEBHOOK_EVENTS |
moyasar.persistence.webhook_events.enabled |
true |
Log + de-dup webhooks via moyasar_webhook_events. |
Note All amounts are integers in the smallest currency unit (halalah).
100.00 SAR = 10000. Use->amountInMajorUnits(100.00)orAmount::toMinorUnits(100.00)to avoid the classic off-by-100 bug.
End-to-end checkout (credit card + 3DS)
The complete, secure flow β create, redirect to 3DS, then verify on return before fulfilling.
Prefer webhooks as your source of truth for fulfilment (see below).
verifyCallback()gives the customer an instant, trustworthy result on return; the webhook guarantees you eventually reconcile even if the browser never comes back.
Payment methods
Apple Pay
Samsung Pay
STC Pay (with OTP follow-up)
Tokenization (card-on-file)
Invoices (hosted payment pages)
Lifecycle & reconciliation
Webhooks
Listen for the typed events anywhere you register listeners:
Available events (each carries $payment + $webhook):
PaymentPaid Β· PaymentFailed Β· PaymentAuthorized Β· PaymentCaptured Β· PaymentRefunded
Β· PaymentVoided Β· PaymentAbandoned Β· PaymentVerified Β· WebhookReceived (catch-all).
Idempotent by design. Moyasar retries non-2xx deliveries up to 6 times. With the
moyasar_webhook_events table enabled, each event is stored by id and claimed before
dispatch, so a retried (or forged) delivery never re-fires your listeners. Keep listeners
idempotent, and for heavy work either queue your listeners (ShouldQueue) or offload the
whole pipeline:
Register your webhook
β¦or from code: Moyasar::webhooks()->create(url: ..., events: [...], sharedSecret: ...).
Custom route
Set MOYASAR_WEBHOOK_ENABLED=false and wire it yourself:
Local persistence (opt-in)
If you published the migrations, three Eloquent models mirror Moyasar state for reporting:
MoyasarToken and MoyasarWebhookEvent work the same way. Rows are written automatically
on API calls and inbound webhooks unless you disable the relevant persistence.* flag.
Money helpers
Exception handling
The full hierarchy:
Testing
Use MoyasarFake to stub the API in your own feature tests:
Helpers: fakePaymentCreated(), fakeValidationError(), fakeAuthenticationError(),
webhookFixture(), assertCreated(), assertRefunded(), assertSentCount(),
assertNothingSent().
Running the package test suite
Contributing
See SECURITY.md.
License
MIT. See LICENSE.
All versions of moyasar with dependencies
ext-json Version *
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/routing Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0