PHPackages                             fereydooni/money-port - 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. fereydooni/money-port

ActiveLibrary[Payment Processing](/categories/payments)

fereydooni/money-port
=====================

A comprehensive Laravel payment package with strategy pattern for multiple payment gateways

v0.1.0(9mo ago)001MITPHPPHP ^8.1

Since Aug 9Pushed 9mo agoCompare

[ Source](https://github.com/Behnamfe76/money-port)[ Packagist](https://packagist.org/packages/fereydooni/money-port)[ RSS](/packages/fereydooni-money-port/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

MoneyPort - Laravel Payment Package
===================================

[](#moneyport---laravel-payment-package)

A comprehensive Laravel payment package with strategy pattern for multiple payment gateways, specifically designed for Iranian payment systems.

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

[](#-features)

- 🔄 **Strategy Pattern** - Easy to switch between payment gateways
- 🏦 **10 Iranian Gateways** - Support for all major Iranian payment providers
- 🚀 **Octane Compatible** - Uses scoped bindings for better Octane performance
- 🔧 **Easy Configuration** - Simple configuration file with environment variables
- 🎯 **Laravel Integration** - Native Laravel service provider and facade
- 📦 **Package Ready** - Easy to install and use in any Laravel project
- 🛡️ **Error Handling** - Comprehensive error handling and logging
- 🔒 **Secure** - Built-in security features and validation

🏦 Supported Payment Gateways
----------------------------

[](#-supported-payment-gateways)

### 1. **Zarinpal** - زرین‌پال

[](#1-zarinpal---زرین‌پال)

- Most popular Iranian payment gateway
- Simple API integration
- Supports sandbox mode

### 2. **Mellat Bank** - بانک ملت

[](#2-mellat-bank---بانک-ملت)

- Official bank gateway
- SOAP-based API
- Comprehensive transaction support

### 3. **Parsian Bank** - بانک پارسیان

[](#3-parsian-bank---بانک-پارسیان)

- PEP (Parsian Electronic Payment) system
- XML-based API
- High security standards

### 4. **Saman Bank** - بانک سامان

[](#4-saman-bank---بانک-سامان)

- SEP (Saman Electronic Payment) system
- RESTful API
- Fast transaction processing

### 5. **Pasargad Bank** - بانک پاسارگاد

[](#5-pasargad-bank---بانک-پاسارگاد)

- Advanced payment system
- Digital signature support
- Multi-currency support

### 6. **IDPay** - آیدی‌پی

[](#6-idpay---آیدی‌پی)

- Modern REST API
- Comprehensive documentation
- Sandbox environment

### 7. **NextPay** - نکست‌پی

[](#7-nextpay---نکست‌پی)

- Simple integration
- Multiple payment methods
- Developer-friendly API

### 8. **Sepehr** - سپهر

[](#8-sepehr---سپهر)

- Shaparak electronic payment
- Bank-independent
- High reliability

### 9. **Shaparak** - شاپرک

[](#9-shaparak---شاپرک)

- Central Bank gateway
- Standardized API
- Multi-bank support

### 10. **BehPardakht** - به‌پرداخت

[](#10-behpardakht---به‌پرداخت)

- Comprehensive payment solutions
- Advanced reporting
- Multi-terminal support

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

[](#-requirements)

- PHP 8.1 or higher
- Laravel 10.x or 11.x
- Guzzle HTTP Client

Laravel Octane Compatibility
----------------------------

[](#laravel-octane-compatibility)

This package is fully compatible with Laravel Octane. It uses `scoped()` bindings instead of `singleton()` to ensure that:

- Each request gets a fresh instance of the PaymentManager
- No state pollution between requests
- Better memory management in long-running processes
- Optimal performance in Octane environments

🚀 Installation
--------------

[](#-installation)

1. **Install the package via Composer:**

```
composer require fereydooni/money-port
```

2. **Publish the configuration file:**

```
php artisan vendor:publish --provider="Fereydooni\MoneyPort\MoneyPortServiceProvider"
```

3. **Configure your environment variables:**

```
# Default Gateway
MONEY_PORT_DEFAULT_GATEWAY=zarinpal

# Zarinpal Configuration
ZARINPAL_ENABLED=true
ZARINPAL_MERCHANT_ID=your_merchant_id
ZARINPAL_BASE_URL=https://www.zarinpal.com/pg
ZARINPAL_SANDBOX=false

# Mellat Configuration
MELLAT_ENABLED=false
MELLAT_TERMINAL_ID=your_terminal_id
MELLAT_USERNAME=your_username
MELLAT_PASSWORD=your_password

# Parsian Configuration
PARSIAN_ENABLED=false
PARSIAN_PIN=your_pin
PARSIAN_ORIGINATOR=your_originator

# Saman Configuration
SAMAN_ENABLED=false
SAMAN_TERMINAL_ID=your_terminal_id
SAMAN_SECRET_KEY=your_secret_key

# Pasargad Configuration
PASARGAD_ENABLED=false
PASARGAD_MERCHANT_CODE=your_merchant_code
PASARGAD_TERMINAL_CODE=your_terminal_code
PASARGAD_PRIVATE_KEY=your_private_key

# IDPay Configuration
IDPAY_ENABLED=false
IDPAY_API_KEY=your_api_key
IDPAY_MERCHANT_NAME=your_merchant_name
IDPAY_MERCHANT_PHONE=your_phone
IDPAY_MERCHANT_EMAIL=your_email

# NextPay Configuration
NEXTPAY_ENABLED=false
NEXTPAY_API_KEY=your_api_key
NEXTPAY_CUSTOMER_PHONE=your_phone

# Sepehr Configuration
SEPEHR_ENABLED=false
SEPEHR_TERMINAL_ID=your_terminal_id
SEPEHR_SECRET_KEY=your_secret_key

# Shaparak Configuration
SHAPARAK_ENABLED=false
SHAPARAK_MERCHANT_ID=your_merchant_id

# BehPardakht Configuration
BEHPARDAKHT_ENABLED=false
BEHPARDAKHT_USERNAME=your_username
BEHPARDAKHT_PASSWORD=your_password
BEHPARDAKHT_PAYER_ID=your_payer_id

# Logging Configuration
MONEY_PORT_LOGGING=true
MONEY_PORT_LOG_CHANNEL=payment
MONEY_PORT_LOG_LEVEL=info

# HTTP Configuration
MONEY_PORT_TIMEOUT=30
MONEY_PORT_RETRY_ATTEMPTS=3
MONEY_PORT_RETRY_DELAY=1000
```

📖 Basic Usage
-------------

[](#-basic-usage)

### Gateway Selection Behavior

[](#gateway-selection-behavior)

The package now uses a **smart gateway selection** system:

1. **Default Gateway**: Zarinpal is always the default and fallback gateway
2. **Current Gateway**: When you specify a gateway in `initialize()`, it becomes the current gateway for subsequent operations
3. **Automatic Fallback**: If no gateway is specified, the system uses the current gateway or falls back to Zarinpal

### Using the Facade

[](#using-the-facade)

```
use Fereydooni\MoneyPort\Facades\MoneyPort;

// Initialize payment with default gateway (Zarinpal)
$payment = MoneyPort::initialize([
    'amount' => 100000, // Amount in Rials
    'description' => 'Payment for order #123',
    'callback_url' => 'https://yoursite.com/payment/callback',
    'currency' => 'IRR'
]);

// Initialize payment with specific gateway
$payment = MoneyPort::initialize([
    'amount' => 100000,
    'description' => 'Payment for order #123',
    'callback_url' => 'https://yoursite.com/payment/callback',
    'currency' => 'IRR'
], 'mellat'); // This will set Mellat as current gateway for subsequent operations

// Verify payment (will use the current gateway set in initialize, or default if none specified)
$verification = MoneyPort::verify([
    'token' => 'payment_token_from_callback',
    'amount' => 100000,
    'transaction_id' => 'order_123'
]);

// Or specify a different gateway for verification
$verification = MoneyPort::verify([
    'token' => 'payment_token_from_callback',
    'amount' => 100000,
    'transaction_id' => 'order_123'
], 'mellat');

// Get available gateways
$gateways = MoneyPort::getAvailableGateways();
```

### Using the Service Class

[](#using-the-service-class)

```
use Fereydooni\MoneyPort\Services\PaymentManager;

class PaymentController extends Controller
{
    public function __construct(
        private PaymentManager $paymentManager
    ) {}

    public function processPayment(Request $request)
    {
        $payment = $this->paymentManager->initialize([
            'amount' => $request->amount,
            'description' => $request->description,
            'callback_url' => route('payment.callback'),
            'currency' => 'IRR'
        ], 'zarinpal');

        return redirect($payment['payment_url']);
    }

    public function verifyPayment(Request $request)
    {
        $verification = $this->paymentManager->verify([
            'token' => $request->token,
            'amount' => $request->amount,
            'transaction_id' => $request->transaction_id
        ], 'zarinpal');

        if ($verification['success']) {
            // Payment successful
            return response()->json(['message' => 'Payment verified']);
        }

        return response()->json(['error' => 'Payment verification failed'], 400);
    }
}
```

🔧 Adding New Gateways
---------------------

[](#-adding-new-gateways)

To add a new payment gateway:

1. **Create a new gateway class:**

```
