PHPackages                             fiachehr/laravel-pardakht - 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. fiachehr/laravel-pardakht

ActiveLibrary[Payment Processing](/categories/payments)

fiachehr/laravel-pardakht
=========================

Professional Laravel payment gateway package for Iranian payment providers with SOLID principles and clean architecture

1.0.7(1mo ago)111MITPHPPHP ^8.1|^8.2|^8.3|^8.4

Since Oct 16Pushed 1mo agoCompare

[ Source](https://github.com/fiachehr/laravel-pardakht)[ Packagist](https://packagist.org/packages/fiachehr/laravel-pardakht)[ Docs](https://github.com/fiachehr/laravel-pardakht)[ RSS](/packages/fiachehr-laravel-pardakht/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (14)Versions (8)Used By (0)

Laravel Pardakht
================

[](#laravel-pardakht)

[![Latest Version](https://camo.githubusercontent.com/485e87ab8cda798ebb6c0a72d4c9f60662706b6ea4cd869406e6aa029868abc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66696163686568722f6c61726176656c2d70617264616b68742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fiachehr/laravel-pardakht)[![Total Downloads](https://camo.githubusercontent.com/826c1e075d33365baee23bd3abc23576809a9944c63c2460959ae3542c2cf0f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66696163686568722f6c61726176656c2d70617264616b68742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fiachehr/laravel-pardakht)[![License](https://camo.githubusercontent.com/767fd934330d6fe1984c6ce7acf0ec35f77e15e8810a76c58e8cf34ffe4dde58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f66696163686568722f6c61726176656c2d70617264616b68742e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Tests](https://camo.githubusercontent.com/f6cfef4b188082f1042e15b45b7ffbc949e8ed95a9e8028a669e75774346d1dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f66696163686568722f6c61726176656c2d70617264616b68742f54657374733f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/fiachehr/laravel-pardakht/actions)

Professional Laravel payment gateway package for Iranian payment providers with full SOLID principles and Clean Architecture.

Documentation
-------------

[](#documentation)

**[Laravel Pardakht — Documentation](https://fiachehr.ir/docs/laravel-pardakht.html)** (hosted on [fiachehr.ir](https://fiachehr.ir))

Table of Contents
-----------------

[](#table-of-contents)

- [Documentation](#documentation)
- [Supported Gateways](#supported-gateways)
- [Key Features](#key-features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Testing](#testing)
- [Architecture](#architecture)
- [Contributing](#contributing)
- [Security](#security)
- [License](#license)

Supported Gateways
------------------

[](#supported-gateways)

- ✅ **Bank Mellat** (Bank-e Mellat) - SOAP
- ✅ **Mabna Card** (Sepehr) - REST API
- ✅ **ZarinPal** - REST API

Key Features
------------

[](#key-features)

### Architecture &amp; Design

[](#architecture--design)

- 🏗️ **SOLID Principles** - Full adherence to SOLID principles
- 🎨 **Clean Architecture** - Clean and maintainable architecture
- 🎯 **Design Patterns** - Repository, Factory, Facade patterns
- 🧩 **Contract-Based** - Interface-driven programming

### Capabilities

[](#capabilities)

- 📦 **Auto Storage** - Automatic transaction storage in database
- 🔄 **Easy Switching** - Switch between gateways easily
- 🛡️ **Error Handling** - Professional exception handling
- ✨ **Value Objects** - Type-safe value objects
- 🧪 **Test Coverage** - Comprehensive unit and feature tests
- 🔌 **Extensible** - Easy to add custom gateways
- 🌐 **Sandbox Support** - Full sandbox/test environment support

### Developer Experience

[](#developer-experience)

- 📝 **Full Documentation** - Comprehensive docs with examples
- 🎓 **Educational** - Self-documented, readable code
- 🔧 **Simple Config** - Easy configuration via .env

Requirements
------------

[](#requirements)

- PHP 8.1 or higher (use **PHP 8.2+** when running **Laravel 12**)
- Laravel 10.x, 11.x, or **12.x**
- PHP SOAP extension (for Mellat gateway)
- PHP JSON extension

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require fiachehr/laravel-pardakht
```

### 2. Publish Assets

[](#2-publish-assets)

```
# Publish all (config + migrations)
php artisan vendor:publish --provider="Fiachehr\Pardakht\PardakhtServiceProvider"
```

Or separately:

```
# Config only
php artisan vendor:publish --tag=pardakht-config

# Migrations only
php artisan vendor:publish --tag=pardakht-migrations
```

### 3. Run Migrations

[](#3-run-migrations)

```
php artisan migrate
```

This creates the `pardakht_transactions` table for storing transactions.

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

Add to your `.env` file:

```
# Default gateway
PARDAKHT_DEFAULT_GATEWAY=mellat

# ========================================
# Bank Mellat (Production)
# ========================================
MELLAT_TERMINAL_ID=your_terminal_id
MELLAT_USERNAME=your_username
MELLAT_PASSWORD=your_password
MELLAT_CALLBACK_URL=https://yoursite.com/payment/callback
MELLAT_SANDBOX=false

# ========================================
# Mabna Card / Sepehr (Production)
# ========================================
MABNA_TERMINAL_ID=your_terminal_id
MABNA_CALLBACK_URL=https://yoursite.com/payment/callback
MABNA_SANDBOX=false

# ========================================
# ZarinPal (Production)
# ========================================
ZARINPAL_MERCHANT_ID=your_merchant_id
ZARINPAL_CALLBACK_URL=https://yoursite.com/payment/callback
ZARINPAL_SANDBOX=false
ZARINPAL_DESCRIPTION="Payment via ZarinPal"
```

### Sandbox Mode (Testing)

[](#sandbox-mode-testing)

For development and testing, enable sandbox mode:

```
# Bank Mellat - Test Mode
MELLAT_SANDBOX=true
MELLAT_TERMINAL_ID=test_terminal_id
MELLAT_USERNAME=test_username
MELLAT_PASSWORD=test_password

# Mabna - Test Mode
MABNA_SANDBOX=true
MABNA_TERMINAL_ID=test_terminal_id

# ZarinPal - Test Mode
ZARINPAL_SANDBOX=true
ZARINPAL_MERCHANT_ID=test_merchant_id
```

**Get Test Credentials:**

- For Bank Mellat and Mabna: [BankTest.ir](https://banktest.ir)
- For ZarinPal: [ZarinPal Sandbox](https://sandbox.zarinpal.com)

### Advanced Configuration

[](#advanced-configuration)

The `config/pardakht.php` file:

```
return [
    // Default gateway
    'default' => env('PARDAKHT_DEFAULT_GATEWAY', 'mellat'),

    // Auto-store transactions
    'store_transactions' => true,

    // Gateway configurations
    'gateways' => [
        'mellat' => [
            'driver' => 'mellat',
            'terminal_id' => env('MELLAT_TERMINAL_ID'),
            'username' => env('MELLAT_USERNAME'),
            'password' => env('MELLAT_PASSWORD'),
            'callback_url' => env('MELLAT_CALLBACK_URL'),
            'sandbox' => env('MELLAT_SANDBOX', false),
        ],
        // ...
    ],
];
```

Usage
-----

[](#usage)

### 1. Create Payment Request

[](#1-create-payment-request)

```
use Fiachehr\Pardakht\Facades\Pardakht;
use Fiachehr\Pardakht\ValueObjects\PaymentRequest;

public function payment()
{
    // Create payment request
    $paymentRequest = new PaymentRequest(
        amount: 100000,              // Amount in Rials
        orderId: 'ORDER-12345',      // Order ID
        callbackUrl: route('payment.callback'),
        description: 'Order payment #12345',
        mobile: '09123456789',       // Optional
        email: 'user@example.com',   // Optional
        metadata: [                  // Optional
            'user_id' => auth()->id(),
            'product_id' => 5
        ]
    );

    try {
        // Send request to default gateway
        $response = Pardakht::request($paymentRequest);

        // Or use specific gateway
        // $response = Pardakht::request($paymentRequest, 'zarinpal');

        if ($response->isSuccessful()) {
            // Store tracking code in session
            session(['payment_tracking_code' => $response->trackingCode]);

            // Redirect user to payment gateway
            return redirect($response->getPaymentUrl());
        }

    } catch (\Fiachehr\Pardakht\Exceptions\GatewayException $e) {
        // Handle error
        \Log::error('Payment request failed', [
            'gateway' => $e->getGatewayName(),
            'message' => $e->getMessage(),
            'code' => $e->getGatewayCode()
        ]);

        return back()->with('error', 'Payment request failed: ' . $e->getMessage());
    }
}
```

### 2. Verify Payment (Callback)

[](#2-verify-payment-callback)

```
use Fiachehr\Pardakht\Facades\Pardakht;
use Fiachehr\Pardakht\ValueObjects\VerificationRequest;
use Illuminate\Http\Request;

public function callback(Request $request)
{
    // Get tracking code from session
    $trackingCode = session('payment_tracking_code');

    if (!$trackingCode) {
        return redirect()->route('payment.failed')
            ->with('error', 'Payment information not found');
    }

    // Create verification request
    $verificationRequest = new VerificationRequest(
        trackingCode: $trackingCode,
        gatewayData: $request->all() // All data returned from gateway
    );

    try {
        // Verify payment
        $response = Pardakht::verify($verificationRequest);

        // Or specify gateway
        // $response = Pardakht::verify($verificationRequest, 'mellat');

        if ($response->isSuccessful()) {
            // Payment successful - perform required operations

            // Example: Update order status
            $order = Order::where('id', $orderId)->first();
            $order->update([
                'status' => 'paid',
                'payment_reference' => $response->referenceId,
                'paid_at' => now()
            ]);

            // Clear session
            session()->forget('payment_tracking_code');

            return view('payment.success', [
                'referenceId' => $response->referenceId,
                'cardNumber' => $response->getMaskedCardNumber(),
                'amount' => $response->amount,
                'transactionId' => $response->transactionId,
            ]);
        }

    } catch (\Fiachehr\Pardakht\Exceptions\GatewayException $e) {
        \Log::error('Payment verification failed', [
            'gateway' => $e->getGatewayName(),
            'message' => $e->getMessage(),
            'code' => $e->getGatewayCode()
        ]);

        return view('payment.failed', [
            'message' => $e->getMessage(),
            'code' => $e->getGatewayCode(),
        ]);
    }
}
```

### 3. Advanced Usage

[](#3-advanced-usage)

#### Working with Multiple Gateways

[](#working-with-multiple-gateways)

```
// Get list of available gateways
$gateways = Pardakht::available();
// ['mellat', 'mabna', 'zarinpal']

// Get specific gateway instance
$mellatGateway = Pardakht::gateway('mellat');
$zarinpalGateway = Pardakht::gateway('zarinpal');

// Use gateway directly
$response = $mellatGateway->request($paymentRequest);
```

#### Working with Transactions via Repository

[](#working-with-transactions-via-repository)

```
use Fiachehr\Pardakht\Contracts\TransactionRepositoryInterface;

class PaymentController extends Controller
{
    public function __construct(
        protected TransactionRepositoryInterface $transactionRepository
    ) {}

    public function history()
    {
        // Get successful transactions
        $successful = $this->transactionRepository->getSuccessful();

        // Get failed transactions
        $failed = $this->transactionRepository->getFailed();

        // Find by tracking code
        $transaction = $this->transactionRepository->findByTrackingCode($trackingCode);

        // Find by order ID
        $transaction = $this->transactionRepository->findByOrderId($orderId);
    }
}
```

#### Using Transaction Model

[](#using-transaction-model)

```
use Fiachehr\Pardakht\Models\Transaction;

// Get successful transactions for specific gateway
$transactions = Transaction::gateway('mellat')
    ->successful()
    ->latest()
    ->get();

// Get pending transactions
$pending = Transaction::pending()->get();

// Filter by date
$transactions = Transaction::whereDate('created_at', today())
    ->successful()
    ->get();

// Check transaction status
$transaction = Transaction::find(1);
if ($transaction->isSuccessful()) {
    // Transaction was successful
}
```

#### Adding Custom Gateway

[](#adding-custom-gateway)

```
use Fiachehr\Pardakht\Facades\Pardakht;
use Fiachehr\Pardakht\Gateways\AbstractGateway;

class CustomGateway extends AbstractGateway
{
    public function getName(): string
    {
        return 'custom';
    }

    public function request(PaymentRequest $request): PaymentResponse
    {
        // Implement payment request
    }

    public function verify(VerificationRequest $request): VerificationResponse
    {
        // Implement payment verification
    }

    protected function validateConfig(): void
    {
        // Validate configuration
    }
}

// Register custom gateway
Pardakht::extend('custom', CustomGateway::class);
```

Testing
-------

[](#testing)

### Running Tests

[](#running-tests)

```
# Run all tests
composer test

# Run with coverage
composer test-coverage

# Run only unit tests
vendor/bin/phpunit --testsuite=Unit

# Run only feature tests
vendor/bin/phpunit --testsuite=Feature
```

### Available Tests

[](#available-tests)

- ✅ Value Objects Tests
- ✅ Gateway Manager Tests
- ✅ Transaction Model Tests
- ✅ Exception Handling Tests
- ✅ Facade Tests
- ✅ Repository Tests

Security
--------

[](#security)

### Reporting Security Vulnerabilities

[](#reporting-security-vulnerabilities)

If you discover a security vulnerability, please email .

### Best Practices

[](#best-practices)

- ✅ Always store credentials in `.env`
- ✅ Never commit credentials
- ✅ Always use SSL in production
- ✅ Ensure `SANDBOX=false` in production
- ✅ Review payment logs regularly

Contributing
------------

[](#contributing)

Contributions are welcome! Please:

1. Fork the repository
2. Create a new branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### Contribution Guidelines

[](#contribution-guidelines)

- Code must follow PSR-12
- Add necessary tests
- Update documentation
- Record changes in CHANGELOG.md

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for full changelog.

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license. See [LICENSE](LICENSE) for details.

Author
------

[](#author)

**Fiachehr**

- GitHub: [@fiachehr](https://github.com/fiachehr)
- Email:

Acknowledgments
---------------

[](#acknowledgments)

- Laravel community
- Payment gateway developers
- All contributors

Useful Links
------------

[](#useful-links)

- [Laravel Documentation](https://laravel.com/docs)
- [BankTest.ir](https://banktest.ir) - Bank gateway testing environment
- [ZarinPal Documentation](https://docs.zarinpal.com)

FAQ
---

[](#faq)

### How do I switch between gateways?

[](#how-do-i-switch-between-gateways)

```
// Method 1: Change default gateway in .env
PARDAKHT_DEFAULT_GATEWAY=zarinpal

// Method 2: Specify gateway at runtime
Pardakht::request($paymentRequest, 'zarinpal');
```

### How do I disable transaction storage?

[](#how-do-i-disable-transaction-storage)

```
// In config/pardakht.php
'store_transactions' => false,
```

### How do I handle errors?

[](#how-do-i-handle-errors)

```
try {
    $response = Pardakht::request($paymentRequest);
} catch (\Fiachehr\Pardakht\Exceptions\GatewayException $e) {
    // Gateway error
    $e->getMessage();
    $e->getGatewayName();
    $e->getGatewayCode();
} catch (\Exception $e) {
    // General error
}
```

---

**If you find this package useful, give it a ⭐️!**

Made by Fiachehr with ❤️ for Laravel

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance92

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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 ~27 days

Recently: every ~41 days

Total

7

Last Release

41d ago

PHP version history (2 changes)v1.0.0PHP ^8.1|^8.2|^8.3

1.0.7PHP ^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/535c8f29f90b6f75ba28d952c79d2861c115652851314b7f6330e204493f1c48?d=identicon)[fiachehr](/maintainers/fiachehr)

---

Top Contributors

[![fiachehr](https://avatars.githubusercontent.com/u/13856735?v=4)](https://github.com/fiachehr "fiachehr (1 commits)")

---

Tags

gatewayiranlaravelmabnamelatpaymentzarinpallaravelpaymentgatewaypayment gatewayiranpersianonline-paymentzarinpalmellatmabna

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fiachehr-laravel-pardakht/health.svg)

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

###  Alternatives

[parsisolution/gateway

A Laravel package for connecting to all Iraninan payment gateways

231.7k](/packages/parsisolution-gateway)[larabook/gateway

A Laravel package for connecting to all Iraninan payment gateways

24553.7k](/packages/larabook-gateway)[omalizadeh/laravel-multi-payment

A driver-based laravel package for online payments via multiple gateways

491.1k](/packages/omalizadeh-laravel-multi-payment)[dena-a/iran-payment

a Laravel package to handle Internet Payment Gateways for Iran Banking System

312.4k1](/packages/dena-a-iran-payment)

PHPackages © 2026

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