Download the PHP package mlquarizm/payment-gateway without Composer

On this page you can find all versions of the php package mlquarizm/payment-gateway. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package payment-gateway

ML Payment Gateway Package

Laravel package for integrating Tabby and Tamara payment gateways.

📋 For detailed architecture and development plan, see PLAN.md

Installation

Via Composer (if published to Packagist)

Via Git Repository (Private Package)

Add to your composer.json:

Then run:

Via Local Path (Development)

Add to your composer.json:

Then run:

Configuration

Publish the configuration files:

Run migrations:

CSRF Configuration

Since payment callbacks and webhooks come from external sources, you need to exclude them from CSRF verification.

Add the following routes to your app/Http/Middleware/VerifyCsrfToken.php:

Environment Variables

Add to your .env file:

Callback vs redirect URLs

Configuration Files

The package includes three configuration files that you can customize after publishing:

1. config/payment-gateway.php (Main Configuration)

This is the main configuration file for the package:

Configuration Options:

2. config/tabby.php (Tabby Gateway Configuration)

Configuration specific to Tabby payment gateway:

Configuration Options:

3. config/tamara.php (Tamara Gateway Configuration)

Configuration specific to Tamara payment gateway:

Configuration Options:

Usage

Basic Usage with Tabby

Important: You must call PaymentGateway::recordTransaction(...) (or create a row with the package’s PaymentTransaction model) after initiatePayment and before redirecting the user to the gateway. Otherwise the callback/webhook will not find a transaction to update.

Handling Tabby Pre-scoring Rejection

Tabby performs a Background Pre-scoring check when you call initiatePayment(). If the buyer is not eligible (e.g. credit risk, amount limits), Tabby rejects the session immediately — before the user is ever redirected to Tabby’s checkout page.

You must check $paymentInfo[‘success’] before redirecting. If you skip this check and blindly call redirect($paymentInfo[‘url’]), the URL will be null and the user will see a broken page instead of a helpful rejection message.

Response on rejection:

Rejection reasons:

Reason English Message Arabic Message
not_available Sorry, Tabby is unable to approve this purchase. Please use an alternative payment method for your order. ... تابي غير قادرة على الموافقة
order_amount_too_high This purchase is above your current spending limit with Tabby, try a smaller cart or use another payment method. ... قيمة الطلب تفوق الحد الأقصى
order_amount_too_low The purchase amount is below the minimum amount required to use Tabby, try adding more items or use another payment method. ... قيمة الطلب أقل من الحد الأدنى

The message language is determined automatically based on app()->getLocale().

Testing pre-scoring rejection: See Tabby Testing Guidelines - Background Pre-scoring Reject for test credentials that trigger rejection.

Callback flow: default is package Blade (never JSON)

The package callback (GET or POST to payment/callback/{gateway}) uses the same “pay or not” logic as the webhook: it finds the transaction by track_id/payment_id, updates status, and fires events. The only difference is the response:

The webhook endpoint is unchanged (returns 200, no redirect).

Using Builder Pattern

Important: buyerHistory() and orderHistory() are required for Tabby. Tabby uses this data for pre-scoring and risk assessment. If you don't provide them, the builder will throw an InvalidArgumentException. Pass an empty array [] to orderHistory() if the buyer has no previous orders.

Note: shippingAddress() is optional. buyer() requires only nameemail and phone are optional (pass null or empty string to omit them from the Tabby request).

Full Example

Using OrderHistoryDTO

Instead of raw arrays, you can use OrderHistoryDTO instances for type safety:

Note: orderHistory() accepts both raw arrays and OrderHistoryDTO[]. Raw arrays are sent to Tabby as-is, while OrderHistoryDTO instances are serialized by the package.

Minimal Example (no shipping address, no email/phone, new buyer with no order history)

Multiple Items

You can add multiple items in two ways:

Option 1: Using item() method multiple times

Option 2: Using items() method with array

Option 3: Using items() with array of arrays

Using Tamara

Multiple Items

You can add multiple items using the same methods as Tabby:

Using item() method multiple times:

Using items() method with array:

Handling Payment Events

The package uses Laravel Events to handle payment events. This allows you to listen to payment events in your application without modifying the package code.

Available Events

The package dispatches the following events:

Listening to Events

Register event listeners in your app/Providers/EventServiceProvider.php:

Creating Event Listeners

Create listeners using Artisan:

Example listener:

Using Closures (Alternative)

You can also use closures in EventServiceProvider:

How to Use Callback and Webhook

The package handles payment results in two ways: callback (when the user is sent back to your site after paying) and webhook (when the gateway sends a server-to-server request). Both use the same logic to update the transaction and fire events; only the entry point and response differ.

Callback (user redirect)

What it is: After the user completes or cancels payment on Tabby/Tamara, the gateway redirects the user to a URL you provide. That URL must be your app so the package can process the result and then send the user to your success/error/cancel page.

How to use it:

  1. Register the callback URL with the gateway
    In Tabby/Tamara merchant settings (and in your .env), set:

    • Success URL: https://yourdomain.com/payment/callback/tabby (or .../payment/callback/tamara)
    • Failure URL: same path
    • Cancel URL: same path
      The package uses one route and decides success/failure/cancel from the request data.
  2. Exclude the callback from CSRF
    In app/Http/Middleware/VerifyCsrfToken.php add:

  3. Set redirect URLs in config
    So the user is sent to your status page after processing, set in .env (or config):

    • TABBY_REDIRECT_SUCCESS_URL, TABBY_REDIRECT_FAILURE_URL, TABBY_REDIRECT_CANCEL_URL
    • TAMARA_REDIRECT_SUCCESS_URL, etc.
      Example: https://yourdomain.com/payment-status/success/ar.
      The callback always redirects (never returns JSON). If these are not set, it uses PAYMENT_REDIRECT_FALLBACK_URL or the app root with ?status=...&gateway=....
  4. Flow
    User finishes on gateway → gateway redirects to GET /payment/callback/{gateway} (with query params) → package runs HandlePaymentAction, updates PaymentTransaction, fires events → package redirects to your redirect_success_url / redirect_error_url / redirect_cancel_url.

Route: GET|POST /payment/callback/{gateway} (e.g. payment/callback/tabby, payment/callback/tamara).

Webhook (server-to-server)

What it is: Tabby/Tamara send an HTTP POST to your server to notify payment status. No user is in the browser; the gateway calls your URL directly.

How to use it:

  1. Register the webhook URL with the gateway
    In Tabby/Tamara merchant/dashboard settings, set the webhook URL to:

    • https://yourdomain.com/webhooks/payment/tabby
    • https://yourdomain.com/webhooks/payment/tamara
  2. Exclude the webhook from CSRF
    Same as above: add webhooks/payment/* to VerifyCsrfToken::$except.

  3. Configure verification (recommended)

    • Tamara: set TAMARA_NOTIFICATION_TOKEN in .env; the package verifies the JWT.
    • Tabby: set TABBY_SECRET_KEY and optionally TABBY_WEBHOOK_VERIFY_SIGNATURE=true for HMAC verification.
  4. Flow
    Gateway sends POST /webhooks/payment/{gateway} → package verifies signature/token → runs same HandlePaymentAction, updates transaction, fires same events → returns 200 so the gateway does not retry.

Route: POST /webhooks/payment/{gateway}.

Summary: callback vs webhook

Callback Webhook
Who calls User’s browser (redirect from gateway) Gateway’s server
Method GET (or POST) POST
Route /payment/callback/{gateway} /webhooks/payment/{gateway}
Response Redirect to your redirect_*_url or JSON Always 200 (body not used by gateway)
Logic Same: find transaction, update status, fire events Same

Reacting to payment result (both callback and webhook)

Listen to package events; they are fired for both callback and webhook:

Routes

The package automatically registers:

Webhook Signature Verification

The package includes built-in webhook signature verification for security. All webhooks are automatically verified before processing.

Tamara Webhook Verification

Tamara uses JWT tokens for webhook verification. The token can be provided in:

The package verifies:

Configuration:

Tabby Webhook Verification

Tabby uses HMAC-SHA256 signature verification. The signature is expected in:

Configuration:

Note: By default, Tabby webhook signature verification is disabled (TABBY_WEBHOOK_VERIFY_SIGNATURE=false) to maintain backward compatibility. Enable it when you're ready to enforce signature verification.

How It Works

  1. Webhook request arrives at POST /webhooks/payment/{gateway}
  2. WebhookVerificationService verifies the signature/token
  3. If verification fails, the request is rejected (but returns 200 to prevent gateway retries)
  4. If verification succeeds, the request is processed normally

Custom Verification

You can extend WebhookVerificationService to add custom verification logic for other gateways or modify existing verification methods.

Payment Transaction Model

The PaymentTransaction model uses polymorphic relationships, so it can be associated with any model:

License

MIT


All versions of payment-gateway with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0
illuminate/http Version ^10.0|^11.0
illuminate/database Version ^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mlquarizm/payment-gateway contains the following files

Loading the files please wait ...