PHPackages                             darshphpdev/laravel-edfapay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. darshphpdev/laravel-edfapay

ActiveLibrary[Payment Processing](/categories/payments)

darshphpdev/laravel-edfapay
===========================

A fluent, modern EdfaPay v2.0 payment gateway integration for Laravel.

v1.1.3(3w ago)810↓100%MITPHPPHP ^7.4|^8.0

Since May 19Pushed 3w agoCompare

[ Source](https://github.com/DarshPhpDev/laravel-edfapay)[ Packagist](https://packagist.org/packages/darshphpdev/laravel-edfapay)[ RSS](/packages/darshphpdev-laravel-edfapay/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

Laravel EdfaPay
===============

[](#laravel-edfapay)

[![Latest Version on Packagist](https://camo.githubusercontent.com/da4d9044d63ef7d5c7996b6f6068f7e2e0808ae8ccbddc745d6ac3cf55bebd10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64617273687068706465762f6c61726176656c2d656466617061793f7374796c653d666c61742d737175617265)](https://packagist.org/packages/darshphpdev/laravel-edfapay)[![Total Downloads](https://camo.githubusercontent.com/4deb01341dc32cb37e6ae40217830f31cabc681138cb41b96c76bb2e2b6ac72e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64617273687068706465762f6c61726176656c2d656466617061793f7374796c653d666c61742d737175617265)](https://packagist.org/packages/darshphpdev/laravel-edfapay)[![License](https://camo.githubusercontent.com/88e1dabf4d223df0950e0985948e231325fefca9fa7fe9e446cf8b1c5e9d9e47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e)](LICENSE)

A fluent, modern Laravel wrapper for the EdfaPay v2.0 REST API engine. Effortlessly initiate secure hosted payments and capture transactional callbacks using a clean builder pattern and an decoupled, event-driven webhook architecture.

For full API insights, please review the official [EdfaPay API Documentation Guide](https://docs.edfapay.com/v2.0/docs/welcome-to-edfapay).

✨ Features
----------

[](#-features)

- 🏎️ **Modern Authentication:** Fully optimized for the modern `X-API-KEY` header system.
- 🌊 **Fluent Payment Builder:** Chainable setters ensure clean, error-free transaction payloads.
- ⚡ **Environment Toggle:** Seamless runtime switching between `demo` and `live` servers.
- 🔔 **Decoupled Webhooks:** Automatic stream-parsing fallback that broadcasts standard Laravel events.
- ⚙️ **Configurable Paths:** Fully customize or completely disable default package webhook routing.
- 🪓 **Cross-Version Stability:** Native Guzzle abstraction ensures stability across various Laravel installations.

📋 Requirements
--------------

[](#-requirements)

- 🐘 PHP 7.4 | 8.0 | 8.1 | 8.2 | 8.3
- ⚡ Laravel 8.0 | 9.0 | 10.0 | 11.0 | 12.0 | 13.0

📥 Installation
--------------

[](#-installation)

You can pull the package into your project via composer:

```
composer require darshphpdev/laravel-edfapay
```

🔧 Setup
-------

[](#-setup)

Publish the vendor configuration file to your application's config directory:

```
php artisan vendor:publish --provider="DarshPhpDev\EdfaPay\EdfaPayServiceProvider" --tag="edfapay-config"
```

Add your operational keys to your application's environment file (`.env`):

```
EDFAPAY_MODE=demo
EDFAPAY_API_KEY=your-api-key-here
EDFAPAY_CURRENCY=SAR

```

⚙️ Configuration
----------------

[](#️-configuration)

The published configuration maps out as follows under `config/edfapay.php`:

```
return [
    // Choose operating environment mode: 'demo' or 'live'
    'mode' => env('EDFAPAY_MODE', 'demo'),

    // EdfaPay API Key
    'api_key' => env('EDFAPAY_API_KEY'),

    // API Environment Base URLs
    'urls' => [
        'demo' => '[https://demo-api.edfapay.com](https://demo-api.edfapay.com)',
        'live' => '[https://app-api.edfapay.com](https://app-api.edfapay.com)',
    ],

    // Default Fallback Currency
    'currency' => env('EDFAPAY_CURRENCY', 'SAR'),

    // Webhook Route Settings
    'webhook' => [
        'enable_default_route' => true,
        'path' => 'api/v1/payments/edfapay/webhook',
        'middleware' => ['api'],
    ],
];
```

🩺 Verifying Your Setup
----------------------

[](#-verifying-your-setup)

After configuration, run the following command to validate your credentials and confirm API connectivity:

```
php artisan edfapay:check
```

A successful output looks like:

```
API Key: ✓
Mode: demo
Currency: SAR
Testing API connectivity...
API connectivity: ✓

```

If `EDFAPAY_API_KEY` is missing, the package will throw a `RuntimeException` on first use to prevent silent failures in production.

📖 Usage
-------

[](#-usage)

### 🚀 Initiating a Payment Intent

[](#-initiating-a-payment-intent)

Leverage the EdfaPay Facade and its fluent chain builders to spin up an absolute transaction payload. Per the EdfaPay Webhook Docs, you can set your notification capture endpoint dynamically per-transaction using setNotificationUrl() or rely on your global merchant dashboard webhook configurations.

```
use DarshPhpDev\EdfaPay\Facades\EdfaPay;

$response = EdfaPay::initSale()
    ->setOrderId('INV-2026-00941')
    ->setAmount(250.50) // Float or numeric strings are safely converted to precise decimals
    ->setCurrency('SAR')
    ->setUrls('https://yourdomain.com/payment/success', 'https://yourdomain.com/payment/failure')
    ->setNotificationUrl('https://yourdomain.com/api/v1/payments/edfapay/webhook') // Dynamic dynamic webhook link option
    ->setCustomerDetails([
        'name'  => 'Mustafa Ahmed',
        'email' => 'customer@domain.com',
        'phone' => '+966500000001',
    ])
    ->setAddress([
        'country' => 'SA',
        'city'    => 'Riyadh',
        'address' => 'Olaya District',
    ])
    ->initiate();

// Extract the gateway checkout URL from the response array
if (isset($response['redirectUrl'])) {
    return redirect()->away($response['redirectUrl']);
}
```

### ⚠️ Validation &amp; Error Handling

[](#️-validation--error-handling)

Calling `initiate()` automatically validates the payload before dispatching the request. The following fields are required: `orderId`, `currency`, `amount`, `customerDetails.name`, `customerDetails.email`, `customerDetails.phone`, `successUrl`, and `failureUrl`.

Use the package's typed exceptions to handle failures cleanly:

```
use DarshPhpDev\EdfaPay\Facades\EdfaPay;
use DarshPhpDev\EdfaPay\Exceptions\EdfaPayValidationException;
use DarshPhpDev\EdfaPay\Exceptions\EdfaPayApiException;

try {
    $response = EdfaPay::initSale()
        ->setOrderId('INV-2026-00941')
        ->setAmount(250.50)
        ->setUrls('https://yourdomain.com/payment/success', 'https://yourdomain.com/payment/failure')
        ->setCustomerDetails(['name' => 'Mustafa Ahmed', 'email' => 'customer@domain.com', 'phone' => '+966500000001'])
        ->initiate();
} catch (EdfaPayValidationException $e) {
    // Missing or invalid required fields — no HTTP call was made
    dd($e->getErrors()); // ['customerDetails.phone is required', ...]
} catch (EdfaPayApiException $e) {
    // HTTP request was made but EdfaPay returned an error
    dd($e->getCode(), $e->getResponseBody());
}
```

Sample edfaapay successful response:

```
{
  "code": 200,
  "message": "Success",
  "errorCode": null,
  "data": {
    "redirectUrl": "https://edfa-demo.edfapay.com/pay/checkout?sessionId=fa522cc3-7b92-467b-b132-40794bf4734f",
    "id": "fa522cc3-7b92-467b-b132-40794bf4734f"
  }
}
```

🔍 Querying a Transaction Status
-------------------------------

[](#-querying-a-transaction-status)

Use `queryTransaction()` to fetch the current status of any transaction by its ID. Useful for reconciliation jobs or when a webhook is missed.

```
use DarshPhpDev\EdfaPay\Facades\EdfaPay;
use DarshPhpDev\EdfaPay\Exceptions\EdfaPayApiException;

try {
    $response = EdfaPay::queryTransaction('fa522cc3-7b92-467b-b132-40794bf4734f');
} catch (EdfaPayApiException $e) {
    dd($e->getCode(), $e->getResponseBody());
}
```

💸 Initiating a Refund
---------------------

[](#-initiating-a-refund)

Use the `initRefund()` fluent builder to refund a previously approved transaction. `transactionId` and `amount` are required. `reason` is optional.

```
use DarshPhpDev\EdfaPay\Facades\EdfaPay;
use DarshPhpDev\EdfaPay\Exceptions\EdfaPayValidationException;
use DarshPhpDev\EdfaPay\Exceptions\EdfaPayApiException;

try {
    $response = EdfaPay::initRefund()
        ->setTransactionId('fa522cc3-7b92-467b-b132-40794bf4734f')
        ->setAmount(250.50)
        ->setReason('Customer requested cancellation') // optional
        ->refund();
} catch (EdfaPayValidationException $e) {
    dd($e->getErrors());
} catch (EdfaPayApiException $e) {
    dd($e->getCode(), $e->getResponseBody());
}
```

🔔 Handling Webhook Notifications (IPN)
--------------------------------------

[](#-handling-webhook-notifications-ipn)

This package automatically captures postback webhook stream payloads under the route defined in your configuration file, writes production metrics, and converts them into a standard decoupled event payload.

### 1. Register a Listener

[](#1-register-a-listener)

Map your custom listener to the package event inside your application's `App\Providers\EventServiceProvider` array matrix:

```
protected $listen = [
    \DarshPhpDev\EdfaPay\Events\EdfaPayWebhookReceived::class => [
        \App\Listeners\ProcessEdfaPayCallback::class,
    ],
];
```

### 2. Write the Database Sync Logic

[](#2-write-the-database-sync-logic)

Inside your listener, fetch the verified data payload seamlessly to run your model syncs:

```
namespace App\Listeners;

use DarshPhpDev\EdfaPay\Events\EdfaPayWebhookReceived;
use App\Models\Order;

class ProcessEdfaPayCallback
{
    public function handle(EdfaPayWebhookReceived $event)
    {
        $payload = $event->payload;

        $orderId       = $payload['orderId'] ?? null;
        $status        = $payload['status'] ?? null; // e.g. 'Approved' or 'Declined'
        $transactionId = $payload['transactionId'] ?? null;

        $order = Order::where('id', $orderId)->firstOrFail();

        $order->update([
            'status'         => strtolower($status) === 'approved' ? 'paid' : 'failed',
            'transaction_id' => $transactionId,
        ]);
    }
}
```

🛡️ Security
-----------

[](#️-security)

If you discover any security-related issues, please email  instead of using the issue tracker.

👨‍💻 Credits
-----------

[](#‍-credits)

- [Mustafa Ahmed](https://github.com/darshphpdev)

📄 License
---------

[](#-license)

This package is open-source software licensed under the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance95

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

21d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.1.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5dc427456706f88e785b5ded5d2e9673e9bc7fa8a742b5949a62db0272de5181?d=identicon)[DarshPhpDev](/maintainers/DarshPhpDev)

---

Top Contributors

[![DarshPhpDev](https://avatars.githubusercontent.com/u/29954627?v=4)](https://github.com/DarshPhpDev "DarshPhpDev (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/darshphpdev-laravel-edfapay/health.svg)

```
[![Health](https://phpackages.com/badges/darshphpdev-laravel-edfapay/health.svg)](https://phpackages.com/packages/darshphpdev-laravel-edfapay)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[spatie/laravel-export

Create a static site bundle from a Laravel app

670139.5k6](/packages/spatie-laravel-export)[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4849.3k](/packages/sebdesign-laravel-viva-payments)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

232.5k](/packages/eslazarev-wildberries-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
